Top Description Fields Constructors Methods
org.apache.bcel.generic

public Class FieldGen

extends FieldGenOrMethodGen
Class Inheritance
Imports
java.util.ArrayList, .List, .Objects, java.util.stream.Stream, org.apache.bcel.Const, org.apache.bcel.classfile.Annotations, .Attribute, .Constant, .ConstantObject, .ConstantPool, .ConstantValue, .Field, .Utility, org.apache.bcel.util.BCELComparator

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

Modifier and TypeField and Description
private static BCELComparator<FieldGen>
private List<FieldObserver>
private Object
Inherited from org.apache.bcel.generic.FieldGenOrMethodGen:
cpnametype

Constructor Summary

AccessConstructor and Description
public
FieldGen(final Field
Field object.
field
,
final ConstantPoolGen
constant pool (must contain the same entries as the field's constant pool).
cp
)

Instantiate from existing field.

public
FieldGen(final int
access qualifiers
accessFlags
,
final Type
field type
type
,
final String
field name
name
,
final ConstantPoolGen
constant pool
cp
)

Declare a field.

Method Summary

Modifier and TypeMethod and Description
private void
private int
public void
addObserver(final FieldObserver o)

Add observer for this object.

public void
cancelInitValue()

Remove any initial value.

private void
checkType(final Type atype)

public FieldGen

Returns:

deep copy of this field
copy
(final ConstantPoolGen cp)

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Return value as defined by given BCELComparator strategy.
public static BCELComparator<FieldGen>

Returns:

Comparison strategy object.
getComparator
()

public Field
getField()

Gets field object after having set up all necessary values.

public String
public String
public int
hashCode()

Overrides java.lang.Object.hashCode.

Return value as defined by given BCELComparator strategy.
public void
removeObserver(final FieldObserver o)

Remove observer for this object.

public static void
setComparator(final BCELComparator<FieldGen>
Comparison strategy object.
comparator
)

public void
setInitValue(final boolean b)

public void
setInitValue(final byte b)

public void
setInitValue(final char c)

public void
setInitValue(final double d)

public void
setInitValue(final float f)

public void
setInitValue(final int i)

public void
setInitValue(final long l)

public void
setInitValue(final short s)

public void
setInitValue(final String str)

Sets (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.

private void
setValue(final int index)

public final String

Returns:

String representation of field
toString
()

Overrides java.lang.Object.toString.

Return string representation close to declaration format, 'public static final short MAX = 100', e.g..
public void
update()

Call notify() method on all observers.

Inherited from org.apache.bcel.generic.FieldGenOrMethodGen:
addAlladdAnnotationEntryaddAttributeclonegetAnnotationEntriesgetAttributesgetConstantPoolgetNamegetTyperemoveAnnotationEntriesremoveAnnotationEntryremoveAttributeremoveAttributessetConstantPoolsetNamesetType

Field Detail

bcelComparatorback to summary
private static BCELComparator<FieldGen> bcelComparator
observersback to summary
private List<FieldObserver> observers
valueback to summary
private Object value

Constructor Detail

FieldGenback to summary
public FieldGen(final Field field, final ConstantPoolGen cp)

Instantiate from existing field.

Parameters
field:Field

Field object.

cp:ConstantPoolGen

constant pool (must contain the same entries as the field's constant pool).

FieldGenback to summary
public FieldGen(final int accessFlags, final Type type, final String name, final 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:int

access qualifiers

type:Type

field type

name:String

field name

cp:ConstantPoolGen

constant pool

Method Detail

addAnnotationsAsAttributeback to summary
private void addAnnotationsAsAttribute(final ConstantPoolGen cp)
addConstantback to summary
private int addConstant()
addObserverback to summary
public void addObserver(final FieldObserver o)

Add observer for this object.

cancelInitValueback to summary
public void cancelInitValue()

Remove any initial value.

checkTypeback to summary
private void checkType(final Type atype)
copyback to summary
public FieldGen copy(final ConstantPoolGen cp)
Returns:FieldGen

deep copy of this field

equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

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.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
See Also
Object#equals(Object)
getComparatorback to summary
public static BCELComparator<FieldGen> getComparator()
Returns:BCELComparator<FieldGen>

Comparison strategy object.

getFieldback to summary
public Field getField()

Gets field object after having set up all necessary values.

getInitValueback to summary
public String getInitValue()
getSignatureback to summary
public String getSignature()

Implements abstract org.apache.bcel.generic.FieldGenOrMethodGen.getSignature.

Returns:String

Doc from org.apache.bcel.generic.FieldGenOrMethodGen.getSignature.

signature of method/field.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Return value as defined by given BCELComparator strategy. By default return the hash code of the field's name XOR signature.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
See Also
Object#hashCode()
removeObserverback to summary
public void removeObserver(final FieldObserver o)

Remove observer for this object.

setComparatorback to summary
public static void setComparator(final BCELComparator<FieldGen> comparator)
Parameters
comparator:BCELComparator<FieldGen>

Comparison strategy object.

setInitValueback to summary
public void setInitValue(final boolean b)
setInitValueback to summary
public void setInitValue(final byte b)
setInitValueback to summary
public void setInitValue(final char c)
setInitValueback to summary
public void setInitValue(final double d)
setInitValueback to summary
public void setInitValue(final float f)
setInitValueback to summary
public void setInitValue(final int i)
setInitValueback to summary
public void setInitValue(final long l)
setInitValueback to summary
public void setInitValue(final short s)
setInitValueback to summary
public void setInitValue(final String str)

Sets (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.

setValueback to summary
private void setValue(final int index)
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Return string representation close to declaration format, 'public static final short MAX = 100', e.g..

Returns:String

String representation of field

Annotations
@Override
updateback to summary
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.