Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5ae43a

Browse files
tamasvajksmowton
authored andcommitted
Remove empty annotations node from PrintAST
1 parent 3b09cb2 commit b5ae43a

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

java/ql/lib/semmle/code/java/PrintAst.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ private newtype TPrintAstNode =
120120
shouldPrint(lvde, _) and lvde.getParent() instanceof SingleLocalVarDeclParent
121121
} or
122122
TAnnotationsNode(Annotatable ann) {
123-
shouldPrint(ann, _) and ann.hasDeclaredAnnotation() and not partOfAnnotation(ann)
123+
shouldPrint(ann, _) and
124+
ann.hasDeclaredAnnotation() and
125+
not partOfAnnotation(ann) and
126+
// The Kotlin compiler might add annotations that are only present in byte code, although the annotatable element is
127+
// present in source code.
128+
exists(Annotation a | a.getAnnotatedElement() = ann and shouldPrint(a, _))
124129
} or
125130
TParametersNode(Callable c) { shouldPrint(c, _) and not c.hasNoParameters() } or
126131
TBaseTypesNode(ClassOrInterface ty) { shouldPrint(ty, _) } or

java/ql/test/kotlin/library-tests/annotation_classes/PrintAst.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ def.kt:
1111
# 14| 0: [MethodAccess] abc(...)
1212
# 14| -1: [VarAccess] a
1313
# 1| 2: [Interface] SomeAnnotation
14-
#-----| -3: (Annotations)
1514
# 1| 1: [Method] abc
16-
#-----| 1: (Annotations)
1715
# 1| 2: [Method] y
1816
# 3| 3: [Interface] ReplaceWith
19-
#-----| -3: (Annotations)
2017
# 3| 1: [Method] expression
2118
# 5| 4: [Interface] Deprecated
22-
#-----| -3: (Annotations)
2319
# 6| 1: [Method] message
2420
# 7| 2: [Method] replaceWith
2521
# 9| 5: [Class] X

0 commit comments

Comments
 (0)