public final class ElementHelper
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
private |
ElementHelper()
Disable instantiation.
|
Modifier and Type | Method and Description |
---|---|
static java.util.Collection<javax.lang.model.element.ExecutableElement> |
findByName(java.util.Collection<javax.lang.model.element.ExecutableElement> methods,
javax.lang.model.element.Name methodName)
Returns a collection of methods with the same name.
|
static java.util.Collection<javax.lang.model.element.ExecutableElement> |
findByName(java.util.Collection<javax.lang.model.element.ExecutableElement> methods,
javax.lang.model.element.Name methodName,
int paramCount)
Returns a collection of methods with the same name.
|
static javax.lang.model.element.Element |
fromMessageObject(MessageObject object)
If the
MessageObject.reference() is an instance of Element , then the value is returned, otherwise null is returned. |
static javax.lang.model.element.TypeElement |
getClassAnnotationValue(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Retrieves the first attribute value from the annotation and assumes it's a
class type. |
static javax.lang.model.element.TypeElement |
getClassAnnotationValue(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.String attributeName)
Retrieves the attribute value from the annotation and assumes it's a
class type. |
static java.util.List<javax.lang.model.element.TypeElement> |
getClassArrayAnnotationValue(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.String attributeName)
Retrieves the attribute value from the annotation and assumes it's an array
classes . |
static java.lang.String |
getPrimaryClassNamePrefix(javax.lang.model.element.TypeElement element)
Returns the primary class simple name prefix for an element
who represents a MessageBundle or MessageLogger interface.
|
static boolean |
hasCause(java.util.Collection<? extends javax.lang.model.element.VariableElement> params)
Checks to see if there is a cause parameter.
|
static boolean |
inheritsMessage(java.util.Collection<javax.lang.model.element.ExecutableElement> methods,
javax.lang.model.element.ExecutableElement method)
Checks to see if the method has or inherits a
Message
annotation. |
static boolean |
isAnnotatedWith(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Check if an element is annotated with the given annotation.
|
static boolean |
isOverloaded(java.util.Collection<javax.lang.model.element.ExecutableElement> methods,
javax.lang.model.element.ExecutableElement method)
Checks to see if the method is overloaded.
|
static int |
parameterCount(java.util.Collection<? extends javax.lang.model.element.VariableElement> params)
|
static java.lang.String |
typeToString(java.lang.Class<?> type)
Converts a class type to a string recognizable by the
Elements.getTypeElement(CharSequence) . |
static java.lang.String |
typeToString(java.lang.String qualifiedType)
Converts a qualified type name to a string recognizable by the
Elements.getTypeElement(CharSequence) . |
public static boolean isAnnotatedWith(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
element
- the element to look for the annotation on.clazz
- the annotation classtrue
if the element is annotated, otherwise false
java.lang.IllegalArgumentException
- if element parameter is nullpublic static java.lang.String getPrimaryClassNamePrefix(javax.lang.model.element.TypeElement element)
element
- the elementjava.lang.IllegalArgumentException
- if element is null or the element is not an interfacepublic static java.util.Collection<javax.lang.model.element.ExecutableElement> findByName(java.util.Collection<javax.lang.model.element.ExecutableElement> methods, javax.lang.model.element.Name methodName)
methods
- the methods to process.methodName
- the method name to find.public static java.util.Collection<javax.lang.model.element.ExecutableElement> findByName(java.util.Collection<javax.lang.model.element.ExecutableElement> methods, javax.lang.model.element.Name methodName, int paramCount)
methods
- the methods to process.methodName
- the method name to find.paramCount
- the number of parameters the method must have.public static boolean hasCause(java.util.Collection<? extends javax.lang.model.element.VariableElement> params)
params
- the parameters to check.true
if there is a cause, otherwise false
.public static int parameterCount(java.util.Collection<? extends javax.lang.model.element.VariableElement> params)
params
- the parameters to get the count for.public static boolean inheritsMessage(java.util.Collection<javax.lang.model.element.ExecutableElement> methods, javax.lang.model.element.ExecutableElement method)
Message
annotation.methods
- the method to search.method
- the method to check.true
if the method has or inherits a message annotation, otherwise false
.public static boolean isOverloaded(java.util.Collection<javax.lang.model.element.ExecutableElement> methods, javax.lang.model.element.ExecutableElement method)
Cause
or
Param
are not counted.methods
- the method to search.method
- the method to check.true
if the method is overloaded, otherwise false
.public static java.lang.String typeToString(java.lang.Class<?> type)
Elements.getTypeElement(CharSequence)
. Essentially replaces any $'s to
. (dots).type
- the type to convert.public static java.lang.String typeToString(java.lang.String qualifiedType)
Elements.getTypeElement(CharSequence)
. Essentially replaces any $'s to
. (dots).qualifiedType
- the qualified type name.public static javax.lang.model.element.Element fromMessageObject(MessageObject object)
MessageObject.reference()
is an instance of Element
, then the value is returned, otherwise null
is returned.object
- the object to check the reference onnull
public static javax.lang.model.element.TypeElement getClassAnnotationValue(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
class
type.element
- the element the annotation is onannotation
- the annotation to get the value fromTypeElement
representing the value for the first annotation attribute or null
if no
attributes were foundpublic static javax.lang.model.element.TypeElement getClassAnnotationValue(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.String attributeName)
class
type.element
- the element the annotation is onannotation
- the annotation to get the value fromattributeName
- the name of the attribute to retrieve the class value forTypeElement
representing the value for the annotation attribute or null
if the
attribute was not foundpublic static java.util.List<javax.lang.model.element.TypeElement> getClassArrayAnnotationValue(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.String attributeName)
classes
.element
- the element the annotation is onannotation
- the annotation to get the value fromattributeName
- the name of the attribute to retrieve the class value array forTypeElement
representing the value for the annotation attribute or an empty list