Skip to content

Commit e38b583

Browse files
Java: PrintAst: Add tests
1 parent b73e7d8 commit e38b583

40 files changed

+1270
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Print AST
3+
* @description Outputs a representation of the Abstract Syntax Tree.
4+
* @id csharp/print-ast
5+
* @kind graph
6+
*/
7+
8+
import java
9+
import PrintAst
10+
11+
/**
12+
* Temporarily tweak this class or make a copy to control which functions are
13+
* printed.
14+
*/
15+
class PrintAstConfigurationOverride extends PrintAstConfiguration {
16+
/**
17+
* TWEAK THIS PREDICATE AS NEEDED.
18+
*/
19+
override predicate shouldPrint(Element e, Location l) { super.shouldPrint(e, l) }
20+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
jdk/A.java:
2+
# 0| [CompilationUnit] A
3+
# 3| 1: [Class] A
4+
# 4| 2: [Method] main
5+
# 4| 3: [TypeAccess] void
6+
# 4| 4: (Parameters)
7+
# 4| 0: [Parameter] args
8+
# 4| 0: [ArrayTypeAccess] ...[]
9+
# 4| 0: [TypeAccess] String
10+
# 4| 5: [BlockStmt] stmt
11+
# 7| 2: [Class] B
12+
# 8| 2: [Method] main
13+
# 8| 3: [TypeAccess] void
14+
# 8| 4: (Parameters)
15+
# 8| 0: [Parameter] args
16+
# 8| 0: [ArrayTypeAccess] ...[]
17+
# 8| 0: [TypeAccess] String
18+
# 8| 5: [BlockStmt] stmt
19+
# 11| 3: [Class] C
20+
# 12| 2: [Method] main
21+
# 12| 3: [TypeAccess] void
22+
# 12| 4: (Parameters)
23+
# 12| 0: [Parameter] args
24+
# 12| 0: [ArrayTypeAccess] ...[]
25+
# 12| 0: [TypeAccess] String
26+
# 12| 5: [BlockStmt] stmt
27+
# 15| 4: [Class] D
28+
# 16| 2: [Method] main
29+
# 16| 3: [TypeAccess] int
30+
# 16| 4: (Parameters)
31+
# 16| 0: [Parameter] args
32+
# 16| 0: [ArrayTypeAccess] ...[]
33+
# 16| 0: [TypeAccess] String
34+
# 16| 5: [BlockStmt] stmt
35+
# 16| 0: [ReturnStmt] stmt
36+
# 16| 0: [IntegerLiteral] 0
37+
# 19| 5: [Class] E
38+
# 20| 2: [Method] main
39+
# 20| 3: [TypeAccess] void
40+
# 20| 4: (Parameters)
41+
# 20| 0: [Parameter] argc
42+
# 20| 0: [TypeAccess] int
43+
# 20| 1: [Parameter] args
44+
# 20| 0: [ArrayTypeAccess] ...[]
45+
# 20| 0: [TypeAccess] String
46+
# 20| 5: [BlockStmt] stmt
47+
# 23| 6: [Class] F
48+
# 24| 2: [Method] main
49+
# 24| 3: [TypeAccess] void
50+
# 24| 4: (Parameters)
51+
# 24| 0: [Parameter] arg
52+
# 24| 0: [TypeAccess] String
53+
# 24| 5: [BlockStmt] stmt
54+
# 27| 7: [Class] G
55+
# 28| 2: [Method] main
56+
# 28| 3: [TypeAccess] void
57+
# 28| 4: (Parameters)
58+
# 28| 0: [Parameter] args
59+
# 28| 0: [ArrayTypeAccess] ...[]
60+
# 28| 0: [ArrayTypeAccess] ...[]
61+
# 28| 0: [TypeAccess] String
62+
# 28| 5: [BlockStmt] stmt
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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
arrays/A.java:
2+
# 0| [CompilationUnit] A
3+
# 3| 1: [Class] A
4+
# 4| 2: [FieldDeclaration] ...[] a, ...;
5+
# 4| -1: [ArrayTypeAccess] ...[]
6+
# 4| 0: [TypeAccess] String
7+
# 5| 3: [FieldDeclaration] ...[] b, ...;
8+
# 5| -1: [ArrayTypeAccess] ...[]
9+
# 5| 0: [ArrayTypeAccess] ...[]
10+
# 5| 0: [TypeAccess] String
11+
arrays/B.java:
12+
# 0| [CompilationUnit] B
13+
# 3| 1: [Class] B
14+
# 4| 2: [Method] m
15+
# 4| 3: [TypeAccess] void
16+
# 4| 4: (Parameters)
17+
# 4| 0: [Parameter] a
18+
# 4| 0: [TypeAccess] A
19+
# 4| 5: [BlockStmt] stmt
20+
# 5| 0: [LocalVariableDeclStmt] stmt
21+
# 5| 0: [ArrayTypeAccess] ...[]
22+
# 5| 0: [TypeAccess] A
23+
# 5| 1: [LocalVariableDeclExpr] aa
24+
# 5| 0: [ArrayCreationExpr] new A[]
25+
# 5| -2: [ArrayInit] {...}
26+
# 5| 0: [VarAccess] a
27+
# 5| -1: [TypeAccess] A
28+
# 6| 1: [LocalVariableDeclStmt] stmt
29+
# 6| 0: [ArrayTypeAccess] ...[]
30+
# 6| 0: [ArrayTypeAccess] ...[]
31+
# 6| 0: [TypeAccess] A
32+
# 6| 1: [LocalVariableDeclExpr] aaa
33+
# 6| 0: [ArrayCreationExpr] new A[][]
34+
# 6| -2: [ArrayInit] {...}
35+
# 6| 0: [ArrayInit] {...}
36+
# 6| 0: [VarAccess] a
37+
# 6| -1: [ArrayTypeAccess] ...[]
38+
# 6| 0: [TypeAccess] A
39+
# 7| 2: [LocalVariableDeclStmt] stmt
40+
# 7| 0: [ArrayTypeAccess] ...[]
41+
# 7| 0: [ArrayTypeAccess] ...[]
42+
# 7| 0: [ArrayTypeAccess] ...[]
43+
# 7| 0: [TypeAccess] A
44+
# 7| 1: [LocalVariableDeclExpr] aaaa
45+
# 7| 0: [ArrayCreationExpr] new A[][][]
46+
# 7| -2: [ArrayInit] {...}
47+
# 7| 0: [ArrayInit] {...}
48+
# 7| 0: [ArrayInit] {...}
49+
# 7| 0: [VarAccess] a
50+
# 7| -1: [ArrayTypeAccess] ...[]
51+
# 7| 0: [ArrayTypeAccess] ...[]
52+
# 7| 0: [TypeAccess] A
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
collections/Test.java:
2+
# 0| [CompilationUnit] Test
3+
# 3| 1: [ImportOnDemandFromPackage] import java.util.*
4+
# 5| 2: [Class] Test
5+
# 6| 3: [FieldDeclaration] Map<String,Integer> m, ...;
6+
# 6| -1: [TypeAccess] Map<String,Integer>
7+
# 6| 0: [TypeAccess] String
8+
# 6| 1: [TypeAccess] Integer
9+
# 6| 0: [ClassInstanceExpr] new LinkedHashMap<String,Integer>(...)
10+
# 6| -3: [TypeAccess] LinkedHashMap<String,Integer>
11+
# 6| 0: [TypeAccess] String
12+
# 6| 1: [TypeAccess] Integer
13+
# 8| 4: [BlockStmt] stmt
14+
# 9| 0: [ExprStmt] stmt
15+
# 9| 0: [MethodAccess] put(...)
16+
# 9| -1: [VarAccess] m
17+
# 9| 0: [StringLiteral] "key"
18+
# 9| 1: [IntegerLiteral] 23
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Test.java:
2+
# 0| [CompilationUnit] Test
3+
# 5| 1: [Class] Test
4+
# 1| -4: [Javadoc] /** A JavaDoc comment ... */
5+
# 2| 0: [JavadocText] A JavaDoc comment
6+
# 3| 1: [JavadocText] with multiple lines.
7+
# 7| 2: [Method] m
8+
# 6| 0: [Javadoc] /** A JavaDoc comment with a single line. */
9+
# 6| 0: [JavadocText] A JavaDoc comment with a single line.
10+
# 7| 3: [TypeAccess] void
11+
# 7| 5: [BlockStmt] stmt
12+
# 21| 3: [Method] test
13+
# 21| 3: [TypeAccess] void
14+
# 21| 5: [BlockStmt] stmt
15+
TestWindows.java:
16+
# 0| [CompilationUnit] TestWindows
17+
# 5| 1: [Class] TestWindows
18+
# 1| -4: [Javadoc] /** A JavaDoc comment ... */
19+
# 2| 0: [JavadocText] A JavaDoc comment
20+
# 3| 1: [JavadocText] with multiple lines.
21+
# 7| 2: [Method] m
22+
# 6| 0: [Javadoc] /** A JavaDoc comment with a single line. */
23+
# 6| 0: [JavadocText] A JavaDoc comment with a single line.
24+
# 7| 3: [TypeAccess] void
25+
# 7| 5: [BlockStmt] stmt
26+
# 21| 3: [Method] test
27+
# 21| 3: [TypeAccess] void
28+
# 21| 5: [BlockStmt] stmt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/java/PrintAst.ql

0 commit comments

Comments
 (0)