@Internal public class GroovyClassElement extends AbstractGroovyElement implements ArrayableClassElement
ClassNode
.Modifier and Type | Field and Description |
---|---|
protected org.codehaus.groovy.ast.ClassNode |
classNode |
compilationUnit, sourceUnit, visitorContext
ZERO_CLASS_ELEMENTS
EMPTY_ELEMENT_ARRAY
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
EMPTY
Constructor and Description |
---|
GroovyClassElement(GroovyVisitorContext visitorContext,
org.codehaus.groovy.ast.ClassNode classNode,
AnnotationMetadata annotationMetadata) |
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<? extends 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 . |
Map<String,Map<String,org.codehaus.groovy.ast.ClassNode>> |
getGenericTypeInfo()
Builds and returns the generic type information.
|
Collection<ClassElement> |
getInterfaces() |
Set<ElementModifier> |
getModifiers() |
String |
getName() |
Object |
getNativeType()
Returns the native underlying type.
|
PackageElement |
getPackage()
The package name.
|
String |
getPackageName()
The package name.
|
Optional<MethodElement> |
getPrimaryConstructor()
Find and return a single primary constructor.
|
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 |
isFinal() |
boolean |
isInner()
Is this type an inner class.
|
boolean |
isInterface() |
boolean |
isPrimitive()
Whether the type is primitive.
|
boolean |
isPrivate() |
boolean |
isProtected() |
boolean |
isPublic() |
boolean |
isStatic() |
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 . |
protected ClassElement |
toClassElement(org.codehaus.groovy.ast.ClassNode classNode) |
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. |
alignNewGenericsInfo, annotate, annotate, equals, getAnnotationMetadata, getDocumentation, getGenericElement, hashCode, isPackagePrivate, removeAnnotation, removeAnnotationIf, removeStereotype, resolveAnnotationMetadata, resolveModifiers, resolveModifiers, resolveModifiers
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
fromArray, toArray
addAssociatedBean, foldBoundGenericTypes, getCanonicalName, getEnclosedElement, getFields, getFields, getFirstTypeArgument, getRawClassElement, getType, getTypeArguments, isAssignable, isEnum, isGenericPlaceholder, isIterable, isOptional, isProxy, isRecord, isWildcard, of, of, of, of, of, of
getGenericType
annotate, annotate, annotate, annotate, annotate, getDescription, getDescription, getDocumentation, isPackagePrivate, 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, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, 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, getAnnotationValuesByStereotype, getDeclaredAnnotationValuesByName, getValues, hasDeclaredStereotype, isAnnotationPresent, isDeclaredAnnotationPresent
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
getAnnotationMetadata
public GroovyClassElement(GroovyVisitorContext visitorContext, org.codehaus.groovy.ast.ClassNode classNode, AnnotationMetadata annotationMetadata)
visitorContext
- The visitor contextclassNode
- The ClassNode
annotationMetadata
- The annotation metadatapublic 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 <T extends Element> List<T> getEnclosedElements(@NonNull ElementQuery<T> query)
ClassElement
getEnclosedElements
in interface ClassElement
T
- The element typequery
- The query to use.public Set<ElementModifier> getModifiers()
getModifiers
in interface Element
ElementModifier
types for this class elementpublic boolean isInner()
ClassElement
isInner
in interface ClassElement
public Optional<ClassElement> getEnclosingType()
ClassElement
ClassElement.isInner()
return true
.getEnclosingType
in interface ClassElement
public boolean isInterface()
isInterface
in interface ClassElement
public boolean isPrimitive()
TypedElement
isPrimitive
in interface TypedElement
public Collection<ClassElement> getInterfaces()
getInterfaces
in interface ClassElement
public Optional<ClassElement> getSuperType()
ClassElement
getSuperType
in interface ClassElement
@NonNull public Optional<MethodElement> getPrimaryConstructor()
ClassElement
Creator
or Inject
.getPrimaryConstructor
in interface ClassElement
@NonNull public Optional<MethodElement> getDefaultConstructor()
ClassElement
getDefaultConstructor
in interface ClassElement
public Map<String,Map<String,org.codehaus.groovy.ast.ClassNode>> getGenericTypeInfo()
@NonNull public Map<String,ClassElement> getTypeArguments(@NonNull String type)
ClassElement
getTypeArguments
in interface ClassElement
type
- The type to retrieve type arguments for@NonNull public Map<String,Map<String,ClassElement>> getAllTypeArguments()
ClassElement
getAllTypeArguments
in interface ClassElement
@NonNull public Map<String,ClassElement> getTypeArguments()
getTypeArguments
in interface ClassElement
public List<PropertyElement> getBeanProperties()
ClassElement
getBeanProperties
in interface ClassElement
public boolean isArray()
TypedElement
isArray
in interface TypedElement
public ClassElement withArrayDimensions(int arrayDimensions)
ArrayableClassElement
withArrayDimensions
in interface ArrayableClassElement
arrayDimensions
- The number of array dimensions of the new class elementpublic int getArrayDimensions()
TypedElement
getArrayDimensions
in interface TypedElement
public String getName()
public String getSimpleName()
ClassElement
getSimpleName
in interface ClassElement
getSimpleName
in interface Element
public String getPackageName()
ClassElement
getPackageName
in interface ClassElement
public PackageElement getPackage()
ClassElement
getPackage
in interface ClassElement
public boolean isAbstract()
isAbstract
in interface Element
public boolean isStatic()
public boolean isPublic()
public boolean isPrivate()
public boolean isFinal()
public boolean isProtected()
isProtected
in interface Element
public Object getNativeType()
Element
getNativeType
in interface Element
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 List<? extends 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
protected final ClassElement toClassElement(org.codehaus.groovy.ast.ClassNode classNode)
@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.