Java/Kotlin: Tweak consistency queries

This commit is contained in:
Ian Lynagh
2021-12-07 16:17:25 +00:00
parent fa5c3f9159
commit ab93d166b8
3 changed files with 24 additions and 15 deletions

View File

@@ -7,9 +7,9 @@ Element nthChildOf(Element e, int i) {
predicate duplicateChildren(Element e, int i) {
nthChildOf(e, i) != nthChildOf(e, i)
// Bug?:
// Java #165
and not e instanceof Method
// Bug?:
// Java #165
and not e instanceof Constructor
}
@@ -23,10 +23,13 @@ predicate gapInChildren(Element e, int i) {
and not e instanceof Interface
// TODO: Tighten this up:
and not e instanceof ClassInstanceExpr
// TODO: Tighten this up:
and not e instanceof TypeAccess
// TODO: Tighten this up:
and not e instanceof TryStmt
// Type access have annotations from -2 down, and type
// arguments from 0 up, but may or may not have a qualifier
// at -1.
and not (e instanceof TypeAccess and i = -1)
// Try statements have their 'finally' clause as child 2,
// and that may or may not exist.
and (not e instanceof TryStmt and i = -2)
// TODO: Tighten this up:
and not e instanceof ForStmt
// Kotlin bug?
@@ -37,10 +40,16 @@ predicate lateFirstChild(Element e, int i) {
i > 0
and exists(nthChildOf(e, i))
and forex(int j | exists(nthChildOf(e, j)) | j >= i)
// TODO: Tighten this up:
and not e instanceof WildcardTypeAccess
// TODO: Tighten this up:
and not e instanceof LocalVariableDeclStmt
// A wildcard type access can be `?` with no children,
// `? extends T` with only a child 0, or `? super T`
// with only a child 1.
and not (e instanceof WildcardTypeAccess and i = 1)
// For a normal local variable decl, child 0 is the type.
// However, for a Java 10 `var x = ...` declaration, there is
// no type, so the first child is the variable as child 1.
// There can only be one variable declared in these declarations,
// so there will never be a child 2.
and not (e instanceof LocalVariableDeclStmt and i = 1 and not exists(nthChildOf(e, 2)))
// TODO: Tighten this up:
and not e instanceof ForStmt
}
@@ -50,4 +59,4 @@ where problem = "duplicate" and duplicateChildren(e, i)
or problem = "gap" and gapInChildren(e, i)
or problem = "late" and lateFirstChild(e, i)
select e, e.getPrimaryQlClasses(), i, problem, nthChildOf(e, i),
concat(int j | exists(nthChildOf(e, j)) | j.toString(), ", ")
concat(int j | exists(nthChildOf(e, j)) | j.toString(), ", " order by j)

View File

@@ -2,9 +2,9 @@ import java
from Top t
where t.getAPrimaryQlClass() = "???"
// TypeBound doesn't extend Top (but probably should)
// TypeBound doesn't extend Top (but probably should); part of Kotlin #6
and not t instanceof TypeBound
// XMLLocatable doesn't extend Top (but probably should)
// XMLLocatable doesn't extend Top (but probably should); part of Kotlin #6
and not t instanceof XMLLocatable
select t,
concat(t.getAPrimaryQlClass(), ",")

View File

@@ -3,10 +3,10 @@ import java
string topToString(Top t) {
result = t.toString()
or
// TypeBound doesn't extend Top (but probably should)
// TypeBound doesn't extend Top (but probably should); part of Kotlin #6
result = t.(TypeBound).toString()
or
// XMLLocatable doesn't extend Top (but probably should)
// XMLLocatable doesn't extend Top (but probably should); part of Kotlin #6
result = t.(XMLLocatable).toString()
or
// Java #142