Skip to content

Commit ba9eb8c

Browse files
committed
Fix stub generator
Add line break after all stubbed annotations to avoid malformed code See https://github.com/github/codeql/pull/8695\#discussion_r985674245
1 parent d52d3d7 commit ba9eb8c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

java/ql/src/utils/stub-generator/Stubs.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ abstract private class GeneratedType extends ClassOrInterface {
3636
}
3737

3838
private string stubAnnotations() {
39-
result =
40-
concat(Annotation an |
41-
this.(AnnotationType).getAnAnnotation() = an
42-
|
43-
stubAnnotation(an), "\n" order by an.getType().getQualifiedName()
44-
)
39+
if exists(this.(AnnotationType).getAnAnnotation())
40+
then
41+
result =
42+
concat(Annotation an |
43+
this.(AnnotationType).getAnAnnotation() = an
44+
|
45+
stubAnnotation(an), "\n" order by an.getType().getQualifiedName()
46+
) + "\n"
47+
else result = ""
4548
}
4649

4750
/** Gets the entire Java stub code for this type. */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
noGeneratedStubs
22
multipleGeneratedStubs
33
#select
4-
| 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 |
4+
| 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 |
55
| 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 |

0 commit comments

Comments
 (0)