|
| 1 | +import java |
| 2 | + |
| 3 | +Element enclosingStmtOrOther(ExprParent ep) { |
| 4 | + result = ep.(Stmt) or |
| 5 | + result = enclosingStmtOrOther(ep.(Expr).getParent()) or |
| 6 | + result = enclosingStmtOrOther(ep.(WhenBranch).getWhenExpr()) or |
| 7 | + result = ep.(Callable) or |
| 8 | + result = enclosingStmtOrOther(ep.(Field).getDeclaration()) or |
| 9 | + result = ep.(FieldDeclaration) or |
| 10 | + result = ep.(Class) or |
| 11 | + result = ep.(Interface) or |
| 12 | + result = ep.(Parameter) or |
| 13 | + result = enclosingStmtOrOther(ep.(LocalVariableDecl).getDeclExpr()) or |
| 14 | + result = ep.(TypeVariable) |
| 15 | +} |
| 16 | + |
| 17 | +predicate multipleSpecified(Expr e) { |
| 18 | + e.getEnclosingStmt() != e.getEnclosingStmt() |
| 19 | +} |
| 20 | + |
| 21 | +predicate multipleInferred(Expr e) { |
| 22 | + enclosingStmtOrOther(e) != enclosingStmtOrOther(e) |
| 23 | +} |
| 24 | + |
| 25 | +predicate noneInferred(Expr e) { |
| 26 | + not exists(enclosingStmtOrOther(e)) |
| 27 | +} |
| 28 | + |
| 29 | +predicate difference(Expr e) { |
| 30 | + e.getEnclosingStmt() != enclosingStmtOrOther(e) |
| 31 | + // bug in Java?: |
| 32 | + and not enclosingStmtOrOther(e) instanceof LocalVariableDeclStmt |
| 33 | +} |
| 34 | + |
| 35 | +predicate notSpecified(Expr e) { |
| 36 | + enclosingStmtOrOther(e) instanceof Stmt and not exists(e.getEnclosingStmt()) |
| 37 | + // bug in Java? |
| 38 | + and not e instanceof Annotation and e.getFile().getExtension() = "java" |
| 39 | + // bug in Kotlin? |
| 40 | + and not e instanceof TypeAccess and e.getFile().getExtension() = "kt" |
| 41 | +} |
| 42 | + |
| 43 | +predicate problem(Expr e, string s) { |
| 44 | + multipleSpecified(e) and s = "multiple specified" or |
| 45 | + multipleInferred(e) and s = "multiple inferred" or |
| 46 | + noneInferred(e) and s = "none inferred" or |
| 47 | + difference(e) and s = "difference" or |
| 48 | + notSpecified(e) and s = "not specified" |
| 49 | +} |
| 50 | + |
| 51 | +from Expr e, string s |
| 52 | +where problem(e, s) |
| 53 | + and // bug in external deps? |
| 54 | + e.getCompilationUnit().fromSource() |
| 55 | +select e, s, e.getPrimaryQlClasses() |
| 56 | + |
0 commit comments