Package io.micronaut.ast.groovy.visitor
Class GroovyClassElement
java.lang.Object
io.micronaut.inject.ast.annotation.AbstractAnnotationElement
io.micronaut.ast.groovy.visitor.AbstractGroovyElement
io.micronaut.ast.groovy.visitor.GroovyClassElement
- All Implemented Interfaces:
AnnotatedElement,AnnotationMetadata,AnnotationMetadataDelegate,AnnotationMetadataProvider,AnnotationSource,Described,Named,MutableAnnotationMetadataDelegate<Element>,ArrayableClassElement,ClassElement,Element,TypedElement
@Internal
public class GroovyClassElement
extends AbstractGroovyElement
implements ArrayableClassElement
A class element returning data from a
ClassNode.- Since:
- 1.0
- Author:
- James Kleeh, Denis Stepanov
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.codehaus.groovy.ast.ClassNodeprotected Map<String,ClassElement> Fields inherited from class io.micronaut.ast.groovy.visitor.AbstractGroovyElement
compilationUnit, sourceUnit, 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
ConstructorsConstructorDescriptionGroovyClassElement(GroovyVisitorContext visitorContext, GroovyNativeElement nativeElement, ElementAnnotationMetadataFactory annotationMetadataFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected @NonNull GroovyClassElementConstructs this element by invoking the constructor.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.@NonNull List<? extends 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.@NonNull List<? extends GenericPlaceholderElement>The type arguments declared on the raw class.Find and return a single default constructor.getEnclosedElements(@NonNull ElementQuery<T> query) Return the elements that match the given query.Returns the enclosing type ifClassElement.isInner()returntrue.getName()Gets optional value type.The package name.The package name.Find and return a single primary constructor.The simple name without the package name.getSourceEnclosedElements(@NonNull ElementQuery<T> query) This method will produce th 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.Returns the synthetic bean properties.getType()Returns the type annotations.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.booleanisFinal()booleanisInner()Is this type an inner class.booleanbooleanWhether the type is primitive.booleanbooleanbooleanisPublic()booleanisRecord()booleanisStatic()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.final @NonNull ClassElementwithTypeArguments(@NonNull Collection<ClassElement> typeArguments) Copies this element and overrides its type arguments.withTypeArguments(Map<String, ClassElement> typeArguments) Copies this element and overrides its type arguments.Methods inherited from class io.micronaut.ast.groovy.visitor.AbstractGroovyElement
copy, copyValues, equals, getDocumentation, getNativeType, hashCode, isPackagePrivate, newClassElement, newClassElement, newClassElement, resolveClassTypeArguments, resolveMethodTypeArguments, resolveModifiers, resolveModifiers, resolveModifiers, resolveTypeArgumentsToObjectMethods 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, getAccessibleStaticCreators, getAllTypeArguments, getCanonicalName, getEnclosedElement, getFields, getFirstTypeArgument, getMethods, getRawClassElement, getTypeArguments, getTypeArguments, hasUnresolvedTypes, 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, getNativeType, isPackagePrivate, isSynthetic, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotypeMethods inherited from interface io.micronaut.inject.ast.TypedElement
getGenericType, isVoid
-
Field Details
-
classNode
protected final org.codehaus.groovy.ast.ClassNode classNode -
resolvedTypeArguments
-
-
Constructor Details
-
GroovyClassElement
public GroovyClassElement(GroovyVisitorContext visitorContext, GroovyNativeElement nativeElement, ElementAnnotationMetadataFactory annotationMetadataFactory) - Parameters:
visitorContext- The visitor contextnativeElement- The native elementannotationMetadataFactory- The annotation metadata
-
-
Method Details
-
copyConstructor
Description copied from class:AbstractGroovyElementConstructs this element by invoking the constructor.- Specified by:
copyConstructorin classAbstractGroovyElement- Returns:
- the copy
-
getAnnotationMetadata
Description copied from interface:AnnotationMetadataProviderSupplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA.- Specified by:
getAnnotationMetadatain interfaceAnnotationMetadataProvider- Overrides:
getAnnotationMetadatain classAbstractAnnotationElement- Returns:
- The
AnnotationMetadata
-
getAnnotationMetadataToWrite
Description copied from class:AbstractAnnotationElementGet annotation metadata to add or remove annotations.- Overrides:
getAnnotationMetadataToWritein classAbstractAnnotationElement- Returns:
- The annotation metadata to write
-
withAnnotationMetadata
Description copied from interface:ElementCopies this element and overrides its annotations.- Specified by:
withAnnotationMetadatain interfaceClassElement- Specified by:
withAnnotationMetadatain interfaceElement- Overrides:
withAnnotationMetadatain classAbstractGroovyElement- Parameters:
annotationMetadata- The annotation metadata- Returns:
- A new element
-
withTypeArguments
Description copied from interface:ClassElementCopies this element and overrides its type arguments.- Specified by:
withTypeArgumentsin interfaceClassElement- Parameters:
typeArguments- The type arguments- Returns:
- A new element
-
withTypeArguments
@NonNull public final @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
-
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.
-
isRecord
public boolean isRecord()- Specified by:
isRecordin interfaceClassElement- Returns:
- Whether this element is a record
-
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 th 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
-
getModifiers
- Specified by:
getModifiersin interfaceElement- Returns:
- The
ElementModifiertypes for this class element
-
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
-
getEnclosingType
Description copied from interface:ClassElementReturns the enclosing type ifClassElement.isInner()returntrue.- Specified by:
getEnclosingTypein interfaceClassElement- Returns:
- The enclosing type if any
-
isInterface
public boolean isInterface()- Specified by:
isInterfacein interfaceClassElement- Returns:
- Whether the class element is an interface
-
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
-
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
-
getDefaultConstructor
Description copied from interface:ClassElementFind and return a single default constructor. A default constructor is one without arguments that is accessible.- Specified by:
getDefaultConstructorin interfaceClassElement- Returns:
- The default constructor if one is present
-
getTypeArguments
- Specified by:
getTypeArgumentsin interfaceClassElement- Returns:
- The type arguments for this class element
-
getSyntheticBeanProperties
Description copied from interface:ClassElementReturns the synthetic bean properties. The properties where one of the methods (getter or setter) is synthetic - not user defined but created by the compiler.- Specified by:
getSyntheticBeanPropertiesin 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
-
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
-
isArray
public boolean isArray()Description copied from interface:TypedElementIs the type an array.- Specified by:
isArrayin interfaceTypedElement- Returns:
- True if it is.
-
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
-
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
-
toString
-
getName
-
getSimpleName
Description copied from interface:ClassElementThe simple name without the package name.- Specified by:
getSimpleNamein interfaceClassElement- Specified by:
getSimpleNamein interfaceElement- Returns:
- The simple name
-
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
-
isAbstract
public boolean isAbstract()- Specified by:
isAbstractin interfaceElement- Returns:
- True if the element is abstract.
-
isStatic
public boolean isStatic() -
isPublic
public boolean isPublic() -
isPrivate
public boolean isPrivate() -
isFinal
public boolean isFinal() -
isProtected
public boolean isProtected()- Specified by:
isProtectedin interfaceElement- Returns:
- True if the element is protected.
-
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
-
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.
-
getType
- Specified by:
getTypein interfaceClassElement- Specified by:
getTypein interfaceTypedElement- Returns:
- The type of the element
-
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
-