FileDocCategorySizeDatePackage
AttributeInfo.javaAPI DocJ2ME CLDC 1.16737Wed Feb 05 15:56:04 GMT 2003kdp.classparser.attributes

AttributeInfo

public class AttributeInfo extends Object
Encapsulates an attribute of a class, field, or method of a Java class file.
author
Aaron Dietrich
version
$Id: AttributeInfo.java,v 1.1.1.1 2000/07/07 13:34:23 jrv Exp $ Revision History $Log: AttributeInfo.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:30:39 ritsun Initial revision

Fields Summary
public static final int
ATTR_CODE
The possible types of attributes this AttributeInfo can represent
public static final int
ATTR_CONST
public static final int
ATTR_DEPRECATED
public static final int
ATTR_EXCEPTIONS
public static final int
ATTR_INNERCLASS
public static final int
ATTR_LINENUMBER
public static final int
ATTR_LOCALVAR
public static final int
ATTR_SOURCEFILE
public static final int
ATTR_SYNTHETIC
private int
attributeNameIndex
index into the constant pool table containing the name of this class
private int
attributeLength
length of this attribute in bytes
private Attribute
info
the attribute itself
private int
attrType
the type of attribute this is
private ConstantPoolInfo[]
constantPool
reference to the class's constant pool
Constructors Summary
public AttributeInfo(DataInputStream iStream, ConstantPoolInfo[] constantPool)
Constructor. Creates an AttributeInfo object by reading in the information about the attribute and the attribute.

param
iStream input on which to read the data
param
constantPool the constant pool of the class file
exception
IOException just pass IOExceptions up


                                                                              
      
                           
                                                        
     
      //read the name index and the attribute length
      attributeNameIndex = iStream.readUnsignedShort ();
      attributeLength = iStream.readInt ();

      //get the name of the attribute out of the constant pool
      ConstantUtf8Info    utf8Info = (ConstantUtf8Info)
                                        constantPool[attributeNameIndex];
      String            s = utf8Info.toString ();

      //branch based on the type of attribute
      //and create the appropriate attribute object
      //and store the attribute type
      if (s.equals ("ConstantValue"))
        {
         info = new ConstantValueAttribute (iStream, attributeNameIndex,
                                           attributeLength);
         attrType = ATTR_CONST;
        }
      else
        if (s.equals ("Synthetic"))
          {
           info = new SyntheticAttribute (iStream, attributeNameIndex,
                                         attributeLength);
           attrType = ATTR_SYNTHETIC;
          }
        else
          if (s.equals ("Deprecated"))
            {
             info = new DeprecatedAttribute (iStream, attributeNameIndex,
                                            attributeLength);
             attrType = ATTR_DEPRECATED;
            }
          else
            if (s.equals ("Code"))
              {
               info = new CodeAttribute (iStream, constantPool,
                                        attributeNameIndex, attributeLength);
               attrType = ATTR_CODE;
              }
            else
              if (s.equals ("Exceptions"))
                {
                 info = new ExceptionsAttribute (iStream, attributeNameIndex,
                                                attributeLength);
                 attrType = ATTR_EXCEPTIONS;
                }
              else
                if (s.equals ("InnerClasses"))
                  {
                   info = new InnerClassesAttribute (iStream, attributeNameIndex,
                                                    attributeLength);
                   attrType = ATTR_INNERCLASS;
                  }
                else
                  if (s.equals ("LineNumberTable"))
                    {
                     info = new LineNumberTableAttribute (iStream,
                                                         attributeNameIndex,
                                                         attributeLength);
                     attrType = ATTR_LINENUMBER;
                    }
                  else
                    if (s.equals ("SourceFile"))
                      {
                       info = new SourceFileAttribute (iStream, constantPool,
                                                      attributeNameIndex,
                                                      attributeLength);
                       attrType = ATTR_SOURCEFILE;
                      }
                    else
                      if (s.equals ("LocalVariableTable"))
                        {
                         info = new LocalVariableTableAttribute (iStream,
                                           attributeNameIndex, attributeLength);
                         attrType = ATTR_LOCALVAR;
                        }
                      else
                        for (int lcv = 0; lcv < attributeLength; ++lcv)
                          iStream.readByte ();
                          
      this.constantPool = constantPool;
     
Methods Summary
public AttributegetInfo()
Retrieves the info that this AttributeInfo represents.

return
Attribute the info represented by this AttributeInfo

      return info;
     
public intgetType()
Retrieves the type of this AttributeInfo.

return
int the type of this attribute from the list specified above

      return attrType;
     
public java.lang.StringtoString()
Returns the attribute in an easy to read format as a String.

return
String the attribute in a nice string format

      if (info == null)
        return ("AttributeInfo:\n\t\t" + "Unrecognized attribute");
      else
        return ("AttributeInfo:\n\t\t" + info.toString (constantPool));