mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Java: Add compact source file tests
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
| Test.java:0:0:0:0 | Test | Test.java:1:1:1:1 | Test | Compact source file 'Test' contains implicit class 'Test' |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import java
|
||||||
|
|
||||||
|
from CompilationUnit cu, Class c
|
||||||
|
where
|
||||||
|
cu.isCompactSourceFile() and
|
||||||
|
c.getCompilationUnit() = cu and
|
||||||
|
c.isImplicit()
|
||||||
|
select cu, c,
|
||||||
|
"Compact source file '" + cu.getName() + "' contains implicit class '" + c.getName() + "'"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
| Test.java:0:0:0:0 | Test |
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import java
|
||||||
|
|
||||||
|
from CompilationUnit cu
|
||||||
|
where cu.isCompactSourceFile()
|
||||||
|
select cu
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
| Test.java:1:1:1:1 | Test | implicit |
|
||||||
|
| Test.java:25:7:25:16 | NotCompact | not implicit |
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import java
|
||||||
|
|
||||||
|
from Class c, string res
|
||||||
|
where
|
||||||
|
exists(c.getCompilationUnit().getRelativePath()) and
|
||||||
|
if c.isImplicit() then res = "implicit" else res = "not implicit"
|
||||||
|
select c, res
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
Test.java:
|
||||||
|
# 0| [CompilationUnit] Test
|
||||||
|
# 1| 1: [Class] Test
|
||||||
|
# 1| 4: [FieldDeclaration] int instanceField;
|
||||||
|
# 1| -1: [TypeAccess] int
|
||||||
|
# 1| 0: [IntegerLiteral] 10
|
||||||
|
# 2| 5: [FieldDeclaration] int STATIC_CONSTANT;
|
||||||
|
# 2| -1: [TypeAccess] int
|
||||||
|
# 2| 0: [IntegerLiteral] 42
|
||||||
|
# 3| 6: [FieldDeclaration] String privateField;
|
||||||
|
# 3| -1: [TypeAccess] String
|
||||||
|
# 3| 0: [StringLiteral] "data"
|
||||||
|
# 5| 7: [Method] main
|
||||||
|
# 5| 3: [TypeAccess] void
|
||||||
|
# 5| 5: [BlockStmt] { ... }
|
||||||
|
# 6| 0: [ExprStmt] <Expr>;
|
||||||
|
# 6| 0: [MethodCall] processData(...)
|
||||||
|
# 7| 1: [ExprStmt] <Expr>;
|
||||||
|
# 7| 0: [MethodCall] testStaticAccess(...)
|
||||||
|
# 11| 8: [Method] processData
|
||||||
|
# 11| 3: [TypeAccess] void
|
||||||
|
# 11| 5: [BlockStmt] { ... }
|
||||||
|
# 12| 0: [ExprStmt] <Expr>;
|
||||||
|
# 12| 0: [PostIncExpr] ...++
|
||||||
|
# 12| 0: [VarAccess] instanceField
|
||||||
|
# 13| 1: [ExprStmt] <Expr>;
|
||||||
|
# 13| 0: [MethodCall] updatePrivateField(...)
|
||||||
|
# 16| 9: [Method] updatePrivateField
|
||||||
|
# 16| 3: [TypeAccess] void
|
||||||
|
# 16| 5: [BlockStmt] { ... }
|
||||||
|
# 17| 0: [ExprStmt] <Expr>;
|
||||||
|
# 17| 0: [AssignExpr] ...=...
|
||||||
|
# 17| 0: [VarAccess] privateField
|
||||||
|
# 17| 1: [StringLiteral] "updated"
|
||||||
|
# 21| 10: [Method] testStaticAccess
|
||||||
|
# 21| 3: [TypeAccess] void
|
||||||
|
# 21| 5: [BlockStmt] { ... }
|
||||||
|
# 22| 0: [ExprStmt] <Expr>;
|
||||||
|
# 22| 0: [MethodCall] println(...)
|
||||||
|
# 22| -1: [TypeAccess] IO
|
||||||
|
# 22| 0: [StringLiteral] "Static access test"
|
||||||
|
# 25| 11: [Class] NotCompact
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
semmle/code/java/PrintAst.ql
|
||||||
27
java/ql/test/library-tests/compact-source-files/Test.java
Normal file
27
java/ql/test/library-tests/compact-source-files/Test.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
int instanceField = 10;
|
||||||
|
static final int STATIC_CONSTANT = 42;
|
||||||
|
private String privateField = "data";
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
processData();
|
||||||
|
testStaticAccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test instance methods
|
||||||
|
void processData() {
|
||||||
|
instanceField++;
|
||||||
|
updatePrivateField();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePrivateField() {
|
||||||
|
privateField = "updated";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test static method access
|
||||||
|
static void testStaticAccess() {
|
||||||
|
IO.println("Static access test");
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotCompact {
|
||||||
|
//Test explict class
|
||||||
|
}
|
||||||
1
java/ql/test/library-tests/compact-source-files/options
Normal file
1
java/ql/test/library-tests/compact-source-files/options
Normal file
@@ -0,0 +1 @@
|
|||||||
|
//semmle-extractor-options: --javac-args --release 25 --enable-preview
|
||||||
Reference in New Issue
Block a user