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

Skip to content

Commit 77fec17

Browse files
committed
Kotlin: Autoformat QL
1 parent c5e3aef commit 77fec17

51 files changed

Lines changed: 316 additions & 243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import java
22

33
from BinaryExpr be, string reason
4-
where not exists(be.getLeftOperand()) and reason = "No left operand"
5-
or not exists(be.getRightOperand()) and reason = "No right operand"
6-
or exists(Expr e, int i | e.isNthChildOf(be, i) and i != 0 and i != 1 and reason = "Unexpected operand " + i.toString())
7-
or be.getOp() = " ?? " and reason = "No operator name"
4+
where
5+
not exists(be.getLeftOperand()) and reason = "No left operand"
6+
or
7+
not exists(be.getRightOperand()) and reason = "No right operand"
8+
or
9+
exists(Expr e, int i |
10+
e.isNthChildOf(be, i) and i != 0 and i != 1 and reason = "Unexpected operand " + i.toString()
11+
)
12+
or
13+
be.getOp() = " ?? " and reason = "No operator name"
814
select be, reason
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import java
22

33
from UnaryExpr ue
4-
where not exists(ue.getExpr())
5-
or exists(Expr e, int i | e.isNthChildOf(ue, i) and i != 0)
4+
where
5+
not exists(ue.getExpr())
6+
or
7+
exists(Expr e, int i | e.isNthChildOf(ue, i) and i != 0)
68
select ue

java/ql/consistency-queries/blocks.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ import java
33
from BlockStmt b, Expr e
44
where e.getParent() = b
55
select b, e
6-

java/ql/consistency-queries/cfgDeadEnds.ql

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,63 @@ import java
22
import semmle.code.java.ControlFlowGraph
33

44
predicate shouldBeDeadEnd(ControlFlowNode n) {
5-
n instanceof BreakStmt and n.getFile().isKotlinSourceFile() or // TODO
6-
n instanceof ReturnStmt and n.getFile().isKotlinSourceFile() or // TODO
7-
n instanceof Interface or // TODO
8-
n instanceof Class or // TODO
9-
n instanceof Parameter or // TODO
10-
n instanceof Field or // TODO
11-
n instanceof Annotation or // TODO
12-
n instanceof TypeAccess or // TODO
13-
n instanceof ArrayTypeAccess or // TODO
14-
n instanceof UnionTypeAccess or // TODO
15-
n instanceof IntersectionTypeAccess or // TODO
16-
n instanceof ArrayAccess or // TODO
17-
n instanceof AddExpr or // TODO
18-
n instanceof MinusExpr or // TODO
19-
n instanceof LocalVariableDecl or // TODO
20-
n instanceof FieldDeclaration or // TODO
21-
n instanceof ArrayInit or // TODO
22-
n instanceof VarAccess or // TODO
23-
n instanceof Literal or // TODO
24-
n instanceof TypeLiteral or // TODO
25-
n instanceof TypeVariable or // TODO
26-
n instanceof WildcardTypeAccess or // TODO
27-
n instanceof MethodAccess or // TODO
28-
n instanceof Method or
29-
n instanceof Constructor or
30-
not exists(n.getFile().getRelativePath()) or // TODO
5+
n instanceof BreakStmt and n.getFile().isKotlinSourceFile() // TODO
6+
or
7+
n instanceof ReturnStmt and n.getFile().isKotlinSourceFile() // TODO
8+
or
9+
n instanceof Interface // TODO
10+
or
11+
n instanceof Class // TODO
12+
or
13+
n instanceof Parameter // TODO
14+
or
15+
n instanceof Field // TODO
16+
or
17+
n instanceof Annotation // TODO
18+
or
19+
n instanceof TypeAccess // TODO
20+
or
21+
n instanceof ArrayTypeAccess // TODO
22+
or
23+
n instanceof UnionTypeAccess // TODO
24+
or
25+
n instanceof IntersectionTypeAccess // TODO
26+
or
27+
n instanceof ArrayAccess // TODO
28+
or
29+
n instanceof AddExpr // TODO
30+
or
31+
n instanceof MinusExpr // TODO
32+
or
33+
n instanceof LocalVariableDecl // TODO
34+
or
35+
n instanceof FieldDeclaration // TODO
36+
or
37+
n instanceof ArrayInit // TODO
38+
or
39+
n instanceof VarAccess // TODO
40+
or
41+
n instanceof Literal // TODO
42+
or
43+
n instanceof TypeLiteral // TODO
44+
or
45+
n instanceof TypeVariable // TODO
46+
or
47+
n instanceof WildcardTypeAccess // TODO
48+
or
49+
n instanceof MethodAccess // TODO
50+
or
51+
n instanceof Method
52+
or
53+
n instanceof Constructor
54+
or
55+
not exists(n.getFile().getRelativePath()) // TODO
56+
or
3157
n = any(ConstCase c).getValue(_) // TODO
3258
}
3359

3460
from ControlFlowNode n, string s
35-
where // TODO: exists(n.getASuccessor()) and shouldBeDeadEnd(n) and s = "expected dead end"
36-
not exists(n.getASuccessor()) and not shouldBeDeadEnd(n) and s = "unexpected dead end"
61+
where
62+
// TODO: exists(n.getASuccessor()) and shouldBeDeadEnd(n) and s = "expected dead end"
63+
not exists(n.getASuccessor()) and not shouldBeDeadEnd(n) and s = "unexpected dead end"
3764
select n, n.getPrimaryQlClasses(), s
38-

java/ql/consistency-queries/children.ql

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,69 @@ Element nthChildOf(Element e, int i) {
66
}
77

88
predicate 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

1616
predicate 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

4647
predicate 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

6566
from 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)
6973
select 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)
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import java
22

33
predicate goodCompilation(Compilation c) {
4-
forex(int i |
5-
exists(c.getFileCompiled(i)) |
6-
(exists(c.getFileCompiled(i - 1)) or i = 0)
7-
and c.fileCompiledSuccessful(i)) and
8-
forex(int i |
9-
exists(c.getArgument(i)) |
10-
exists(c.getArgument(i - 1)) or i = 0) and
4+
forex(int i | exists(c.getFileCompiled(i)) |
5+
(exists(c.getFileCompiled(i - 1)) or i = 0) and
6+
c.fileCompiledSuccessful(i)
7+
) and
8+
forex(int i | exists(c.getArgument(i)) | exists(c.getArgument(i - 1)) or i = 0) and
119
c.extractionStarted() and
1210
c.extractionSuccessful()
1311
}
1412

1513
from Compilation c
16-
where c.isKotlin()
17-
and not goodCompilation(c)
14+
where
15+
c.isKotlin() and
16+
not goodCompilation(c)
1817
select c
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import java
22

33
from Expr e, int n
4-
where n = count(e.getType())
5-
and n != 1
4+
where
5+
n = count(e.getType()) and
6+
n != 1 and
67
// Java #144
7-
and not e instanceof ReflectiveAccessAnnotation
8+
not e instanceof ReflectiveAccessAnnotation
89
select e, n
9-

java/ql/consistency-queries/file_classes.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import java
33
// File classes should only be extracted if we need somewhere to
44
// put top-level members.
55
from Class c
6-
where file_class(c)
7-
and not exists(c.getAMember())
6+
where
7+
file_class(c) and
8+
not exists(c.getAMember())
89
select c
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import java
22

33
from Top t
4-
where t.getAPrimaryQlClass() = "???"
4+
where
5+
t.getAPrimaryQlClass() = "???" and
56
// TypeBound doesn't extend Top (but probably should); part of Kotlin #6
6-
and not t instanceof TypeBound
7+
not t instanceof TypeBound and
78
// XMLLocatable doesn't extend Top (but probably should); part of Kotlin #6
8-
and not t instanceof XMLLocatable
9-
select t,
10-
concat(t.getAPrimaryQlClass(), ",")
9+
not t instanceof XMLLocatable
10+
select t, concat(t.getAPrimaryQlClass(), ",")

java/ql/consistency-queries/kotlinTypes.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ predicate badKotlinType(Element e, int i) {
1010
}
1111

1212
from Element e, int i
13-
where // TODO: Java extractor doesn't populate these yet
14-
e.getFile().isKotlinSourceFile()
15-
and badKotlinType(e, i)
16-
and i != 1
13+
where
14+
// TODO: Java extractor doesn't populate these yet
15+
e.getFile().isKotlinSourceFile() and
16+
badKotlinType(e, i) and
17+
i != 1
1718
select e, i
18-

0 commit comments

Comments
 (0)