Class CtField.Initializer
- java.lang.Object
-
- javassist.CtField.Initializer
-
- Enclosing class:
- CtField
public abstract static class CtField.Initializer extends java.lang.Object
Instances of this class specify how to initialize a field.Initializer
is passed toCtClass.addField()
with aCtField
.This class cannot be instantiated with the
new
operator. Factory methods such asbyParameter()
andbyNew
must be used for the instantiation. They create a new instance with the given parameters and return it.
-
-
Constructor Summary
Constructors Constructor Description Initializer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CtField.Initializer
byCall(CtClass methodClass, java.lang.String methodName)
Makes an initializer calling a static method.static CtField.Initializer
byCall(CtClass methodClass, java.lang.String methodName, java.lang.String[] stringParams)
Makes an initializer calling a static method.static CtField.Initializer
byCallWithParams(CtClass methodClass, java.lang.String methodName)
Makes an initializer calling a static method.static CtField.Initializer
byCallWithParams(CtClass methodClass, java.lang.String methodName, java.lang.String[] stringParams)
Makes an initializer calling a static method.static CtField.Initializer
byExpr(java.lang.String source)
Makes an initializer.static CtField.Initializer
byNew(CtClass objectType)
Makes an initializer creating a new object.static CtField.Initializer
byNew(CtClass objectType, java.lang.String[] stringParams)
Makes an initializer creating a new object.static CtField.Initializer
byNewArray(CtClass type, int size)
Makes an initializer creating a new array.static CtField.Initializer
byNewArray(CtClass type, int[] sizes)
Makes an initializer creating a new multi-dimensional array.static CtField.Initializer
byNewWithParams(CtClass objectType)
Makes an initializer creating a new object.static CtField.Initializer
byNewWithParams(CtClass objectType, java.lang.String[] stringParams)
Makes an initializer creating a new object.static CtField.Initializer
byParameter(int nth)
Makes an initializer using a constructor parameter.static CtField.Initializer
constant(boolean b)
Makes an initializer that assigns a constant boolean value.static CtField.Initializer
constant(double d)
Makes an initializer that assigns a constant double value.static CtField.Initializer
constant(float l)
Makes an initializer that assigns a constant float value.static CtField.Initializer
constant(int i)
Makes an initializer that assigns a constant integer value.static CtField.Initializer
constant(long l)
Makes an initializer that assigns a constant long value.static CtField.Initializer
constant(java.lang.String s)
Makes an initializer that assigns a constant string value.
-
-
-
Method Detail
-
constant
public static CtField.Initializer constant(int i)
Makes an initializer that assigns a constant integer value. The field must be integer, short, char, or byte type.
-
constant
public static CtField.Initializer constant(boolean b)
Makes an initializer that assigns a constant boolean value. The field must be boolean type.
-
constant
public static CtField.Initializer constant(long l)
Makes an initializer that assigns a constant long value. The field must be long type.
-
constant
public static CtField.Initializer constant(float l)
Makes an initializer that assigns a constant float value. The field must be float type.
-
constant
public static CtField.Initializer constant(double d)
Makes an initializer that assigns a constant double value. The field must be double type.
-
constant
public static CtField.Initializer constant(java.lang.String s)
Makes an initializer that assigns a constant string value. The field must bejava.lang.String
type.
-
byParameter
public static CtField.Initializer byParameter(int nth)
Makes an initializer using a constructor parameter.The initial value is the N-th parameter given to the constructor of the object including the field. If the constructor takes less than N parameters, the field is not initialized. If the field is static, it is never initialized.
- Parameters:
nth
- the n-th (>= 0) parameter is used as the initial value. If nth is 0, then the first parameter is used.
-
byNew
public static CtField.Initializer byNew(CtClass objectType)
Makes an initializer creating a new object.This initializer creates a new object and uses it as the initial value of the field. The constructor of the created object receives the parameter:
Object obj
- the object including the field.If the initialized field is static, then the constructor does not receive any parameters.
- Parameters:
objectType
- the class instantiated for the initial value.
-
byNew
public static CtField.Initializer byNew(CtClass objectType, java.lang.String[] stringParams)
Makes an initializer creating a new object.This initializer creates a new object and uses it as the initial value of the field. The constructor of the created object receives the parameters:
Object obj
- the object including the field.
String[] strs
- the character strings specified bystringParams
If the initialized field is static, then the constructor receives only
strs
.- Parameters:
objectType
- the class instantiated for the initial value.stringParams
- the array of strings passed to the constructor.
-
byNewWithParams
public static CtField.Initializer byNewWithParams(CtClass objectType)
Makes an initializer creating a new object.This initializer creates a new object and uses it as the initial value of the field. The constructor of the created object receives the parameters:
Object obj
- the object including the field.
Object[] args
- the parameters passed to the constructor of the object including the filed.If the initialized field is static, then the constructor does not receive any parameters.
- Parameters:
objectType
- the class instantiated for the initial value.- See Also:
byNewArray(CtClass,int)
,byNewArray(CtClass,int[])
-
byNewWithParams
public static CtField.Initializer byNewWithParams(CtClass objectType, java.lang.String[] stringParams)
Makes an initializer creating a new object.This initializer creates a new object and uses it as the initial value of the field. The constructor of the created object receives the parameters:
Object obj
- the object including the field.
String[] strs
- the character strings specified bystringParams
Object[] args
- the parameters passed to the constructor of the object including the filed.If the initialized field is static, then the constructor receives only
strs
.- Parameters:
objectType
- the class instantiated for the initial value.stringParams
- the array of strings passed to the constructor.
-
byCall
public static CtField.Initializer byCall(CtClass methodClass, java.lang.String methodName)
Makes an initializer calling a static method.This initializer calls a static method and uses the returned value as the initial value of the field. The called method receives the parameters:
Object obj
- the object including the field.If the initialized field is static, then the method does not receive any parameters.
The type of the returned value must be the same as the field type.
- Parameters:
methodClass
- the class that the static method is declared in.methodName
- the name of the satic method.
-
byCall
public static CtField.Initializer byCall(CtClass methodClass, java.lang.String methodName, java.lang.String[] stringParams)
Makes an initializer calling a static method.This initializer calls a static method and uses the returned value as the initial value of the field. The called method receives the parameters:
Object obj
- the object including the field.
String[] strs
- the character strings specified bystringParams
If the initialized field is static, then the method receive only
strs
.The type of the returned value must be the same as the field type.
- Parameters:
methodClass
- the class that the static method is declared in.methodName
- the name of the satic method.stringParams
- the array of strings passed to the static method.
-
byCallWithParams
public static CtField.Initializer byCallWithParams(CtClass methodClass, java.lang.String methodName)
Makes an initializer calling a static method.This initializer calls a static method and uses the returned value as the initial value of the field. The called method receives the parameters:
Object obj
- the object including the field.
Object[] args
- the parameters passed to the constructor of the object including the filed.If the initialized field is static, then the method does not receive any parameters.
The type of the returned value must be the same as the field type.
- Parameters:
methodClass
- the class that the static method is declared in.methodName
- the name of the satic method.
-
byCallWithParams
public static CtField.Initializer byCallWithParams(CtClass methodClass, java.lang.String methodName, java.lang.String[] stringParams)
Makes an initializer calling a static method.This initializer calls a static method and uses the returned value as the initial value of the field. The called method receives the parameters:
Object obj
- the object including the field.
String[] strs
- the character strings specified bystringParams
Object[] args
- the parameters passed to the constructor of the object including the filed.If the initialized field is static, then the method receive only
strs
.The type of the returned value must be the same as the field type.
- Parameters:
methodClass
- the class that the static method is declared in.methodName
- the name of the satic method.stringParams
- the array of strings passed to the static method.
-
byNewArray
public static CtField.Initializer byNewArray(CtClass type, int size) throws NotFoundException
Makes an initializer creating a new array.- Parameters:
type
- the type of the array.size
- the size of the array.- Throws:
NotFoundException
- if the type of the array components is not found.
-
byNewArray
public static CtField.Initializer byNewArray(CtClass type, int[] sizes)
Makes an initializer creating a new multi-dimensional array.- Parameters:
type
- the type of the array.sizes
- anint
array of the size in every dimension. The first element is the size in the first dimension. The second is in the second, etc.
-
byExpr
public static CtField.Initializer byExpr(java.lang.String source)
Makes an initializer.- Parameters:
source
- initializer expression.
-
-