Class ResolverTest

java.lang.Object
org.checkerframework.javacutil.ResolverTest

public class ResolverTest extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The statement of a case rule is the only statement of the rule, so it does not share the environment of another statement.
    void
    A this(...) call ends a constructor prologue, so it is not part of the run of expression statements after it.
    void
    A variable declared in an earlier case of an old-style switch is in scope in the later cases.
    void
    The explicit and implicit parameters of a lambda and the local variables of its body are found in the source.
    void
    In a local class, a field hides a local variable of the same name around the class.
    void
    A variable declared in an earlier sibling block or later in the same block is not in scope.
    void
    A pattern variable is in scope where the pattern matched, and javac finds it; it is not in scope after the if, and javac decides that too.
    void
    The expression statements of a run of expression statements share the environment of the first, but a declaration ends the run: x is not in scope before its declaration, even after the scope at u++ has been computed, and it is in scope after the declaration.
    void
    The expression statements of a run of expression statements in a case share the environment of the first, and a declaration ends the run.
    void
    Parses and attributes SOURCE.
    void
    The variables of a for, an enhanced for, a try-with-resources, and a catch are in scope in their bodies, and the lookup returns the symbols of their declarations.
    void
    At a tree in a method of an anonymous class, the scope includes the variables of the method and of the enclosing method.
    void
    At a tree in the body of a lambda, the scope includes the lambda's variables.
    void
    At a tree in the compilation unit, the scope is that of the tree.
    void
    At a path that the CFG builder makes for a statement in a switch, without the case, the scope is that of the statement, which includes the variables declared in the case.
    void
    A try-with-resources variable is in scope in the try block, where the source lookup finds it, and not in the catch block, where javac decides.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ResolverTest

      public ResolverTest()
  • Method Details

    • setUp

      public void setUp() throws IOException
      Parses and attributes SOURCE.
      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 includes b, 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: x is not in scope before its declaration, even after the scope at u++ has been computed, and it is in scope after the declaration.
    • constructorCallEndsRun

      public void constructorCallEndsRun()
      A this(...) 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 a for, an enhanced for, a try-with-resources, and a catch are 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 a switch, without the case, the scope is that of the statement, which includes the variables declared in the case.
    • 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 earlier case of an old-style switch is in scope in the later cases. The source lookup does not search the earlier cases, so javac finds it.
    • tryWithResources

      public void tryWithResources()
      A try-with-resources variable is in scope in the try block, where the source lookup finds it, and not in the catch block, 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

      public void patternVariable() throws IOException
      A pattern variable is in scope where the pattern matched, and javac finds it; it is not in scope after the if, 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 a case share the environment of the first, and a declaration ends the run.
    • caseRule

      public void caseRule() throws IOException
      The statement of a case rule 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