Interface ClassTypeDef
- All Superinterfaces:
TypeDef
- All Known Implementing Classes:
ClassTypeDef.ClassDefType, ClassTypeDef.ClassElementType, ClassTypeDef.ClassName, ClassTypeDef.JavaClass, ClassTypeDef.Parameterized
- Since:
- 1.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordA combined type for representing a ClassTypeDef with annotations.static final recordThe class def element type.static final recordThe class element type.static final recordThe class name type.static final recordThe class type.static final recordThe parameterized type definition.Nested classes/interfaces inherited from interface TypeDef
TypeDef.Annotated, TypeDef.AnnotatedTypeDef, TypeDef.Array, TypeDef.Primitive, TypeDef.TypeVariable, TypeDef.Wildcard -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionannotated(AnnotationDef... annotations) Define a ClassTypeDef with annotations.annotated(List<AnnotationDef> annotations) Define a ClassTypeDef with annotations.default MethodReferenceExpressionconstructorReference(ClassTypeDef owner) Implement this interface with a reference to a constructor, e.g.default MethodReferenceExpressionconstructorReference(ClassTypeDef owner, MethodDef constructor) Implement this interface with a reference to a constructor, e.g.static ClassTypeDeferasure(io.micronaut.inject.ast.ClassElement classElement) Create a new type definition that is an erasure.findDeclaredMethods(String name, int argumentCount) Find the methods this type declares that a call with the given name and number of arguments could target, variable arity included.default Stringdefault LambdaDefFind the method that can be represented as a lambda.default LambdaDefFind the method that can be represented as a lambda.default LambdaDefFind the method that can be represented as a lambda.getName()default Stringdefault Stringdefault VariableDef.StaticFieldgetStaticField(FieldDef field) Get static field.default VariableDef.StaticFieldgetStaticField(Field field) Get static field.default VariableDef.StaticFieldgetStaticField(String name, TypeDef type) Get static field.The names of the type variables this type declares, in declaration order.default ExpressionDef.NewInstanceinstantiate(io.micronaut.inject.ast.MethodElement methodElement, List<? extends ExpressionDef> values) The new instance expression.default ExpressionDef.NewInstanceinstantiate(ExpressionDef... values) The new instance expression.default ExpressionDef.NewInstanceinstantiate(Constructor<?> constructor, ExpressionDef... values) The new instance expression.default ExpressionDef.NewInstanceinstantiate(Constructor<?> constructor, List<? extends ExpressionDef> values) The new instance expression.default ExpressionDef.NewInstanceinstantiate(List<? extends ExpressionDef> values) The new instance expression.default ExpressionDef.NewInstanceinstantiate(List<TypeDef> parameterTypes, ExpressionDef... values) The new instance expression.default ExpressionDef.NewInstanceinstantiate(List<TypeDef> parameterTypes, List<? extends ExpressionDef> values) The new instance expression.default ExpressionDef.InvokeStaticMethodinvokeStatic(io.micronaut.inject.ast.MethodElement methodElement, ExpressionDef... values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(io.micronaut.inject.ast.MethodElement methodElement, List<? extends ExpressionDef> values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(MethodDef method, ExpressionDef... values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(MethodDef method, List<? extends ExpressionDef> values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(Method method, ExpressionDef... values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(Method method, List<? extends ExpressionDef> values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(String name, TypeDef returningType, ExpressionDef... values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(String name, TypeDef returningType, List<? extends ExpressionDef> values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(String name, List<TypeDef> parameterTypes, TypeDef returningType, ExpressionDef... values) Invoke static method.default ExpressionDef.InvokeStaticMethodinvokeStatic(String name, List<TypeDef> parameterTypes, TypeDef returningType, List<? extends ExpressionDef> values) Invoke static method.default booleanisEnum()default booleanisInner()default booleandefault MethodReferenceExpressionmethodReference(ExpressionDef instance, MethodDef method) Implement this interface with a reference to a method of the given receiver, e.g.default MethodReferenceExpressionmethodReference(ExpressionDef instance, Method method) Implement this interface with a reference to a method of the given receiver, e.g.default MethodReferenceExpressionmethodReference(ExpressionDef instance, String name) Implement this interface with a reference to a method of the given receiver, e.g.static ClassTypeDefof(io.micronaut.inject.ast.ClassElement classElement) Create a new type definition.static ClassTypeDefof(io.micronaut.inject.ast.ClassElement classElement, Function<String, TypeDef> resolvedVariableFn, boolean erasure) Create a new type definition.static ClassTypeDefof(io.micronaut.inject.ast.ClassElement classElement, Map<String, TypeDef> resolvedTypeVariables, boolean erasure) Deprecated, for removal: This API element is subject to removal in a future version.static ClassTypeDefCreate a new type definition.static ClassTypeDefCreate a new type definition.static ClassTypeDefCreate a new type definition.static ClassTypeDefCreate a new type definition.default ClassTypeDefresolveTypeVariables(Function<String, @Nullable TypeDef> resolveVariableFn) Resolve the type variables.default MethodReferenceExpressionstaticMethodReference(ClassTypeDef owner, MethodDef method) Implement this interface with a reference to a static method, e.g.default MethodReferenceExpressionstaticMethodReference(ClassTypeDef owner, String name) Implement this interface with a reference to a static method, e.g.Methods inherited from interface TypeDef
array, array, isArray, isNullable, isPrimitive, resolveTypeVariables
-
Field Details
-
OBJECT
-
-
Method Details
-
getName
String getName()- Returns:
- The type name
-
resolveTypeVariables
Description copied from interface:TypeDefResolve the type variables.- Specified by:
resolveTypeVariablesin interfaceTypeDef- Parameters:
resolveVariableFn- The resolved variable function- Returns:
- The resolved type or the previous.
-
getCanonicalName
- Returns:
- The canonical type name
- Since:
- 1.5
-
getSimpleName
- Returns:
- The simple name
-
getPackageName
- Returns:
- The package name
-
makeNullable
ClassTypeDef makeNullable()- Specified by:
makeNullablein interfaceTypeDef- Returns:
- A new nullable type
-
isEnum
default boolean isEnum()- Returns:
- True if the class is an enum
- Since:
- 1.2
-
isInterface
default boolean isInterface()- Returns:
- True if interface
- Since:
- 1.5
-
isInner
default boolean isInner()- Returns:
- True if inner
- Since:
- 1.5
-
findDeclaredMethods
Find the methods this type declares that a call with the given name and number of arguments could target, variable arity included.Used by the convenience overloads that would otherwise build the invoked signature from the static types of the arguments, which names a method that does not exist whenever an argument is statically narrower than the declared parameter.
Bridge methods are included, because their descriptors are real: a covariant override such as
ReentrantReadWriteLock.readLock()leaves a bridge returning the supertype, and a call declaring that return type does resolve.Only implementations that carry member information return anything -
of(Class),of(ClassElement)and a definition being generated.of(String)has nothing to resolve against and returns an empty list, which leaves the signature inferred as before.- Parameters:
name- The method name, orMethodDef.CONSTRUCTORargumentCount- The number of arguments at the call site- Returns:
- The candidate methods, or an empty list when they cannot be resolved
- Since:
- 2.2
-
getTypeVariableNames
The names of the type variables this type declares, in declaration order.Used to line up the arguments of a
ClassTypeDef.Parameterizedtype with the variables the raw type declares. Only implementations that carry member information return anything.- Returns:
- The type variable names, or an empty list when they cannot be resolved
- Since:
- 2.2
-
getLambda
-
getLambda
-
getLambda
Find the method that can be represented as a lambda.- Returns:
- The lambda method
- Since:
- 1.7
-
methodReference
Implement this interface with a reference to a method of the given receiver, e.g.myInstance::instanceMethod.Here
thisis the functional interface being implemented, as it is forgetLambda(). The receiver is evaluated where the reference is created, not where the interface method is called.Parameterize the interface -
TypeDef.parameterized(Function.class, String.class, String.class)- so that its type variables resolve; a raw interface leaves them erased toObjectand the reference fails to link.- Parameters:
instance- The receiver the reference is bound tomethod- The referenced method- Returns:
- The method reference
- Since:
- 2.2
-
methodReference
Implement this interface with a reference to a method of the given receiver, e.g.myInstance::instanceMethod.- Parameters:
instance- The receiver the reference is bound tomethod- The referenced method- Returns:
- The method reference
- Since:
- 2.2
-
methodReference
Implement this interface with a reference to a method of the given receiver, e.g.myInstance::instanceMethod.The method is resolved with
findDeclaredMethods(String, int)against the type ofinstance, which requires it to carry member information. UsemethodReference(ExpressionDef, MethodDef)when it does not.- Parameters:
instance- The receiver the reference is bound toname- The name of the referenced method- Returns:
- The method reference
- Since:
- 2.2
-
staticMethodReference
Implement this interface with a reference to a static method, e.g.MyClass::staticMethod.Parameterize this interface -
TypeDef.parameterized(Function.class, String.class, String.class)- so that its type variables resolve; a raw interface leaves them erased toObjectand the reference fails to link.- Parameters:
owner- The type declaring the methodmethod- The referenced method- Returns:
- The method reference
- Since:
- 2.2
-
staticMethodReference
Implement this interface with a reference to a static method, e.g.MyClass::staticMethod.- Parameters:
owner- The type declaring the methodname- The name of the referenced method- Returns:
- The method reference
- Since:
- 2.2
-
constructorReference
Implement this interface with a reference to a constructor, e.g.MyClass::new.- Parameters:
owner- The type to constructconstructor- The referenced constructor- Returns:
- The method reference
- Since:
- 2.2
-
constructorReference
Implement this interface with a reference to a constructor, e.g.MyClass::new.The constructor is resolved with
findDeclaredMethods(String, int), which requiresownerto carry member information. UseconstructorReference(ClassTypeDef, MethodDef)when it does not, or when more than one constructor takes the arguments of the interface.- Parameters:
owner- The type to construct- Returns:
- The method reference
- Since:
- 2.2
-
instantiate
The new instance expression.- Parameters:
values- The constructor values- Returns:
- The new instance
-
instantiate
The new instance expression.The constructor is resolved with
findDeclaredMethods(String, int)when this type carries member information. When it does not, the signature is inferred from the static types of the values, which names a constructor that does not exist if any of them is narrower than the declared parameter - useinstantiate(List, List)orinstantiate(Constructor, List)then.- Parameters:
values- The constructor values- Returns:
- The new instance
-
instantiate
default ExpressionDef.NewInstance instantiate(List<TypeDef> parameterTypes, ExpressionDef... values) The new instance expression.- Parameters:
parameterTypes- The constructor parameter typesvalues- The constructor values- Returns:
- The new instance
-
instantiate
default ExpressionDef.NewInstance instantiate(List<TypeDef> parameterTypes, List<? extends ExpressionDef> values) The new instance expression.- Parameters:
parameterTypes- The constructor parameter typesvalues- The constructor values- Returns:
- The new instance
-
instantiate
The new instance expression.- Parameters:
constructor- The constructorvalues- The constructor values- Returns:
- The new instance
-
instantiate
default ExpressionDef.NewInstance instantiate(Constructor<?> constructor, List<? extends ExpressionDef> values) The new instance expression.- Parameters:
constructor- The constructorvalues- The constructor values- Returns:
- The new instance
-
instantiate
default ExpressionDef.NewInstance instantiate(io.micronaut.inject.ast.MethodElement methodElement, List<? extends ExpressionDef> values) The new instance expression.- Parameters:
methodElement- The method elementvalues- The constructor values- Returns:
- The new instance
-
getStaticField
Get static field.- Parameters:
name- The field nametype- The field type- Returns:
- the get static field expression
- Since:
- 1.5
-
getStaticField
Get static field.- Parameters:
field- The field- Returns:
- the get static field expression
- Since:
- 1.5
-
getStaticField
Get static field.- Parameters:
field- The field- Returns:
- the get static field expression
- Since:
- 1.5
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(String name, TypeDef returningType, List<? extends ExpressionDef> values) Invoke static method.The method is resolved with
findDeclaredMethods(String, int)when this type carries member information. When it does not, the signature is inferred from the static types of the values, which names a method that does not exist if any of them is narrower than the declared parameter - useinvokeStatic(String, List, TypeDef, List),invokeStatic(Method, List)orinvokeStatic(MethodElement, List)then.- Parameters:
name- The method namereturningType- The return typevalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.2
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(String name, List<TypeDef> parameterTypes, TypeDef returningType, List<? extends ExpressionDef> values) Invoke static method.- Parameters:
name- The method nameparameterTypes- The parameter typesreturningType- The return typevalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(String name, TypeDef returningType, ExpressionDef... values) Invoke static method.- Parameters:
name- The method namereturningType- The return typevalues- The parameters- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(String name, List<TypeDef> parameterTypes, TypeDef returningType, ExpressionDef... values) Invoke static method.- Parameters:
name- The method nameparameterTypes- The parameter typesreturningType- The return typevalues- The parameters- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
Invoke static method.- Parameters:
method- The methodvalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
Invoke static method.- Parameters:
method- The methodvalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(Method method, List<? extends ExpressionDef> values) Invoke static method.- Parameters:
method- The methodvalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(io.micronaut.inject.ast.MethodElement methodElement, ExpressionDef... values) Invoke static method.- Parameters:
methodElement- The method elementvalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(io.micronaut.inject.ast.MethodElement methodElement, List<? extends ExpressionDef> values) Invoke static method.- Parameters:
methodElement- The method elementvalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.5
-
invokeStatic
default ExpressionDef.InvokeStaticMethod invokeStatic(MethodDef method, List<? extends ExpressionDef> values) Invoke static method.- Parameters:
method- The methodvalues- The values- Returns:
- the invoke static method expression
- Since:
- 1.5
-
of
Create a new type definition.- Parameters:
type- The class- Returns:
- type definition
-
of
Create a new type definition.- Parameters:
className- The class name- Returns:
- type definition
-
erasure
Create a new type definition that is an erasure. This means that no type arguments will be copied.- Parameters:
classElement- The class element- Returns:
- type definition
-
of
Create a new type definition.- Parameters:
className- The class nameisInner- Is inner type- Returns:
- type definition
- Since:
- 1.5
-
of
Create a new type definition.- Parameters:
classElement- The class element- Returns:
- type definition
-
of
@Deprecated(since="2.0", forRemoval=true) static ClassTypeDef of(io.micronaut.inject.ast.ClassElement classElement, Map<String, TypeDef> resolvedTypeVariables, boolean erasure) Deprecated, for removal: This API element is subject to removal in a future version.Replaced withTypeDef.of(TypedElement, Function, boolean)Create a new type definition.- Parameters:
classElement- The class elementresolvedTypeVariables- The resolved type variableserasure- The erasure- Returns:
- type definition
-
of
static ClassTypeDef of(io.micronaut.inject.ast.ClassElement classElement, Function<String, TypeDef> resolvedVariableFn, boolean erasure) Create a new type definition.- Parameters:
classElement- The class elementresolvedVariableFn- The resolved variable functionerasure- The erasure- Returns:
- type definition
- Since:
- 2.0
-
of
Create a new type definition.- Parameters:
objectDef- The object definition- Returns:
- type definition
-
annotated
Define a ClassTypeDef with annotations. -
annotated
Define a ClassTypeDef with annotations.
-
TypeDef.of(TypedElement, Function, boolean)