JBoss Logging I18n Tools 1.0.0.Beta7

org.jboss.logging.util
Class ElementHelper

java.lang.Object
  extended by org.jboss.logging.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, int paramCount)
          Returns a collection of methods with the same name.
static Map<String,String> getAllMessageMethods(Collection<ExecutableElement> methods)
          Returns a collection of all Message methods.
static Collection<ExecutableElement> getInterfaceMethods(TypeElement element, Types types)
          Returns all methods of the given interface.
static String getPrimaryClassName(TypeElement element)
          Returns the primary class simple name for an element who represents a MessageBundle or MessageLogger interface.
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 hasOrInheritsMessage(TypeElement root, ExecutableElement method, Types types)
          Checks to see if the method has or inherits a Annotations.message() annotation.
static boolean isAnnotatedWith(Element element, Class<? extends Annotation> clazz)
          Check if an element is annotated with the given annotation.
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 isOverloadedMethod(Collection<ExecutableElement> methods, ExecutableElement method)
          Checks to see if there is a cause parameter.
static int parameterCount(Collection<? extends VariableElement> params)
          Returns the number of parameters excluding the Annotations.cause() parameter if found.
 
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, false otherwise
Throws:
NullPointerException - if element parameter is null

getPrimaryClassName

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

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

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:
NullPointerException - if element is null
IllegalArgumentException - if element is not an interface

getInterfaceMethods

public static Collection<ExecutableElement> getInterfaceMethods(TypeElement element,
                                                                Types types)
Returns all methods of the given interface. Include all declared and inherited methods, with the exception of any methods in the Loggers.basicLoggerClass() interface.

Parameters:
element - the interface element
types - the type util
Returns:
the collection of all methods
Throws:
IllegalArgumentException - if element is not an interface

getAllMessageMethods

public static Map<String,String> getAllMessageMethods(Collection<ExecutableElement> methods)
Returns a collection of all Message methods. A message method is annotated with Annotations.message().

The key returned is comprised of the method name and the number of parameters of the method if the method is overloaded. Otherwise the method name is the key.

Parameters:
methods - the methods collection
Returns:
a map containing the message where the key is the method 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.

isOverloadedMethod

public static boolean isOverloadedMethod(Collection<ExecutableElement> methods,
                                         ExecutableElement method)
Checks to see if there is a cause parameter.

Parameters:
methods - a collections of methods to check.
method - the method to check.
Returns:
true if there is a cause, otherwise false.

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 Annotations.cause() parameter if found.

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

hasOrInheritsMessage

public static boolean hasOrInheritsMessage(TypeElement root,
                                           ExecutableElement method,
                                           Types types)
Checks to see if the method has or inherits a Annotations.message() annotation.

Parameters:
root - the interface, root element.
method - the method to check.
types - the type util
Returns:
true if the method has or inherits a message annotation, 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.

JBoss Logging I18n Tools 1.0.0.Beta7

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.