APIdia Launch Partner
Top Description Inners Methods
javax.lang.model.util

public Interface Elements

Imports
java.util.Collections, .List, .Map, .Set, .LinkedHashSet, .Objects, javax.lang.model.AnnotatedConstruct, javax.lang.model.element.*

Utility methods for operating on program elements.

Compatibility Note: Methods may be added to this interface in future releases of the platform.

Since
1.6
See Also
javax.annotation.processing.ProcessingEnvironment#getElementUtils

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Elements.DocCommentKind

The kind of documentation comment.

public static enum
Elements.Origin

The origin of an element or other language model item.

Method Summary

Modifier and TypeMethod and Description
public List<? extends AnnotationMirror>

Returns:

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

Returns all annotations present on an element, whether directly present or present via inheritance.

public List<? extends Element>

Returns:

all members of the type
getAllMembers
(TypeElement
the type being examined
type
)

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

public default Set<? extends ModuleElement>

Returns:

the known module elements, or an empty set if there are no modules
getAllModuleElements
()

Returns all module elements in the current environment.

public default Set<? extends PackageElement>

Returns:

the package elements, or an empty set if no package with the name can be found
getAllPackageElements
(CharSequence
the canonical name
name
)

Returns all package elements with the given canonical name.

public default Set<? extends TypeElement>

Returns:

the type elements, or an empty set if no type with the name can be found
getAllTypeElements
(CharSequence
the canonical name
name
)

Returns all type elements with the given canonical name.

public Name

Returns:

the binary name of a type element
getBinaryName
(TypeElement
the type element being examined
type
)

Returns the binary name of a type element.

public String

Returns:

the text of a constant expression
getConstantExpression
(Object
a primitive value or string
value
)

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

public String

Returns:

the documentation comment of the element, or null if there is none
getDocComment
(Element
the element being examined
e
)

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

public default Elements.DocCommentKind

Returns:

the kind of the documentation comment for the given element, or null if there is no comment or the kind is not known
getDocCommentKind
(Element
the element being examined
e
)

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<? extends ExecutableElement, ? extends AnnotationValue>

Returns:

the values of an annotation's elements, including defaults
getElementValuesWithDefaults
(AnnotationMirror
annotation to examine
a
)

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

public default TypeElement

Returns:

the class body of an enum constant if the argument is an enum constant declared with an optional class body, null otherwise
getEnumConstantBody
(VariableElement
an enum constant
enumConstant
)

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

public default JavaFileObject

Returns:

the file object for this element or null if there is no such file object
getFileObjectOf
(Element
the element to find a file object for
e
)

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

public default ModuleElement

Returns:

the named module element, or null if it cannot be found
getModuleElement
(CharSequence
the name, or an empty string for an unnamed module
name
)

Returns a module element given its fully qualified name.

public default ModuleElement

Returns:

the module of an element
getModuleOf
(Element
the element being examined
e
)

Returns the module of an element.

public Name

Returns:

a name with the same sequence of characters as the argument
getName
(CharSequence
the character sequence to return as a name
cs
)

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

public default Elements.Origin

Returns:

the origin of the given element
getOrigin
(Element
the element being examined
e
)

Returns the origin of the given element.

public default Elements.Origin

Returns:

the origin of the given annotation mirror
getOrigin
(AnnotatedConstruct
the construct the annotation mirror modifies
c
,
AnnotationMirror
the annotation mirror being examined
a
)

Returns the origin of the given annotation mirror.

public default Elements.Origin

Returns:

the origin of the given module directive
getOrigin
(ModuleElement
the module of the directive
m
,
ModuleElement.Directive
the module directive being examined
directive
)

Returns the origin of the given module directive.

public default TypeElement

Returns:

the outermost type element an element is contained in if such a containing element exists; otherwise returns null
getOutermostTypeElement
(Element
the element being examined
e
)

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

public PackageElement

Returns:

the specified package, or null if no package can be uniquely determined.
getPackageElement
(CharSequence
fully qualified package name, or an empty string for an unnamed package
name
)

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

public default PackageElement

Returns:

the specified package, or null if it cannot be found
getPackageElement
(ModuleElement
module relative to which the lookup should happen
module
,
CharSequence
fully qualified package name, or an empty string for an unnamed package
name
)

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

public PackageElement

Returns:

the package of an element
getPackageOf
(Element
the element being examined
e
)

Returns the package of an element.

public TypeElement

Returns:

the named type element, or null if no type element can be uniquely determined.
getTypeElement
(CharSequence
the canonical name
name
)

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

public default TypeElement

Returns:

the named type element, or null if it cannot be found
getTypeElement
(ModuleElement
module relative to which the lookup should happen
module
,
CharSequence
the canonical name
name
)

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

public boolean

Returns:

true if and only if the first element hides the second
hides
(Element
the first element
hider
,
Element
the second element
hidden
)

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

public default boolean

Returns:

true if the module element is an automatic module, false otherwise
isAutomaticModule
(ModuleElement
the module element being examined
module
)

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

public default boolean

Returns:

true if the executable element is a bridge method, false otherwise
isBridge
(ExecutableElement
the executable being examined
e
)

Returns true if the executable element is a bridge method, false otherwise.

public default boolean

Returns:

true if the executable element can be determined to be a canonical constructor of a record, false otherwise
isCanonicalConstructor
(ExecutableElement
the executable being examined
e
)

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

public default boolean

Returns:

true if the executable element can be determined to be a compact constructor of a record, false otherwise
isCompactConstructor
(ExecutableElement
the executable being examined
e
)

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

public boolean

Returns:

true if the element is deprecated, false otherwise
isDeprecated
(Element
the element being examined
e
)

Returns true if the element is deprecated, false otherwise.

public boolean

Returns:

true if the type element is a functional interface, false otherwise
isFunctionalInterface
(TypeElement
the type element being examined
type
)

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

public boolean

Returns:

true if and only if the first method overrides the second
overrides
(ExecutableElement
the first method, possible overrider
overrider
,
ExecutableElement
the second method, possibly being overridden
overridden
,
TypeElement
the class or interface of which the first method is a member
type
)

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
)

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

public default RecordComponentElement

Returns:

the record component, or null if the given method is not a record component accessor
recordComponentFor
(ExecutableElement
the method for which the record component should be found.
accessor
)

Returns the record component for the given accessor.

Method Detail

getAllAnnotationMirrorsback to summary
public List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e)

Returns all annotations present on an element, whether directly present or present via inheritance.

Note that any annotations returned by this method are declaration annotations.

Parameters
e:Element

the element being examined

Returns:List<? extends AnnotationMirror>

all annotations of the element

See Also
Element#getAnnotationMirrors, javax.lang.model.AnnotatedConstruct
getAllMembersback to summary
public List<? extends Element> getAllMembers(TypeElement type)

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.

API Note

Elements of certain kinds can be isolated using methods in ElementFilter.

Parameters
type:TypeElement

the type being examined

Returns:List<? extends Element>

all members of the type

See Also
Element#getEnclosedElements
getAllModuleElementsback to summary
public default Set<? extends ModuleElement> 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.

Implementation Specification

The default implementation of this method returns an empty set.

API Note

When an environment includes modules, both named modules and unnamed modules may be returned.

Returns:Set<? extends ModuleElement>

the known module elements, or an empty set if there are no modules

Since
9
See Also
getModuleElement(CharSequence)
getAllPackageElementsback to summary
public default Set<? extends PackageElement> getAllPackageElements(CharSequence name)

Returns all package elements with the given canonical name. There may be more than one package element with the same canonical name if the package elements are in different modules.

Implementation Specification

The default implementation of this method calls getAllModuleElements and stores the result. If the set of modules is empty, getPackageElement(name) is called passing through the name argument. If getPackageElement(name) is null, an empty set of package elements is returned; otherwise, a single-element set with the found package element is returned. If the set of modules is nonempty, the modules are iterated over and any non-null results of getPackageElement(module, name) are accumulated into a set. The set is then returned.

Parameters
name:CharSequence

the canonical name

Returns:Set<? extends PackageElement>

the package elements, or an empty set if no package with the name can be found

Since
9
See Also
getPackageElement(ModuleElement, CharSequence)
getAllTypeElementsback to summary
public default Set<? extends TypeElement> getAllTypeElements(CharSequence name)

Returns all type elements with the given canonical name. There may be more than one type element with the same canonical name if the type elements are in different modules.

Implementation Specification

The default implementation of this method calls getAllModuleElements and stores the result. If the set of modules is empty, getTypeElement(name) is called passing through the name argument. If getTypeElement(name) is null, an empty set of type elements is returned; otherwise, a single-element set with the found type element is returned. If the set of modules is nonempty, the modules are iterated over and any non-null results of getTypeElement(module, name) are accumulated into a set. The set is then returned.

Parameters
name:CharSequence

the canonical name

Returns:Set<? extends TypeElement>

the type elements, or an empty set if no type with the name can be found

Since
9
See Also
getTypeElement(ModuleElement, CharSequence)
getBinaryNameback to summary
public Name getBinaryName(TypeElement type)

Returns the binary name of a type element.

Parameters
type:TypeElement

the type element being examined

Returns:Name

the binary name of a type element

Java Language Specification
13.1 The Form of a Binary
See Also
TypeElement#getQualifiedName
getConstantExpressionback to summary
public String getConstantExpression(Object value)

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.

Parameters
value:Object

a primitive value or string

Returns:String

the text of a constant expression

Exceptions
IllegalArgumentException:
if the argument is not a primitive value or string
See Also
VariableElement#getConstantValue()
getDocCommentback to summary
public String getDocComment(Element e)

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.

API Note

Documentation comments are processed by the standard doclet used by the javadoc tool to generate API documentation.

Parameters
e:Element

the element being examined

Returns:String

the documentation comment of the element, or null if there is none

Java Language Specification
3.6 White Space, 3.7 Comments
getDocCommentKindback to summary
public default Elements.DocCommentKind getDocCommentKind(Element e)

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

Implementation Specification

The default implementation of this method returns null.

Parameters
e:Element

the element being examined

Returns:Elements.DocCommentKind

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

Since
23
getElementValuesWithDefaultsback to summary
public Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror a)

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

Parameters
a:AnnotationMirror

annotation to examine

Returns:Map<? extends ExecutableElement, ? extends AnnotationValue>

the values of an annotation's elements, including defaults

See Also
AnnotationMirror#getElementValues()
getEnumConstantBodyback to summary
public default TypeElement getEnumConstantBody(VariableElement enumConstant)

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

Implementation Specification

The default implementation of this method throws UnsupportedOperationException if the argument is an enum constant and throws an IllegalArgumentException if it is not.

Parameters
enumConstant:VariableElement

an enum constant

Returns:TypeElement

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

Exceptions
IllegalArgumentException:
if the argument is not an enum constant
Since
22
Java Language Specification
8.9.1 Enum Constants
getFileObjectOfback to summary
public default JavaFileObject getFileObjectOf(Element e)

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.

Implementation Specification

The default implementation unconditionally throws UnsupportedOperationException.

Parameters
e:Element

the element to find a file object for

Returns:JavaFileObject

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

Exceptions
UnsupportedOperationException:
if this functionality is not supported
Since
18
getModuleElementback to summary
public default ModuleElement getModuleElement(CharSequence name)

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.

Implementation Specification

The default implementation of this method returns null.

Parameters
name:CharSequence

the name, or an empty string for an unnamed module

Returns:ModuleElement

the named module element, or null if it cannot be found

Since
9
See Also
getAllModuleElements
getModuleOfback to summary
public default ModuleElement getModuleOf(Element e)

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.

Implementation Specification

The default implementation of this method returns null.

Parameters
e:Element

the element being examined

Returns:ModuleElement

the module of an element

Since
9
getNameback to summary
public Name getName(CharSequence cs)

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

Parameters
cs:CharSequence

the character sequence to return as a name

Returns:Name

a name with the same sequence of characters as the argument

getOriginback to summary
public default Elements.Origin getOrigin(Element e)

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.

Implementation Specification

The default implementation of this method returns EXPLICIT.

Parameters
e:Element

the element being examined

Returns:Elements.Origin

the origin of the given element

Since
9
getOriginback to summary
public default Elements.Origin getOrigin(AnnotatedConstruct c, AnnotationMirror a)

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.

Implementation Specification

The default implementation of this method returns EXPLICIT.

Parameters
c:AnnotatedConstruct

the construct the annotation mirror modifies

a:AnnotationMirror

the annotation mirror being examined

Returns:Elements.Origin

the origin of the given annotation mirror

Since
9
Java Language Specification
9.6.3 Repeatable Annotation Interfaces, 9.7.5 Multiple Annotations of the Same Interface
getOriginback to summary
public default Elements.Origin getOrigin(ModuleElement m, ModuleElement.Directive directive)

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.

Implementation Specification

The default implementation of this method returns EXPLICIT.

Parameters
m:ModuleElement

the module of the directive

directive:ModuleElement.Directive

the module directive being examined

Returns:Elements.Origin

the origin of the given module directive

Since
9
getOutermostTypeElementback to summary
public default TypeElement getOutermostTypeElement(Element e)

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.

Implementation Specification

The default implementation of this method first checks the kind of the argument. For elements of kind PACKAGE, MODULE, and OTHER, null is returned. For elements of other kinds, the element is examined to see if it is a top-level class or interface. If so, that element is returned; otherwise, the enclosing element chain is followed until a top-level class or interface is found. The element for the eventual top-level class or interface is returned.

Parameters
e:Element

the element being examined

Returns:TypeElement

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

Since
18
See Also
Element#getEnclosingElement
getPackageElementback to summary
public PackageElement getPackageElement(CharSequence name)

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.
Parameters
name:CharSequence

fully qualified package name, or an empty string for an unnamed package

Returns:PackageElement

the specified package, or null if no package can be uniquely determined.

getPackageElementback to summary
public default PackageElement getPackageElement(ModuleElement module, CharSequence name)

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

Implementation Specification

The default implementation of this method returns null.

Parameters
module:ModuleElement

module relative to which the lookup should happen

name:CharSequence

fully qualified package name, or an empty string for an unnamed package

Returns:PackageElement

the specified package, or null if it cannot be found

Since
9
See Also
getAllPackageElements
getPackageOfback to summary
public PackageElement getPackageOf(Element e)

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.

Parameters
e:Element

the element being examined

Returns:PackageElement

the package of an element

getTypeElementback to summary
public TypeElement getTypeElement(CharSequence name)

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.
Parameters
name:CharSequence

the canonical name

Returns:TypeElement

the named type element, or null if no type element can be uniquely determined.

getTypeElementback to summary
public default TypeElement getTypeElement(ModuleElement module, CharSequence name)

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

Implementation Specification

The default implementation of this method returns null.

Parameters
module:ModuleElement

module relative to which the lookup should happen

name:CharSequence

the canonical name

Returns:TypeElement

the named type element, or null if it cannot be found

Since
9
See Also
getAllTypeElements
hidesback to summary
public boolean hides(Element hider, Element hidden)

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

Parameters
hider:Element

the first element

hidden:Element

the second element

Returns:boolean

true if and only if the first element hides the second

Java Language Specification
8.4.8 Inheritance, Overriding, and Hiding
isAutomaticModuleback to summary
public default boolean isAutomaticModule(ModuleElement module)

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

Implementation Specification

The default implementation of this method returns false.

Parameters
module:ModuleElement

the module element being examined

Returns:boolean

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

Since
17
Java Language Specification
7.7.1 Dependences
isBridgeback to summary
public default boolean isBridge(ExecutableElement e)

Returns true if the executable element is a bridge method, false otherwise.

Implementation Specification

The default implementation of this method returns false.

Parameters
e:ExecutableElement

the executable being examined

Returns:boolean

true if the executable element is a bridge method, false otherwise

Since
9
isCanonicalConstructorback to summary
public default boolean isCanonicalConstructor(ExecutableElement e)

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.

Implementation Specification

The default implementation of this method unconditionally returns false.

Parameters
e:ExecutableElement

the executable being examined

Returns:boolean

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

Since
20
Java Language Specification
8.10.4.1 Normal Canonical Constructors
isCompactConstructorback to summary
public default boolean isCompactConstructor(ExecutableElement e)

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.

Implementation Specification

The default implementation of this method unconditionally returns false.

Parameters
e:ExecutableElement

the executable being examined

Returns:boolean

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

Since
20
Java Language Specification
8.10.4.2 Compact Canonical Constructors
isDeprecatedback to summary
public boolean isDeprecated(Element e)

Returns true if the element is deprecated, false otherwise.

Parameters
e:Element

the element being examined

Returns:boolean

true if the element is deprecated, false otherwise

isFunctionalInterfaceback to summary
public boolean isFunctionalInterface(TypeElement type)

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

Parameters
type:TypeElement

the type element being examined

Returns:boolean

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

Since
1.8
Java Language Specification
9.8 Functional Interfaces
overridesback to summary
public boolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type)

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"));

API Note

This method examines the method's name, signature, subclass relationship, and accessibility in determining whether one method overrides another, as specified in JLS 8.4.8.1. In addition, an implementation may have stricter checks including method modifiers, return types and exception types as described in JLS 8.4.8.1 and 8.4.8.3. Note that such additional compile-time checks are not guaranteed and may vary between implementations.

Parameters
overrider:ExecutableElement

the first method, possible overrider

overridden:ExecutableElement

the second method, possibly being overridden

type:TypeElement

the class or interface of which the first method is a member

Returns:boolean

true if and only if the first method overrides the second

Java Language Specification
8.4.8 Inheritance, Overriding, and Hiding, 9.4.1 Inheritance and Overriding
printElementsback to summary
public void printElements(Writer w, Element... elements)

Prints 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

recordComponentForback to summary
public default RecordComponentElement recordComponentFor(ExecutableElement accessor)

Returns the record component for the given accessor. Returns null if the given method is not a record component accessor.

Implementation Specification

The default implementation of this method checks if the element enclosing the accessor has kind RECORD, if that is the case, then all the record components of the accessor's enclosing element are isolated by invoking ElementFilter#recordComponentsIn(Iterable). If the accessor of at least one of the record components retrieved happens to be equal to the accessor passed as a parameter to this method, then that record component is returned, in any other case null is returned.

Parameters
accessor:ExecutableElement

the method for which the record component should be found.

Returns:RecordComponentElement

the record component, or null if the given method is not a record component accessor

Since
16
javax.lang.model.util back to summary

public final Enum Elements.DocCommentKind

extends Enum<Elements.DocCommentKind>
Class Inheritance

The kind of documentation comment.
Since
23

Field Summary

Modifier and TypeField and Description
public static final Elements.DocCommentKind
END_OF_LINE

The kind of comments whose lines are prefixed by ///.

public static final Elements.DocCommentKind
TRADITIONAL

The kind of comments that begin with /**.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Elements.DocCommentKind
public static Elements.DocCommentKind[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

END_OF_LINEback to summary
public static final Elements.DocCommentKind END_OF_LINE

The kind of comments whose lines are prefixed by ///.

API Note

The standard doclet used by the javadoc tool treats these comments as containing Markdown and documentation comment tags.

See Also
JEP 467: Markdown Documentation Comments
TRADITIONALback to summary
public static final Elements.DocCommentKind TRADITIONAL

The kind of comments that begin with /**.

API Note

The standard doclet used by the javadoc tool treats these comments as containing HTML and documentation comment tags.

Constructor Detail

DocCommentKindback to summary
private DocCommentKind()

Method Detail

valueOfback to summary
public static Elements.DocCommentKind valueOf(String name)
valuesback to summary
public static Elements.DocCommentKind[] values()
javax.lang.model.util back to summary

public final Enum Elements.Origin

extends Enum<Elements.Origin>
Class Inheritance

The origin of an element or other language model item. The origin of an element or item models how a construct in a program is declared in the source code, explicitly, implicitly, etc.

Note that it is possible additional kinds of origin values will be added in future versions of the platform.

Since
9
Java Language Specification
13.1 The Form of a Binary

Field Summary

Modifier and TypeField and Description
public static final Elements.Origin
EXPLICIT

Describes a construct explicitly declared in source code.

public static final Elements.Origin
MANDATED

A mandated construct is one that is not explicitly declared in the source code, but whose presence is mandated by the specification.

public static final Elements.Origin
SYNTHETIC

A synthetic construct is one that is neither implicitly nor explicitly declared in the source code.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true for EXPLICIT and MANDATED, false otherwise.
isDeclared
()

Returns true for values corresponding to constructs that are implicitly or explicitly declared, false otherwise.

public static Elements.Origin
public static Elements.Origin[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EXPLICITback to summary
public static final Elements.Origin EXPLICIT

Describes a construct explicitly declared in source code.

MANDATEDback to summary
public static final Elements.Origin MANDATED

A mandated construct is one that is not explicitly declared in the source code, but whose presence is mandated by the specification. Such a construct is said to be implicitly declared. One example of a mandated element is a default constructor in a class that contains no explicit constructor declarations. Another example of a mandated construct is an implicitly declared container annotation used to hold multiple annotations of a repeatable annotation interface.

Java Language Specification
8.8.9 Default Constructor, 8.9.3 Enum Members, 8.10.3 Record Members, 9.6.3 Repeatable Annotation Interfaces, 9.7.5 Multiple Annotations of the Same Interface
SYNTHETICback to summary
public static final Elements.Origin SYNTHETIC

A synthetic construct is one that is neither implicitly nor explicitly declared in the source code. Such a construct is typically a translation artifact created by a compiler.

Constructor Detail

Originback to summary
private Origin()

Method Detail

isDeclaredback to summary
public boolean isDeclared()

Returns true for values corresponding to constructs that are implicitly or explicitly declared, false otherwise.

Returns:boolean

true for EXPLICIT and MANDATED, false otherwise.

valueOfback to summary
public static Elements.Origin valueOf(String name)
valuesback to summary
public static Elements.Origin[] values()