Package org.checkerframework.javacutil
Class Resolver
java.lang.Object
org.checkerframework.javacutil.Resolver
A utility class to find symbols corresponding to string references (identifiers).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectBuild an instance ofResolve$MethodResolutionContext.Finds the class literal with namename.@Nullable com.sun.tools.javac.code.Symbol.ClassSymbolfindClassInPackage(String name, com.sun.tools.javac.code.Symbol.PackageSymbol pck, TreePath path) Finds the class with namenamein a given package.findField(String name, TypeMirror type, TreePath path) Finds the field with namenameintypeor a superclass or superinterface oftype.findLocalVariableOrParameter(String name, TreePath path) Finds the local variable (including formal parameters) with namenamein the given scope.findMethod(String methodName, TypeMirror receiverType, TreePath path, List<TypeMirror> argumentTypes) Finds the method element for a given name and list of expected parameter types.@Nullable com.sun.tools.javac.code.Symbol.PackageSymbolfindPackage(String name, TreePath path) Finds the package with namename.com.sun.tools.javac.comp.Env<com.sun.tools.javac.comp.AttrContext> getEnvForPath(TreePath path) Determine the environment for the given path.
-
Constructor Details
-
Resolver
-
-
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 namename.- Parameters:
name- the name of the packagepath- the tree path to the local scope- Returns:
- the
PackageSymbolfor the package if it is found,nullotherwise
-
findField
Finds the field with namenameintypeor a superclass or superinterface oftype.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 fieldtype- 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,
nullotherwise
-
findLocalVariableOrParameter
Finds the local variable (including formal parameters) with namenamein the given scope.- Parameters:
name- the name of the local variablepath- the tree path to the local scope- Returns:
- the element for the local variable,
nullotherwise
-
findClass
Finds the class literal with namename.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 classpath- 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 namenamein a given package.- Parameters:
name- the name of the classpck- the PackageSymbol for the packagepath- the tree path to the local scope- Returns:
- the
ClassSymbolfor the class if it is found,nullotherwise
-
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 findreceiverType- type of the receiver of the methodpath- tree pathargumentTypes- types of arguments passed to the method call- Returns:
- the method element (if found)
-
buildMethodContext
protected Object buildMethodContext() throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldExceptionBuild an instance ofResolve$MethodResolutionContext.- Returns:
- a MethodResolutionContext
- Throws:
ClassNotFoundException- if there is trouble constructing the instanceInstantiationException- if there is trouble constructing the instanceIllegalAccessException- if there is trouble constructing the instanceInvocationTargetException- if there is trouble constructing the instanceNoSuchFieldException- if there is trouble constructing the instance
-