Class dec.trek.Field

The Field object allows you to manipulate the fields of a class. This includes both variables and constants. Also a field can be passed as an argument when the method’s corresponding parameter is of class Member. This is because Member is the superclass of Field and Method.

The Field class does not have a public constructor. To reach a classfile’s fields, you must use firstField() or lastField() in the ClassFile class, getMember() in the Instruction class, or override at(Field) in the Trek class.

Method Summary

  • getClassFile – returns the ClassFile object of the class that this field is part of
  • getSize – returns the number of bytes in this field
  • hasModifier – returns true if this field has any of the specified access modifiers
  • isArray – returns true if this field is an array
  • next – returns the Field object of the next field of the current classfile
  • prev – returns the Field object of the previous field of the current classfile
  • toName – returns the unqualified name of this field
  • toObjectId – returns the object Id of this field
  • toString – returns the source code for the declaration of this field
  • toType – returns the data type of this field

Fields

public Object userDefined

Field that can be used by an application developer to store arbitrary data about this object during the trek.

Methods

public ClassFile getClassFile()

Returns the ClassFile object for this field’s class

public int getSize()

Returns the number of bytes of storage required for this field: byte fields return 1, short and char fields return 2, long and double fields return 8, and all other fields – including arrays and objects – return 4.

public boolean hasModifier(int flags)

Returns true if this field was declared with any of the specified access flags.

Parameters:

flags – one or more of the ACC constants defined in the Trek class.

public boolean isArray()

Returns true if this field is an array.

public Field next()

Returns the Field of the alphabetically next field in this field’s classfile.

public Field prev()

Returns the Field of the alphabetically previous field in this field’s classfile.

public String toName()

Returns the unqualified name of this field.

public String toObjectId()

Returns a persistent value that identifies this field. A reference to this field can be acquired by calling getObject on a trek that this field is within.

public String toString()

Returns the source statement that defined this field.

public String toType()

Returns the data type of this field, for example int or java.lang.Object.