@Internal public class JavaClassElement extends AbstractJavaElement implements ArrayableClassElement
TypeElement
.Modifier and Type | Field and Description |
---|---|
protected TypeElement |
classElement |
protected JavaVisitorContext |
visitorContext |
ZERO_CLASS_ELEMENTS
EMPTY_ELEMENT_ARRAY
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
EMPTY
Constructor and Description |
---|
JavaClassElement(TypeElement classElement,
AnnotationMetadata annotationMetadata,
JavaVisitorContext visitorContext) |
Modifier and Type | Method and Description |
---|---|
Map<String,Map<String,ClassElement>> |
getAllTypeArguments()
Builds a map of all the type parameters for a class, its super classes and interfaces.
|
int |
getArrayDimensions()
If the type is an array, the number of dimensions.
|
List<PropertyElement> |
getBeanProperties()
Returns the bean properties (getters and setters) for this class element.
|
List<ClassElement> |
getBoundGenericTypes()
The list of type arguments bound to this type, or an empty list if there are no type arguments or this is a raw
type.
|
List<? extends GenericPlaceholderElement> |
getDeclaredGenericPlaceholders()
The type arguments declared on the raw class.
|
Optional<MethodElement> |
getDefaultConstructor()
Find and return a single default constructor.
|
<T extends Element> |
getEnclosedElements(ElementQuery<T> query)
Return the elements that match the given query.
|
Optional<ClassElement> |
getEnclosingType()
Returns the enclosing type if
ClassElement.isInner() return true . |
Collection<ClassElement> |
getInterfaces() |
String |
getName() |
PackageElement |
getPackage()
The package name.
|
String |
getPackageName()
The package name.
|
Optional<MethodElement> |
getPrimaryConstructor()
Find and return a single primary constructor.
|
ClassElement |
getRawClassElement()
Get a
ClassElement instance corresponding to this type, but without any type arguments bound. |
String |
getSimpleName()
The simple name without the package name.
|
Optional<ClassElement> |
getSuperType()
Returns the super type of this element or empty if the element has no super type.
|
Map<String,ClassElement> |
getTypeArguments() |
Map<String,ClassElement> |
getTypeArguments(String type)
Get the type arguments for the given type name.
|
boolean |
isAbstract() |
boolean |
isArray()
Is the type an array.
|
boolean |
isAssignable(ClassElement type)
Tests whether one type is assignable to another.
|
boolean |
isAssignable(String type)
Tests whether one type is assignable to another.
|
boolean |
isInner()
Is this type an inner class.
|
boolean |
isInterface() |
boolean |
isPrimitive()
Whether the type is primitive.
|
boolean |
isRecord() |
boolean |
isTypeVariable()
In this case of calling
ClassElement.getTypeArguments() a returned ClassElement may represent a type variable
in which case this method will return true . |
String |
toString() |
ClassElement |
withArrayDimensions(int arrayDimensions)
Convert the class element to an element for the same type, but with the given number of array dimensions.
|
ClassElement |
withBoundGenericTypes(List<? extends ClassElement> typeArguments)
Get a
ClassElement instance corresponding to this type, but with the given type arguments. |
annotate, annotate, equals, getAnnotationMetadata, getModifiers, getNativeType, hashCode, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, mirrorToClassElement, mirrorToClassElement, mirrorToClassElement, mirrorToClassElement, parameterizedClassElement, removeAnnotation, removeAnnotationIf, removeStereotype
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
fromArray, toArray
addAssociatedBean, foldBoundGenericTypes, getCanonicalName, getEnclosedElement, getFields, getFields, getFirstTypeArgument, getType, getTypeArguments, isAssignable, isEnum, isGenericPlaceholder, isIterable, isOptional, isProxy, isWildcard, of, of, of, of, of, of
getGenericType
annotate, annotate, annotate, annotate, annotate, getDescription, getDescription, getDocumentation, getModifiers, getNativeType, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotype
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByType
getAnnotationValuesByName, getDeclaredAnnotationValuesByName, getValues, hasDeclaredStereotype, isAnnotationPresent, isDeclaredAnnotationPresent
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
getAnnotationMetadata
protected final TypeElement classElement
protected final JavaVisitorContext visitorContext
@Internal public JavaClassElement(TypeElement classElement, AnnotationMetadata annotationMetadata, JavaVisitorContext visitorContext)
classElement
- The TypeElement
annotationMetadata
- The annotation metadatavisitorContext
- The visitor contextpublic boolean isTypeVariable()
ClassElement
ClassElement.getTypeArguments()
a returned ClassElement
may represent a type variable
in which case this method will return true
.isTypeVariable
in interface ClassElement
public String toString()
toString
in class AbstractJavaElement
public boolean isInner()
ClassElement
isInner
in interface ClassElement
public boolean isRecord()
isRecord
in interface ClassElement
@NonNull public Map<String,ClassElement> getTypeArguments(@NonNull String type)
ClassElement
getTypeArguments
in interface ClassElement
type
- The type to retrieve type arguments forpublic boolean isPrimitive()
TypedElement
isPrimitive
in interface TypedElement
public Collection<ClassElement> getInterfaces()
getInterfaces
in interface ClassElement
public Optional<ClassElement> getSuperType()
ClassElement
getSuperType
in interface ClassElement
public boolean isAbstract()
isAbstract
in interface Element
isAbstract
in class AbstractJavaElement
public boolean isInterface()
isInterface
in interface ClassElement
public List<PropertyElement> getBeanProperties()
ClassElement
getBeanProperties
in interface ClassElement
public <T extends Element> List<T> getEnclosedElements(@NonNull ElementQuery<T> query)
ClassElement
getEnclosedElements
in interface ClassElement
T
- The element typequery
- The query to use.public boolean isArray()
TypedElement
isArray
in interface TypedElement
public int getArrayDimensions()
TypedElement
getArrayDimensions
in interface TypedElement
public ClassElement withArrayDimensions(int arrayDimensions)
ArrayableClassElement
withArrayDimensions
in interface ArrayableClassElement
arrayDimensions
- The number of array dimensions of the new class elementpublic String getSimpleName()
ClassElement
getSimpleName
in interface ClassElement
getSimpleName
in interface Element
public String getName()
public String getPackageName()
ClassElement
getPackageName
in interface ClassElement
public PackageElement getPackage()
ClassElement
getPackage
in interface ClassElement
public boolean isAssignable(String type)
ClassElement
isAssignable
in interface ClassElement
type
- The type to checktrue
if and only if this type is assignable to the secondpublic boolean isAssignable(ClassElement type)
ClassElement
isAssignable
in interface ClassElement
type
- The type to checktrue
if and only if this type is assignable to the second@NonNull public Optional<MethodElement> getPrimaryConstructor()
ClassElement
Creator
or Inject
.getPrimaryConstructor
in interface ClassElement
public Optional<MethodElement> getDefaultConstructor()
ClassElement
getDefaultConstructor
in interface ClassElement
public Optional<ClassElement> getEnclosingType()
ClassElement
ClassElement.isInner()
return true
.getEnclosingType
in interface ClassElement
@NonNull public List<ClassElement> getBoundGenericTypes()
ClassElement
Note that for compatibility reasons, this method is inconsistent with ClassElement.getTypeArguments()
. In particular,
this method reflects the declaration type: If there is a class Test<T> { T field; }
, this method
will return T
as the field type, even if the field type was obtained through a Test<String>
.
getBoundGenericTypes
in interface ClassElement
ClassElement.getDeclaredGenericPlaceholders()
. Must be empty or
of the same length as ClassElement.getDeclaredGenericPlaceholders()
.@NonNull public List<? extends GenericPlaceholderElement> getDeclaredGenericPlaceholders()
ClassElement
bound type arguments
.
This method will resolve the generic placeholders defined of the declaring class, if any.
For example List<String>
will result a single placeholder called E
of type Object
.
getDeclaredGenericPlaceholders
in interface ClassElement
@NonNull public ClassElement getRawClassElement()
ClassElement
ClassElement
instance corresponding to this type, but without any type arguments bound. For
List<String>
, this returns List
.getRawClassElement
in interface ClassElement
@NonNull public ClassElement withBoundGenericTypes(@NonNull List<? extends ClassElement> typeArguments)
ClassElement
ClassElement
instance corresponding to this type, but with the given type arguments. This is best
effort – implementations may only support ClassElement
s that come from the same visitor context, and
other ClassElement
s only to a limited degree.withBoundGenericTypes
in interface ClassElement
typeArguments
- The new type arguments.ClassElement
of the same raw class with the new type arguments.@NonNull public Map<String,ClassElement> getTypeArguments()
getTypeArguments
in interface ClassElement
@NonNull public Map<String,Map<String,ClassElement>> getAllTypeArguments()
ClassElement
getAllTypeArguments
in interface ClassElement