Class JavaClassElement
java.lang.Object
io.micronaut.inject.ast.annotation.AbstractAnnotationElement
io.micronaut.annotation.processing.visitor.AbstractJavaElement
io.micronaut.annotation.processing.visitor.JavaClassElement
- All Implemented Interfaces:
AnnotatedElement
,AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,AnnotationSource
,Described
,Named
,MutableAnnotationMetadataDelegate<Element>
,ArrayableClassElement
,ClassElement
,Element
,TypedElement
@Internal
public class JavaClassElement
extends AbstractJavaElement
implements ArrayableClassElement
A class element returning data from a
TypeElement
.- Since:
- 1.0
- Author:
- James Kleeh, graemerocher, Denis Stepanov
-
Field Summary
Fields inherited from class io.micronaut.annotation.processing.visitor.AbstractJavaElement
visitorContext
Fields inherited from class io.micronaut.inject.ast.annotation.AbstractAnnotationElement
elementAnnotationMetadataFactory, presetAnnotationMetadata
Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
Fields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTY
Fields inherited from interface io.micronaut.inject.ast.ClassElement
ZERO_CLASS_ELEMENTS
Fields inherited from interface io.micronaut.inject.ast.Element
EMPTY_ELEMENT_ARRAY
Fields inherited from interface io.micronaut.inject.ast.annotation.MutableAnnotationMetadataDelegate
EMPTY
-
Constructor Summary
ConstructorDescriptionJavaClassElement
(JavaNativeElement.Class nativeType, ElementAnnotationMetadataFactory annotationMetadataFactory, JavaVisitorContext visitorContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected JavaClassElement
copyThis()
Get accessible static creators.Builds a map of all the type parameters for a class, its super classes and interfaces.Supplies the metadata.protected MutableAnnotationMetadataDelegate<?>
Get annotation metadata to add or remove annotations.int
If the type is an array, the number of dimensions.Returns the bean properties (getters and setters) for this class element.getBeanProperties
(PropertyElementQuery propertyElementQuery) Returns the bean properties (getters and setters) for this class element based on custom configuration.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.@NonNull List<? extends GenericPlaceholderElement>
The type arguments declared on the raw class.getEnclosedElements
(@NonNull ElementQuery<T> query) Return the elements that match the given query.Returns the enclosing type ifClassElement.isInner()
returntrue
.getName()
Returns the native underlying type.Gets optional value type.The package name.The package name.Find and return a single primary constructor.Get aClassElement
instance corresponding to this type, but without any type arguments bound.The simple name without the package name.Returns the super type of this element or empty if the element has no super type.getType()
Returns the type annotations.boolean
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
boolean
Whether the type is primitive.boolean
isRecord()
boolean
In this case of callingClassElement.getTypeArguments()
a returnedClassElement
may represent a type variable in which case this method will returntrue
.toString()
withAnnotationMetadata
(AnnotationMetadata annotationMetadata) Copies this element and overrides its annotations.withArrayDimensions
(int arrayDimensions) Convert the class element to an element for the same type, but with the given number of array dimensions.withTypeArguments
(@NonNull Collection<ClassElement> typeArguments) Copies this element and overrides its type arguments.withTypeArguments
(Map<String, ClassElement> newTypeArguments) Copies this element and overrides its type arguments.Methods inherited from class io.micronaut.annotation.processing.visitor.AbstractJavaElement
copyValues, equals, getDocumentation, getModifiers, hashCode, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, makeCopy, newClassElement, newClassElement, resolveTypeArguments, resolveTypeArguments
Methods inherited from class io.micronaut.inject.ast.annotation.AbstractAnnotationElement
annotate, annotate, annotate, annotate, annotate, getElementAnnotationMetadata, getElementAnnotationMetadataFactory, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotype
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.micronaut.core.annotation.AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresent
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, 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, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, 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
Methods inherited from interface io.micronaut.inject.ast.ArrayableClassElement
fromArray, toArray
Methods inherited from interface io.micronaut.inject.ast.ClassElement
addAssociatedBean, findDefaultStaticCreator, findField, findMethod, findStaticCreator, foldBoundGenericTypes, getAccessibleConstructors, getCanonicalName, getDefaultConstructor, getEnclosedElement, getFields, getFirstTypeArgument, getMethods, getSyntheticBeanProperties, getTypeArguments, getTypeArguments, isAssignable, isContainerType, isEnum, isGenericPlaceholder, isIterable, isOptional, isProxy, isRawType, isWildcard, withBoundGenericTypes
Methods inherited from interface io.micronaut.inject.ast.Element
annotate, annotate, annotate, annotate, annotate, getDescription, getDescription, getDocumentation, getModifiers, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, isSynthetic, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotype
Methods inherited from interface io.micronaut.inject.ast.TypedElement
getGenericType, isVoid
-
Field Details
-
classElement
-
arrayDimensions
protected final int arrayDimensions
-
-
Constructor Details
-
JavaClassElement
@Internal public JavaClassElement(JavaNativeElement.Class nativeType, ElementAnnotationMetadataFactory annotationMetadataFactory, JavaVisitorContext visitorContext) - Parameters:
nativeType
- The native typeannotationMetadataFactory
- The annotation metadata factoryvisitorContext
- The visitor context
-
-
Method Details
-
getNativeType
Description copied from interface:Element
Returns the native underlying type. This API is extended by all of the inject language implementations. The object returned by this method will be the language native type the information is being retrieved from.- Specified by:
getNativeType
in interfaceElement
- Overrides:
getNativeType
in classAbstractJavaElement
- Returns:
- The native type
-
copyThis
- Specified by:
copyThis
in classAbstractJavaElement
- Returns:
- copy of this element
-
withTypeArguments
Description copied from interface:ClassElement
Copies this element and overrides its type arguments.- Specified by:
withTypeArguments
in interfaceClassElement
- Parameters:
newTypeArguments
- The type arguments- Returns:
- A new element
-
withAnnotationMetadata
Description copied from interface:Element
Copies this element and overrides its annotations.- Specified by:
withAnnotationMetadata
in interfaceClassElement
- Specified by:
withAnnotationMetadata
in interfaceElement
- Overrides:
withAnnotationMetadata
in classAbstractJavaElement
- Parameters:
annotationMetadata
- The annotation metadata- Returns:
- A new element
-
getAnnotationMetadataToWrite
Description copied from class:AbstractAnnotationElement
Get annotation metadata to add or remove annotations.- Overrides:
getAnnotationMetadataToWrite
in classAbstractAnnotationElement
- Returns:
- The annotation metadata to write
-
getAnnotationMetadata
Description copied from interface:AnnotationMetadataProvider
Supplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA
.- Specified by:
getAnnotationMetadata
in interfaceAnnotationMetadataProvider
- Overrides:
getAnnotationMetadata
in classAbstractAnnotationElement
- Returns:
- The
AnnotationMetadata
-
getTypeAnnotationMetadata
Description copied from interface:ClassElement
Returns the type annotations. Added by: - The declaration of the type variableElementType.TYPE_PARAMETER
- The use of the typeElementType.TYPE
- Specified by:
getTypeAnnotationMetadata
in interfaceClassElement
- Returns:
- the type annotations
-
isTypeVariable
public boolean isTypeVariable()Description copied from interface:ClassElement
In this case of callingClassElement.getTypeArguments()
a returnedClassElement
may represent a type variable in which case this method will returntrue
.- Specified by:
isTypeVariable
in interfaceClassElement
- Returns:
- Is this type a type variable.
-
toString
- Overrides:
toString
in classAbstractJavaElement
-
isInner
public boolean isInner()Description copied from interface:ClassElement
Is this type an inner class.- Specified by:
isInner
in interfaceClassElement
- Returns:
- True if it is an inner class
-
isRecord
public boolean isRecord()- Specified by:
isRecord
in interfaceClassElement
- Returns:
- Whether this element is a record
-
isPrimitive
public boolean isPrimitive()Description copied from interface:TypedElement
Whether the type is primitive.- Specified by:
isPrimitive
in interfaceTypedElement
- Returns:
- True if it is
-
getInterfaces
- Specified by:
getInterfaces
in interfaceClassElement
- Returns:
- The interfaces implemented by this class element
-
getSuperType
Description copied from interface:ClassElement
Returns the super type of this element or empty if the element has no super type.- Specified by:
getSuperType
in interfaceClassElement
- Returns:
- An optional of the super type
-
isAbstract
public boolean isAbstract()- Specified by:
isAbstract
in interfaceElement
- Overrides:
isAbstract
in classAbstractJavaElement
- Returns:
- True if the element is abstract.
-
isInterface
public boolean isInterface()- Specified by:
isInterface
in interfaceClassElement
- Returns:
- Whether the class element is an interface
-
getBeanProperties
Description copied from interface:ClassElement
Returns the bean properties (getters and setters) for this class element.- Specified by:
getBeanProperties
in interfaceClassElement
- Returns:
- The bean properties for this class element
-
getBeanProperties
Description copied from interface:ClassElement
Returns the bean properties (getters and setters) for this class element based on custom configuration.- Specified by:
getBeanProperties
in interfaceClassElement
- Parameters:
propertyElementQuery
- The configuration- Returns:
- The bean properties for this class element
-
getEnclosedElements
Description copied from interface:ClassElement
Return the elements that match the given query.- Specified by:
getEnclosedElements
in interfaceClassElement
- Type Parameters:
T
- The element type- Parameters:
query
- The query to use.- Returns:
- The fields
-
isArray
public boolean isArray()Description copied from interface:TypedElement
Is the type an array.- Specified by:
isArray
in interfaceTypedElement
- Returns:
- True if it is.
-
getArrayDimensions
public int getArrayDimensions()Description copied from interface:TypedElement
If the type is an array, the number of dimensions. String[] should return 1, String[][] should return 2- Specified by:
getArrayDimensions
in interfaceTypedElement
- Returns:
- The number of dimensions
-
withArrayDimensions
Description copied from interface:ArrayableClassElement
Convert the class element to an element for the same type, but with the given number of array dimensions. Do not mutate the existing instance. Create a new instance instead.- Specified by:
withArrayDimensions
in interfaceArrayableClassElement
- Parameters:
arrayDimensions
- The number of array dimensions of the new class element- Returns:
- A new class element
-
getSimpleName
Description copied from interface:ClassElement
The simple name without the package name.- Specified by:
getSimpleName
in interfaceClassElement
- Specified by:
getSimpleName
in interfaceElement
- Returns:
- The simple name
-
getName
-
getPackageName
Description copied from interface:ClassElement
The package name.- Specified by:
getPackageName
in interfaceClassElement
- Returns:
- The package name
-
getPackage
Description copied from interface:ClassElement
The package name.- Specified by:
getPackage
in interfaceClassElement
- Returns:
- The package name
-
isAssignable
Description copied from interface:ClassElement
Tests whether one type is assignable to another.- Specified by:
isAssignable
in interfaceClassElement
- Parameters:
type
- The type to check- Returns:
true
if and only if this type is assignable to the second
-
isAssignable
Description copied from interface:ClassElement
Tests whether one type is assignable to another.- Specified by:
isAssignable
in interfaceClassElement
- Parameters:
type
- The type to check- Returns:
true
if and only if this type is assignable to the second
-
getOptionalValueType
Description copied from interface:ClassElement
Gets optional value type.- Specified by:
getOptionalValueType
in interfaceClassElement
- Returns:
- the value type
-
getPrimaryConstructor
Description copied from interface:ClassElement
Find and return a single primary constructor. If more than constructor candidate exists, then return empty unless a constructor is found that is annotated with eitherCreator
orAnnotationUtil.INJECT
.- Specified by:
getPrimaryConstructor
in interfaceClassElement
- Returns:
- The primary constructor if one is present
-
getAccessibleStaticCreators
Description copied from interface:ClassElement
Get accessible static creators. A static creator is a static method annotated withCreator
that can be used to create the class. For enums "valueOf" is picked as a static creator.- Specified by:
getAccessibleStaticCreators
in interfaceClassElement
- Returns:
- static creators
-
getEnclosingType
Description copied from interface:ClassElement
Returns the enclosing type ifClassElement.isInner()
returntrue
.- Specified by:
getEnclosingType
in interfaceClassElement
- Returns:
- The enclosing type if any
-
getBoundGenericTypes
Description copied from interface:ClassElement
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.Note that for compatibility reasons, this method is inconsistent with
ClassElement.getTypeArguments()
. In particular, this method reflects the declaration type: If there is aclass Test<T> { T field; }
, this method will returnT
as the field type, even if the field type was obtained through aTest<String>
.- Specified by:
getBoundGenericTypes
in interfaceClassElement
- Returns:
- The list of type arguments, in the same order as
ClassElement.getDeclaredGenericPlaceholders()
. Must be empty or of the same length asClassElement.getDeclaredGenericPlaceholders()
.
-
getDeclaredGenericPlaceholders
Description copied from interface:ClassElement
The type arguments declared on the raw class. Independent of the actualbound 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 calledE
of typeObject
.- Specified by:
getDeclaredGenericPlaceholders
in interfaceClassElement
- Returns:
- The type arguments declared on this class.
-
getRawClassElement
Description copied from interface:ClassElement
Get aClassElement
instance corresponding to this type, but without any type arguments bound. ForList<String>
, this returnsList
.- Specified by:
getRawClassElement
in interfaceClassElement
- Returns:
- The raw class of this potentially parameterized type.
-
withTypeArguments
@NonNull public @NonNull ClassElement withTypeArguments(@NonNull @NonNull Collection<ClassElement> typeArguments) Description copied from interface:ClassElement
Copies this element and overrides its type arguments. Variation ofClassElement.withTypeArguments(Map)
that doesn't require type argument names.- Specified by:
withTypeArguments
in interfaceClassElement
- Parameters:
typeArguments
- The type arguments- Returns:
- A new element
-
getTypeArguments
- Specified by:
getTypeArguments
in interfaceClassElement
- Returns:
- The type arguments for this class element
-
getAllTypeArguments
Description copied from interface:ClassElement
Builds a map of all the type parameters for a class, its super classes and interfaces. The resulting map contains the name of the class to the a map of the resolved generic types.- Specified by:
getAllTypeArguments
in interfaceClassElement
- Returns:
- The type arguments for this class element
-
getType
- Specified by:
getType
in interfaceClassElement
- Specified by:
getType
in interfaceTypedElement
- Returns:
- The type of the element
-