Class Resolver

java.lang.Object
org.checkerframework.javacutil.Resolver

public class Resolver extends Object
A utility class to find symbols corresponding to string references (identifiers).
  • Constructor Details

  • Method Details

    • getEnvForPath

      public com.sun.tools.javac.comp.Env<com.sun.tools.javac.comp.AttrContext> getEnvForPath(TreePath path)
      Determine the environment for the given path.
      Parameters:
      path - the tree path to the local scope
      Returns:
      the corresponding attribution environment
    • findPackage

      public @Nullable com.sun.tools.javac.code.Symbol.PackageSymbol findPackage(String name, TreePath path)
      Finds the package with name name.
      Parameters:
      name - the name of the package
      path - the tree path to the local scope
      Returns:
      the PackageSymbol for the package if it is found, null otherwise
    • findField

      public @Nullable VariableElement findField(String name, TypeMirror type, TreePath path)
      Finds the field with name name in type or a superclass or superinterface of type.

      The method adheres to all the rules of Java's scoping (while also considering the imports) for name resolution.

      Parameters:
      name - the name of the field
      type - the type of the receiver (i.e., the type in which to look for the field)
      path - the tree path to the local scope
      Returns:
      the element for the field, null otherwise
    • findLocalVariableOrParameter

      public @Nullable VariableElement findLocalVariableOrParameter(String name, TreePath path)
      Finds the local variable (including formal parameters) with name name in the given scope.
      Parameters:
      name - the name of the local variable
      path - the tree path to the local scope
      Returns:
      the element for the local variable, null otherwise
    • findClass

      public Element findClass(String name, TreePath path)
      Finds the class literal with name name.

      The method adheres to all the rules of Java's scoping (while also considering the imports) for name resolution.

      Parameters:
      name - the name of the class
      path - the tree path to the local scope
      Returns:
      the element for the class
    • findClassInPackage

      public @Nullable com.sun.tools.javac.code.Symbol.ClassSymbol findClassInPackage(String name, com.sun.tools.javac.code.Symbol.PackageSymbol pck, TreePath path)
      Finds the class with name name in a given package.
      Parameters:
      name - the name of the class
      pck - the PackageSymbol for the package
      path - the tree path to the local scope
      Returns:
      the ClassSymbol for the class if it is found, null otherwise
    • findMethod

      public @Nullable ExecutableElement findMethod(String methodName, TypeMirror receiverType, TreePath path, List<TypeMirror> argumentTypes)
      Finds the method element for a given name and list of expected parameter types.

      The method adheres to all the rules of Java's scoping (while also considering the imports) for name resolution.

      (This method takes into account autoboxing.)

      This method is a wrapper around com.sun.tools.javac.comp.Resolve.findMethod.

      Parameters:
      methodName - name of the method to find
      receiverType - type of the receiver of the method
      path - tree path
      argumentTypes - types of arguments passed to the method call
      Returns:
      the method element (if found)
    • buildMethodContext

      Build an instance of Resolve$MethodResolutionContext.
      Returns:
      a MethodResolutionContext
      Throws:
      ClassNotFoundException - if there is trouble constructing the instance
      InstantiationException - if there is trouble constructing the instance
      IllegalAccessException - if there is trouble constructing the instance
      InvocationTargetException - if there is trouble constructing the instance
      NoSuchFieldException - if there is trouble constructing the instance