Skip to content

Commit 8cdf2bc

Browse files
committed
Java: Add compact source file tests
1 parent fcce2ac commit 8cdf2bc

10 files changed

+96
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Test.java:0:0:0:0 | Test | Test.java:1:1:1:1 | Test | Compact source file 'Test' contains implicit class 'Test' |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java
2+
3+
from CompilationUnit cu, Class c
4+
where
5+
cu.isCompactSourceFile() and
6+
c.getCompilationUnit() = cu and
7+
c.isImplicit()
8+
select cu, c,
9+
"Compact source file '" + cu.getName() + "' contains implicit class '" + c.getName() + "'"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Test.java:0:0:0:0 | Test |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from CompilationUnit cu
4+
where cu.isCompactSourceFile()
5+
select cu
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Test.java:1:1:1:1 | Test | implicit |
2+
| Test.java:25:7:25:16 | NotCompact | not implicit |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java
2+
3+
from Class c, string res
4+
where
5+
exists(c.getCompilationUnit().getRelativePath()) and
6+
if c.isImplicit() then res = "implicit" else res = "not implicit"
7+
select c, res
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Test.java:
2+
# 0| [CompilationUnit] Test
3+
# 1| 1: [Class] Test
4+
# 1| 4: [FieldDeclaration] int instanceField;
5+
# 1| -1: [TypeAccess] int
6+
# 1| 0: [IntegerLiteral] 10
7+
# 2| 5: [FieldDeclaration] int STATIC_CONSTANT;
8+
# 2| -1: [TypeAccess] int
9+
# 2| 0: [IntegerLiteral] 42
10+
# 3| 6: [FieldDeclaration] String privateField;
11+
# 3| -1: [TypeAccess] String
12+
# 3| 0: [StringLiteral] "data"
13+
# 5| 7: [Method] main
14+
# 5| 3: [TypeAccess] void
15+
# 5| 5: [BlockStmt] { ... }
16+
# 6| 0: [ExprStmt] <Expr>;
17+
# 6| 0: [MethodCall] processData(...)
18+
# 7| 1: [ExprStmt] <Expr>;
19+
# 7| 0: [MethodCall] testStaticAccess(...)
20+
# 11| 8: [Method] processData
21+
# 11| 3: [TypeAccess] void
22+
# 11| 5: [BlockStmt] { ... }
23+
# 12| 0: [ExprStmt] <Expr>;
24+
# 12| 0: [PostIncExpr] ...++
25+
# 12| 0: [VarAccess] instanceField
26+
# 13| 1: [ExprStmt] <Expr>;
27+
# 13| 0: [MethodCall] updatePrivateField(...)
28+
# 16| 9: [Method] updatePrivateField
29+
# 16| 3: [TypeAccess] void
30+
# 16| 5: [BlockStmt] { ... }
31+
# 17| 0: [ExprStmt] <Expr>;
32+
# 17| 0: [AssignExpr] ...=...
33+
# 17| 0: [VarAccess] privateField
34+
# 17| 1: [StringLiteral] "updated"
35+
# 21| 10: [Method] testStaticAccess
36+
# 21| 3: [TypeAccess] void
37+
# 21| 5: [BlockStmt] { ... }
38+
# 22| 0: [ExprStmt] <Expr>;
39+
# 22| 0: [MethodCall] println(...)
40+
# 22| -1: [TypeAccess] IO
41+
# 22| 0: [StringLiteral] "Static access test"
42+
# 25| 11: [Class] NotCompact
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/java/PrintAst.ql
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
int instanceField = 10;
2+
static final int STATIC_CONSTANT = 42;
3+
private String privateField = "data";
4+
5+
void main() {
6+
processData();
7+
testStaticAccess();
8+
}
9+
10+
// Test instance methods
11+
void processData() {
12+
instanceField++;
13+
updatePrivateField();
14+
}
15+
16+
private void updatePrivateField() {
17+
privateField = "updated";
18+
}
19+
20+
// Test static method access
21+
static void testStaticAccess() {
22+
IO.println("Static access test");
23+
}
24+
25+
class NotCompact {
26+
//Test explict class
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args --release 25 --enable-preview

0 commit comments

Comments
 (0)