|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavassist.CtMember
javassist.CtField
public class CtField
An instance of CtField represents a field.
CtClass.getDeclaredFields()
Nested Class Summary | |
---|---|
static class |
CtField.Initializer
Instances of this class specify how to initialize a field. |
Field Summary | |
---|---|
protected FieldInfo |
fieldInfo
|
Fields inherited from class javassist.CtMember |
---|
declaringClass |
Constructor Summary | |
---|---|
CtField(CtClass type,
java.lang.String name,
CtClass declaring)
Creates a CtField object. |
|
CtField(CtField src,
CtClass declaring)
Creates a copy of the given field. |
Method Summary | |
---|---|
protected void |
extendToString(java.lang.StringBuffer buffer)
Invoked by CtMember.toString() to add to the buffer and provide the
complete value. |
java.lang.Object |
getAnnotation(java.lang.Class clz)
Returns the annotation if the class has the specified annotation class. |
java.lang.Object[] |
getAnnotations()
Returns the annotations associated with this field. |
byte[] |
getAttribute(java.lang.String name)
Obtains an attribute with the given name. |
java.lang.Object[] |
getAvailableAnnotations()
Returns the annotations associated with this field. |
java.lang.Object |
getConstantValue()
Returns the value of this field if it is a constant field. |
CtClass |
getDeclaringClass()
Returns the class declaring the field. |
FieldInfo |
getFieldInfo()
Returns the FieldInfo representing the field in the class file. |
FieldInfo |
getFieldInfo2()
Returns the FieldInfo representing the field in the class file (read only). |
protected ASTree |
getInitAST()
|
int |
getModifiers()
Returns the encoded modifiers of the field. |
java.lang.String |
getName()
Returns the name of the field. |
java.lang.String |
getSignature()
Returns the character string representing the type of the field. |
CtClass |
getType()
Returns the type of the field. |
boolean |
hasAnnotation(java.lang.Class clz)
Returns true if the class has the specified annotation class. |
static CtField |
make(java.lang.String src,
CtClass declaring)
Compiles the given source code and creates a field. |
void |
setAttribute(java.lang.String name,
byte[] data)
Adds an attribute. |
void |
setModifiers(int mod)
Sets the encoded modifiers of the field. |
void |
setName(java.lang.String newName)
Changes the name of the field. |
void |
setType(CtClass clazz)
Sets the type of the field. |
java.lang.String |
toString()
Returns a String representation of the object. |
Methods inherited from class javassist.CtMember |
---|
visibleFrom |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected FieldInfo fieldInfo
Constructor Detail |
---|
public CtField(CtClass type, java.lang.String name, CtClass declaring) throws CannotCompileException
CtField
object.
The created field must be added to a class
with CtClass.addField()
.
An initial value of the field is specified
by a CtField.Initializer
object.
If getter and setter methods are needed,
call CtNewMethod.getter()
and
CtNewMethod.setter()
.
type
- field typename
- field namedeclaring
- the class to which the field will be added.
CannotCompileException
CtClass.addField(CtField)
,
CtNewMethod.getter(String,CtField)
,
CtNewMethod.setter(String,CtField)
,
CtField.Initializer
public CtField(CtField src, CtClass declaring) throws CannotCompileException
CtClass.addField()
.
An initial value of the field is specified
by a CtField.Initializer
object.
If getter and setter methods are needed,
call CtNewMethod.getter()
and
CtNewMethod.setter()
.
src
- the original fielddeclaring
- the class to which the field will be added.
CannotCompileException
CtNewMethod.getter(String,CtField)
,
CtNewMethod.setter(String,CtField)
,
CtField.Initializer
Method Detail |
---|
public java.lang.String toString()
toString
in class CtMember
protected void extendToString(java.lang.StringBuffer buffer)
CtMember
CtMember.toString()
to add to the buffer and provide the
complete value. Subclasses should invoke this method, adding a
space before each token. The modifiers for the member are
provided first; subclasses should provide additional data such
as return type, field or method name, etc.
extendToString
in class CtMember
protected ASTree getInitAST()
public static CtField make(java.lang.String src, CtClass declaring) throws CannotCompileException
"public String name;" "public int k = 3;"
Note that the source code ends with ';'
(semicolon).
src
- the source text.declaring
- the class to which the created field is added.
CannotCompileException
public FieldInfo getFieldInfo()
public FieldInfo getFieldInfo2()
getFieldInfo()
.
The FieldInfo
object obtained by this method
is read only. Changes to this object might not be reflected
on a class file generated by toBytecode()
,
toClass()
, etc in CtClass
.
This method is available even if the CtClass
containing this field is frozen. However, if the class is
frozen, the FieldInfo
might be also pruned.
getFieldInfo()
,
CtClass.isFrozen()
,
CtClass.prune()
public CtClass getDeclaringClass()
getDeclaringClass
in class CtMember
public java.lang.String getName()
getName
in class CtMember
CtConstructor.getName()
public void setName(java.lang.String newName)
public int getModifiers()
getModifiers
in class CtMember
javassist.Modifier
.Modifier
public void setModifiers(int mod)
setModifiers
in class CtMember
Modifier
public boolean hasAnnotation(java.lang.Class clz)
hasAnnotation
in class CtMember
clz
- the annotation class.
true
if the annotation is found, otherwise false
.public java.lang.Object getAnnotation(java.lang.Class clz) throws java.lang.ClassNotFoundException
@Author
is associated
with this field, an Author
object is returned.
The member values can be obtained by calling methods on
the Author
object.
getAnnotation
in class CtMember
clz
- the annotation class.
null
.
java.lang.ClassNotFoundException
public java.lang.Object[] getAnnotations() throws java.lang.ClassNotFoundException
getAnnotations
in class CtMember
java.lang.ClassNotFoundException
getAvailableAnnotations()
public java.lang.Object[] getAvailableAnnotations()
getAvailableAnnotations
in class CtMember
getAnnotations()
public java.lang.String getSignature()
getSignature()
returns the same string.
Note that the returned string is not the type signature
contained in the SignatureAttirbute
. It is
a descriptor. To obtain a type signature, call the following
methods:
getFieldInfo().getAttribute(SignatureAttribute.tag)
getSignature
in class CtMember
Descriptor
,
SignatureAttribute
public CtClass getType() throws NotFoundException
NotFoundException
public void setType(CtClass clazz)
public java.lang.Object getConstantValue()
String
type. Otherwise, it returns null
.
A constant field is static
and final
.
Integer
, Long
, Float
,
Double
, Boolean
,
or String
object
representing the constant value.
null
if it is not a constant field
or if the field type is not a primitive type
or String
.public byte[] getAttribute(java.lang.String name)
Note that an attribute is a data block specified by
the class file format.
See AttributeInfo
.
getAttribute
in class CtMember
name
- attribute namepublic void setAttribute(java.lang.String name, byte[] data)
Note that an attribute is a data block specified by
the class file format.
See AttributeInfo
.
setAttribute
in class CtMember
name
- attribute namedata
- attribute value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |