Interface ClassTypeDef

All Superinterfaces:
TypeDef
All Known Implementing Classes:
ClassTypeDef.ClassDefType, ClassTypeDef.ClassElementType, ClassTypeDef.ClassName, ClassTypeDef.JavaClass, ClassTypeDef.Parameterized

The class type definition. Not-null by default.
Since:
1.0
Author:
Denis Stepanov
  • Field Details

  • Method Details

    • getName

      String getName()
      Returns:
      The type name
    • resolveTypeVariables

      default ClassTypeDef resolveTypeVariables(Function<String, @Nullable TypeDef> resolveVariableFn)
      Description copied from interface: TypeDef
      Resolve the type variables.
      Specified by:
      resolveTypeVariables in interface TypeDef
      Parameters:
      resolveVariableFn - The resolved variable function
      Returns:
      The resolved type or the previous.
    • getCanonicalName

      default String getCanonicalName()
      Returns:
      The canonical type name
      Since:
      1.5
    • getSimpleName

      default String getSimpleName()
      Returns:
      The simple name
    • getPackageName

      default String getPackageName()
      Returns:
      The package name
    • makeNullable

      ClassTypeDef makeNullable()
      Specified by:
      makeNullable in interface TypeDef
      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

      default List<MethodDef> 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.

      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, or MethodDef.CONSTRUCTOR
      argumentCount - 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

      default List<String> getTypeVariableNames()
      The names of the type variables this type declares, in declaration order.

      Used to line up the arguments of a ClassTypeDef.Parameterized type 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

      default LambdaDef getLambda(Map<String,TypeDef> resolvedTypeVariables)
      Find the method that can be represented as a lambda.
      Parameters:
      resolvedTypeVariables - The resolved type variables
      Returns:
      The lambda method
      Since:
      1.7
    • getLambda

      default LambdaDef getLambda(Function<String, @Nullable TypeDef> resolveVariableFn)
      Find the method that can be represented as a lambda.
      Parameters:
      resolveVariableFn - The resolved variable function
      Returns:
      The lambda method
      Since:
      2.0
    • getLambda

      default LambdaDef getLambda()
      Find the method that can be represented as a lambda.
      Returns:
      The lambda method
      Since:
      1.7
    • methodReference

      default MethodReferenceExpression methodReference(ExpressionDef instance, MethodDef method)
      Implement this interface with a reference to a method of the given receiver, e.g. myInstance::instanceMethod.

      Here this is the functional interface being implemented, as it is for getLambda(). 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 to Object and the reference fails to link.

      Parameters:
      instance - The receiver the reference is bound to
      method - The referenced method
      Returns:
      The method reference
      Since:
      2.2
    • methodReference

      default MethodReferenceExpression methodReference(ExpressionDef instance, Method method)
      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 to
      method - The referenced method
      Returns:
      The method reference
      Since:
      2.2
    • methodReference

      default MethodReferenceExpression methodReference(ExpressionDef instance, String name)
      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 of instance, which requires it to carry member information. Use methodReference(ExpressionDef, MethodDef) when it does not.

      Parameters:
      instance - The receiver the reference is bound to
      name - The name of the referenced method
      Returns:
      The method reference
      Since:
      2.2
    • staticMethodReference

      default MethodReferenceExpression staticMethodReference(ClassTypeDef owner, MethodDef method)
      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 to Object and the reference fails to link.

      Parameters:
      owner - The type declaring the method
      method - The referenced method
      Returns:
      The method reference
      Since:
      2.2
    • staticMethodReference

      default MethodReferenceExpression staticMethodReference(ClassTypeDef owner, String name)
      Implement this interface with a reference to a static method, e.g. MyClass::staticMethod.
      Parameters:
      owner - The type declaring the method
      name - The name of the referenced method
      Returns:
      The method reference
      Since:
      2.2
    • constructorReference

      default MethodReferenceExpression constructorReference(ClassTypeDef owner, MethodDef constructor)
      Implement this interface with a reference to a constructor, e.g. MyClass::new.
      Parameters:
      owner - The type to construct
      constructor - The referenced constructor
      Returns:
      The method reference
      Since:
      2.2
    • constructorReference

      default MethodReferenceExpression constructorReference(ClassTypeDef owner)
      Implement this interface with a reference to a constructor, e.g. MyClass::new.

      The constructor is resolved with findDeclaredMethods(String, int), which requires owner to carry member information. Use constructorReference(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

      default ExpressionDef.NewInstance instantiate(ExpressionDef... values)
      The new instance expression.
      Parameters:
      values - The constructor values
      Returns:
      The new instance
    • instantiate

      default ExpressionDef.NewInstance instantiate(List<? extends ExpressionDef> values)
      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 - use instantiate(List, List) or instantiate(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 types
      values - 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 types
      values - The constructor values
      Returns:
      The new instance
    • instantiate

      default ExpressionDef.NewInstance instantiate(Constructor<?> constructor, ExpressionDef... values)
      The new instance expression.
      Parameters:
      constructor - The constructor
      values - 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 constructor
      values - 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 element
      values - The constructor values
      Returns:
      The new instance
    • getStaticField

      default VariableDef.StaticField getStaticField(String name, TypeDef type)
      Get static field.
      Parameters:
      name - The field name
      type - The field type
      Returns:
      the get static field expression
      Since:
      1.5
    • getStaticField

      default VariableDef.StaticField getStaticField(FieldDef field)
      Get static field.
      Parameters:
      field - The field
      Returns:
      the get static field expression
      Since:
      1.5
    • getStaticField

      default VariableDef.StaticField getStaticField(Field field)
      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 - use invokeStatic(String, List, TypeDef, List), invokeStatic(Method, List) or invokeStatic(MethodElement, List) then.

      Parameters:
      name - The method name
      returningType - The return type
      values - 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 name
      parameterTypes - The parameter types
      returningType - The return type
      values - 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 name
      returningType - The return type
      values - 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 name
      parameterTypes - The parameter types
      returningType - The return type
      values - The parameters
      Returns:
      the invoke static method expression
      Since:
      1.5
    • invokeStatic

      default ExpressionDef.InvokeStaticMethod invokeStatic(MethodDef method, ExpressionDef... values)
      Invoke static method.
      Parameters:
      method - The method
      values - The values
      Returns:
      the invoke static method expression
      Since:
      1.5
    • invokeStatic

      default ExpressionDef.InvokeStaticMethod invokeStatic(Method method, ExpressionDef... values)
      Invoke static method.
      Parameters:
      method - The method
      values - 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 method
      values - 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 element
      values - 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 element
      values - 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 method
      values - The values
      Returns:
      the invoke static method expression
      Since:
      1.5
    • of

      static ClassTypeDef of(Class<?> type)
      Create a new type definition.
      Parameters:
      type - The class
      Returns:
      type definition
    • of

      static ClassTypeDef of(String className)
      Create a new type definition.
      Parameters:
      className - The class name
      Returns:
      type definition
    • erasure

      static ClassTypeDef erasure(io.micronaut.inject.ast.ClassElement classElement)
      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

      static ClassTypeDef of(String className, boolean isInner)
      Create a new type definition.
      Parameters:
      className - The class name
      isInner - Is inner type
      Returns:
      type definition
      Since:
      1.5
    • of

      static ClassTypeDef of(io.micronaut.inject.ast.ClassElement classElement)
      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.
      Create a new type definition.
      Parameters:
      classElement - The class element
      resolvedTypeVariables - The resolved type variables
      erasure - 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 element
      resolvedVariableFn - The resolved variable function
      erasure - The erasure
      Returns:
      type definition
      Since:
      2.0
    • of

      static ClassTypeDef of(ObjectDef objectDef)
      Create a new type definition.
      Parameters:
      objectDef - The object definition
      Returns:
      type definition
    • annotated

      default ClassTypeDef.AnnotatedClassTypeDef annotated(AnnotationDef... annotations)
      Define a ClassTypeDef with annotations.
      Specified by:
      annotated in interface TypeDef
      Parameters:
      annotations - the annotation definitions to be added
      Returns:
      The AnnotatedClassTypeDef
      Since:
      1.4
    • annotated

      default ClassTypeDef.AnnotatedClassTypeDef annotated(List<AnnotationDef> annotations)
      Define a ClassTypeDef with annotations.
      Specified by:
      annotated in interface TypeDef
      Parameters:
      annotations - The list of the AnnotationDef
      Returns:
      The AnnotatedClassTypeDef
      Since:
      1.4