FileDocCategorySizeDatePackage
CodeAttribute.javaAPI DocphoneME MR2 API (J2ME)5038Wed May 02 17:59:48 BST 2007components

CodeAttribute

public class CodeAttribute extends Attribute

Fields Summary
public int
stack
public int
locals
public byte[]
code
public ExceptionEntry[]
exceptionTable
public Attribute[]
codeAttributes
private static Hashtable
codeAttributeTypes
Constructors Summary
public CodeAttribute(UnicodeConstant name, int l, int ns, int nl, byte[] c, ExceptionEntry[] et, Attribute[] ca)

	super( name, l );
	stack  = ns;
	locals = nl;
	code   = c;
	exceptionTable = et;
	codeAttributes = ca;
    
Methods Summary
public voidcountConstantReferences(boolean isRelocatable)

	super.countConstantReferences( isRelocatable );
	if ( exceptionTable != null ){
	    for( int i = 0; i < exceptionTable.length; i++ ){
		exceptionTable[i].countConstantReferences();
	    }
	}
	Attribute.countConstantReferences( codeAttributes, isRelocatable );
    
public voidexternalize(ConstantPool p)

	super.externalize( p );
	Attribute.externalizeAttributes( codeAttributes, p );
    
public static AttributefinishReadAttribute(java.io.DataInput in, UnicodeConstant name, ConstantObject[] locals, ConstantObject[] globals)

	int l;
	int nstack;
	int nlocals;
	ConstantObject d;
	ExceptionEntry exceptionTable[];

	l       = in.readInt();
	nstack  = in.readUnsignedShort();
	nlocals = in.readUnsignedShort();

	int codesize = in.readInt();
	byte code[] = new byte[ codesize ];
	in.readFully( code );

	int tableSize = in.readUnsignedShort();
	exceptionTable = new ExceptionEntry[tableSize];
	for (int j = 0; j < tableSize; j++) {
	    int sPC = in.readUnsignedShort();
	    int e = in.readUnsignedShort();
	    int h = in.readUnsignedShort();
	    int catchTypeIndex = in.readUnsignedShort();
	    ClassConstant ctype;
	    if ( catchTypeIndex == 0 ){
		ctype = null;
	    } else {
		ctype = (ClassConstant)locals[ catchTypeIndex ];
	    }
	    exceptionTable[j] = new ExceptionEntry( 
		sPC, e, h, ctype );
	}

	Attribute a[] = Attribute.readAttributes( in, locals, globals, codeAttributeTypes, false );
	return new CodeAttribute(
	    name, l, nstack, nlocals, code, exceptionTable, a );
    
public static AttributereadAttribute(java.io.DataInput i, ConstantObject[] locals, ConstantObject[] globals)

    
	codeAttributeTypes.put( "LineNumberTable", LineNumberTableAttributeFactory.instance );
	codeAttributeTypes.put( "LocalVariableTable", LocalVariableTableAttributeFactory.instance );
	codeAttributeTypes.put( "StackMap", StackMapAttributeFactory.instance );
    
	UnicodeConstant name;

	name = (UnicodeConstant)globals[i.readUnsignedShort()];
	return finishReadAttribute( i, name, locals, globals );
    
protected intwriteData(java.io.DataOutput o)

	int trueLength = 8 + code.length;
	o.writeShort( stack );
	o.writeShort( locals );
	o.writeInt( code.length );
	o.write( code, 0, code.length );
	if ( exceptionTable == null ){
	    o.writeShort( 0 );
	    trueLength += 2;
	} else {
	    o.writeShort( exceptionTable.length );
	    for ( int i = 0; i < exceptionTable.length ; i ++ ){
		exceptionTable[i].write( o );
	    }
	    trueLength += 2 + exceptionTable.length*ExceptionEntry.size;
	}
	if ( codeAttributes == null ){
	    o.writeShort(0);
	    trueLength += 2;
	} else {
	    Attribute.writeAttributes( codeAttributes, o, false );
	    trueLength += Attribute.length( codeAttributes );
	}
	return trueLength;