public class JavaModelAnalyzerUtil
extends java.lang.Object
| Constructor and Description |
|---|
JavaModelAnalyzerUtil(javax.lang.model.util.Elements elements,
javax.lang.model.util.Types types) |
| Modifier and Type | Method and Description |
|---|---|
java.util.Collection<? extends javax.lang.model.element.Element> |
findAnnotatedElements(java.util.Collection<javax.lang.model.element.TypeElement> typeElements,
java.lang.Class<?> annotationType) |
java.lang.String |
getClassname(javax.lang.model.element.TypeElement typeElem)
Returns the classname (without any package qualifier) of the given type element.
|
javax.lang.model.element.TypeElement |
getCompilationUnit(javax.lang.model.element.Element elem)
Returns the top-level Java class that contains the given element.
|
java.lang.String |
getPackage(javax.lang.model.type.DeclaredType type)
Returns the Java package the given type (or it's outer type) belongs to.
|
java.lang.String |
getPackage(javax.lang.model.element.TypeElement typeElem)
Returns the Java package the given type element (or it's outer type) belongs to.
|
javax.lang.model.type.PrimitiveType |
getPrimitiveBooleanType() |
java.lang.String |
getPropertyName(javax.lang.model.element.ExecutableElement methodEl)
Returns the name of the property that is accessed by the given [G|S]etter method.
|
javax.lang.model.type.TypeMirror |
getType(javax.lang.model.type.DeclaredType ownerType,
javax.lang.model.element.Element element)
Returns the effective type of the given element when is is viewed as a member of the given
owner type.
|
javax.lang.model.type.NoType |
getVoidType() |
boolean |
hasBuildMethod(javax.lang.model.element.TypeElement typeElement,
javax.lang.model.type.TypeMirror requiredReturnType)
Returns true, if the given type element has a method called "build" with no parameters and
which has an actual return type that is compatible with the given return type.
|
boolean |
hasMethod(javax.lang.model.element.TypeElement typeElement,
java.lang.String name,
javax.lang.model.type.TypeMirror requiredReturnType,
javax.lang.model.type.TypeMirror requiredParamType)
Returns true, if the given type element has a method with the given name and has an actual
return type that is compatible with the given return type, and has an actual parameter that is
compatible with the given parameter type.
|
boolean |
hasPublicNoArgsConstructor(javax.lang.model.element.TypeElement typeEl)
Returns true if the given type element defines a public no-args constructor.
|
boolean |
isAccessibleForBuilder(javax.lang.model.element.Element el,
BuilderM builderM)
Returns true if the given element is accessible for the given builder.
|
boolean |
isDeclaredInObject(javax.lang.model.element.Element el)
Returns whether the given element is directly declared in
Object. |
boolean |
isGetterMethod(javax.lang.model.element.ExecutableElement el)
Returns true if the given element is a Getter-method.
|
boolean |
isSetterMethod(javax.lang.model.element.ExecutableElement el)
Returns true if the given element is a Setter-method.
|
boolean |
isStatic(javax.lang.model.element.Element el)
Returns true if the given element is marked with a 'static' modifier.
|
boolean |
isUpperBoundToObject(javax.lang.model.element.TypeParameterElement typeParamEl)
Returns true if the given type parameter has an upper bound of type
Object. |
boolean |
isValidJavaIdentifier(java.lang.String string)
Returns
true if the given string is a valid Java identifier. |
boolean |
isValidJavaPackageName(java.lang.String string)
Returns
true if the given string is a valid Java package name. |
boolean |
matchesUpperBound(javax.lang.model.element.TypeElement typeElement,
javax.lang.model.element.TypeParameterElement typeParamEl)
Returns true if the given typeElement is a subtype of the given type parameter's upper bound.
|
static java.lang.String |
uncapitalize(java.lang.String str) |
public JavaModelAnalyzerUtil(javax.lang.model.util.Elements elements,
javax.lang.model.util.Types types)
public javax.lang.model.type.PrimitiveType getPrimitiveBooleanType()
public javax.lang.model.type.NoType getVoidType()
public java.lang.String getClassname(javax.lang.model.element.TypeElement typeElem)
typeElem - the type elementpublic java.lang.String getPackage(javax.lang.model.type.DeclaredType type)
type - the typepublic java.lang.String getPackage(javax.lang.model.element.TypeElement typeElem)
typeElem - the type elementpublic javax.lang.model.element.TypeElement getCompilationUnit(javax.lang.model.element.Element elem)
elem - the elementpublic boolean isAccessibleForBuilder(javax.lang.model.element.Element el,
BuilderM builderM)
el - the elementbuilderM - the builderpublic boolean isStatic(javax.lang.model.element.Element el)
el - the elementpublic boolean isSetterMethod(javax.lang.model.element.ExecutableElement el)
el - the elementpublic boolean isGetterMethod(javax.lang.model.element.ExecutableElement el)
el - the elementpublic boolean isDeclaredInObject(javax.lang.model.element.Element el)
Object.el - the elementObjectpublic java.lang.String getPropertyName(javax.lang.model.element.ExecutableElement methodEl)
methodEl - the method elementpublic javax.lang.model.type.TypeMirror getType(javax.lang.model.type.DeclaredType ownerType,
javax.lang.model.element.Element element)
ownerType - the owner typeelement - the elementpublic boolean hasBuildMethod(javax.lang.model.element.TypeElement typeElement,
javax.lang.model.type.TypeMirror requiredReturnType)
typeElement - the type elementrequiredReturnType - the required return type (maybe NoType)public boolean hasMethod(javax.lang.model.element.TypeElement typeElement,
java.lang.String name,
javax.lang.model.type.TypeMirror requiredReturnType,
javax.lang.model.type.TypeMirror requiredParamType)
typeElement - the type elementname - the required name of the methodrequiredReturnType - the required return type (maybe NoType).requiredParamType - the type of the required (first) parameter, or null if no
parameter is requiredpublic boolean hasPublicNoArgsConstructor(javax.lang.model.element.TypeElement typeEl)
typeEl - public boolean matchesUpperBound(javax.lang.model.element.TypeElement typeElement,
javax.lang.model.element.TypeParameterElement typeParamEl)
typeElement - the type elementtypeParamEl - the type parameter elementpublic boolean isUpperBoundToObject(javax.lang.model.element.TypeParameterElement typeParamEl)
Object.typeParamEl - the type parameterObjectpublic boolean isValidJavaIdentifier(java.lang.String string)
true if the given string is a valid Java identifier.string - the stringtrue if the given string is a valid Java identifierpublic boolean isValidJavaPackageName(java.lang.String string)
true if the given string is a valid Java package name.
This does not check if the package exists.
string - the stringtrue if the given string is a valid Java package name.public java.util.Collection<? extends javax.lang.model.element.Element> findAnnotatedElements(java.util.Collection<javax.lang.model.element.TypeElement> typeElements,
java.lang.Class<?> annotationType)
public static java.lang.String uncapitalize(java.lang.String str)