Package EDU.purdue.cs.bloat.file
Class Field
- java.lang.Object
-
- EDU.purdue.cs.bloat.file.Field
-
- All Implemented Interfaces:
FieldInfo
public class Field extends java.lang.Object implements 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:
ConstantValue
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intconstantValue()Get the index into the constant pool of the field's constant value, if any.ClassInfodeclaringClass()Get the class which declared the field.intmodifiers()Get the modifiers of the field.intnameIndex()Get 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.java.lang.StringtoString()Convert the field to a string.inttypeIndex()Get the index into the constant pool of the type of the field.voidwrite(java.io.DataOutputStream out)Write the field to a class file.
-
-
-
Constructor Detail
-
Field
public Field(java.io.DataInputStream in, ClassInfo classInfo) throws java.io.IOExceptionConstructor. Read a field from a class file.- Parameters:
in- The data stream of the class file.classInfo- The class file containing the field.- Throws:
java.io.IOException- If an error occurs while reading.
-
-
Method Detail
-
declaringClass
public ClassInfo 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
public int nameIndex()
Get the index into the constant pool of the name of the field.
-
typeIndex
public int typeIndex()
Get the index into the constant pool of the type of the field.
-
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
-
modifiers
public int modifiers()
Get the modifiers of the field. The values correspond to the constants in the Modifiers class.
-
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:
ClassInfo.constants()
-
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:
ClassInfo.constants()
-
write
public void write(java.io.DataOutputStream out) throws java.io.IOExceptionWrite the field to a class file.- Parameters:
out- The data stream of the class file.- Throws:
java.io.IOException- If an error occurs while writing.
-
toString
public java.lang.String toString()
Convert the field to a string.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of the field.
-
-