Interface TypeCreator

All Superinterfaces:
AnnotatableCreator, GenericTyped, ModifiableCreator, SimpleTyped, Typed
All Known Subinterfaces:
AnonymousClassCreator, ClassCreator, InterfaceCreator

public sealed interface TypeCreator extends ModifiableCreator, GenericTyped permits ClassCreator, InterfaceCreator (not exhaustive)
A creator for a type.
  • Method Details

    • setVersion

      void setVersion(Runtime.Version version)
      Set the class file version to correspond with a run time version. If not called, the generated class has the version of Java 17.
      Parameters:
      version - the run time version (must not be null)
    • setVersion

      void setVersion(ClassVersion version)
      Set the class file version. If not called, the generated class has the version of Java 17.
      Parameters:
      version - the class file version (must not be null)
    • sourceFile

      void sourceFile(String name)
      Set the source file name for this type.
      Parameters:
      name - the source file name (must not be null)
    • type

      ClassDesc type()
      Returns the descriptor of the type of this class.
      Specified by:
      type in interface SimpleTyped
      Specified by:
      type in interface Typed
      Returns:
      the descriptor of the type of this class
    • genericType

      GenericType.OfClass genericType()
      Returns the generic type of this class.
      Specified by:
      genericType in interface GenericTyped
      Returns:
      the generic type of this class
    • staticInitializer

      void staticInitializer(Consumer<BlockCreator> builder)
      Add a general static initializer block to the type. A type may have many static initializers; they will be concatenated in the order that they are added.
      Parameters:
      builder - the builder (must not be null)
    • staticMethod

      MethodDesc staticMethod(String name, Consumer<StaticMethodCreator> builder)
      Add a static method to this type.

      Static methods on interfaces are always public.

      Parameters:
      name - the method name (must not be null)
      builder - the builder for the method (must not be null)
      Returns:
      the descriptor of the new method (not null)
    • staticMethod

      default MethodDesc staticMethod(String name, MethodTypeDesc type, Consumer<StaticMethodCreator> builder)
      Add a static method to this type having the given predefined method type.

      Static methods on interfaces are always public.

      Parameters:
      name - the method name (must not be null)
      type - the method type (must not be null)
      builder - the builder for the method (must not be null)
      Returns:
      the descriptor of the new method (not null)
    • staticMethod

      default MethodDesc staticMethod(MethodDesc desc, Consumer<StaticMethodCreator> builder)
      Add a static method to this type having the same name and type as the given method.

      Static methods on interfaces are always public.

      Parameters:
      desc - the original method descriptor (must not be null)
      builder - the builder for the method (must not be null)
      Returns:
      the descriptor of the new method (not null)
    • staticField

      StaticFieldVar staticField(String name, Consumer<StaticFieldCreator> builder)
      Add a static field to this type.

      Static fields on interfaces are always public and final.

      Parameters:
      name - the field name (must not be null)
      builder - the builder for the field (must not be null)
      Returns:
      a variable for the static field (not null)
    • staticField

      default StaticFieldVar staticField(String name, Const initial)
      Add a static field to this type.
      Parameters:
      name - the field name (must not be null)
      initial - the field's initial value (must not be null)
      Returns:
      a variable for the static field (not null)
    • constantField

      default StaticFieldVar constantField(String name, Const value)
      Add a public static final field to this type. The field is initialized to the given value.
      Parameters:
      name - the field name (must not be null)
      value - the constant value (must not be null)
      Returns:
      a variable for the static field (not null)
    • stringListResourceConstant

      Const stringListResourceConstant(String name, List<String> items)
      Create a private constant which loads the given list of strings from a generated resource file. The constant may not be used outside of this class. Any number of strings may be stored in the constant; however, for smaller lists, Const.of(List) is preferred.
      Parameters:
      name - the constant name (must not be null)
      items - the list of strings for the constant (must not be null)
      Returns:
      the constant (not null)
    • stringSetResourceConstant

      Const stringSetResourceConstant(String name, Set<String> items)
      Create a private constant which loads the given set of strings from a generated resource file. The constant may not be used outside of this class. Any number of strings may be stored in the constant; however, for smaller sets, Const.of(Set) is preferred.
      Parameters:
      name - the constant name (must not be null)
      items - the set of strings for the constant (must not be null)
      Returns:
      the constant (not null)
    • stringMapResourceConstant

      Const stringMapResourceConstant(String name, Map<String,String> items)
      Create a private constant which loads the given map of strings from a generated resource file. The constant may not be used outside of this class. Any number of strings may be stored in the constant; however, for smaller maps, Const.of(Map) is preferred.
      Parameters:
      name - the constant name (must not be null)
      items - the map of strings for the constant (must not be null)
      Returns:
      the constant (not null)
    • this_

      This this_()
      Returns the this expression. This expression is only valid for instance methods and constructors.
      Returns:
      the this expression
    • staticFields

      List<FieldDesc> staticFields()
      Returns a list of descriptors of all static fields added to this class so far.
      Returns:
      a list of descriptors of all static fields added to this class so far
    • instanceFields

      List<FieldDesc> instanceFields()
      Returns a list of descriptors of all instance fields added to this class so far.
      Returns:
      a list of descriptors of all instance fields added to this class so far
    • staticMethods

      List<MethodDesc> staticMethods()
      Returns a list of descriptors of all static methods added to this class so far.
      Returns:
      a list of descriptors of all static methods added to this class so far
    • instanceMethods

      List<MethodDesc> instanceMethods()
      Returns a list of descriptors of all instance methods added to this class so far.
      Returns:
      a list of descriptors of all instance methods added to this class so far
    • constructors

      List<ConstructorDesc> constructors()
      Returns a list of descriptors of all constructors added to this class so far.
      Returns:
      a list of descriptors of all constructors added to this class so far