Skip to content

ClassBuilder.FieldBuilder ​

com.jsmacrosce.jsmacros.core.library.impl.classes.ClassBuilder.FieldBuilder

Builds a field of the class being built. The field is added only when end is called; use this builder to configure its name, modifiers, annotations, and initializer.

js
builder.addField(Reflection.getClass("java.lang.String"), "label")
 .makePrivate()
 .toggleFinal()
 .initializer().setString("unnamed")
 .end();

Nested type declared in ClassBuilder.

Nested types ​

Constructors ​

new ClassBuilder.FieldBuilder ​

new ClassBuilder.FieldBuilder(ClassBuilder<T> classBuilder, CtClass fieldType, String name)#
Starts a field builder for the given type and name; normally obtained through addField(java.lang.Class, java.lang.String).

Parameters:

  • fieldType: the type of the field
  • name: the name of the field

Fields ​

fieldInitializer ​

fieldInitializer: CtField.Initializer#
The configured field initializer, or null if none is set. It is applied when end() adds the field.

Methods ​

addAnnotation ​

Starts building an annotation for this field. Its retention policy determines whether the annotation is stored as runtime-visible or runtime-invisible metadata.

Parameters:

  • type: the annotation type to put on the field
Returns: a builder for the annotation, which is put on the field when it is finished

compile ​

compile(String code): ClassBuilder<T>#
Adds this field to the class without modifiers, annotations, or an initializer, ignoring code. Unlike end(), this does not apply settings configured on this builder.

Parameters:

  • code: not used, the field is added as this builder was started
Returns: the class builder, so more members can be added

end ​

end(): ClassBuilder<T>#
Adds the field with its configured modifiers, annotations, and initializer, then returns the class builder. Unlike compile(String), this applies the builder settings.
Returns: the class builder, so more members can be added

getMods ​

getMods(): int#
Returns the Java modifier bit mask currently configured for this field, or zero when no modifiers are set.
Returns: the modifier bits set on this field

getModString ​

getModString(): String#
Returns the configured modifiers as words, or the empty string when none are set.
Returns: the modifiers in words

initializer ​

Starts configuring this field's initializer. The last initializer operation performed before end() is applied when the field is added.
Returns: a builder for the value, whose calls hand back the field builder so it can be ended

makePackagePrivate ​

makePackagePrivate(): ClassBuilder.FieldBuilder#
Resets the field to package-private visibility while keeping its static and final flags.
Returns: self for chaining

makePrivate ​

Sets private visibility while preserving the static and final flags. The visibility methods replace one another; call this after toggling static or final to preserve those flags, since the builder starts with no modifiers.
Returns: self for chaining

makeProtected ​

Sets protected visibility while preserving the static and final flags. This replaces any visibility set by another visibility method; see makePrivate() for ordering.
Returns: self for chaining

makePublic ​

Sets public visibility while preserving the static and final flags. This replaces any visibility set by another visibility method; see makePrivate() for ordering.
Returns: self for chaining

rename ​

Sets the name under which the field will be added when end() is called.

Parameters:

  • name: the name to add the field under
Returns: self for chaining

toggleFinal ​

Toggles the final modifier; calling this twice restores its original state.
Returns: self for chaining

toggleStatic ​

Toggles the static modifier; calling this twice restores its original state.
Returns: self for chaining