APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.tools.javac.model

public Class JavacElements

extends Object
implements Elements
Class Inheritance
All Implemented Interfaces
javax.lang.model.util.Elements
Imports
java.util.Arrays, .Collections, .HashMap, .HashSet, .LinkedHashSet, .Map, .Optional, .Set, java.util.function.BiFunction, java.util.stream.Collectors, javax.lang.model.AnnotatedConstruct, .SourceVersion, javax.lang.model.element.*, javax.lang.model.type.DeclaredType, javax.lang.model.util.Elements, javax.tools.JavaFileObject, com.sun.source.util.JavacTask, com.sun.tools.javac.api.JavacTaskImpl, com.sun.tools.javac.code.*, .Attribute.Compound, .Directive.ExportsDirective, .Directive.ExportsFlag, .Directive.OpensDirective, .Directive.OpensFlag, .Directive.RequiresDirective, .Directive.RequiresFlag, .Scope.WriteableScope, .Source.Feature, com.sun.tools.javac.code.Symbol.*, com.sun.tools.javac.comp.AttrContext, .Enter, .Env, .Attr, .Modules, .Resolve, com.sun.tools.javac.main.JavaCompiler, com.sun.tools.javac.processing.PrintingProcessor, com.sun.tools.javac.tree.DocCommentTable, .JCTree, com.sun.tools.javac.tree.JCTree.*, .TreeInfo, .TreeScanner, com.sun.tools.javac.util.*, .DefinedBy.Api, .Name, com.sun.tools.javac.resources.CompilerProperties.Notes

Utility methods for operating on program elements.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Field Summary

Modifier and TypeField and Description
private final boolean
private final Set<String>
private final Attr
private final Enter
private final JavaCompiler
private final JavacTaskImpl
private final Log
private final Modules
private final Names
private final Resolve
private final Map<Pair<String, String>, Optional<Symbol>>
private final Symtab
private final Types

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private void
private static <T> T
cast(Class<T> clazz, Object o)

Returns an object cast to the specified type.

private static boolean
containsAnnoOfType(List<Attribute.Compound> annos, Type type)

Tests whether a list of annotations contains an annotation of a given type.

private <S extends Symbol> S
doGetElement(ModuleElement module, String methodName, CharSequence name, Class<S> clazz)

private Symbol.PackageSymbol
private Symbol.ClassSymbol
private void
ensureEntered(String methodName)

public List<Attribute.Compound>

Returns:

all annotations of the element
getAllAnnotationMirrors
(Element
the element being examined
e
)

Implements javax.lang.model.util.Elements.getAllAnnotationMirrors.

Returns all annotations of an element, whether inherited or directly present.

public FilteredMemberList
getAllMembers(TypeElement element)

Implements javax.lang.model.util.Elements.getAllMembers.

Returns all members of a type element, whether inherited or declared directly.

public Set<? extends ModuleElement>
getAllModuleElements()

Overrides default javax.lang.model.util.Elements.getAllModuleElements.

Returns all module elements in the current environment.

public Name
getBinaryName(TypeElement type)

Implements javax.lang.model.util.Elements.getBinaryName.

Returns the binary name of a type element.

public String
getConstantExpression(Object value)

Implements javax.lang.model.util.Elements.getConstantExpression.

Returns the text of a constant expression representing a primitive value or a string.

public String
getDocComment(Element e)

Implements javax.lang.model.util.Elements.getDocComment.

Returns the text of the documentation ("JavaDoc") comment of an element.

private <R> R
public Elements.DocCommentKind
getDocCommentKind(Element e)

Overrides default javax.lang.model.util.Elements.getDocCommentKind.

Returns the kind of the documentation comment for the given element, or null if there is no comment or the kind is not known.

public Map<Symbol.MethodSymbol, Attribute>
getElementValuesWithDefaults(AnnotationMirror a)

Implements javax.lang.model.util.Elements.getElementValuesWithDefaults.

Returns the values of an annotation's elements, including defaults.

private Env<AttrContext>
getEnterEnv(Symbol sym)

Returns a symbol's enter environment, or null if it has none.

public TypeElement
getEnumConstantBody(VariableElement enumConstant)

Overrides default javax.lang.model.util.Elements.getEnumConstantBody.

Returns the class body of an enum constant if the argument is an enum constant declared with an optional class body, null otherwise.

public JavaFileObject
getFileObjectOf(Element e)

Overrides default javax.lang.model.util.Elements.getFileObjectOf.

Returns the file object for this element or null if there is no such file object.

public Symbol.ModuleSymbol
getModuleElement(CharSequence name)

Overrides default javax.lang.model.util.Elements.getModuleElement.

Returns a module element given its fully qualified name.

public ModuleElement
getModuleOf(Element e)

Overrides default javax.lang.model.util.Elements.getModuleOf.

Returns the module of an element.

public Name
getName(CharSequence cs)

Implements javax.lang.model.util.Elements.getName.

Returns a name with the same sequence of characters as the argument.

public Elements.Origin
getOrigin(Element e)

Overrides default javax.lang.model.util.Elements.getOrigin.

Returns the origin of the given element.

public Elements.Origin
getOrigin(AnnotatedConstruct c, AnnotationMirror a)

Overrides default javax.lang.model.util.Elements.getOrigin.

Returns the origin of the given annotation mirror.

public Elements.Origin
getOrigin(ModuleElement m, ModuleElement.Directive directive)

Overrides default javax.lang.model.util.Elements.getOrigin.

Returns the origin of the given module directive.

public TypeElement
getOutermostTypeElement(Element e)

Overrides default javax.lang.model.util.Elements.getOutermostTypeElement.

Returns the outermost type element an element is contained in if such a containing element exists; otherwise returns null.

public Symbol.PackageSymbol
getPackageElement(CharSequence name)

Implements javax.lang.model.util.Elements.getPackageElement.

Returns a package given its fully qualified name if the package is uniquely determinable in the environment.

public Symbol.PackageSymbol
getPackageElement(ModuleElement module, CharSequence name)

Overrides default javax.lang.model.util.Elements.getPackageElement.

Returns a package given its fully qualified name, as seen from the given module.

public PackageElement
getPackageOf(Element e)

Implements javax.lang.model.util.Elements.getPackageOf.

Returns the package of an element.

public JCTree
getTree(Element e)

Returns the tree node corresponding to this element, or null if none can be found.

private JCTree
private Pair<JCTree, JCTree.JCCompilationUnit>
getTreeAndTopLevel(Element e)

Returns the tree node and compilation unit corresponding to this element, or null if they can't be found.

public Pair<JCTree, JCTree.JCCompilationUnit>
getTreeAndTopLevel(Element e, AnnotationMirror a, AnnotationValue v)

Returns the best approximation for the tree node and compilation unit corresponding to the given element, annotation and value.

public Symbol.ClassSymbol
getTypeElement(CharSequence name)

Implements javax.lang.model.util.Elements.getTypeElement.

Returns a type element given its canonical name if the type element is uniquely determinable in the environment.

public Symbol.ClassSymbol
getTypeElement(ModuleElement module, CharSequence name)

Overrides default javax.lang.model.util.Elements.getTypeElement.

Returns a type element given its canonical name, as seen from the given module.

public boolean
hides(Element hiderEl, Element hideeEl)

Implements javax.lang.model.util.Elements.hides.

Tests whether one type, method, or field hides another.

public static JavacElements
instance(Context context)

public boolean
isAutomaticModule(ModuleElement module)

Overrides default javax.lang.model.util.Elements.isAutomaticModule.

Returns true if the module element is an automatic module, false otherwise.

public boolean
isCanonicalConstructor(ExecutableElement e)

Overrides default javax.lang.model.util.Elements.isCanonicalConstructor.

Returns true if the executable element can be determined to be a canonical constructor of a record, false otherwise.

public boolean
isCompactConstructor(ExecutableElement e)

Overrides default javax.lang.model.util.Elements.isCompactConstructor.

Returns true if the executable element can be determined to be a compact constructor of a record, false otherwise.

public boolean
isDeprecated(Element e)

Implements javax.lang.model.util.Elements.isDeprecated.

Returns true if the element is deprecated, false otherwise.

public boolean
isFunctionalInterface(TypeElement element)

Implements javax.lang.model.util.Elements.isFunctionalInterface.

Returns true if the type element is a functional interface, false otherwise.

private boolean
isInherited(Type annotype)

Tests whether an annotation type is @Inherited.

private JCTree
matchAnnoToTree(AnnotationMirror findme, Element e, JCTree tree)

Returns the tree for an annotation given the annotated element and the element's own tree.

private JCTree
matchAnnoToTree(Attribute.Compound findme, List<Attribute.Compound> annos, List<JCTree.JCAnnotation> trees)

Returns the tree for an annotation given a list of annotations in which to search (recursively) and their corresponding trees.

private JCTree
matchAttributeToTree(final Attribute findme, final Attribute attr, final JCTree tree)

Returns the tree for an attribute given an enclosing attribute to search (recursively) and the enclosing attribute's corresponding tree.

private <S extends Symbol> S
nameToSymbol(Symbol.ModuleSymbol module, String nameStr, Class<S> clazz)

Returns a symbol given the type's or package's canonical name, or null if the name isn't found.

public void
public boolean
overrides(ExecutableElement riderEl, ExecutableElement rideeEl, TypeElement typeEl)

Implements javax.lang.model.util.Elements.overrides.

Tests whether one method, as a member of a given class or interface, overrides another method.

public void
printElements(Writer
the writer to print the output to
w
,
Element...
the elements to print
elements
)

Implements javax.lang.model.util.Elements.printElements.

Print a representation of the elements to the given writer in the specified order.

private JCTree.JCExpression
scanForAssign(final Symbol.MethodSymbol sym, final JCTree tree)

Scans for a JCAssign node with a LHS matching a given symbol, and returns its RHS.

private <S extends Symbol> S
unboundNameToSymbol(String methodName, String nameStr, Class<S> clazz)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowModulesback to summary
private final boolean allowModules
alreadyWarnedDuplicatesback to summary
private final Set<String> alreadyWarnedDuplicates
attrback to summary
private final Attr attr
enterback to summary
private final Enter enter
javaCompilerback to summary
private final JavaCompiler javaCompiler
javacTaskImplback to summary
private final JavacTaskImpl javacTaskImpl
logback to summary
private final Log log
modulesback to summary
private final Modules modules
namesback to summary
private final Names names
resolveback to summary
private final Resolve resolve
resultCacheback to summary
private final Map<Pair<String, String>, Optional<Symbol>> resultCache
symsback to summary
private final Symtab syms
typesback to summary
private final Types types

Constructor Detail

JavacElementsback to summary
protected JavacElements(Context context)
Annotations
@SuppressWarnings:this-escape

Method Detail

addMembersback to summary
private void addMembers(Scope.WriteableScope scope, Type type)
castback to summary
private static <T> T cast(Class<T> clazz, Object o)

Returns an object cast to the specified type.

Exceptions
NullPointerException:
if the object is null
IllegalArgumentException:
if the object is of the wrong type
containsAnnoOfTypeback to summary
private static boolean containsAnnoOfType(List<Attribute.Compound> annos, Type type)

Tests whether a list of annotations contains an annotation of a given type.

doGetElementback to summary
private <S extends Symbol> S doGetElement(ModuleElement module, String methodName, CharSequence name, Class<S> clazz)
doGetPackageElementback to summary
private Symbol.PackageSymbol doGetPackageElement(ModuleElement module, CharSequence name)
doGetTypeElementback to summary
private Symbol.ClassSymbol doGetTypeElement(ModuleElement module, CharSequence name)
ensureEnteredback to summary
private void ensureEntered(String methodName)
getAllAnnotationMirrorsback to summary
public List<Attribute.Compound> getAllAnnotationMirrors(Element e)

Implements javax.lang.model.util.Elements.getAllAnnotationMirrors.

Returns all annotations of an element, whether inherited or directly present.

Parameters
e:Element

the element being examined

Returns:List<Attribute.Compound>

all annotations of the element

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getAllMembersback to summary
public FilteredMemberList getAllMembers(TypeElement element)

Implements javax.lang.model.util.Elements.getAllMembers.

Doc from javax.lang.model.util.Elements.getAllMembers.

Returns all members of a type element, whether inherited or declared directly. For a class, the result also includes its constructors, but not local or anonymous classes.

Annotations
@DefinedBy:LANGUAGE_MODEL
getAllModuleElementsback to summary
public Set<? extends ModuleElement> getAllModuleElements()

Overrides default javax.lang.model.util.Elements.getAllModuleElements.

Doc from javax.lang.model.util.Elements.getAllModuleElements.

Returns all module elements in the current environment. If no modules are present, an empty set is returned. One situation where no modules are present occurs when the environment does not include modules, such as an annotation processing environment configured for a source version without modules.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getBinaryNameback to summary
public Name getBinaryName(TypeElement type)

Implements javax.lang.model.util.Elements.getBinaryName.

Doc from javax.lang.model.util.Elements.getBinaryName.

Returns the binary name of a type element.

Annotations
@DefinedBy:LANGUAGE_MODEL
getConstantExpressionback to summary
public String getConstantExpression(Object value)

Implements javax.lang.model.util.Elements.getConstantExpression.

Doc from javax.lang.model.util.Elements.getConstantExpression.

Returns the text of a constant expression representing a primitive value or a string. The text returned is in a form suitable for representing the value in source code.

Annotations
@DefinedBy:LANGUAGE_MODEL
getDocCommentback to summary
public String getDocComment(Element e)

Implements javax.lang.model.util.Elements.getDocComment.

Doc from javax.lang.model.util.Elements.getDocComment.

Returns the text of the documentation ("JavaDoc") comment of an element.

A documentation comment of an element is a particular kind of comment that immediately precedes the element, ignoring white space, annotations and any other comments that are not themselves documentation comments.

There are two kinds of documentation comments, either based on traditional comments or based on a series of end-of-line comments. For both kinds, the text returned for the documentation comment is a processed form of the comment as it appears in source code, as described below.

A traditional documentation comment is a traditional comment that begins with "/**", and ends with a separate "*/". (Therefore, such a comment contains at least three "*" characters.) The lines of such a comment are processed as follows:

  • The leading "/**" is removed, as are any immediately following space characters on that line. If all the characters of the line are removed, it makes no contribution to the returned comment.
  • For subsequent lines of the doc comment starting after the initial "/**", if the lines start with zero or more whitespace characters followed by one or more "*" characters, those leading whitespace characters are discarded as are any consecutive "*" characters appearing after the white space or starting the line. Otherwise, if a line does not have a prefix of the described form, the entire line is retained.
  • The trailing "*/" is removed. The line with the trailing" */" also undergoes leading space and "*" character removal as described above.
  • The processed lines are then concatenated together, separated by newline ("\n") characters, and returned.

An end-of-line documentation comment is a series of adjacent end-of-line comments, each on a line by itself, ignoring any whitespace characters at the beginning of the line, and each beginning with "///". The lines of such a comment are processed as follows:

  • Any leading whitespace and the three initial "/" characters are removed from each line.
  • The lines are shifted left, by removing leading whitespace characters, until the non-blank line with the least leading whitespace characters has no remaining leading whitespace characters.
  • Additional leading whitespace characters and any trailing whitespace characters in each line are preserved.
  • The processed lines are then concatenated together, separated by newline ("\n") characters, and returned. If the last line is not blank, the returned value will not be terminated by a newline character.
Annotations
@DefinedBy:LANGUAGE_MODEL
getDocCommentItemback to summary
private <R> R getDocCommentItem(Element e, BiFunction<DocCommentTable, JCTree, R> f)
getDocCommentKindback to summary
public Elements.DocCommentKind getDocCommentKind(Element e)

Overrides default javax.lang.model.util.Elements.getDocCommentKind.

Doc from javax.lang.model.util.Elements.getDocCommentKind.

Returns the kind of the documentation comment for the given element, or null if there is no comment or the kind is not known.

Annotations
@DefinedBy:LANGUAGE_MODEL
getElementValuesWithDefaultsback to summary
public Map<Symbol.MethodSymbol, Attribute> getElementValuesWithDefaults(AnnotationMirror a)

Implements javax.lang.model.util.Elements.getElementValuesWithDefaults.

Doc from javax.lang.model.util.Elements.getElementValuesWithDefaults.

Returns the values of an annotation's elements, including defaults.

Annotations
@DefinedBy:LANGUAGE_MODEL
getEnterEnvback to summary
private Env<AttrContext> getEnterEnv(Symbol sym)

Returns a symbol's enter environment, or null if it has none.

getEnumConstantBodyback to summary
public TypeElement getEnumConstantBody(VariableElement enumConstant)

Overrides default javax.lang.model.util.Elements.getEnumConstantBody.

Doc from javax.lang.model.util.Elements.getEnumConstantBody.

Returns the class body of an enum constant if the argument is an enum constant declared with an optional class body, null otherwise.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getFileObjectOfback to summary
public JavaFileObject getFileObjectOf(Element e)

Overrides default javax.lang.model.util.Elements.getFileObjectOf.

Doc from javax.lang.model.util.Elements.getFileObjectOf.

Returns the file object for this element or null if there is no such file object.

The returned file object is for the reference representation of the information used to construct the element. For example, if during compilation or annotation processing, a source file for class Foo is compiled into a class file, the file object returned for the element representing Foo would be for the source file and not for the class file.

An implementation may choose to not support the functionality of this method, in which case UnsupportedOperationException is thrown.

In the context of annotation processing, a non-null value is returned if the element was included as part of the initial inputs or the containing file was created during the run of the annotation processing tool. Otherwise, a null may be returned. In annotation processing, if a class file is created, that class file can serve as the reference representation for elements.

If it has a file object, the file object for a package will be a package-info file. A package may exist and not have any package-info file even if the package is (implicitly) created during an annotation processing run from the creation of source or class files in that package. An unnamed package will have a null file since it cannot be declared in a compilation unit.

If it has a file object, the file object for a module will be a module-info file. An unnamed module will have a null file since it cannot be declared in a compilation unit. An automatic module will have a null file since it is implicitly declared.

If it has a file object, the file object for a top-level public class or interface will be a source or class file corresponding to that class or interface. In this case, typically the leading portion of the name of the file will match the name of the class or interface. A single compilation unit can define multiple top-level classes and interfaces, such as a primary public class or interfaces whose name corresponds to the file name and one or more auxiliary classes or interfaces whose names do not correspond to the file name. If a source file is providing the reference representation of an auxiliary class or interface, the file for the primary class is returned. (An auxiliary class or interface can also be defined in a package-info source file, in which case the file for the package-info file is returned.) If a class file is providing the reference representation of an auxiliary class or interface, the separate class file for the auxiliary class is returned.

For a nested class or interface, if it has a file object:

  • if a source file is providing the reference representation, the file object will be that of the outermost enclosing class or interface
  • if a class file is providing the reference representation, the file object will be that of the nested class or interface itself

For other lexically enclosed elements, such as variables, methods, and constructors, if they have a file object, the file object will be the object associated with the enclosing element of the lexically enclosed element.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getModuleElementback to summary
public Symbol.ModuleSymbol getModuleElement(CharSequence name)

Overrides default javax.lang.model.util.Elements.getModuleElement.

Doc from javax.lang.model.util.Elements.getModuleElement.

Returns a module element given its fully qualified name. If the requested module cannot be found, null is returned. One situation where a module cannot be found is if the environment does not include modules, such as an annotation processing environment configured for a source version without modules.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getModuleOfback to summary
public ModuleElement getModuleOf(Element e)

Overrides default javax.lang.model.util.Elements.getModuleOf.

Doc from javax.lang.model.util.Elements.getModuleOf.

Returns the module of an element. The module of a module is itself. If a package has a module as its enclosing element, that module is the module of the package. If the enclosing element of a package is null, null is returned for the package's module. (One situation where a package may have a null module is if the environment does not include modules, such as an annotation processing environment configured for a source version without modules.) Otherwise, the module of an element is equal to the module of the package of the element.

Annotations
@DefinedBy:LANGUAGE_MODEL
getNameback to summary
public Name getName(CharSequence cs)

Implements javax.lang.model.util.Elements.getName.

Doc from javax.lang.model.util.Elements.getName.

Returns a name with the same sequence of characters as the argument.

Annotations
@DefinedBy:LANGUAGE_MODEL
getOriginback to summary
public Elements.Origin getOrigin(Element e)

Overrides default javax.lang.model.util.Elements.getOrigin.

Doc from javax.lang.model.util.Elements.getOrigin.

Returns the origin of the given element.

Note that if this method returns EXPLICIT and the element was created from a class file, then the element may not, in fact, correspond to an explicitly declared construct in source code. This is due to limitations of the fidelity of the class file format in preserving information from source code. For example, at least some versions of the class file format do not preserve whether a constructor was explicitly declared by the programmer or was implicitly declared as the default constructor.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getOriginback to summary
public Elements.Origin getOrigin(AnnotatedConstruct c, AnnotationMirror a)

Overrides default javax.lang.model.util.Elements.getOrigin.

Doc from javax.lang.model.util.Elements.getOrigin.

Returns the origin of the given annotation mirror. An annotation mirror is mandated if it is an implicitly declared container annotation used to hold repeated annotations of a repeatable annotation interface.

Note that if this method returns EXPLICIT and the annotation mirror was created from a class file, then the element may not, in fact, correspond to an explicitly declared construct in source code. This is due to limitations of the fidelity of the class file format in preserving information from source code. For example, at least some versions of the class file format do not preserve whether an annotation was explicitly declared by the programmer or was implicitly declared as a container annotation.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getOriginback to summary
public Elements.Origin getOrigin(ModuleElement m, ModuleElement.Directive directive)

Overrides default javax.lang.model.util.Elements.getOrigin.

Doc from javax.lang.model.util.Elements.getOrigin.

Returns the origin of the given module directive.

Note that if this method returns EXPLICIT and the module directive was created from a class file, then the module directive may not, in fact, correspond to an explicitly declared construct in source code. This is due to limitations of the fidelity of the class file format in preserving information from source code. For example, at least some versions of the class file format do not preserve whether a uses directive was explicitly declared by the programmer or was added as a synthetic construct.

Note that an implementation may not be able to reliably determine the origin status of the directive if the directive is created from a class file due to limitations of the fidelity of the class file format in preserving information from source code.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getOutermostTypeElementback to summary
public TypeElement getOutermostTypeElement(Element e)

Overrides default javax.lang.model.util.Elements.getOutermostTypeElement.

Doc from javax.lang.model.util.Elements.getOutermostTypeElement.

Returns the outermost type element an element is contained in if such a containing element exists; otherwise returns null. Modules and packages do not have a containing type element and therefore null is returned for those kinds of elements. A top-level class or interface is its own outermost type element.

Annotations
@DefinedBy:LANGUAGE_MODEL
getPackageElementback to summary
public Symbol.PackageSymbol getPackageElement(CharSequence name)

Implements javax.lang.model.util.Elements.getPackageElement.

Doc from javax.lang.model.util.Elements.getPackageElement.

Returns a package given its fully qualified name if the package is uniquely determinable in the environment. If running with modules, packages of the given name are searched in a two-stage process:

If this process leads to a list with a single element, the single element is returned, otherwise null is returned.
Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getPackageElementback to summary
public Symbol.PackageSymbol getPackageElement(ModuleElement module, CharSequence name)

Overrides default javax.lang.model.util.Elements.getPackageElement.

Doc from javax.lang.model.util.Elements.getPackageElement.

Returns a package given its fully qualified name, as seen from the given module.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getPackageOfback to summary
public PackageElement getPackageOf(Element e)

Implements javax.lang.model.util.Elements.getPackageOf.

Doc from javax.lang.model.util.Elements.getPackageOf.

Returns the package of an element. The package of a package is itself. The package of a module is null. The package of a top-level class or interface is its enclosing package. Otherwise, the package of an element is equal to the package of the enclosing element.

Annotations
@DefinedBy:LANGUAGE_MODEL
getTreeback to summary
public JCTree getTree(Element e)

Returns the tree node corresponding to this element, or null if none can be found.

getTreeAltback to summary
private JCTree getTreeAlt(Element e)
getTreeAndTopLevelback to summary
private Pair<JCTree, JCTree.JCCompilationUnit> getTreeAndTopLevel(Element e)

Returns the tree node and compilation unit corresponding to this element, or null if they can't be found.

getTreeAndTopLevelback to summary
public Pair<JCTree, JCTree.JCCompilationUnit> getTreeAndTopLevel(Element e, AnnotationMirror a, AnnotationValue v)

Returns the best approximation for the tree node and compilation unit corresponding to the given element, annotation and value. If the element is null, null is returned. If the annotation is null or cannot be found, the tree node and compilation unit for the element is returned. If the annotation value is null or cannot be found, the tree node and compilation unit for the annotation is returned.

getTypeElementback to summary
public Symbol.ClassSymbol getTypeElement(CharSequence name)

Implements javax.lang.model.util.Elements.getTypeElement.

Doc from javax.lang.model.util.Elements.getTypeElement.

Returns a type element given its canonical name if the type element is uniquely determinable in the environment. If running with modules, type elements of the given name are searched in a two-stage process:

If this process leads to a list with a single element, the single element is returned, otherwise null is returned.
Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
getTypeElementback to summary
public Symbol.ClassSymbol getTypeElement(ModuleElement module, CharSequence name)

Overrides default javax.lang.model.util.Elements.getTypeElement.

Doc from javax.lang.model.util.Elements.getTypeElement.

Returns a type element given its canonical name, as seen from the given module.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
hidesback to summary
public boolean hides(Element hiderEl, Element hideeEl)

Implements javax.lang.model.util.Elements.hides.

Doc from javax.lang.model.util.Elements.hides.

Tests whether one type, method, or field hides another.

Annotations
@DefinedBy:LANGUAGE_MODEL
instanceback to summary
public static JavacElements instance(Context context)
isAutomaticModuleback to summary
public boolean isAutomaticModule(ModuleElement module)

Overrides default javax.lang.model.util.Elements.isAutomaticModule.

Doc from javax.lang.model.util.Elements.isAutomaticModule.

Returns true if the module element is an automatic module, false otherwise.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
isCanonicalConstructorback to summary
public boolean isCanonicalConstructor(ExecutableElement e)

Overrides default javax.lang.model.util.Elements.isCanonicalConstructor.

Doc from javax.lang.model.util.Elements.isCanonicalConstructor.

Returns true if the executable element can be determined to be a canonical constructor of a record, false otherwise. Note that in some cases there may be insufficient information to determine if a constructor is a canonical constructor, such as if the executable element is built backed by a class file. In such cases, false is returned.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
isCompactConstructorback to summary
public boolean isCompactConstructor(ExecutableElement e)

Overrides default javax.lang.model.util.Elements.isCompactConstructor.

Doc from javax.lang.model.util.Elements.isCompactConstructor.

Returns true if the executable element can be determined to be a compact constructor of a record, false otherwise. By definition, a compact constructor is also a canonical constructor. Note that in some cases there may be insufficient information to determine if a constructor is a compact constructor, such as if the executable element is built backed by a class file. In such cases, false is returned.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
isDeprecatedback to summary
public boolean isDeprecated(Element e)

Implements javax.lang.model.util.Elements.isDeprecated.

Doc from javax.lang.model.util.Elements.isDeprecated.

Returns true if the element is deprecated, false otherwise.

Annotations
@DefinedBy:LANGUAGE_MODEL
isFunctionalInterfaceback to summary
public boolean isFunctionalInterface(TypeElement element)

Implements javax.lang.model.util.Elements.isFunctionalInterface.

Doc from javax.lang.model.util.Elements.isFunctionalInterface.

Returns true if the type element is a functional interface, false otherwise.

Annotations
@Override
@DefinedBy:LANGUAGE_MODEL
isInheritedback to summary
private boolean isInherited(Type annotype)

Tests whether an annotation type is @Inherited.

matchAnnoToTreeback to summary
private JCTree matchAnnoToTree(AnnotationMirror findme, Element e, JCTree tree)

Returns the tree for an annotation given the annotated element and the element's own tree. Returns null if the tree cannot be found.

matchAnnoToTreeback to summary
private JCTree matchAnnoToTree(Attribute.Compound findme, List<Attribute.Compound> annos, List<JCTree.JCAnnotation> trees)

Returns the tree for an annotation given a list of annotations in which to search (recursively) and their corresponding trees. Returns null if the tree cannot be found.

matchAttributeToTreeback to summary
private JCTree matchAttributeToTree(final Attribute findme, final Attribute attr, final JCTree tree)

Returns the tree for an attribute given an enclosing attribute to search (recursively) and the enclosing attribute's corresponding tree. Returns null if the tree cannot be found.

nameToSymbolback to summary
private <S extends Symbol> S nameToSymbol(Symbol.ModuleSymbol module, String nameStr, Class<S> clazz)

Returns a symbol given the type's or package's canonical name, or null if the name isn't found.

newRoundback to summary
public void newRound()
overridesback to summary
public boolean overrides(ExecutableElement riderEl, ExecutableElement rideeEl, TypeElement typeEl)

Implements javax.lang.model.util.Elements.overrides.

Doc from javax.lang.model.util.Elements.overrides.

Tests whether one method, as a member of a given class or interface, overrides another method. When a non-abstract method overrides an abstract one, the former is also said to implement the latter. As implied by JLS 8.4.8.1, a method does not override itself. The overrides relation is irreflexive.

In the simplest and most typical usage, the value of the type parameter will simply be the class or interface directly enclosing overrider (the possibly-overriding method). For example, suppose m1 represents the method String.hashCode and m2 represents Object.hashCode. We can then ask whether m1 overrides m2 within the class String (it does):

assert elements.overrides(m1, m2, elements.getTypeElement("java.lang.String"));
A more interesting case can be illustrated by the following example in which a method in class A does not override a like-named method in interface B:
class A { public void m() {} }
interface B { void m(); }
...
m1 = ...; // A.m
m2 = ...; // B.m
assert ! elements.overrides(m1, m2, elements.getTypeElement("A"));
When viewed as a member of a third class C, however, the method in A does override the one in B:
class C extends A implements B {}
...
assert elements.overrides(m1, m2, elements.getTypeElement("C"));
Consistent with the usage of the @Override annotation, if an interface declares a method override-equivalent to a public method of java.lang.Object, such a method of the interface is regarded as overriding the corresponding Object method; for example:
interface I { @Override String toString(); } ... assert elements.overrides(elementForItoString, elementForObjecttoString, elements.getTypeElement("I"));
interface I {
  @Override
  String toString();
}
...
assert elements.overrides(elementForItoString,
                          elementForObjecttoString,
                          elements.getTypeElement("I"));
Annotations
@DefinedBy:LANGUAGE_MODEL
printElementsback to summary
public void printElements(Writer w, Element... elements)

Implements javax.lang.model.util.Elements.printElements.

Print a representation of the elements to the given writer in the specified order. The main purpose of this method is for diagnostics. The exact format of the output is not specified and is subject to change.

Parameters
w:Writer

the writer to print the output to

elements:Element[]

the elements to print

Annotations
@DefinedBy:LANGUAGE_MODEL
scanForAssignback to summary
private JCTree.JCExpression scanForAssign(final Symbol.MethodSymbol sym, final JCTree tree)

Scans for a JCAssign node with a LHS matching a given symbol, and returns its RHS. Does not scan nested JCAnnotations.

unboundNameToSymbolback to summary
private <S extends Symbol> S unboundNameToSymbol(String methodName, String nameStr, Class<S> clazz)
Annotations
@SuppressWarnings:unchecked