org.apache.bcel.generic

Class FieldGen

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 152690 2001-10-29 19:59:54Z jvanzyl $

Author: M. Dahm

See Also: Field

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
voidaddObserver(FieldObserver o)
Add observer for this object.
voidcancelInitValue()
Remove any initial value.
FieldGencopy(ConstantPoolGen cp)
FieldgetField()
Get field object after having set up all necessary values.
StringgetInitValue()
StringgetSignature()
voidremoveObserver(FieldObserver o)
Remove observer for this object.
voidsetInitValue(String str)
Set (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.
voidsetInitValue(long l)
voidsetInitValue(int i)
voidsetInitValue(short s)
voidsetInitValue(char c)
voidsetInitValue(byte b)
voidsetInitValue(boolean b)
voidsetInitValue(float f)
voidsetInitValue(double d)
StringtoString()
Return string representation close to declaration format, `public static final short MAX = 100', e.g..
voidupdate()
Call notify() method on all observers.

Constructor Detail

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 Detail

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

getField

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

getInitValue

public String getInitValue()

getSignature

public String getSignature()

removeObserver

public void removeObserver(FieldObserver o)
Remove observer for this 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(long l)

setInitValue

public void setInitValue(int i)

setInitValue

public void setInitValue(short s)

setInitValue

public void setInitValue(char c)

setInitValue

public void setInitValue(byte b)

setInitValue

public void setInitValue(boolean b)

setInitValue

public void setInitValue(float f)

setInitValue

public void setInitValue(double d)

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.