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
Modifier and TypeFieldDescriptionprotected final org.codehaus.groovy.ast.ClassNode
protected Map<String,
ClassElement> Fields inherited from class io.micronaut.ast.groovy.visitor.AbstractGroovyElement
compilationUnit, sourceUnit, 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
ConstructorDescriptionGroovyClassElement
(GroovyVisitorContext visitorContext, GroovyNativeElement nativeElement, ElementAnnotationMetadataFactory annotationMetadataFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected @NonNull GroovyClassElement
Constructs this element by invoking the constructor.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
(@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.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
isFinal()
boolean
isInner()
Is this type an inner class.boolean
boolean
Whether the type is primitive.boolean
boolean
boolean
isPublic()
boolean
isStatic()
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.final @NonNull ClassElement
withTypeArguments
(@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, resolveTypeArgumentsToObject
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, getAccessibleStaticCreators, getAllTypeArguments, getCanonicalName, getEnclosedElement, getFields, getFirstTypeArgument, getMethods, getRawClassElement, getTypeArguments, getTypeArguments, isAssignable, isContainerType, isEnum, isGenericPlaceholder, isIterable, isOptional, isProxy, isRawType, isRecord, isWildcard, withBoundGenericTypes
Methods inherited from interface io.micronaut.inject.ast.Element
annotate, annotate, annotate, annotate, annotate, getDescription, getDescription, getDocumentation, getNativeType, isPackagePrivate, isSynthetic, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotype
Methods 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:AbstractGroovyElement
Constructs this element by invoking the constructor.- Specified by:
copyConstructor
in classAbstractGroovyElement
- Returns:
- the copy
-
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
-
getAnnotationMetadataToWrite
Description copied from class:AbstractAnnotationElement
Get annotation metadata to add or remove annotations.- Overrides:
getAnnotationMetadataToWrite
in classAbstractAnnotationElement
- Returns:
- The annotation metadata to write
-
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 classAbstractGroovyElement
- Parameters:
annotationMetadata
- The annotation metadata- Returns:
- A new element
-
withTypeArguments
Description copied from interface:ClassElement
Copies this element and overrides its type arguments.- Specified by:
withTypeArguments
in 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: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
-
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.
-
getEnclosedElements
@NonNull public <T extends Element> @NonNull List<T> getEnclosedElements(@NonNull @NonNull ElementQuery<T> query) 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
-
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:
getModifiers
in interfaceElement
- Returns:
- The
ElementModifier
types for this class element
-
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
-
getEnclosingType
Description copied from interface:ClassElement
Returns the enclosing type ifClassElement.isInner()
returntrue
.- Specified by:
getEnclosingType
in interfaceClassElement
- Returns:
- The enclosing type if any
-
isInterface
public boolean isInterface()- Specified by:
isInterface
in interfaceClassElement
- Returns:
- Whether the class element is an interface
-
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
-
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
-
getDefaultConstructor
Description copied from interface:ClassElement
Find and return a single default constructor. A default constructor is one without arguments that is accessible.- Specified by:
getDefaultConstructor
in interfaceClassElement
- Returns:
- The default constructor if one is present
-
getTypeArguments
- Specified by:
getTypeArguments
in interfaceClassElement
- Returns:
- The type arguments for this class element
-
getSyntheticBeanProperties
Description copied from interface:ClassElement
Returns 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:
getSyntheticBeanProperties
in interfaceClassElement
- Returns:
- The bean properties for this class element
-
getBeanProperties
@NonNull public @NonNull List<PropertyElement> getBeanProperties(@NonNull @NonNull PropertyElementQuery propertyElementQuery) 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
-
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
-
isArray
public boolean isArray()Description copied from interface:TypedElement
Is the type an array.- Specified by:
isArray
in interfaceTypedElement
- Returns:
- True if it is.
-
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
-
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
-
toString
-
getName
-
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
-
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
-
isAbstract
public boolean isAbstract()- Specified by:
isAbstract
in 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:
isProtected
in interfaceElement
- Returns:
- True if the element is protected.
-
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
-
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.
-
getType
- Specified by:
getType
in interfaceClassElement
- Specified by:
getType
in interfaceTypedElement
- Returns:
- The type of the element
-
getTypeAnnotationMetadata
@NonNull public @NonNull MutableAnnotationMetadataDelegate<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
-