public class ElementUtils extends Object
Element
s.Modifier and Type | Method and Description |
---|---|
static TypeElement |
enclosingClass(Element elem)
Returns the innermost type element enclosing the given element
|
static PackageElement |
enclosingPackage(Element elem)
Returns the innermost package element enclosing the given element.
|
static VariableElement |
findFieldInType(TypeElement type,
String name)
Returns the field of the class
|
static Set<VariableElement> |
findFieldsInType(TypeElement type,
Collection<String> names) |
static List<VariableElement> |
getAllFieldsIn(TypeElement type)
Return all fields declared in the given type or any superclass/interface.
|
static List<ExecutableElement> |
getAllMethodsIn(TypeElement type)
Return all methods declared in the given type or any superclass/interface.
|
static @Nullable Name |
getQualifiedClassName(Element element)
Returns the qualified name of the inner most class enclosing
the provided
Element |
static List<TypeElement> |
getSuperTypes(TypeElement type)
Determine all type elements for the classes and interfaces referenced
in the extends/implements clauses of the given type element.
|
static TypeMirror |
getType(Element element)
Returns the
TypeMirror for usage of Element as a value. |
static String |
getVerboseName(Element elt)
Returns a verbose name that identifies the element.
|
static boolean |
hasReceiver(Element element)
Does the given element need a receiver for accesses?
For example, an access to a local variable does not require a receiver.
|
static boolean |
isCompileTimeConstant(Element elt)
Returns true if the element is a constant time reference
|
static boolean |
isEffectivelyFinal(Element element)
Returns true if the element is a effectively final element.
|
static boolean |
isElementFromByteCode(Element elt)
Returns true if the element is declared in ByteCode.
|
static boolean |
isError(Element element) |
static boolean |
isFinal(Element element)
Returns true if the element is a final element: a final field, final
method, or final class
|
static boolean |
isObject(TypeElement element)
Check if the element is an element for 'java.lang.Object'
|
static boolean |
isStatic(Element element)
Returns true if the element is a static element: whether it is a static
field, static method, or static class
|
static boolean |
isTypeDeclaration(Element elt) |
static boolean |
matchesElement(ExecutableElement method,
String methodName,
Class<?>... parameters)
Check that a method Element matches a signature.
|
static PackageElement |
parentPackage(Elements e,
PackageElement elem)
Returns the "parent" package element for the given package element.
|
public static TypeElement enclosingClass(Element elem)
elem
- the enclosed element of a classpublic static PackageElement enclosingPackage(Element elem)
Elements.getPackageOf(Element)
.
Returns the element itself if it is a package.elem
- the enclosed element of a packagepublic static PackageElement parentPackage(Elements e, PackageElement elem)
elem
- the package to start frompublic static boolean isStatic(Element element)
public static boolean isFinal(Element element)
public static boolean isEffectivelyFinal(Element element)
public static TypeMirror getType(Element element)
TypeMirror
for usage of Element as a value. It
returns the return type of a method element, the class type of a
constructor, or simply the type mirror of the element itself.public static @Nullable Name getQualifiedClassName(Element element)
Element
element
- an element enclosed by a class, or a
TypeElement
Name
of the innermost class
enclosing the elementpublic static String getVerboseName(Element elt)
public static boolean isObject(TypeElement element)
element
- the type elementpublic static boolean isCompileTimeConstant(Element elt)
public static boolean isElementFromByteCode(Element elt)
public static VariableElement findFieldInType(TypeElement type, String name)
public static Set<VariableElement> findFieldsInType(TypeElement type, Collection<String> names)
public static boolean isError(Element element)
public static boolean hasReceiver(Element element)
element
- The element to test.public static List<TypeElement> getSuperTypes(TypeElement type)
public static List<VariableElement> getAllFieldsIn(TypeElement type)
public static List<ExecutableElement> getAllMethodsIn(TypeElement type)
public static boolean isTypeDeclaration(Element elt)
public static boolean matchesElement(ExecutableElement method, String methodName, Class<?>... parameters)
method
- the method ElementmethodName
- the name of the methodparameters
- the formal parameters' Classes