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
FieldsFields inherited from class io.micronaut.annotation.processing.visitor.AbstractJavaElement
visitorContextFields inherited from class io.micronaut.inject.ast.annotation.AbstractAnnotationElement
elementAnnotationMetadataFactory, presetAnnotationMetadataFields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBERFields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTYFields inherited from interface io.micronaut.inject.ast.ClassElement
ZERO_CLASS_ELEMENTSFields inherited from interface io.micronaut.inject.ast.Element
EMPTY_ELEMENT_ARRAYFields inherited from interface io.micronaut.inject.ast.annotation.MutableAnnotationMetadataDelegate
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionJavaClassElement(JavaNativeElement.Class nativeType, ElementAnnotationMetadataFactory annotationMetadataFactory, JavaVisitorContext visitorContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected JavaClassElementcopyThis()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.intIf the type is an array, the number of dimensions.Returns the bean properties (getters and setters) for this class element.getBeanProperties(@NonNull 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.This method will return the name of the underlying type automatically unwrapping in the case of an optional or wrapped representation of the 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 aClassElementinstance corresponding to this type, but without any type arguments bound.The simple name without the package name.getSourceEnclosedElements(@NonNull ElementQuery<T> query) This method will produce the elements just likegetEnclosedElements(ElementQuery)but the elements are constructed as the source ones.Returns the super type of this element or empty if the element has no super type.getType()Returns the type annotations.booleanhasUnresolvedTypes(UnresolvedTypeKind... kind) booleanbooleanisArray()Is the type an array.booleanisAssignable(ClassElement type) Tests whether one type is assignable to another.booleanisAssignable(String type) Tests whether one type is assignable to another.booleanisInner()Is this type an inner class.booleanbooleanWhether the type is primitive.booleanisRecord()booleanIn this case of callingClassElement.getTypeArguments()a returnedClassElementmay 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, resolveTypeArgumentsMethods inherited from class io.micronaut.inject.ast.annotation.AbstractAnnotationElement
annotate, annotate, annotate, annotate, annotate, getElementAnnotationMetadata, getElementAnnotationMetadataFactory, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotypeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.micronaut.core.annotation.AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullableMethods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods 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, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface io.micronaut.inject.ast.ArrayableClassElement
fromArray, toArrayMethods inherited from interface io.micronaut.inject.ast.ClassElement
addAssociatedBean, findDefaultStaticCreator, findField, findMethod, findStaticCreator, foldBoundGenericTypes, getAccessibleConstructors, getDefaultConstructor, getEnclosedElement, getFields, getFirstTypeArgument, getMethods, getSyntheticBeanProperties, getTypeArguments, getTypeArguments, isAssignable, isContainerType, isEnum, isGenericPlaceholder, isIterable, isOptional, isProxy, isRawType, isWildcard, withBoundGenericTypesMethods 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, removeStereotypeMethods 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
-
getCanonicalName
Description copied from interface:ClassElementThis method will return the name of the underlying type automatically unwrapping in the case of an optional or wrapped representation of the type.- Specified by:
getCanonicalNamein interfaceClassElement- Returns:
- Returns the canonical name of the type.
-
hasUnresolvedTypes
- Specified by:
hasUnresolvedTypesin interfaceClassElement- Parameters:
kind- The kind of error- Returns:
- Whether errors are present in the type element.
-
getNativeType
Description copied from interface:ElementReturns the native underlying type. This API is extended by all inject language implementations. The object returned by this method will be the language native type the information is being retrieved from.- Specified by:
getNativeTypein interfaceElement- Overrides:
getNativeTypein classAbstractJavaElement- Returns:
- The native type
-
copyThis
- Specified by:
copyThisin classAbstractJavaElement- Returns:
- copy of this element
-
withTypeArguments
Description copied from interface:ClassElementCopies this element and overrides its type arguments.- Specified by:
withTypeArgumentsin interfaceClassElement- Parameters:
newTypeArguments- The type arguments- Returns:
- A new element
-
withAnnotationMetadata
Description copied from interface:ElementCopies this element and overrides its annotations.- Specified by:
withAnnotationMetadatain interfaceClassElement- Specified by:
withAnnotationMetadatain interfaceElement- Overrides:
withAnnotationMetadatain classAbstractJavaElement- Parameters:
annotationMetadata- The annotation metadata- Returns:
- A new element
-
getAnnotationMetadataToWrite
Description copied from class:AbstractAnnotationElementGet annotation metadata to add or remove annotations.- Overrides:
getAnnotationMetadataToWritein classAbstractAnnotationElement- Returns:
- The annotation metadata to write
-
getAnnotationMetadata
Description copied from interface:AnnotationMetadataProviderSupplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA.- Specified by:
getAnnotationMetadatain interfaceAnnotationMetadataProvider- Overrides:
getAnnotationMetadatain classAbstractAnnotationElement- Returns:
- The
AnnotationMetadata
-
getTypeAnnotationMetadata
@NonNull public @NonNull MutableAnnotationMetadataDelegate<AnnotationMetadata> getTypeAnnotationMetadata()Description copied from interface:ClassElementReturns the type annotations. Added by: - The declaration of the type variableElementType.TYPE_PARAMETER- The use of the typeElementType.TYPE- Specified by:
getTypeAnnotationMetadatain interfaceClassElement- Returns:
- the type annotations
-
isTypeVariable
public boolean isTypeVariable()Description copied from interface:ClassElementIn this case of callingClassElement.getTypeArguments()a returnedClassElementmay represent a type variable in which case this method will returntrue.- Specified by:
isTypeVariablein interfaceClassElement- Returns:
- Is this type a type variable.
-
toString
- Overrides:
toStringin classAbstractJavaElement
-
isInner
public boolean isInner()Description copied from interface:ClassElementIs this type an inner class.- Specified by:
isInnerin interfaceClassElement- Returns:
- True if it is an inner class
-
isRecord
public boolean isRecord()- Specified by:
isRecordin interfaceClassElement- Returns:
- Whether this element is a record
-
isPrimitive
public boolean isPrimitive()Description copied from interface:TypedElementWhether the type is primitive.- Specified by:
isPrimitivein interfaceTypedElement- Returns:
- True if it is
-
getInterfaces
- Specified by:
getInterfacesin interfaceClassElement- Returns:
- The interfaces implemented by this class element
-
getSuperType
Description copied from interface:ClassElementReturns the super type of this element or empty if the element has no super type.- Specified by:
getSuperTypein interfaceClassElement- Returns:
- An optional of the super type
-
isAbstract
public boolean isAbstract()- Specified by:
isAbstractin interfaceElement- Overrides:
isAbstractin classAbstractJavaElement- Returns:
- True if the element is abstract.
-
isInterface
public boolean isInterface()- Specified by:
isInterfacein interfaceClassElement- Returns:
- Whether the class element is an interface
-
getBeanProperties
Description copied from interface:ClassElementReturns the bean properties (getters and setters) for this class element.- Specified by:
getBeanPropertiesin interfaceClassElement- Returns:
- The bean properties for this class element
-
getBeanProperties
@NonNull public @NonNull List<PropertyElement> getBeanProperties(@NonNull @NonNull PropertyElementQuery propertyElementQuery) Description copied from interface:ClassElementReturns the bean properties (getters and setters) for this class element based on custom configuration.- Specified by:
getBeanPropertiesin interfaceClassElement- Parameters:
propertyElementQuery- The configuration- Returns:
- The bean properties for this class element
-
getEnclosedElements
@NonNull public <T extends Element> @NonNull List<T> getEnclosedElements(@NonNull @NonNull ElementQuery<T> query) Description copied from interface:ClassElementReturn the elements that match the given query.- Specified by:
getEnclosedElementsin interfaceClassElement- Type Parameters:
T- The element type- Parameters:
query- The query to use.- Returns:
- The fields
-
getSourceEnclosedElements
public final <T extends Element> List<T> getSourceEnclosedElements(@NonNull @NonNull ElementQuery<T> query) This method will produce the elements just likegetEnclosedElements(ElementQuery)but the elements are constructed as the source ones.ElementFactory.newSourceMethodElement(ClassElement, Object, ElementAnnotationMetadataFactory).- Type Parameters:
T- The element type- Parameters:
query- The query- Returns:
- The list of elements
-
isArray
public boolean isArray()Description copied from interface:TypedElementIs the type an array.- Specified by:
isArrayin interfaceTypedElement- Returns:
- True if it is.
-
getArrayDimensions
public int getArrayDimensions()Description copied from interface:TypedElementIf the type is an array, the number of dimensions. String[] should return 1, String[][] should return 2- Specified by:
getArrayDimensionsin interfaceTypedElement- Returns:
- The number of dimensions
-
withArrayDimensions
Description copied from interface:ArrayableClassElementConvert 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:
withArrayDimensionsin interfaceArrayableClassElement- Parameters:
arrayDimensions- The number of array dimensions of the new class element- Returns:
- A new class element
-
getSimpleName
Description copied from interface:ClassElementThe simple name without the package name.- Specified by:
getSimpleNamein interfaceClassElement- Specified by:
getSimpleNamein interfaceElement- Returns:
- The simple name
-
getName
-
getPackageName
Description copied from interface:ClassElementThe package name.- Specified by:
getPackageNamein interfaceClassElement- Returns:
- The package name
-
getPackage
Description copied from interface:ClassElementThe package name.- Specified by:
getPackagein interfaceClassElement- Returns:
- The package name
-
isAssignable
Description copied from interface:ClassElementTests whether one type is assignable to another.- Specified by:
isAssignablein interfaceClassElement- Parameters:
type- The type to check- Returns:
trueif and only if this type is assignable to the second
-
isAssignable
Description copied from interface:ClassElementTests whether one type is assignable to another.- Specified by:
isAssignablein interfaceClassElement- Parameters:
type- The type to check- Returns:
trueif and only if this type is assignable to the second
-
getOptionalValueType
Description copied from interface:ClassElementGets optional value type.- Specified by:
getOptionalValueTypein interfaceClassElement- Returns:
- the value type
-
getPrimaryConstructor
Description copied from interface:ClassElementFind and return a single primary constructor. If more than constructor candidate exists, then return empty unless a constructor is found that is annotated with eitherCreatororAnnotationUtil.INJECT.- Specified by:
getPrimaryConstructorin interfaceClassElement- Returns:
- The primary constructor if one is present
-
getAccessibleStaticCreators
Description copied from interface:ClassElementGet accessible static creators. A static creator is a static method annotated withCreatorthat can be used to create the class. For enums "valueOf" is picked as a static creator.- Specified by:
getAccessibleStaticCreatorsin interfaceClassElement- Returns:
- static creators
-
getEnclosingType
Description copied from interface:ClassElementReturns the enclosing type ifClassElement.isInner()returntrue.- Specified by:
getEnclosingTypein interfaceClassElement- Returns:
- The enclosing type if any
-
getBoundGenericTypes
Description copied from interface:ClassElementThe 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 returnTas the field type, even if the field type was obtained through aTest<String>.- Specified by:
getBoundGenericTypesin 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:ClassElementThe 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 calledEof typeObject.- Specified by:
getDeclaredGenericPlaceholdersin interfaceClassElement- Returns:
- The type arguments declared on this class.
-
getRawClassElement
Description copied from interface:ClassElementGet aClassElementinstance corresponding to this type, but without any type arguments bound. ForList<String>, this returnsList.- Specified by:
getRawClassElementin 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:ClassElementCopies this element and overrides its type arguments. Variation ofClassElement.withTypeArguments(Map)that doesn't require type argument names.- Specified by:
withTypeArgumentsin interfaceClassElement- Parameters:
typeArguments- The type arguments- Returns:
- A new element
-
getTypeArguments
- Specified by:
getTypeArgumentsin interfaceClassElement- Returns:
- The type arguments for this class element
-
getAllTypeArguments
Description copied from interface:ClassElementBuilds 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 map of the resolved generic types.- Specified by:
getAllTypeArgumentsin interfaceClassElement- Returns:
- The type arguments for this class element
-
getType
- Specified by:
getTypein interfaceClassElement- Specified by:
getTypein interfaceTypedElement- Returns:
- The type of the element
-