-
public interface Elements
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:
ProcessingEnvironment.getElementUtils()
-
-
Method Summary
Methods Modifier and Type Method and Description List<? extends AnnotationMirror>
getAllAnnotationMirrors(Element e)
Returns all annotations of an element, whether inherited or directly present.List<? extends Element>
getAllMembers(TypeElement type)
Returns all members of a type element, whether inherited or declared directly.Name
getBinaryName(TypeElement type)
Returns the binary name of a type element.String
getConstantExpression(Object value)
Returns the text of a constant expression representing a primitive value or a string.String
getDocComment(Element e)
Returns the text of the documentation ("Javadoc") comment of an element.Map<? extends ExecutableElement,? extends AnnotationValue>
getElementValuesWithDefaults(AnnotationMirror a)
Returns the values of an annotation's elements, including defaults.Name
getName(CharSequence cs)
Return a name with the same sequence of characters as the argument.PackageElement
getPackageElement(CharSequence name)
Returns a package given its fully qualified name.PackageElement
getPackageOf(Element type)
Returns the package of an element.TypeElement
getTypeElement(CharSequence name)
Returns a type element given its canonical name.boolean
hides(Element hider, Element hidden)
Tests whether one type, method, or field hides another.boolean
isDeprecated(Element e)
Returnstrue
if the element is deprecated,false
otherwise.boolean
overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type)
Tests whether one method, as a member of a given type, overrides another method.void
printElements(Writer w, Element... elements)
Prints a representation of the elements to the given writer in the specified order.
-
-
-
Method Detail
-
getPackageElement
PackageElement getPackageElement(CharSequence name)
Returns a package given its fully qualified name.- Parameters:
name
- fully qualified package name, or "" for an unnamed package- Returns:
- the named package, or
null
if it cannot be found
-
getTypeElement
TypeElement getTypeElement(CharSequence name)
Returns a type element given its canonical name.- Parameters:
name
- the canonical name- Returns:
- the named type element, or
null
if it cannot be found
-
getElementValuesWithDefaults
Map<? extends ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror a)
Returns the values of an annotation's elements, including defaults.- Parameters:
a
- annotation to examine- Returns:
- the values of the annotation's elements, including defaults
- See Also:
AnnotationMirror.getElementValues()
-
getDocComment
String getDocComment(Element e)
Returns the text of the documentation ("Javadoc") comment of an element.A documentation comment of an element is a comment that begins with "
/**
" , ends with a separate "*/
", and immediately precedes the element, ignoring white space. Therefore, a documentation comment contains at least three"*
" characters. The text returned for the documentation comment is a processed form of the comment as it appears in source code. The leading "/**
" and trailing "*/
" are removed. For lines of the comment starting after the initial "/**
", leading white space characters are discarded as are any consecutive "*
" characters appearing after the white space or starting the line. The processed lines are then concatenated together (including line terminators) and returned.- Parameters:
e
- the element being examined- Returns:
- the documentation comment of the element, or
null
if there is none - See The Java™ Language Specification:
- 3.6 White Space
-
isDeprecated
boolean isDeprecated(Element e)
Returnstrue
if the element is deprecated,false
otherwise.- Parameters:
e
- the element being examined- Returns:
true
if the element is deprecated,false
otherwise
-
getBinaryName
Name getBinaryName(TypeElement type)
Returns the binary name of a type element.- Parameters:
type
- the type element being examined- Returns:
- the binary name
- See Also:
TypeElement.getQualifiedName()
- See The Java™ Language Specification:
- 13.1 The Form of a Binary
-
getPackageOf
PackageElement getPackageOf(Element type)
Returns the package of an element. The package of a package is itself.- Parameters:
type
- the element being examined- Returns:
- the package of an element
-
getAllMembers
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.Note that elements of certain kinds can be isolated using methods in
ElementFilter
.- Parameters:
type
- the type being examined- Returns:
- all members of the type
- See Also:
Element.getEnclosedElements()
-
getAllAnnotationMirrors
List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e)
Returns all annotations of an element, whether inherited or directly present.- Parameters:
e
- the element being examined- Returns:
- all annotations of the element
- See Also:
Element.getAnnotationMirrors()
-
hides
boolean hides(Element hider, Element hidden)
Tests whether one type, method, or field hides another.- Parameters:
hider
- the first elementhidden
- the second element- Returns:
true
if and only if the first element hides the second
-
overrides
boolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type)
Tests whether one method, as a member of a given type, overrides another method. When a non-abstract method overrides an abstract one, the former is also said to implement the latter.In the simplest and most typical usage, the value of the
type
parameter will simply be the class or interface directly enclosingoverrider
(the possibly-overriding method). For example, supposem1
represents the methodString.hashCode
andm2
representsObject.hashCode
. We can then ask whetherm1
overridesm2
within the classString
(it does):assert elements.overrides(m1, m2, elements.getTypeElement("java.lang.String"));
A
does not override a like-named method in typeB
:class A { public void m() {} }
interface B { void m(); }
...
m1 = ...; // A.m
m2 = ...; // B.m
assert ! elements.overrides(m1, m2, elements.getTypeElement("A"));
C
, however, the method inA
does override the one inB
:class C extends A implements B {}
...
assert elements.overrides(m1, m2, elements.getTypeElement("C"));
- Parameters:
overrider
- the first method, possible overrideroverridden
- the second method, possibly being overriddentype
- the type of which the first method is a member- Returns:
true
if and only if the first method overrides the second- See The Java™ Language Specification:
- 8.4.8 Inheritance, Overriding, and Hiding, 9.4.1 Inheritance and Overriding
-
getConstantExpression
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
- a primitive value or string- Returns:
- the text of a constant expression
- Throws:
IllegalArgumentException
- if the argument is not a primitive value or string- See Also:
VariableElement.getConstantValue()
-
printElements
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
- the writer to print the output toelements
- the elements to print
-
getName
Name getName(CharSequence cs)
Return a name with the same sequence of characters as the argument.- Parameters:
cs
- the character sequence to return as a name
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/lang/model/util/elements.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.