Class Resolver
-
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. The environment is cached per leaf, and the expression statements of a run of expression statements share one environment (seepathWithSameScope(com.sun.source.util.TreePath)).The leaf of
pathmust be a tree of the compilation unit; for an artificial tree, pass the path of the tree it was created for (seeStringToJavaExpression#atPath).- 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.If the declaration of the variable is found in the source (see
localDeclarationInScope(com.sun.tools.javac.util.Name, com.sun.source.util.TreePath)), the result is the symbol of that declaration. Otherwise, as for a pattern variable, a variable of an earliercaseof an old-styleswitch, or a local variable of an enclosing method used in a local or anonymous class, the result is the symbol from javac's attributed copy of the enclosing code, whichTrees#getScopecreates. The two are different objects, and they differ in flags: the copy can lackEFFECTIVELY_FINAL, so thatElementUtils.isEffectivelyFinal(javax.lang.model.element.Element)is false for it, which makes the Lock Checker reportlock.expression.not.finalfor an effectively final variable (eisop#2375). A caller that compares the result with another symbol by identity, or that tests its flags, must allow for either.LocalVariablecompares variables by name, position, and owner, so both give the sameLocalVariable.- 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 InstantiationException, IllegalAccessException, InvocationTargetExceptionBuild an instance ofResolve$MethodResolutionContext.- Returns:
- a MethodResolutionContext
- Throws:
InstantiationException- if there is trouble constructing the instanceIllegalAccessException- if there is trouble constructing the instanceInvocationTargetException- if there is trouble constructing the instance
-