@@ -6,65 +6,69 @@ Element nthChildOf(Element e, int i) {
66}
77
88predicate duplicateChildren ( Element e , int i ) {
9- nthChildOf ( e , i ) != nthChildOf ( e , i )
9+ nthChildOf ( e , i ) != nthChildOf ( e , i ) and
1010 // Java #165
11- and not e instanceof Method
11+ not e instanceof Method and
1212 // Java #165
13- and not e instanceof Constructor
13+ not e instanceof Constructor
1414}
1515
1616predicate gapInChildren ( Element e , int i ) {
1717 exists ( int left , int right |
18- left = min ( int l | exists ( nthChildOf ( e , l ) ) ) and
19- right = max ( int r | exists ( nthChildOf ( e , r ) ) ) and
20- i in [ left .. right ] and
21- not exists ( nthChildOf ( e , i ) ) )
18+ left = min ( int l | exists ( nthChildOf ( e , l ) ) ) and
19+ right = max ( int r | exists ( nthChildOf ( e , r ) ) ) and
20+ i in [ left .. right ] and
21+ not exists ( nthChildOf ( e , i ) )
22+ ) and
2223 // Annotations are child 0 upwards, 'implements' are -2 downwards,
2324 // and there may or may not be an 'extends' for child -1.
24- and not ( e instanceof ClassOrInterface and i = - 1 )
25+ not ( e instanceof ClassOrInterface and i = - 1 ) and
2526 // A class instance creation expression has the type as child -3,
2627 // may or may not have a qualifier as child -2, and will never have
2728 // a child -1.
28- and not ( e instanceof ClassInstanceExpr and i = [ - 2 , - 1 ] )
29+ not ( e instanceof ClassInstanceExpr and i = [ - 2 , - 1 ] ) and
2930 // Type access have annotations from -2 down, and type
3031 // arguments from 0 up, but may or may not have a qualifier
3132 // at -1.
32- and not ( e instanceof TypeAccess and i = - 1 )
33+ not ( e instanceof TypeAccess and i = - 1 ) and
3334 // Try statements have their 'finally' clause as child 2,
3435 // and that may or may not exist.
35- and not ( e instanceof TryStmt and i = - 2 )
36+ not ( e instanceof TryStmt and i = - 2 ) and
3637 // For statements may or may not declare a new variable (child 0), or
3738 // have a condition (child 1).
38- and not ( e instanceof ForStmt and i = [ 0 , 1 ] )
39+ not ( e instanceof ForStmt and i = [ 0 , 1 ] ) and
3940 // TODO: Clarify situation with Kotlin and MethodAccess.
4041 // -1 can be skipped (type arguments from -2 down, no qualifier at -1,
4142 // then arguments from 0).
4243 // Can we also skip arguments, e.g. due to defaults for parameters?
43- and not ( e instanceof MethodAccess and e .getFile ( ) .isKotlinSourceFile ( ) )
44+ not ( e instanceof MethodAccess and e .getFile ( ) .isKotlinSourceFile ( ) )
4445}
4546
4647predicate lateFirstChild ( Element e , int i ) {
47- i > 0
48- and exists ( nthChildOf ( e , i ) )
49- and forex ( int j | exists ( nthChildOf ( e , j ) ) | j >= i )
48+ i > 0 and
49+ exists ( nthChildOf ( e , i ) ) and
50+ forex ( int j | exists ( nthChildOf ( e , j ) ) | j >= i ) and
5051 // A wildcard type access can be `?` with no children,
5152 // `? extends T` with only a child 0, or `? super T`
5253 // with only a child 1.
53- and not ( e instanceof WildcardTypeAccess and i = 1 )
54+ not ( e instanceof WildcardTypeAccess and i = 1 ) and
5455 // For a normal local variable decl, child 0 is the type.
5556 // However, for a Java 10 `var x = ...` declaration, there is
5657 // no type, so the first child is the variable as child 1.
5758 // There can only be one variable declared in these declarations,
5859 // so there will never be a child 2.
59- and not ( e instanceof LocalVariableDeclStmt and i = 1 and not exists ( nthChildOf ( e , 2 ) ) )
60+ not ( e instanceof LocalVariableDeclStmt and i = 1 and not exists ( nthChildOf ( e , 2 ) ) ) and
6061 // For statements may or may not declare a new variable (child 0), or
6162 // have a condition (child 1).
62- and not ( e instanceof ForStmt and i = [ 1 , 2 ] )
63+ not ( e instanceof ForStmt and i = [ 1 , 2 ] )
6364}
6465
6566from Element e , int i , string problem
66- where problem = "duplicate" and duplicateChildren ( e , i )
67- or problem = "gap" and gapInChildren ( e , i )
68- or problem = "late" and lateFirstChild ( e , i )
67+ where
68+ problem = "duplicate" and duplicateChildren ( e , i )
69+ or
70+ problem = "gap" and gapInChildren ( e , i )
71+ or
72+ problem = "late" and lateFirstChild ( e , i )
6973select e , e .getPrimaryQlClasses ( ) , i , problem ,
70- concat ( int j | exists ( nthChildOf ( e , j ) ) | j .toString ( ) , ", " order by j )
74+ concat ( int j | exists ( nthChildOf ( e , j ) ) | j .toString ( ) , ", " order by j )
0 commit comments