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

Skip to content

Commit ab93d16

Browse files
committed
Java/Kotlin: Tweak consistency queries
1 parent fa5c3f9 commit ab93d16

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

java/ql/consistency-queries/children.ql

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Element nthChildOf(Element e, int i) {
77

88
predicate 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)
5261
select 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)

java/ql/consistency-queries/getAPrimaryQlClass.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import java
22

33
from Top t
44
where t.getAPrimaryQlClass() = "???"
5-
// TypeBound doesn't extend Top (but probably should)
5+
// TypeBound doesn't extend Top (but probably should); part of Kotlin #6
66
and not t instanceof TypeBound
7-
// XMLLocatable doesn't extend Top (but probably should)
7+
// XMLLocatable doesn't extend Top (but probably should); part of Kotlin #6
88
and not t instanceof XMLLocatable
99
select t,
1010
concat(t.getAPrimaryQlClass(), ",")

java/ql/consistency-queries/toString.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import java
33
string topToString(Top t) {
44
result = t.toString()
55
or
6-
// TypeBound doesn't extend Top (but probably should)
6+
// TypeBound doesn't extend Top (but probably should); part of Kotlin #6
77
result = t.(TypeBound).toString()
88
or
9-
// XMLLocatable doesn't extend Top (but probably should)
9+
// XMLLocatable doesn't extend Top (but probably should); part of Kotlin #6
1010
result = t.(XMLLocatable).toString()
1111
or
1212
// Java #142

0 commit comments

Comments
 (0)