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

Skip to content

Commit b38f47f

Browse files
committed
Java/Kotlin: Tweak consistency queries
1 parent c049127 commit b38f47f

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

java/ql/consistency-queries/children.ql

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@ predicate duplicateChildren(Element e, int i) {
1414
}
1515

1616
predicate gapInChildren(Element e, int i) {
17-
exists(nthChildOf(e, i))
18-
and not exists(nthChildOf(e, i - 1))
19-
and exists(int j | j < i | exists(nthChildOf(e, j)))
17+
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)))
2022
// TODO: Tighten this up:
2123
and not e instanceof Class
2224
// TODO: Tighten this up:
2325
and not e instanceof Interface
24-
// TODO: Tighten this up:
25-
and not e instanceof ClassInstanceExpr
26+
// A class instance creation expression has the type as child -3,
27+
// may or may not have a qualifier as child -2, and will never have
28+
// a child -1.
29+
and not (e instanceof ClassInstanceExpr and i = [-2, -1])
2630
// Type access have annotations from -2 down, and type
2731
// arguments from 0 up, but may or may not have a qualifier
2832
// at -1.
2933
and not (e instanceof TypeAccess and i = -1)
3034
// Try statements have their 'finally' clause as child 2,
3135
// and that may or may not exist.
32-
and (not e instanceof TryStmt and i = -2)
36+
and not (e instanceof TryStmt and i = -2)
3337
// TODO: Tighten this up:
3438
and not e instanceof ForStmt
3539
// Kotlin bug?
@@ -58,5 +62,5 @@ from Element e, int i, string problem
5862
where problem = "duplicate" and duplicateChildren(e, i)
5963
or problem = "gap" and gapInChildren(e, i)
6064
or problem = "late" and lateFirstChild(e, i)
61-
select e, e.getPrimaryQlClasses(), i, problem, nthChildOf(e, i),
65+
select e, e.getPrimaryQlClasses(), i, problem,
6266
concat(int j | exists(nthChildOf(e, j)) | j.toString(), ", " order by j)

0 commit comments

Comments
 (0)