ClassBuilder.FieldBuilder.FieldInitializerBuilder
com.jsmacrosce.jsmacros.core.library.impl.classes.ClassBuilder.FieldBuilder.FieldInitializerBuilder
Configures the value assigned to a field when it is added. Each operation replaces the previous initializer; this builder is returned by FieldBuilder.initializer().
Nested type declared in ClassBuilder.FieldBuilder.
Constructors
new ClassBuilder.FieldBuilder.FieldInitializerBuilder
new ClassBuilder.FieldBuilder.FieldInitializerBuilder(ClassBuilder.FieldBuilder fieldBuilder)#Methods
callStaticMethod
callStaticMethod(Class<?> clazz, String methodName, String... code_arg): ClassBuilder.FieldBuilder#Sets the field initializer to a call to a static method on another class. Arguments are Java source expressions, not values.
builder.addField(Reflection.getClass("int"), "parsed")
.initializer().callStaticMethod(
Reflection.getClass("java.lang.Integer"), "parseInt", ""7"")
.end();Parameters:
clazz: the class declaring the static methodmethodName: the name of the static methodcode_arg: java source for the method's arguments
Returns: the field builder, so the field can be ended
callStaticMethodInThisClass
callStaticMethodInThisClass(String methodName, String... code_arg): ClassBuilder.FieldBuilder#Sets the field initializer to a call to a static method on the generated class. Arguments are Java source expressions, not values.
// a static method on the generated class, then a field that reads it
const factory = builder.addMethod(Reflection.getClass("int"), "defaultLimit");
factory.makePublic();
factory.toggleStatic();
factory.body("{ return 10; }");
builder.addField(Reflection.getClass("int"), "limit")
.initializer().callStaticMethodInThisClass("defaultLimit")
.end();Parameters:
methodName: the name of the static method on this classcode_arg: java source for the method's arguments
Returns: the field builder, so the field can be ended
compile
compile(String code): ClassBuilder.FieldBuilder#Sets the initializer to a Java source expression, evaluated once when the field is initialized. The expression is not in a constructor body and has no instance available, so it cannot reference instance members.
builder.addField(Reflection.getClass("int"), "answer")
.initializer().compile("6 * 7")
.end();Parameters:
code: the java source of the expression to evaluate
Returns: the field builder, so the field can be ended
initClass
initClass(Class<?> clazz, String... code_arg): ClassBuilder.FieldBuilder#Sets the initializer to a constructor call. Each argument is Java source for a constructor parameter; the argument forms determine which overloaded constructor is selected.
Parameters:
clazz: the class to make an instance ofcode_arg: Java source expressions for the constructor arguments
Returns: the field builder, so the field can be ended
setBoolean
setBoolean(boolean value): ClassBuilder.FieldBuilder#Sets the field initializer to a boolean constant.
Parameters:
value: the value to start the field at
Returns: the field builder, so the field can be ended
setByte
setByte(byte value): ClassBuilder.FieldBuilder#Sets the field initializer to a byte constant.
Parameters:
value: the value to start the field at
Returns: the field builder, so the field can be ended
setChar
setChar(char value): ClassBuilder.FieldBuilder#Sets the field initializer to a char constant.
Parameters:
value: the character to start the field at
Returns: the field builder, so the field can be ended
setDouble
setDouble(double value): ClassBuilder.FieldBuilder#Sets the field initializer to a double constant.
Parameters:
value: the value to start the field at
Returns: the field builder, so the field can be ended
setFloat
setFloat(double value): ClassBuilder.FieldBuilder#Sets the field initializer to a float constant, narrowing the input double to float.
Parameters:
value: the value to convert to float
Returns: the field builder, so the field can be ended
setInt
setInt(int value): ClassBuilder.FieldBuilder#Sets the field initializer to an integer constant.
Parameters:
value: the value to start the field at
Returns: the field builder, so the field can be ended
setLong
setLong(long value): ClassBuilder.FieldBuilder#Sets the field initializer to a long constant.
Parameters:
value: the value to start the field at
Returns: the field builder, so the field can be ended
setShort
setShort(short value): ClassBuilder.FieldBuilder#Sets the field initializer to a short constant.
Parameters:
value: the value to start the field at
Returns: the field builder, so the field can be ended
setString
setString(String value): ClassBuilder.FieldBuilder#Sets the field initializer to a string constant.
Parameters:
value: the value to start the field at
Returns: the field builder, so the field can be ended