Java: Improve PrintAst tests and rename things

Add tests for `EnhcancedForStmt`s and `InstanceOfExpr`s.
Rename LocalVarDeclParent to SingleLocalVarDeclParent
This commit is contained in:
Joe
2020-09-25 11:19:13 +01:00
parent 9c8a468237
commit 5256c0ba39
5 changed files with 74 additions and 22 deletions

View File

@@ -21,7 +21,7 @@ MultiCatch.java:
# 14| 0: [ClassInstanceExpr] new SQLException(...)
# 14| -3: [TypeAccess] SQLException
# 15| 0: [CatchClause] stmt
#-----| 0: (Local Variable Declaration)
#-----| 0: (Single Local Variable Declaration)
# 15| 0: [UnionTypeAccess] ...|...
# 15| 0: [TypeAccess] IOException
# 15| 1: [TypeAccess] SQLException
@@ -56,7 +56,7 @@ MultiCatch.java:
# 30| 0: [ClassInstanceExpr] new Exception(...)
# 30| -3: [TypeAccess] Exception
# 31| 0: [CatchClause] stmt
#-----| 0: (Local Variable Declaration)
#-----| 0: (Single Local Variable Declaration)
# 31| 0: [UnionTypeAccess] ...|...
# 31| 0: [TypeAccess] IOException
# 31| 1: [TypeAccess] SQLException
@@ -71,7 +71,7 @@ MultiCatch.java:
# 39| 0: [ClassInstanceExpr] new IOException(...)
# 39| -3: [TypeAccess] IOException
# 40| 0: [CatchClause] stmt
#-----| 0: (Local Variable Declaration)
#-----| 0: (Single Local Variable Declaration)
# 40| 0: [TypeAccess] Exception
# 40| 1: [LocalVariableDeclExpr] e
# 41| 1: [BlockStmt] stmt

View File

@@ -40,4 +40,20 @@ class A {
@Ann2(7)
})
String doSomethingElse() { return "c"; }
void varDecls(Object[] things) {
try {
for(Object thing : things) {
if (thing instanceof Integer) {
return;
}
if (thing instanceof String s) {
throw new RuntimeException(s);
}
}
}
catch (RuntimeException rte) {
return;
}
}
}

View File

@@ -87,3 +87,41 @@ A.java:
# 42| 5: [BlockStmt] stmt
# 42| 0: [ReturnStmt] stmt
# 42| 0: [StringLiteral] "c"
# 44| 9: [Method] varDecls
# 44| 3: [TypeAccess] void
#-----| 4: (Parameters)
# 44| 0: [Parameter] things
# 44| 0: [ArrayTypeAccess] ...[]
# 44| 0: [TypeAccess] Object
# 44| 5: [BlockStmt] stmt
# 45| 0: [TryStmt] stmt
# 45| -1: [BlockStmt] stmt
# 46| 0: [EnhancedForStmt] stmt
#-----| 0: (Single Local Variable Declaration)
# 46| 0: [TypeAccess] Object
# 46| 1: [LocalVariableDeclExpr] thing
# 46| 1: [VarAccess] things
# 46| 2: [BlockStmt] stmt
# 47| 0: [IfStmt] stmt
# 47| 0: [InstanceOfExpr] ...instanceof...
# 47| 0: [VarAccess] thing
# 47| 1: [TypeAccess] Integer
# 47| 1: [BlockStmt] stmt
# 48| 0: [ReturnStmt] stmt
# 50| 1: [IfStmt] stmt
# 50| 0: [InstanceOfExpr] ...instanceof...
#-----| 0: (Single Local Variable Declaration)
# 50| 0: [TypeAccess] String
# 50| 1: [LocalVariableDeclExpr] s
# 50| 0: [VarAccess] thing
# 50| 1: [BlockStmt] stmt
# 51| 0: [ThrowStmt] stmt
# 51| 0: [ClassInstanceExpr] new RuntimeException(...)
# 51| -3: [TypeAccess] RuntimeException
# 51| 0: [VarAccess] s
# 55| 0: [CatchClause] stmt
#-----| 0: (Single Local Variable Declaration)
# 55| 0: [TypeAccess] RuntimeException
# 55| 1: [LocalVariableDeclExpr] rte
# 55| 1: [BlockStmt] stmt
# 56| 0: [ReturnStmt] stmt

View File

@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args --enable-preview -source 14 -target 14