FileDocCategorySizeDatePackage
FieldInfo.javaAPI DocJ2ME CLDC 1.15429Wed Feb 05 15:56:04 GMT 2003kdp.classparser

FieldInfo

public class FieldInfo extends Object
Encapsulates a field of a Java class file.
author
Aaron Dietrich
version
$Id: FieldInfo.java,v 1.1.1.1 2000/07/07 13:34:23 jrv Exp $ Revision History $Log: FieldInfo.java,v $ Revision 1.1.1.1 2000/07/07 13:34:23 jrv Initial import of kdp code Revision 1.1.1.1 2000/05/31 19:14:47 ritsun Initial import of kvmdt to CVS Revision 1.1 2000/04/25 00:36:43 ritsun Initial revision

Fields Summary
private static final int
ACC_PUBLIC
Access flag for a public class field
private static final int
ACC_PRIVATE
Access flag for a private class field
private static final int
ACC_PROTECTED
Access flag for a protected class field
private static final int
ACC_STATIC
Access flag for a static class field
private static final int
ACC_FINAL
Access flag for a final class field
private static final int
ACC_VOLATILE
Access flag for a volatile class field
private static final int
ACC_TRANSIENT
Access flag for a transient class field
private int
accessFlags
access flags for this field
private int
nameIndex
index into constant pool with name of this field
private int
descriptorIndex
index into constant pool with type of this field
private int
attributesCount
number of attributes this field has
private AttributeInfo[]
attributes
array holding attributes of this field
private ConstantPoolInfo[]
constantPool
the constant pool for this class
Constructors Summary
public FieldInfo(DataInputStream iStream, ConstantPoolInfo[] constantPool)
Constructor.

param
iStream input stream to read from
param
constantPool this classes constant pool
exception
IOException just pass IO exceptions up


                                                         
      
                            
     
      accessFlags = iStream.readUnsignedShort ();
      nameIndex = iStream.readUnsignedShort ();
      descriptorIndex = iStream.readUnsignedShort ();
      attributesCount = iStream.readUnsignedShort ();

      //allocate space for the attributes and read them in
      attributes = new AttributeInfo[attributesCount];

      for (int lcv = 0; lcv < attributesCount; ++lcv)
        attributes[lcv] = new AttributeInfo (iStream, constantPool);

      this.constantPool = constantPool;
     
Methods Summary
public java.lang.StringgetAccess()
Returns the access permissions of this field in a text form.

return
String access permissions of this field as text

      String        s = new String ("");

      if ((accessFlags & ACC_PUBLIC) > 0)
        s = s + "public ";

      if ((accessFlags & ACC_PRIVATE) > 0)
        s = s + "private ";

      if ((accessFlags & ACC_PROTECTED) > 0)
        s = s + "protected ";

      if ((accessFlags & ACC_STATIC) > 0)
        s = s + "static ";

      if ((accessFlags & ACC_FINAL) > 0)
        s = s + "final ";

      if ((accessFlags & ACC_VOLATILE) > 0)
        s = s + "volatile ";

      if ((accessFlags & ACC_TRANSIENT) > 0)
        s = s + "transient";

      if (s.length () == 0)
        s = "Not explicitly specified.";
        
      return s;
     
public intgetAccessFlags()

    return accessFlags;
    
public java.lang.StringgetName()
Query the name of this field.

return
String the name of this field

      //look up in the constant pool and return the name of this field
      ConstantUtf8Info        utf8Info;

      utf8Info = (ConstantUtf8Info) constantPool[nameIndex];

      return utf8Info.toString ();
     
public java.lang.StringgetType()
Query the type of this field (int, float, etc)

return
String full form of this field's type

      //look up the encoded type in the constant pool and parse it into
      //it's full form
      ConstantUtf8Info        utf8Info;

      utf8Info = (ConstantUtf8Info) constantPool[descriptorIndex];

      return (utf8Info.toString ());
     
public java.lang.StringtoString()
Converts this field into a nice easy to read format for displaying.

return
String this field as a nice easy to read string

      String                s = new String ("");
      ConstantUtf8Info        utf8Info;

      //first determine what access flags are set for this field
      s = s + "Field:\n\tAccess Flags=\t";
      s = s + getAccess ();

      //get the name of this field
      s = s + "\n\tName=\t\t" + getName ();

      //get the type of this field
      s = s + "\n\tClass=\t\t" + getType ();

      //display all the attributes
      for (int lcv = 0; lcv < attributesCount; ++lcv)
        s = s + "\n\t" + attributes[lcv].toString ();

      return s;