org.apache.bcel.generic

Class FieldGen

Implemented Interfaces:
Cloneable, NamedAndTyped, java.io.Serializable

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).
Version:
$Id: FieldGen.java 386056 2006-03-15 11:31:56Z tcurdt $
Author:
M. Dahm
See Also:
Field, Serialized Form

Field Summary

private static BCELComparator
_cmp
private List
observers
private Object
value

Fields inherited from class org.apache.bcel.generic.FieldGenOrMethodGen

attribute_vec, cp, name, type

Fields inherited from class org.apache.bcel.classfile.AccessFlags

access_flags

Constructor Summary

FieldGen(int access_flags, Type type, String name, ConstantPoolGen cp)
Declare a field.
FieldGen(Field field, ConstantPoolGen cp)
Instantiate from existing field.

Method Summary

private int
addConstant()
void
addObserver(FieldObserver o)
Add observer for this object.
void
cancelInitValue()
Remove any initial value.
private void
checkType(Type atype)
FieldGen
copy(ConstantPoolGen cp)
boolean
equals(Object obj)
Return value as defined by given BCELComparator strategy.
static BCELComparator
getComparator()
Field
getField()
Get field object after having set up all necessary values.
String
getInitValue()
String
getSignature()
int
hashCode()
Return value as defined by given BCELComparator strategy.
void
removeObserver(FieldObserver o)
Remove observer for this object.
static void
setComparator(BCELComparator comparator)
void
setInitValue(String str)
Set (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.
void
setInitValue(boolean b)
void
setInitValue(byte b)
void
setInitValue(char c)
void
setInitValue(double d)
void
setInitValue(float f)
void
setInitValue(int i)
void
setInitValue(long l)
void
setInitValue(short s)
private void
setValue(int index)
String
toString()
Return string representation close to declaration format, `public static final short MAX = 100', e.g..
void
update()
Call notify() method on all observers.

Methods inherited from class org.apache.bcel.generic.FieldGenOrMethodGen

addAttribute, clone, getAttributes, getConstantPool, getName, getSignature, getType, 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, isVolatile, isVolatile, setAccessFlags, setFlag, setModifiers

Field Details

_cmp

private static BCELComparator _cmp

observers

private List observers

value

private Object value

Constructor Details

FieldGen

public FieldGen(int access_flags,
                Type type,
                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:
access_flags - access qualifiers
type - field type
name - field name
cp - constant pool

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)

Method Details

addConstant

private int addConstant()

addObserver

public void addObserver(FieldObserver o)
Add observer for this object.

cancelInitValue

public void cancelInitValue()
Remove any initial value.

checkType

private void checkType(Type atype)

copy

public FieldGen copy(ConstantPoolGen cp)
Returns:
deep copy of this field

equals

public boolean equals(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.
See Also:
java.lang.Object.equals(java.lang.Object)

getComparator

public static BCELComparator getComparator()
Returns:
Comparison strategy object

getField

public Field getField()
Get field object after having set up all necessary values.

getInitValue

public String getInitValue()

getSignature

public String getSignature()
Overrides:
getSignature in interface FieldGenOrMethodGen

hashCode

public int hashCode()
Return value as defined by given BCELComparator strategy. By default return the hashcode of the field's name XOR signature.
See Also:
java.lang.Object.hashCode()

removeObserver

public void removeObserver(FieldObserver o)
Remove observer for this object.

setComparator

public static void setComparator(BCELComparator comparator)
Parameters:
comparator - Comparison strategy object

setInitValue

public void setInitValue(String str)
Set (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.

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)

setValue

private void setValue(int index)

toString

public final String toString()
Return string representation close to declaration format, `public static final short MAX = 100', e.g..
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 he has finished editing the object.