JBoss Logging I18n Annotation Processor 1.1.0.Beta1

org.jboss.logging.processor.util
Class ElementHelper

java.lang.Object
  extended by org.jboss.logging.processor.util.ElementHelper

public final class ElementHelper
extends Object

An utility class to work with element.

Author:
Kevin Pollet - SERLI - (kevin.pollet@serli.com), James R. Perkins

Method Summary
static Collection<ExecutableElement> findByName(Collection<ExecutableElement> methods, Name methodName)
          Returns a collection of methods with the same name.
static Collection<ExecutableElement> findByName(Collection<ExecutableElement> methods, Name methodName, int paramCount)
          Returns a collection of methods with the same name.
static Element fromMessageObject(MessageObject object)
          If the MessageObject.reference() is an instance of Element, then the value is returned, otherwise null is returned.
static String getPrimaryClassNamePrefix(TypeElement element)
          Returns the primary class simple name prefix for an element who represents a MessageBundle or MessageLogger interface.
static boolean hasCause(Collection<? extends VariableElement> params)
          Checks to see if there is a cause parameter.
static boolean inheritsMessage(Collection<ExecutableElement> methods, ExecutableElement method)
          Checks to see if the method has or inherits a Message annotation.
static boolean isAnnotatedWith(Element element, Class<? extends Annotation> clazz)
          Check if an element is annotated with the given annotation.
static boolean isAnnotatedWith(Element element, Class<? extends Annotation> clazz1, Class<? extends Annotation> clazz2)
          Checks if an element is annotated with either of the given annotations.
static boolean isAssignableFrom(Class<?> type, TypeElement typeElement)
          Checks to see if the type is assignable from the type element.
static boolean isAssignableFrom(Class<?> type, TypeMirror typeMirror)
          Checks to see if the type is assignable from the type mirror.
static boolean isAssignableFrom(TypeElement typeElement, Class<?> type)
          Checks to see if the type element is assignable from the type.
static boolean isAssignableFrom(TypeMirror typeMirror, Class<?> type)
          Checks to see id the type mirror is assignable from the type.
static boolean isOverloaded(Collection<ExecutableElement> methods, ExecutableElement method)
          Checks to see if the method is overloaded.
static int parameterCount(Collection<? extends VariableElement> params)
          Returns the number of parameters excluding the Cause parameter and any Param parameters if found.
static String typeToString(Class<?> type)
          Converts a class type to a string recognizable by the Elements.getTypeElement(CharSequence).
static String typeToString(String qualifiedType)
          Converts a qualified type name to a string recognizable by the Elements.getTypeElement(CharSequence).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isAnnotatedWith

public static boolean isAnnotatedWith(Element element,
                                      Class<? extends Annotation> clazz)
Check if an element is annotated with the given annotation.

Parameters:
element - the element to look for the annotation on.
clazz - the annotation class
Returns:
true if the element is annotated, otherwise false
Throws:
IllegalArgumentException - if element parameter is null

isAnnotatedWith

public static boolean isAnnotatedWith(Element element,
                                      Class<? extends Annotation> clazz1,
                                      Class<? extends Annotation> clazz2)
Checks if an element is annotated with either of the given annotations.

Parameters:
element - the element to look for the annotation on.
clazz1 - the first class to check
clazz2 - the second class to check
Returns:
true if any of the annotations are found on the element, otherwise false
Throws:
IllegalArgumentException - if element parameter is null

getPrimaryClassNamePrefix

public static String getPrimaryClassNamePrefix(TypeElement element)
Returns the primary class simple name prefix for an element who represents a MessageBundle or MessageLogger interface.

Parameters:
element - the element
Returns:
the translation file name prefix
Throws:
IllegalArgumentException - if element is null or the element is not an interface

findByName

public static Collection<ExecutableElement> findByName(Collection<ExecutableElement> methods,
                                                       Name methodName)
Returns a collection of methods with the same name.

Parameters:
methods - the methods to process.
methodName - the method name to find.
Returns:
a collection of methods with the same name.

findByName

public static Collection<ExecutableElement> findByName(Collection<ExecutableElement> methods,
                                                       Name methodName,
                                                       int paramCount)
Returns a collection of methods with the same name.

Parameters:
methods - the methods to process.
methodName - the method name to find.
paramCount - the number of parameters the method must have.
Returns:
a collection of methods with the same name.

hasCause

public static boolean hasCause(Collection<? extends VariableElement> params)
Checks to see if there is a cause parameter.

Parameters:
params - the parameters to check.
Returns:
true if there is a cause, otherwise false.

parameterCount

public static int parameterCount(Collection<? extends VariableElement> params)
Returns the number of parameters excluding the Cause parameter and any Param parameters if found.

Parameters:
params - the parameters to get the count for.
Returns:
the number of parameters.

inheritsMessage

public static boolean inheritsMessage(Collection<ExecutableElement> methods,
                                      ExecutableElement method)
Checks to see if the method has or inherits a Message annotation.

Parameters:
methods - the method to search.
method - the method to check.
Returns:
true if the method has or inherits a message annotation, otherwise false.

isOverloaded

public static boolean isOverloaded(Collection<ExecutableElement> methods,
                                   ExecutableElement method)
Checks to see if the method is overloaded. An overloaded method has a different parameter count based on the format parameters only. Parameters annotated with Cause or Param are not counted.

Parameters:
methods - the method to search.
method - the method to check.
Returns:
true if the method is overloaded, otherwise false.

isAssignableFrom

public static boolean isAssignableFrom(TypeElement typeElement,
                                       Class<?> type)
Checks to see if the type element is assignable from the type.

Parameters:
typeElement - the type element to check.
type - the type to check.
Returns:
true if the type element is assignable from the type, otherwise false.

isAssignableFrom

public static boolean isAssignableFrom(TypeMirror typeMirror,
                                       Class<?> type)
Checks to see id the type mirror is assignable from the type.

Parameters:
typeMirror - the type mirror to check.
type - the type to check.
Returns:
true if the type mirror is assignable from the type, otherwise false.

isAssignableFrom

public static boolean isAssignableFrom(Class<?> type,
                                       TypeElement typeElement)
Checks to see if the type is assignable from the type element.

Parameters:
type - the type to check.
typeElement - the type element to check.
Returns:
true if the type is assignable from the type element, otherwise false.

isAssignableFrom

public static boolean isAssignableFrom(Class<?> type,
                                       TypeMirror typeMirror)
Checks to see if the type is assignable from the type mirror.

Parameters:
type - the type to check.
typeMirror - the type mirror to check.
Returns:
true if the type is assignable from the type mirror, otherwise false.

typeToString

public static String typeToString(Class<?> type)
Converts a class type to a string recognizable by the Elements.getTypeElement(CharSequence). Essentially replaces any $'s to . (dots).

Parameters:
type - the type to convert.
Returns:
the qualified name of the type.

typeToString

public static String typeToString(String qualifiedType)
Converts a qualified type name to a string recognizable by the Elements.getTypeElement(CharSequence). Essentially replaces any $'s to . (dots).

Parameters:
qualifiedType - the qualified type name.
Returns:
the qualified name of the type.

fromMessageObject

public static Element fromMessageObject(MessageObject object)
If the MessageObject.reference() is an instance of Element, then the value is returned, otherwise null is returned.

Parameters:
object - the object to check the reference on
Returns:
the element reference or null

JBoss Logging I18n Annotation Processor 1.1.0.Beta1

Copyright © 2012 JBoss by Red Hat. All Rights Reserved.