Class NewInstanceCreation

All Implemented Interfaces:
Writable

public class NewInstanceCreation extends ModelElement
Model element representing the head of a new T<>(...) expression. It always renders the diamond operator for generic types, leaving any type-argument inference to the surrounding Java context.

The caller is responsible for emitting the parenthesised argument list after the model.

Imports contributed by this element only include the raw constructor type, not its type parameters: the generated source never references the parameter classes through this expression, so they are not needed here. If the surrounding code references a type parameter elsewhere (e.g. in a variable declaration or a method signature), that reference contributes its own imports through its own model element.

Author:
Filip Hrisafov
  • Method Details

    • forType

      public static NewInstanceCreation forType(Type targetType)
      Creates a NewInstanceCreation for the given target type. If the target has an implementation type (e.g. Collection -> ArrayList), the implementation type is used.
      Parameters:
      targetType - the target type to be instantiated; must not be null
      Returns:
      a new model
    • getType

      public Type getType()
    • getRawType

      public Type getRawType()
    • isGeneric

      public boolean isGeneric()
    • getImportTypes

      public Set<Type> getImportTypes()
      Description copied from class: ModelElement
      Returns a set containing those Types referenced by this model element for which an import statement needs to be declared.
      Specified by:
      getImportTypes in class ModelElement
      Returns:
      A set with type referenced by this model element. Must not be null.