- All Superinterfaces:
AnnotatableCreator,GenericTyped,ModifiableCreator,SimpleTyped,TypeCreator,Typed,TypeParameterizedCreator
- All Known Subinterfaces:
AnonymousClassCreator
public sealed interface ClassCreator
extends TypeCreator, SimpleTyped, TypeParameterizedCreator
permits AnonymousClassCreator (not exhaustive)
A creator for a class type.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidAdd theabstractmodifier flag to this creator.default MethodDescabstractMethod(MethodDesc desc, Consumer<AbstractMethodCreator> builder) Add an abstract instance method to the class having the same name and type as the given method.default MethodDescabstractMethod(String name, MethodTypeDesc type, Consumer<AbstractMethodCreator> builder) Add an abstract instance method to the class having the given predefined type.abstractMethod(String name, Consumer<AbstractMethodCreator> builder) Add an abstract instance method to the class.default ConstructorDescconstructor(ConstructorDesc desc, Consumer<ConstructorCreator> builder) Add a constructor to the class having the same type as the given constructor.default ConstructorDescconstructor(MethodTypeDesc type, Consumer<ConstructorCreator> builder) Add a constructor to the class having the given predefined type.constructor(Consumer<ConstructorCreator> builder) Add a constructor to the class.default ConstructorDescAdd a default constructor to this class.voidextends_(GenericType.OfClass genericType) Extend the given generic class.default voidExtend the given class.voidExtend the given class.default FieldDescAdd an instance field to this class.field(String name, Consumer<InstanceFieldCreator> builder) Add an instance field to this class.default voidgenerateEquals(List<FieldDesc> fields) Generates a structuralequalsmethod in this class that compares givenfields.default voidgenerateEqualsAndHashCode(List<FieldDesc> fields) Generates structuralequalsandhashCodemethods in this class, based on givenfields.default voidgenerateToString(List<FieldDesc> fields) Generates atoStringmethods in this class, based on givenfields.voidimplements_(GenericType.OfClass genericType) Implement a generic interface.default voidimplements_(Class<?> interface_) Implement an interface.voidimplements_(ClassDesc interface_) Implement an interface.voidinstanceInitializer(Consumer<BlockCreator> builder) Add a general instance initializer block to the type.default MethodDescmethod(MethodDesc desc, Consumer<InstanceMethodCreator> builder) Add an instance method to the class having the same name and type as the given method.default MethodDescmethod(String name, MethodTypeDesc type, Consumer<InstanceMethodCreator> builder) Add an instance method to the class having the given predefined type.method(String name, Consumer<InstanceMethodCreator> builder) Add an instance method to the class.default MethodDescnativeMethod(MethodDesc desc, Consumer<AbstractMethodCreator> builder) Add a native instance method to the class having the same name and type as the given method.default MethodDescnativeMethod(String name, MethodTypeDesc type, Consumer<AbstractMethodCreator> builder) Add a native instance method to the class having the given predefined type.nativeMethod(String name, Consumer<AbstractMethodCreator> builder) Add a native instance method to the class.default MethodDescstaticNativeMethod(MethodDesc desc, Consumer<AbstractMethodCreator> builder) Add a native static method to the class having the same name and type as the given method.default MethodDescstaticNativeMethod(String name, MethodTypeDesc type, Consumer<AbstractMethodCreator> builder) Add a native static method to the class having the given predefined type.staticNativeMethod(String name, Consumer<AbstractMethodCreator> builder) Add a native static method to the class.Returns the superclass.Methods inherited from interface io.quarkus.gizmo2.creator.AnnotatableCreator
addAnnotation, addAnnotation, addAnnotation, addAnnotationMethods inherited from interface io.quarkus.gizmo2.GenericTyped
hasGenericTypeMethods inherited from interface io.quarkus.gizmo2.creator.ModifiableCreator
addFlag, addFlags, addFlags, final_, modifierLocation, packagePrivate, private_, protected_, public_, removeFlag, removeFlags, removeFlags, setAccess, supports, syntheticMethods inherited from interface io.quarkus.gizmo2.SimpleTyped
isPrimitive, isVoid, slotSize, typeKindMethods inherited from interface io.quarkus.gizmo2.creator.TypeCreator
constantField, constructors, genericType, instanceFields, instanceMethods, setVersion, setVersion, sourceFile, staticField, staticField, staticFields, staticInitializer, staticMethod, staticMethod, staticMethod, staticMethods, stringListResourceConstant, stringMapResourceConstant, stringSetResourceConstant, this_, typeMethods inherited from interface io.quarkus.gizmo2.creator.TypeParameterizedCreator
typeParameter, typeParameter
-
Method Details
-
superClass
ClassDesc superClass()Returns the superclass.- Returns:
- the superclass
- See Also:
-
extends_
Extend the given generic class.- Parameters:
genericType- the generic class (must not benull)
-
extends_
Extend the given class.- Parameters:
desc- the class (must not benull)
-
implements_
Implement a generic interface.- Parameters:
genericType- the generic interface type (must not benull)
-
implements_
Implement an interface.- Parameters:
interface_- the descriptor of the interface (must not benull)
-
implements_
Implement an interface.- Parameters:
interface_- the interface (must not benull)
-
extends_
Extend the given class.- Parameters:
clazz- the class (must not benull)
-
field
Add an instance field to this class.- Parameters:
name- the field name (must not benull)builder- the builder (must not benull)- Returns:
- the field variable (not
null)
-
field
Add an instance field to this class.- Parameters:
name- the field name (must not benull)initial- the field's initial value (must not benull)- Returns:
- the field variable (not
null)
-
method
Add an instance method to the class.- Parameters:
name- the method name (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
method
default MethodDesc method(String name, MethodTypeDesc type, Consumer<InstanceMethodCreator> builder) Add an instance method to the class having the given predefined type.- Parameters:
name- the method name (must not benull)type- the method type (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
method
Add an instance method to the class having the same name and type as the given method.- Parameters:
desc- the original method descriptor (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
abstractMethod
Add an abstract instance method to the class.- Parameters:
name- the method name (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
abstractMethod
default MethodDesc abstractMethod(String name, MethodTypeDesc type, Consumer<AbstractMethodCreator> builder) Add an abstract instance method to the class having the given predefined type.- Parameters:
name- the method name (must not benull)type- the method type (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
abstractMethod
Add an abstract instance method to the class having the same name and type as the given method.- Parameters:
desc- the original method descriptor (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
nativeMethod
Add a native instance method to the class.- Parameters:
name- the method name (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
nativeMethod
default MethodDesc nativeMethod(String name, MethodTypeDesc type, Consumer<AbstractMethodCreator> builder) Add a native instance method to the class having the given predefined type.- Parameters:
name- the method name (must not benull)type- the method type (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
nativeMethod
Add a native instance method to the class having the same name and type as the given method.- Parameters:
desc- the original method descriptor (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
staticNativeMethod
Add a native static method to the class.- Parameters:
name- the method name (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
staticNativeMethod
default MethodDesc staticNativeMethod(String name, MethodTypeDesc type, Consumer<AbstractMethodCreator> builder) Add a native static method to the class having the given predefined type.- Parameters:
name- the method name (must not benull)type- the method type (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
staticNativeMethod
Add a native static method to the class having the same name and type as the given method.- Parameters:
desc- the original method descriptor (must not benull)builder- the method builder (must not benull)- Returns:
- the built method's selector for invocation (not
null)
-
constructor
Add a constructor to the class.- Parameters:
builder- the constructor builder (must not benull)- Returns:
- the built constructor's selector for invocation (must not be
null)
-
constructor
Add a constructor to the class having the given predefined type. The type must have avoidreturn type.- Parameters:
type- the method type (must not benull)builder- the constructor builder (must not benull)- Returns:
- the built constructor's selector for invocation (must not be
null)
-
constructor
Add a constructor to the class having the same type as the given constructor.- Parameters:
desc- the original constructor descriptor (must not benull)builder- the constructor builder (must not benull)- Returns:
- the built constructor's selector for invocation (must not be
null)
-
defaultConstructor
Add a default constructor to this class.- Returns:
- the built constructor's selector for invocation (must not be
null)
-
instanceInitializer
Add a general instance initializer block to the type. A type may have many instance initializers; they will be concatenated in the order that they are added.- Parameters:
builder- the builder (must not benull)
-
abstract_
default void abstract_()Add theabstractmodifier flag to this creator.- Throws:
IllegalArgumentException- if this creator does not support theabstractmodifier flag
-
generateEquals
Generates a structuralequalsmethod in this class that compares givenfields. The generated code is similar to what IDEs would typically generate from a template:- Reference equality is tested. If
thisis identical to the other object,trueis returned. - Type of the other object is tested using
instanceof. If the other object is not an instance of this class,falseis returned. - All fields are compared. Primitive types are compared using
==, object types are compared usingObjects.equals, single-dimension arrays are compared usingArrays.equals, and multi-dimensional arrays are compared usingArrays.deepEquals. If one of the comparisons fails,falseis returned. - Otherwise,
trueis returned.
If one of the fields doesn't belong to this class, an exception is thrown.
- Parameters:
fields- fields to consider in theequalsmethod (must not benull)
- Reference equality is tested. If
-
generateEqualsAndHashCode
Generates structuralequalsandhashCodemethods in this class, based on givenfields. The generated code is similar to what IDEs would typically generate from a template. SeegenerateEquals(List)for description of the generatedequalsmethod. ThehashCodemethod is generated like so:- If no field is given, 0 is returned.
- Otherwise, a result variable is allocated with initial value of 1.
- For each field, a hash code is computed. Hash code for primitive types
is computed using
Integer.hashCodeand equivalent methods, for object types usingObjects.hashCode, for single-dimension arrays usingArrays.hashCode, and for multi-dimensional arrays usingArrays.deepHashCode. Then, the result is updated like so:result = 31 * result + fieldHashCode. - At the end, the result is returned.
If one of the fields doesn't belong to this class, an exception is thrown.
- Parameters:
fields- fields to consider in theequalsandhashCodemethods (must not benull)
-
generateToString
Generates atoStringmethods in this class, based on givenfields. The generated code is similar to what IDEs would typically generate from a template:- An empty
StringBuilderis allocated. - Simple name of the class is appended.
- An opening parenthesis
'('is appended. - For each field, its name is appended, followed by the equals sign
'=', followed by the field value. Primitive types and object types are appended to theStringBuilderdirectly,Arrays.toStringis used for single-dimension arrays, andArrays.deepToStringfor multi-dimensional arrays. A comma followed by a space", "are appended between fields. - A closing parenthesis
')'is appended. - The
StringBuilder.toString()outcome is returned.
If one of the fields doesn't belong to this class, an exception is thrown.
- Parameters:
fields- fields to consider in thetoStringmethods (must not benull)
- An empty
-