@@ -7,9 +7,9 @@ Element nthChildOf(Element e, int i) {
77
88predicate duplicateChildren ( Element e , int i ) {
99 nthChildOf ( e , i ) != nthChildOf ( e , i )
10- // Bug?:
10+ // Java #165
1111 and not e instanceof Method
12- // Bug?:
12+ // Java #165
1313 and not e instanceof Constructor
1414}
1515
@@ -23,10 +23,13 @@ predicate gapInChildren(Element e, int i) {
2323 and not e instanceof Interface
2424 // TODO: Tighten this up:
2525 and not e instanceof ClassInstanceExpr
26- // TODO: Tighten this up:
27- and not e instanceof TypeAccess
28- // TODO: Tighten this up:
29- and not e instanceof TryStmt
26+ // Type access have annotations from -2 down, and type
27+ // arguments from 0 up, but may or may not have a qualifier
28+ // at -1.
29+ and not ( e instanceof TypeAccess and i = - 1 )
30+ // Try statements have their 'finally' clause as child 2,
31+ // and that may or may not exist.
32+ and ( not e instanceof TryStmt and i = - 2 )
3033 // TODO: Tighten this up:
3134 and not e instanceof ForStmt
3235 // Kotlin bug?
@@ -37,10 +40,16 @@ predicate lateFirstChild(Element e, int i) {
3740 i > 0
3841 and exists ( nthChildOf ( e , i ) )
3942 and forex ( int j | exists ( nthChildOf ( e , j ) ) | j >= i )
40- // TODO: Tighten this up:
41- and not e instanceof WildcardTypeAccess
42- // TODO: Tighten this up:
43- and not e instanceof LocalVariableDeclStmt
43+ // A wildcard type access can be `?` with no children,
44+ // `? extends T` with only a child 0, or `? super T`
45+ // with only a child 1.
46+ and not ( e instanceof WildcardTypeAccess and i = 1 )
47+ // For a normal local variable decl, child 0 is the type.
48+ // However, for a Java 10 `var x = ...` declaration, there is
49+ // no type, so the first child is the variable as child 1.
50+ // There can only be one variable declared in these declarations,
51+ // so there will never be a child 2.
52+ and not ( e instanceof LocalVariableDeclStmt and i = 1 and not exists ( nthChildOf ( e , 2 ) ) )
4453 // TODO: Tighten this up:
4554 and not e instanceof ForStmt
4655}
@@ -50,4 +59,4 @@ where problem = "duplicate" and duplicateChildren(e, i)
5059 or problem = "gap" and gapInChildren ( e , i )
5160 or problem = "late" and lateFirstChild ( e , i )
5261select e , e .getPrimaryQlClasses ( ) , i , problem , nthChildOf ( e , i ) ,
53- concat ( int j | exists ( nthChildOf ( e , j ) ) | j .toString ( ) , ", " )
62+ concat ( int j | exists ( nthChildOf ( e , j ) ) | j .toString ( ) , ", " order by j )
0 commit comments