Package org.checkerframework.javacutil
Class ResolverTest
java.lang.Object
org.checkerframework.javacutil.ResolverTest
Unit tests for how
Resolver finds local variables at a path to a tree of the compilation
unit. A path that ends with an artificial tree, which is not in the compilation unit, must not be
passed to Resolver; StringToJavaExpression#atPath resolves it in the scope of the
tree it was created for.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcaseRule()The statement of acaserule is the only statement of the rule, so it does not share the environment of another statement.voidAthis(...)call ends a constructor prologue, so it is not part of the run of expression statements after it.voidA variable declared in an earliercaseof an old-styleswitchis in scope in the later cases.voidThe explicit and implicit parameters of a lambda and the local variables of its body are found in the source.voidIn a local class, a field hides a local variable of the same name around the class.voidA variable declared in an earlier sibling block or later in the same block is not in scope.voidA pattern variable is in scope where the pattern matched, and javac finds it; it is not in scope after theif, and javac decides that too.voidThe expression statements of a run of expression statements share the environment of the first, but a declaration ends the run:xis not in scope before its declaration, even after the scope atu++has been computed, and it is in scope after the declaration.voidThe expression statements of a run of expression statements in acaseshare the environment of the first, and a declaration ends the run.voidsetUp()Parses and attributesSOURCE.voidThe variables of afor, an enhancedfor, atry-with-resources, and acatchare in scope in their bodies, and the lookup returns the symbols of their declarations.voidAt a tree in a method of an anonymous class, the scope includes the variables of the method and of the enclosing method.voidAt a tree in the body of a lambda, the scope includes the lambda's variables.voidAt a tree in the compilation unit, the scope is that of the tree.voidAt a path that the CFG builder makes for a statement in aswitch, without thecase, the scope is that of the statement, which includes the variables declared in thecase.voidAtry-with-resources variable is in scope in thetryblock, where the source lookup finds it, and not in thecatchblock, where javac decides.
-
Constructor Details
-
ResolverTest
public ResolverTest()
-
-
Method Details
-
setUp
Parses and attributesSOURCE.- Throws:
IOException- if the source cannot be parsed
-
treeInSource
public void treeInSource()At a tree in the compilation unit, the scope is that of the tree. That includesb, which is declared in the innermost block, so the scope is neither that of the method nor that of the block. -
treeInLambda
public void treeInLambda()At a tree in the body of a lambda, the scope includes the lambda's variables. -
treeInAnonymousClass
public void treeInAnonymousClass()At a tree in a method of an anonymous class, the scope includes the variables of the method and of the enclosing method. -
runOfExpressionStatements
public void runOfExpressionStatements()The expression statements of a run of expression statements share the environment of the first, but a declaration ends the run:xis not in scope before its declaration, even after the scope atu++has been computed, and it is in scope after the declaration. -
constructorCallEndsRun
public void constructorCallEndsRun()Athis(...)call ends a constructor prologue, so it is not part of the run of expression statements after it. -
statementVariables
public void statementVariables()The variables of afor, an enhancedfor, atry-with-resources, and acatchare in scope in their bodies, and the lookup returns the symbols of their declarations. A field of an anonymous class hides a local variable of the same name around the class. -
treeInSwitchWithoutCase
public void treeInSwitchWithoutCase()At a path that the CFG builder makes for a statement in aswitch, without thecase, the scope is that of the statement, which includes the variables declared in thecase. -
notInScopeInSameMethod
public void notInScopeInSameMethod()A variable declared in an earlier sibling block or later in the same block is not in scope. The source lookup does not find it, and since a variable of that name is declared in the method, javac decides. -
earlierCase
public void earlierCase()A variable declared in an earliercaseof an old-styleswitchis in scope in the later cases. The source lookup does not search the earlier cases, so javac finds it. -
tryWithResources
public void tryWithResources()Atry-with-resources variable is in scope in thetryblock, where the source lookup finds it, and not in thecatchblock, where javac decides. -
localClassFieldHidesLocal
public void localClassFieldHidesLocal()In a local class, a field hides a local variable of the same name around the class. The source lookup stops at the class, and javac finds the field, so the result is null rather than the local variable. -
lambdaVariables
public void lambdaVariables()The explicit and implicit parameters of a lambda and the local variables of its body are found in the source. -
patternVariable
A pattern variable is in scope where the pattern matched, and javac finds it; it is not in scope after theif, and javac decides that too.- Throws:
IOException- if the source cannot be parsed
-
runOfExpressionStatementsInCase
public void runOfExpressionStatementsInCase()The expression statements of a run of expression statements in acaseshare the environment of the first, and a declaration ends the run. -
caseRule
The statement of acaserule is the only statement of the rule, so it does not share the environment of another statement.- Throws:
IOException- if the source cannot be parsed
-