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 fieldname: the name of the field
Fields
fieldInitializer
Methods
addAnnotation
addAnnotation(Class<?> type): ClassBuilder.AnnotationBuilder<ClassBuilder.FieldBuilder>#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
initializer
initializer(): ClassBuilder.FieldBuilder.FieldInitializerBuilder#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
makePrivate(): ClassBuilder.FieldBuilder#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
makeProtected(): ClassBuilder.FieldBuilder#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
makePublic(): ClassBuilder.FieldBuilder#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
rename(String name): ClassBuilder.FieldBuilder#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
toggleFinal(): ClassBuilder.FieldBuilder#Toggles the final modifier; calling this twice restores its original state.
Returns: self for chaining
toggleStatic
toggleStatic(): ClassBuilder.FieldBuilder#Toggles the static modifier; calling this twice restores its original state.
Returns: self for chaining