Package ball.annotation.processing
Class JavaxLangModelUtilities
- java.lang.Object
-
- ball.annotation.processing.JavaxLangModelUtilities
-
- Direct Known Subclasses:
AbstractProcessor
public abstract class JavaxLangModelUtilities extends Object
Utility methods forProcessorandTagletimplementations.- Author:
- Allen D. Ball
-
-
Field Summary
Fields Modifier and Type Field Description protected Elementselementsprotected JavaFileManagerfmJavacTaskJavaFileManagerinstance.protected Typestypes
-
Constructor Summary
Constructors Constructor Description JavaxLangModelUtilities()
-
Method Summary
-
-
-
Field Detail
-
fm
protected JavaFileManager fm
JavacTaskJavaFileManagerinstance.
-
-
Constructor Detail
-
JavaxLangModelUtilities
public JavaxLangModelUtilities()
-
-
Method Detail
-
getClassLoader
protected ClassLoader getClassLoader()
Method to get theClassLoaderfor loading dependencies.- Returns:
- The
ClassLoader.
-
isGenerated
protected boolean isGenerated(Element element)
-
asClass
protected Class<?> asClass(TypeElement element)
Method to get theClasscorresponding to aTypeElement.- Parameters:
element- TheTypeElement.- Returns:
- The
Classfor theTypeElement.
-
asPackageInfoClass
protected Class<?> asPackageInfoClass(PackageElement element)
- Parameters:
element- ThePackageElement.- Returns:
- The
Classfor thePackageElementpackage-info.class.
-
asTypeElement
protected TypeElement asTypeElement(Class<?> type)
Method to get aTypeElementfor aClass.- Parameters:
type- TheClass.- Returns:
- The
TypeElementfor theClass.
-
asExecutableElement
protected ExecutableElement asExecutableElement(Constructor<?> constructor)
Method to get aExecutableElementfor aConstructor.- Parameters:
constructor- TheConstructor.- Returns:
- The
ExecutableElementfor theConstructor.
-
asExecutableElement
protected ExecutableElement asExecutableElement(Method method)
Method to get aExecutableElementfor aMethod.- Parameters:
method- TheMethod.- Returns:
- The
ExecutableElementfor theMethod.
-
asVariableElement
protected VariableElement asVariableElement(Field field)
Method to get aVariableElementfor aField.- Parameters:
field- TheField.- Returns:
- The
VariableElementfor theField.
-
asTypeMirror
protected TypeMirror asTypeMirror(Class<?> type)
Method to get aTypeMirrorfor aClass.- Parameters:
type- TheClass.- Returns:
- The
TypeMirrorfor theClass.
-
asTypeMirrorList
protected List<TypeMirror> asTypeMirrorList(Class<?>... types)
- Parameters:
types- The array ofClasses.- Returns:
- The
ListofTypeMirrors.
-
getEnclosingTypeElement
protected TypeElement getEnclosingTypeElement(Element element)
Method to get the enclosingTypeElementfor anElement.- Parameters:
element- TheElement.- Returns:
- The enclosing
TypeElement.
-
getTypeElementFor
protected TypeElement getTypeElementFor(Element context, String name)
Method to get theTypeElementfor a contextElement.- Parameters:
context- The contextElement.name- The name of theElement(Class).- Returns:
- The context's
TypeElement.
-
getConstructor
protected ExecutableElement getConstructor(TypeElement type, List<TypeMirror> parameters)
- Parameters:
type- TheTypeElement.parameters- The constructor parameter types.- Returns:
- The
ExecutableElementfor the constructor.
-
getMethod
protected ExecutableElement getMethod(TypeElement type, Method method)
Method to get anExecutableElementfor aMethodprototype.- Parameters:
type- TheTypeElement.method- The prototypeMethod.- Returns:
- The
ExecutableElementfor the method.
-
overrides
protected ExecutableElement overrides(ExecutableElement overrider)
- Parameters:
overrider- TheExecutableElement.- Returns:
- The overridden
ExecutableElementif any;nullotherwise. - See Also:
Elements.overrides(ExecutableElement,ExecutableElement,TypeElement)
-
overrides
protected boolean overrides(ExecutableElement overrider, ExecutableElement overridden)
- Parameters:
overrider- The (possibly) overridingExecutableElement.overridden- The overriddenExecutableElement.- Returns:
trueifoverrideroverridesoverridden;falseotherwise.- See Also:
Elements.overrides(ExecutableElement,ExecutableElement,TypeElement)
-
implementationOf
protected ExecutableElement implementationOf(ExecutableElement overridden, TypeElement type)
Method to return theExecutableElement(Method) the argumentExecutableElementis overriden by (if any).- Parameters:
overridden- TheExecutableElement.type- TheTypeElement.- Returns:
- The overriding
ExecutableElementif any;nullotherwise. - See Also:
overrides(ExecutableElement)
-
specifiedBy
protected ExecutableElement specifiedBy(ExecutableElement method)
Method to return theExecutableElement(Method) the argumentExecutableElementis specified by (if any).- Parameters:
method- TheExecutableElement.- Returns:
- The specification
ExecutableElementif any;nullotherwise. - See Also:
overrides(ExecutableElement)
-
signature
protected String signature(Executable executable)
Method to generate the application signature of anExecutable.- Parameters:
executable- TheExecutable.- Returns:
- The signature
String.
-
signature
protected String signature(ExecutableElement element)
Method to generate the application signature of anExecutableElement.- Parameters:
element- TheExecutableElement.- Returns:
- The signature
String.
-
getAnnotationMirror
protected AnnotationMirror getAnnotationMirror(Element element, Class<? extends Annotation> type)
Method to get anElement'sAnnotationMirror.- Parameters:
element- The annotatedElement.type- TheAnnotationtype (Class).- Returns:
- The
AnnotationMirrorif theElementis annotated with the argument annotation;nullotherwise. - See Also:
Element.getAnnotationMirrors()
-
getAnnotationMirror
protected AnnotationMirror getAnnotationMirror(Element element, TypeElement type)
Method to get anElement'sAnnotationMirror.- Parameters:
element- The annotatedElement.type- TheAnnotationtype (TypeElement).- Returns:
- The
AnnotationMirrorif theElementis annotated with the argument annotation;nullotherwise. - See Also:
Element.getAnnotationMirrors()
-
getAnnotationValue
protected AnnotationValue getAnnotationValue(AnnotationMirror annotation, String name)
Method to get anAnnotationMirrorelement'sAnnotationValue.- Parameters:
annotation- TheAnnotationMirror.name- The simple name of the element.- Returns:
- The
AnnotationValueif it is defined;nullotherwise. - See Also:
Elements.getElementValuesWithDefaults(AnnotationMirror)
-
isEmptyArray
protected boolean isEmptyArray(AnnotationValue value)
Method to determine if anAnnotationValueis "empty":nullor an empty array.- Parameters:
value- TheAnnotationValue.- Returns:
trueif empty; {code false} otherwise.
-
getPropertyName
protected String getPropertyName(ExecutableElement element)
Method to get bean property name from anExecutableElement.- Parameters:
element- TheExecutableElement.- Returns:
- the name
Stringif theExecutableElementis a getter or setter method;nullotherwise.
-
isGetterMethod
protected boolean isGetterMethod(ExecutableElement element)
Method to determine if anExecutableElementis a bean getter.- Parameters:
element- TheExecutableElement.- Returns:
trueif theElementhas a non-private getter method;falseotherwise.
-
getPropertyNames
protected Set<String> getPropertyNames(TypeElement type)
Method to get theSetof bean property names for the specifiedTypeElement.- Parameters:
type- TheTypeElementto analyze.- Returns:
- The
Setof bean property names.
-
hasSameSignatureAs
protected Predicate<Element> hasSameSignatureAs(List<TypeMirror> parameters)
-
hasSameSignatureAs
protected Predicate<Element> hasSameSignatureAs(Executable executable)
-
hasSameSignatureAs
protected Predicate<Element> hasSameSignatureAs(CharSequence name, Class<?>[] parameters)
-
isAssignableTo
protected Predicate<Element> isAssignableTo(Class<?> type)
-
isAssignableTo
protected Predicate<Element> isAssignableTo(TypeMirror type)
-
isAssignableTo
protected Predicate<Element> isAssignableTo(Class<?> type, Function<? super Element,TypeMirror> extractor)
-
isAssignableTo
protected Predicate<Element> isAssignableTo(TypeMirror type, Function<? super Element,TypeMirror> extractor)
-
named
protected Predicate<Element> named(CharSequence name)
-
withParameters
protected Predicate<Element> withParameters(Class<?>[] parameters)
-
withParameters
protected Predicate<Element> withParameters(List<TypeMirror> parameters)
-
withModifiers
protected Predicate<Element> withModifiers(Modifier... modifiers)
-
withModifiers
protected Predicate<Element> withModifiers(Set<Modifier> modifiers)
-
withoutModifiers
protected Predicate<Element> withoutModifiers(Modifier... modifiers)
-
withoutModifiers
protected Predicate<Element> withoutModifiers(Set<Modifier> modifiers)
-
without
protected <E> Predicate<Element> without(Set<E> set, Function<Element,Collection<E>> extractor)
-
getClassPathClassLoader
protected ClassLoader getClassPathClassLoader(JavaFileManager fm, ClassLoader parent)
- Parameters:
fm- TheJavaFileManager.parent- The parentClassLoader.- Returns:
- The
ClassLoader.
-
getClassPathClassLoader
protected ClassLoader getClassPathClassLoader(JavaFileManager fm)
- Parameters:
fm- TheJavaFileManager.- Returns:
- The
ClassLoader.
-
toModifiers
public static int toModifiers(Set<Modifier> set)
- Parameters:
set- TheModifiers.- Returns:
- The flags.
-
-