FileDocCategorySizeDatePackage
Attribute.javaAPI DocGlassfish v2 API8807Thu Mar 02 11:51:12 GMT 2006oracle.toplink.libraries.asm

Attribute

public class Attribute extends Object
A non standard class, field, method or code attribute.
author
Eric Bruneton, Eugene Kuleshov

Fields Summary
public final String
type
The type of this attribute.
public Attribute
next
The next attribute in this attribute list. May be null.
Constructors Summary
protected Attribute(String type)
Constructs a new empty attribute.

param
type the type of the attribute.

    this.type = type;
  
Methods Summary
final intgetCount()
Returns the length of the attribute list that begins with this attribute.

return
the length of the attribute list that begins with this attribute.

    int count = 0;
    Attribute attr = this;
    while (attr != null) {
      if (!attr.isUnknown()) {
        count += 1;
      }
      attr = attr.next;
    }
    return count;
  
protected oracle.toplink.libraries.asm.Label[]getLabels()
Returns the labels corresponding to this attribute.

return
the labels corresponding to this attribute, or null if this attribute is not a code attribute that contains labels.

    return null;
  
final intgetSize(oracle.toplink.libraries.asm.ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals)
Returns the size of all the attributes in this attribute list.

param
cw the class writer to be used to convert the attributes into byte arrays, with the {@link #write write} method.
param
code the bytecode of the method corresponding to these code attributes, or null if these attributes are not code attributes.
param
len the length of the bytecode of the method corresponding to these code attributes, or null if these attributes are not code attributes.
param
maxStack the maximum stack size of the method corresponding to these code attributes, or -1 if these attributes are not code attributes.
param
maxLocals the maximum number of local variables of the method corresponding to these code attributes, or -1 if these attributes are not code attributes.
return
the size of all the attributes in this attribute list. This size includes the size of the attribute headers.

    Attribute attr = this;
    int size = 0;
    while (attr != null) {
      if (!attr.isUnknown()) {
        cw.newUTF8(attr.type);
        size += attr.write(cw, code, len, maxStack, maxLocals).length + 6;
      }
      attr = attr.next;
    }
    return size;
  
public booleanisUnknown()
Returns true if this type of attribute is unknown.

return
true if the class of this object is equal to {@link Attribute}.

    return getClass().getName().equals("oracle.toplink.libraries.asm.Attribute");
  
final voidput(oracle.toplink.libraries.asm.ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals, oracle.toplink.libraries.asm.ByteVector out)
Writes all the attributes of this attribute list in the given byte vector.

param
cw the class writer to be used to convert the attributes into byte arrays, with the {@link #write write} method.
param
code the bytecode of the method corresponding to these code attributes, or null if these attributes are not code attributes.
param
len the length of the bytecode of the method corresponding to these code attributes, or null if these attributes are not code attributes.
param
maxStack the maximum stack size of the method corresponding to these code attributes, or -1 if these attributes are not code attributes.
param
maxLocals the maximum number of local variables of the method corresponding to these code attributes, or -1 if these attributes are not code attributes.
param
out where the attributes must be written.

    if (next != null) {
      next.put(cw, code, len, maxStack, maxLocals, out);
    }
    if (isUnknown()) {
      if (cw.checkAttributes) {
        throw new IllegalArgumentException("Unknown attribute type " + type);
      }
    } else {
      ByteVector b = write(cw, code, len, maxStack, maxLocals);
      out.putShort(cw.newUTF8(type)).putInt(b.length);
      out.putByteArray(b.data, 0, b.length);
    }
  
protected oracle.toplink.libraries.asm.Attributeread(oracle.toplink.libraries.asm.ClassReader cr, int off, int len, char[] buf, int codeOff, oracle.toplink.libraries.asm.Label[] labels)
Reads a {@link #type type} attribute. This method must return a new {@link Attribute} object, of type {@link #type type}, corresponding to the len bytes starting at the given offset, in the given class reader.

param
cr the class that contains the attribute to be read.
param
off index of the first byte of the attribute's content in {@link ClassReader#b cr.b}. The 6 attribute header bytes, containing the type and the length of the attribute, are not taken into account here.
param
len the length of the attribute's content.
param
buf buffer to be used to call {@link ClassReader#readUTF8 readUTF8}, {@link ClassReader#readClass(int,char[]) readClass} or {@link ClassReader#readConst readConst}.
param
codeOff index of the first byte of code's attribute content in {@link ClassReader#b cr.b}, or -1 if the attribute to be read is not a code attribute. The 6 attribute header bytes, containing the type and the length of the attribute, are not taken into account here.
param
labels the labels of the method's code, or null if the attribute to be read is not a code attribute.
return
a new {@link Attribute} object corresponding to the given bytes.

    return new Attribute(type);
  
protected oracle.toplink.libraries.asm.ByteVectorwrite(oracle.toplink.libraries.asm.ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals)
Returns the byte array form of this attribute.

param
cw the class to which this attribute must be added. This parameter can be used to add to the constant pool of this class the items that corresponds to this attribute.
param
code the bytecode of the method corresponding to this code attribute, or null if this attribute is not a code attributes.
param
len the length of the bytecode of the method corresponding to this code attribute, or null if this attribute is not a code attribute.
param
maxStack the maximum stack size of the method corresponding to this code attribute, or -1 if this attribute is not a code attribute.
param
maxLocals the maximum number of local variables of the method corresponding to this code attribute, or -1 if this attribute is not a code attribute.
return
the byte array form of this attribute.

    return new ByteVector();