public interface ClassElement extends TypedElement
Modifier and Type | Field and Description |
---|---|
static ClassElement[] |
ZERO_CLASS_ELEMENTS
Constant for an empty class element array.
|
EMPTY_ELEMENT_ARRAY
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
EMPTY
Modifier and Type | Method and Description |
---|---|
default BeanElementBuilder |
addAssociatedBean(ClassElement type)
This method adds an associated bean using this class element as the originating element.
|
default ClassElement |
foldBoundGenericTypes(Function<ClassElement,ClassElement> fold)
Perform a fold operation on the type arguments (type arguments, wildcard bounds, resolved via
getBoundGenericTypes() ), and then on this
type. |
ClassElement |
fromArray()
Dereference a class element denoting an array type by converting it to its element type.
|
default Map<String,Map<String,ClassElement>> |
getAllTypeArguments()
Builds a map of all the type parameters for a class, its super classes and interfaces.
|
default List<PropertyElement> |
getBeanProperties()
Returns the bean properties (getters and setters) for this class element.
|
default 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.
|
default String |
getCanonicalName()
This method will return the name of the underlying type automatically unwrapping in the case of an optional
or wrapped representation of the type.
|
default List<? extends GenericPlaceholderElement> |
getDeclaredGenericPlaceholders()
The type arguments declared on the raw class.
|
default Optional<MethodElement> |
getDefaultConstructor()
Find and return a single default constructor.
|
default <T extends Element> |
getEnclosedElement(ElementQuery<T> query)
Return the first enclosed element matching the given query.
|
default <T extends Element> |
getEnclosedElements(ElementQuery<T> query)
Return the elements that match the given query.
|
default Optional<ClassElement> |
getEnclosingType()
Returns the enclosing type if
isInner() return true . |
default List<FieldElement> |
getFields()
Return all the fields of this class element.
|
default List<FieldElement> |
getFields(Predicate<Set<ElementModifier>> modifierFilter)
Deprecated.
Use
getEnclosedElements(ElementQuery) instead |
default Optional<ClassElement> |
getFirstTypeArgument() |
default Collection<ClassElement> |
getInterfaces() |
default PackageElement |
getPackage()
The package name.
|
default String |
getPackageName()
The package name.
|
default Optional<MethodElement> |
getPrimaryConstructor()
Find and return a single primary constructor.
|
default ClassElement |
getRawClassElement()
Get a
ClassElement instance corresponding to this type, but without any type arguments bound. |
default String |
getSimpleName()
The simple name without the package name.
|
default Optional<ClassElement> |
getSuperType()
Returns the super type of this element or empty if the element has no super type.
|
default ClassElement |
getType() |
default Map<String,ClassElement> |
getTypeArguments() |
default Map<String,ClassElement> |
getTypeArguments(Class<?> type)
Get the type arguments for the given type name.
|
default Map<String,ClassElement> |
getTypeArguments(String type)
Get the type arguments for the given type name.
|
default boolean |
isAssignable(Class<?> type)
Tests whether one type is assignable to another.
|
default boolean |
isAssignable(ClassElement type)
Tests whether one type is assignable to another.
|
boolean |
isAssignable(String type)
Tests whether one type is assignable to another.
|
default boolean |
isEnum()
Whether this element is an enum.
|
default boolean |
isGenericPlaceholder() |
default boolean |
isInner()
Is this type an inner class.
|
default boolean |
isInterface() |
default boolean |
isIterable() |
default boolean |
isOptional()
Whether this element is an
Optional . |
default boolean |
isProxy() |
default boolean |
isRecord() |
default boolean |
isTypeVariable()
In this case of calling
getTypeArguments() a returned ClassElement may represent a type variable
in which case this method will return true . |
default boolean |
isWildcard() |
static ClassElement |
of(Class<?> type)
Create a class element for the given simple type.
|
static ClassElement |
of(Class<?> type,
AnnotationMetadata annotationMetadata,
Map<String,ClassElement> typeArguments)
Create a class element for the given simple type.
|
static ClassElement |
of(String typeName)
Create a class element for the given simple type.
|
static ClassElement |
of(String typeName,
boolean isInterface,
AnnotationMetadata annotationMetadata)
Create a class element for the given simple type.
|
static ClassElement |
of(String typeName,
boolean isInterface,
AnnotationMetadata annotationMetadata,
Map<String,ClassElement> typeArguments)
Create a class element for the given simple type.
|
static ClassElement |
of(Type type)
Create a class element for the given complex type.
|
ClassElement |
toArray()
Convert the class element to an element for the same type, but representing an array.
|
default ClassElement |
withBoundGenericTypes(List<? extends ClassElement> typeArguments)
Get a
ClassElement instance corresponding to this type, but with the given type arguments. |
getArrayDimensions, getGenericType, isArray, isPrimitive
annotate, annotate, annotate, annotate, annotate, getDescription, getDescription, getDocumentation, getModifiers, getName, getNativeType, isAbstract, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, 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
static final ClassElement[] ZERO_CLASS_ELEMENTS
boolean isAssignable(String type)
type
- The type to checktrue
if and only if this type is assignable to the seconddefault boolean isTypeVariable()
getTypeArguments()
a returned ClassElement
may represent a type variable
in which case this method will return true
.default boolean isGenericPlaceholder()
GenericPlaceholderElement
default boolean isWildcard()
WildcardElement
default boolean isAssignable(ClassElement type)
type
- The type to checktrue
if and only if this type is assignable to the seconddefault boolean isOptional()
Optional
.default String getCanonicalName()
default boolean isRecord()
default boolean isInner()
default boolean isEnum()
default boolean isProxy()
@NonNull default Optional<MethodElement> getPrimaryConstructor()
Creator
or Inject
.@NonNull default Optional<MethodElement> getDefaultConstructor()
default Optional<ClassElement> getSuperType()
default Collection<ClassElement> getInterfaces()
@NonNull default ClassElement getType()
getType
in interface TypedElement
default String getSimpleName()
getSimpleName
in interface Element
default String getPackageName()
default PackageElement getPackage()
default List<PropertyElement> getBeanProperties()
default List<FieldElement> getFields()
@Deprecated default List<FieldElement> getFields(@NonNull Predicate<Set<ElementModifier>> modifierFilter)
getEnclosedElements(ElementQuery)
insteadmodifierFilter
- Can be used to filter fields by modifierdefault <T extends Element> List<T> getEnclosedElements(@NonNull ElementQuery<T> query)
T
- The element typequery
- The query to use.default Optional<ClassElement> getEnclosingType()
isInner()
return true
.default <T extends Element> Optional<T> getEnclosedElement(@NonNull ElementQuery<T> query)
T
- The element typequery
- The query to use.default boolean isInterface()
default boolean isIterable()
Iterable
)@NonNull default List<? extends ClassElement> getBoundGenericTypes()
Note that for compatibility reasons, this method is inconsistent with 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>
.
getDeclaredGenericPlaceholders()
. Must be empty or
of the same length as getDeclaredGenericPlaceholders()
.@NonNull default List<? extends GenericPlaceholderElement> getDeclaredGenericPlaceholders()
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
.
@NonNull default ClassElement getRawClassElement()
ClassElement
instance corresponding to this type, but without any type arguments bound. For
List<String>
, this returns List
.@NonNull default ClassElement withBoundGenericTypes(@NonNull List<? extends ClassElement> typeArguments)
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.typeArguments
- The new type arguments.ClassElement
of the same raw class with the new type arguments.UnsupportedOperationException
- If any of the given type arguments are unsupported.default ClassElement foldBoundGenericTypes(@NonNull Function<ClassElement,ClassElement> fold)
getBoundGenericTypes()
), and then on this
type. For List<? extends String>
, this returns f(List<f(? extends f(String))>)
. The bounds of
type variables are not folded.
null
has special meaning here. Returning null
from a fold operation will try to make the
surrounding type a raw type. For example, for Map<String, Object>
, returning null
for the fold
on Object
will lead to the parameterized Map<String, null>
type being replaced by Map
.
This also means that this method may return null
if the top-level fold operation returned null
.
fold
- The fold operation to apply recursively to all component types.@NonNull default Map<String,ClassElement> getTypeArguments(@NonNull String type)
type
- The type to retrieve type arguments for@NonNull default Map<String,ClassElement> getTypeArguments(@NonNull Class<?> type)
type
- The type to retrieve type arguments for@NonNull default Map<String,ClassElement> getTypeArguments()
@NonNull default Map<String,Map<String,ClassElement>> getAllTypeArguments()
default Optional<ClassElement> getFirstTypeArgument()
default boolean isAssignable(Class<?> type)
type
- The type to checktrue
if and only if the this type is assignable to the second@NonNull ClassElement toArray()
@NonNull ClassElement fromArray()
IllegalStateException
- if this class element doesn't denote an array type@NonNull default BeanElementBuilder addAssociatedBean(@NonNull ClassElement type)
Note that this method can only be called on classes being directly compiled by Micronaut. If the ClassElement is
loaded from pre-compiled code an UnsupportedOperationException
will be thrown.
type
- The type of the bean@NonNull static ClassElement of(@NonNull Class<?> type)
type
- The type@NonNull static ClassElement of(@NonNull Type type)
type
- The type@NonNull static ClassElement of(@NonNull Class<?> type, @NonNull AnnotationMetadata annotationMetadata, @NonNull Map<String,ClassElement> typeArguments)
type
- The typeannotationMetadata
- The annotation metadatatypeArguments
- The type arguments@Internal @NonNull static ClassElement of(@NonNull String typeName)
typeName
- The type@Internal @NonNull static ClassElement of(@NonNull String typeName, boolean isInterface, @Nullable AnnotationMetadata annotationMetadata)
typeName
- The typeisInterface
- Is the type an interfaceannotationMetadata
- The annotation metadata@Internal @NonNull static ClassElement of(@NonNull String typeName, boolean isInterface, @Nullable AnnotationMetadata annotationMetadata, Map<String,ClassElement> typeArguments)
typeName
- The typeisInterface
- Is the type an interfaceannotationMetadata
- The annotation metadatatypeArguments
- The type arguments