Class ModelUtils

java.lang.Object
io.micronaut.sourcegen.generator.visitors.ModelUtils

@Internal public class ModelUtils extends Object
A utility class for working with complex types, like enums and POJOs.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A record for holding the generated model.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.micronaut.sourcegen.model.ExpressionDef
    convertParameterIfRequired(io.micronaut.inject.ast.ClassElement type, String name, List<io.micronaut.sourcegen.model.StatementDef> statements, io.micronaut.sourcegen.model.ExpressionDef paramExpression)
    Converts a parameter value if required.
    static io.micronaut.sourcegen.model.TypeDef
    getType(io.micronaut.inject.visitor.VisitorContext context, String packageName, io.micronaut.inject.ast.ClassElement element, List<ModelUtils.GeneratedModel> objects)
    A utility method for getting a parameter type.
    static boolean
    isModel(io.micronaut.inject.ast.ClassElement type)
    Whether the type is a model, in which case it will be copied.
    static boolean
    isPOJO(io.micronaut.inject.ast.ClassElement element)
    Whether it is considered a POJO.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ModelUtils

      public ModelUtils()
  • Method Details

    • getType

      public static io.micronaut.sourcegen.model.TypeDef getType(io.micronaut.inject.visitor.VisitorContext context, String packageName, io.micronaut.inject.ast.ClassElement element, List<ModelUtils.GeneratedModel> objects)
      A utility method for getting a parameter type. Complex types, like enums and POJOs get copied and re-mapped.
      Parameters:
      context - the Context
      packageName - The package name to use for new created models
      element - The element
      objects - A mutable list that can be extended with new objects
      Returns:
      The type
    • convertParameterIfRequired

      public static io.micronaut.sourcegen.model.ExpressionDef convertParameterIfRequired(io.micronaut.inject.ast.ClassElement type, String name, List<io.micronaut.sourcegen.model.StatementDef> statements, io.micronaut.sourcegen.model.ExpressionDef paramExpression)
      Converts a parameter value if required. Conversion is required if the value is a model, so a new type was generated for it instead of the original one.
      Parameters:
      type - The type
      name - The name to use for local variable
      statements - The modifiable statements to which a local variable may be added if needed
      paramExpression - The current expression for param
      Returns:
      The new expression for param
    • isPOJO

      public static boolean isPOJO(io.micronaut.inject.ast.ClassElement element)
      Whether it is considered a POJO.
      Parameters:
      element - The type
      Returns:
      Whether it is POJO
    • isModel

      public static boolean isModel(io.micronaut.inject.ast.ClassElement type)
      Whether the type is a model, in which case it will be copied.
      Parameters:
      type - The type
      Returns:
      Whether it is a model