Class Field
java.lang.Object
EDU.purdue.cs.bloat.file.Field
- All Implemented Interfaces:
FieldInfo
Field models a field (member variable) in a class. The Field class grants
access to information such as the field's modifiers, its name and type
descriptor (represented as indices into the constant pool), and any
attributes of the field. Static fields have a ConstantValue attribute.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGet the index into the constant pool of the field's constant value, if any.Get the class which declared the field.intGet the modifiers of the field.intGet the index into the constant pool of the name of the field.voidsetConstantValue(int index) Set the index into the constant pool of the field's constant value.voidsetModifiers(int modifiers) Set the modifiers of the field.voidsetNameIndex(int name) Set the index into the constant pool of the name of the field.voidsetTypeIndex(int type) Set the index into the constant pool of the type of the field.toString()Convert the field to a string.intGet the index into the constant pool of the type of the field.voidwrite(DataOutputStream out) Write the field to a class file.
-
Constructor Details
-
Field
Constructor. Read a field from a class file.- Parameters:
in- The data stream of the class file.classInfo- The class file containing the field.- Throws:
IOException- If an error occurs while reading.
-
-
Method Details
-
declaringClass
Get the class which declared the field.- Specified by:
declaringClassin interfaceFieldInfo- Returns:
- The ClassInfo of the class which declared the field.
-
setNameIndex
public void setNameIndex(int name) Set the index into the constant pool of the name of the field.- Specified by:
setNameIndexin interfaceFieldInfo- Parameters:
name- The name of the field.
-
setTypeIndex
public void setTypeIndex(int type) Set the index into the constant pool of the type of the field.- Specified by:
setTypeIndexin interfaceFieldInfo- Parameters:
type- The type of the field.
-
nameIndex
-
typeIndex
-
setModifiers
public void setModifiers(int modifiers) Set the modifiers of the field. The values correspond to the constants in the Modifiers class.- Specified by:
setModifiersin interfaceFieldInfo- Parameters:
modifiers- A bit vector of modifier flags for the field.- See Also:
-
modifiers
-
constantValue
public int constantValue()Get the index into the constant pool of the field's constant value, if any. Returns 0 if the field does not have a constant value.- Specified by:
constantValuein interfaceFieldInfo- See Also:
-
setConstantValue
public void setConstantValue(int index) Set the index into the constant pool of the field's constant value.- Specified by:
setConstantValuein interfaceFieldInfo- See Also:
-
write
Write the field to a class file.- Parameters:
out- The data stream of the class file.- Throws:
IOException- If an error occurs while writing.
-
toString
-