Interface ClassBuilder
- All Superinterfaces:
- ClassFileBuilder<ClassElement, ClassBuilder>, Consumer<ClassElement>
A builder for a 
class file.  ClassFile provides different
build methods that accept handlers to configure such a builder;
ClassFile.build(ClassDesc, Consumer) suffices for basic usage, while
ClassFile.build(ClassEntry, ConstantPoolBuilder, Consumer) allows
fine-grained control over the
constant pool.
Refer to ClassFileBuilder for general guidance and caution around
the use of builders for structures in the class file format.
- Since:
- 24
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptiontransformField(FieldModel field, FieldTransform transform) Adds a field by transforming a field from another class.transformMethod(MethodModel method, MethodTransform transform) Adds a method by transforming a method from another class.default ClassBuilderAdds a field, with only access flags.withField(Utf8Entry name, Utf8Entry descriptor, Consumer<? super FieldBuilder> handler) Adds a field.default ClassBuilderAdds a field, with only access flags.default ClassBuilderwithField(String name, ClassDesc descriptor, Consumer<? super FieldBuilder> handler) Adds a field.default ClassBuilderwithFlags(int flags) Sets the access flags of this class.default ClassBuilderwithFlags(AccessFlag... flags) Sets the access flags of this class.default ClassBuilderwithInterfaces(ClassEntry... interfaces) Sets the interfaces of this class.default ClassBuilderwithInterfaces(List<ClassEntry> interfaces) Sets the interfaces of this class.default ClassBuilderwithInterfaceSymbols(ClassDesc... interfaces) Sets the interfaces of this class.default ClassBuilderwithInterfaceSymbols(List<ClassDesc> interfaces) Sets the interfaces of this class.withMethod(Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super MethodBuilder> handler) Adds a method.default ClassBuilderwithMethod(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super MethodBuilder> handler) Adds a method.default ClassBuilderwithMethodBody(Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super CodeBuilder> handler) Adds a method, with only access flags and aCodeModel.default ClassBuilderwithMethodBody(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super CodeBuilder> handler) Adds a method, with only access flags and aCodeModel.default ClassBuilderwithSuperclass(ClassEntry superclassEntry) Sets the superclass of this class.default ClassBuilderwithSuperclass(ClassDesc desc) Sets the superclass of this class.default ClassBuilderwithVersion(int major, int minor) Sets the version of this class.Methods declared in interface ClassFileBuilderaccept, constantPool, transform, with
- 
Method Details- 
withVersionSets the version of this class.- Parameters:
- major- the major version number
- minor- the minor version number
- Returns:
- this builder
- See Also:
 
- 
withFlagsSets the access flags of this class.- Parameters:
- flags- the access flags, as a bit mask
- Returns:
- this builder
- See Also:
 
- 
withFlagsSets the access flags of this class.- Parameters:
- flags- the access flags, as flag enums
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if any flag cannot be applied to the- AccessFlag.Location.CLASSlocation
- See Also:
 
- 
withSuperclassSets the superclass of this class.- Parameters:
- superclassEntry- the superclass
- Returns:
- this builder
- See Also:
 
- 
withSuperclassSets the superclass of this class.- Parameters:
- desc- the superclass
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- descrepresents a primitive type
- See Also:
 
- 
withInterfacesSets the interfaces of this class.- Parameters:
- interfaces- the interfaces
- Returns:
- this builder
- See Also:
 
- 
withInterfacesSets the interfaces of this class.- Parameters:
- interfaces- the interfaces
- Returns:
- this builder
- See Also:
 
- 
withInterfaceSymbolsSets the interfaces of this class.- Parameters:
- interfaces- the interfaces
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if any element of- interfacesis primitive
- See Also:
 
- 
withInterfaceSymbolsSets the interfaces of this class.- Parameters:
- interfaces- the interfaces
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if any element of- interfacesis primitive
- See Also:
 
- 
withFieldClassBuilder withField(Utf8Entry name, Utf8Entry descriptor, Consumer<? super FieldBuilder> handler) Adds a field.- Parameters:
- name- the field name
- descriptor- the field descriptor string
- handler- handler to supply the contents of the field
- Returns:
- this builder
- See Also:
 
- 
withFieldAdds a field, with only access flags.- Parameters:
- name- the field name
- descriptor- the field descriptor string
- flags- the access flags for this field, as a bit mask
- Returns:
- this builder
- See Also:
 
- 
withFielddefault ClassBuilder withField(String name, ClassDesc descriptor, Consumer<? super FieldBuilder> handler) Adds a field.- Parameters:
- name- the field name
- descriptor- the symbolic field descriptor
- handler- handler to supply the contents of the field
- Returns:
- this builder
- See Also:
 
- 
withFieldAdds a field, with only access flags.- Parameters:
- name- the field name
- descriptor- the symbolic field descriptor
- flags- the access flags for this field, as a bit mask
- Returns:
- this builder
- See Also:
 
- 
transformFieldAdds a field by transforming a field from another class.This method behaves as if: - Parameters:
- field- the field to be transformed
- transform- the transform to apply to the field
- Returns:
- this builder
- See Also:
 
- 
withMethodClassBuilder withMethod(Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super MethodBuilder> handler) Adds a method. The bit forACC_STATICflag cannot be modified by thehandlerlater, and must be set throughmethodFlags.- Parameters:
- name- the method name
- descriptor- the method descriptor
- methodFlags- the access flags as a bit mask, with the- ACC_STATICbit definitely set
- handler- handler to supply the contents of the method
- Returns:
- this builder
- See Also:
 
- 
withMethodBodydefault ClassBuilder withMethodBody(Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super CodeBuilder> handler) Adds a method, with only access flags and aCodeModel. The bit forACC_STATICflag cannot be modified by thehandlerlater, and must be set throughmethodFlags.This method behaves as if: withMethod(name, descriptor, methodFlags, mb -> mb.withCode(handler))- Parameters:
- name- the method name
- descriptor- the method descriptor
- methodFlags- the access flags as a bit mask, with the- ACC_STATICbit definitely set
- handler- handler to supply the contents of the method body
- Returns:
- this builder
- See Also:
 
- 
withMethoddefault ClassBuilder withMethod(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super MethodBuilder> handler) Adds a method. The bit forACC_STATICflag cannot be modified by thehandler, and must be set throughmethodFlags.- Parameters:
- name- the method name
- descriptor- the method descriptor
- methodFlags- the access flags as a bit mask, with the- ACC_STATICbit definitely set
- handler- handler to supply the contents of the method
- Returns:
- this builder
- See Also:
 
- 
withMethodBodydefault ClassBuilder withMethodBody(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super CodeBuilder> handler) Adds a method, with only access flags and aCodeModel. The bit forACC_STATICflag cannot be modified by thehandler, and must be set throughmethodFlags.This method behaves as if: withMethod(name, descriptor, methodFlags, mb -> mb.withCode(handler))- Parameters:
- name- the method name
- descriptor- the method descriptor
- methodFlags- the access flags as a bit mask, with the- ACC_STATICbit definitely set
- handler- handler to supply the contents of the method body
- Returns:
- this builder
- See Also:
 
- 
transformMethodAdds a method by transforming a method from another class. The transform cannot modify theACC_STATICflag of the original method.This method behaves as if: withMethod(method.methodName(), method.methodType(), method.flags().flagMask(), mb -> mb.transform(method, transform))- Parameters:
- method- the method to be transformed
- transform- the transform to apply to the method
- Returns:
- this builder
- See Also:
 
 
-