Package org.apache.bcel.generic
Class FieldGen
- java.lang.Object
-
- org.apache.bcel.classfile.AccessFlags
-
- org.apache.bcel.generic.FieldGenOrMethodGen
-
- org.apache.bcel.generic.FieldGen
-
- All Implemented Interfaces:
java.lang.Cloneable,NamedAndTyped
public class FieldGen extends FieldGenOrMethodGen
Template class for building up a field. The only extraordinary thing one can do is to add a constant value attribute to a field (which must of course be compatible with to the declared type).- See Also:
Field
-
-
Field Summary
-
Fields inherited from class org.apache.bcel.generic.FieldGenOrMethodGen
cp, name, type
-
Fields inherited from class org.apache.bcel.classfile.AccessFlags
access_flags
-
-
Constructor Summary
Constructors Constructor Description FieldGen(int accessFlags, Type type, java.lang.String name, ConstantPoolGen cp)Declare a field.FieldGen(Field field, ConstantPoolGen cp)Instantiate from existing field.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObserver(FieldObserver o)Add observer for this object.voidcancelInitValue()Remove any initial value.FieldGencopy(ConstantPoolGen cp)booleanequals(java.lang.Object obj)Return value as defined by given BCELComparator strategy.static BCELComparator<FieldGen>getComparator()FieldgetField()Gets field object after having set up all necessary values.java.lang.StringgetInitValue()java.lang.StringgetSignature()inthashCode()Return value as defined by given BCELComparator strategy.voidremoveObserver(FieldObserver o)Remove observer for this object.static voidsetComparator(BCELComparator<FieldGen> comparator)voidsetInitValue(boolean b)voidsetInitValue(byte b)voidsetInitValue(char c)voidsetInitValue(double d)voidsetInitValue(float f)voidsetInitValue(int i)voidsetInitValue(long l)voidsetInitValue(short s)voidsetInitValue(java.lang.String str)Sets (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.java.lang.StringtoString()Return string representation close to declaration format, 'public static final short MAX = 100', e.g..voidupdate()Call notify() method on all observers.-
Methods inherited from class org.apache.bcel.generic.FieldGenOrMethodGen
addAll, addAnnotationEntry, addAttribute, clone, getAnnotationEntries, getAttributes, getConstantPool, getName, getType, removeAnnotationEntries, removeAnnotationEntry, removeAttribute, removeAttributes, setConstantPool, setName, setType
-
Methods inherited from class org.apache.bcel.classfile.AccessFlags
getAccessFlags, getModifiers, isAbstract, isAbstract, isAnnotation, isAnnotation, isEnum, isEnum, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isSynthetic, isSynthetic, isTransient, isTransient, isVarArgs, isVarArgs, isVolatile, isVolatile, setAccessFlags, setModifiers
-
-
-
-
Constructor Detail
-
FieldGen
public FieldGen(Field field, ConstantPoolGen cp)
Instantiate from existing field.- Parameters:
field- Field object.cp- constant pool (must contain the same entries as the field's constant pool).
-
FieldGen
public FieldGen(int accessFlags, Type type, java.lang.String name, ConstantPoolGen cp)
Declare a field. If it is static (isStatic() == true) and has a basic type like int or String it may have an initial value associated with it as defined by setInitValue().- Parameters:
accessFlags- access qualifierstype- field typename- field namecp- constant pool
-
-
Method Detail
-
getComparator
public static BCELComparator<FieldGen> getComparator()
- Returns:
- Comparison strategy object.
-
setComparator
public static void setComparator(BCELComparator<FieldGen> comparator)
- Parameters:
comparator- Comparison strategy object.
-
addObserver
public void addObserver(FieldObserver o)
Add observer for this object.
-
cancelInitValue
public void cancelInitValue()
Remove any initial value.
-
copy
public FieldGen copy(ConstantPoolGen cp)
- Returns:
- deep copy of this field
-
equals
public boolean equals(java.lang.Object obj)
Return value as defined by given BCELComparator strategy. By default two FieldGen objects are said to be equal when their names and signatures are equal.- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(Object)
-
getInitValue
public java.lang.String getInitValue()
-
getSignature
public java.lang.String getSignature()
- Specified by:
getSignaturein classFieldGenOrMethodGen- Returns:
- signature of method/field.
-
hashCode
public int hashCode()
Return value as defined by given BCELComparator strategy. By default return the hash code of the field's name XOR signature.- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
removeObserver
public void removeObserver(FieldObserver o)
Remove observer for this object.
-
setInitValue
public void setInitValue(boolean b)
-
setInitValue
public void setInitValue(byte b)
-
setInitValue
public void setInitValue(char c)
-
setInitValue
public void setInitValue(double d)
-
setInitValue
public void setInitValue(float f)
-
setInitValue
public void setInitValue(int i)
-
setInitValue
public void setInitValue(long l)
-
setInitValue
public void setInitValue(short s)
-
setInitValue
public void setInitValue(java.lang.String str)
Sets (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.
-
toString
public final java.lang.String toString()
Return string representation close to declaration format, 'public static final short MAX = 100', e.g..- Overrides:
toStringin classjava.lang.Object- Returns:
- String representation of field
-
update
public void update()
Call notify() method on all observers. This method is not called automatically whenever the state has changed, but has to be called by the user after they have finished editing the object.
-
-