Fix stub generator

Add line break after all stubbed annotations to avoid malformed code

See https://github.com/github/codeql/pull/8695\#discussion_r985674245
This commit is contained in:
Tony Torralba
2022-10-03 14:27:07 +02:00
parent d52d3d7b75
commit ba9eb8c73c
2 changed files with 10 additions and 7 deletions

View File

@@ -36,12 +36,15 @@ abstract private class GeneratedType extends ClassOrInterface {
}
private string stubAnnotations() {
result =
concat(Annotation an |
this.(AnnotationType).getAnAnnotation() = an
|
stubAnnotation(an), "\n" order by an.getType().getQualifiedName()
)
if exists(this.(AnnotationType).getAnAnnotation())
then
result =
concat(Annotation an |
this.(AnnotationType).getAnAnnotation() = an
|
stubAnnotation(an), "\n" order by an.getType().getQualifiedName()
) + "\n"
else result = ""
}
/** Gets the entire Java stub code for this type. */

View File

@@ -1,5 +1,5 @@
noGeneratedStubs
multipleGeneratedStubs
#select
| org.test.SampleAnnotationType | // Generated automatically from org.test.SampleAnnotationType for testing purposes\n\npackage org.test;\n\nimport java.lang.annotation.Annotation;\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Target;\n\n@Target(value={java.lang.annotation.ElementType.METHOD})public @interface SampleAnnotationType\n{\n}\n |
| org.test.SampleAnnotationType | // Generated automatically from org.test.SampleAnnotationType for testing purposes\n\npackage org.test;\n\nimport java.lang.annotation.Annotation;\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Target;\n\n@Target(value={java.lang.annotation.ElementType.METHOD})\npublic @interface SampleAnnotationType\n{\n}\n |
| org.test.SampleType | // Generated automatically from org.test.SampleType for testing purposes\n\npackage org.test;\n\n\npublic class SampleType\n{\n public Object sampleField = null;\n public SampleType(){}\n public void sampleMethod(){}\n}\n |