FileDocCategorySizeDatePackage
ByteCatchList.javaAPI DocAndroid 1.5 API9849Wed May 06 22:41:02 BST 2009com.android.dx.cf.code

ByteCatchList

public final class ByteCatchList extends com.android.dx.util.FixedSizeList
List of catch entries, that is, the elements of an "exception table," which is part of a standard Code attribute.

Fields Summary
public static final ByteCatchList
EMPTY
non-null; convenient zero-entry instance
Constructors Summary
public ByteCatchList(int count)
Constructs an instance.

param
count the number of elements to be in the table


                       
       
        super(count);
    
Methods Summary
public intbyteLength()
Gets the total length of this structure in bytes, when included in a Code attribute. The returned value includes the two bytes for exception_table_length.

return
>= 2; the total length, in bytes

        return 2 + size() * 8;
    
public com.android.dx.cf.code.ByteCatchList$Itemget(int n)
Gets the indicated item.

param
n >= 0; which item
return
null-ok; the indicated item

        return (Item) get0(n);
    
public com.android.dx.cf.code.ByteCatchListlistFor(int pc)
Gets the list of items active at the given address. The result is automatically made immutable.

param
pc which address
return
non-null; list of exception handlers active at pc

        int sz = size();
        Item[] resultArr = new Item[sz];
        int resultSz = 0;

        for (int i = 0; i < sz; i++) {
            Item one = get(i);
            if (one.covers(pc) && typeNotFound(one, resultArr, resultSz)) {
                resultArr[resultSz] = one;
                resultSz++;
            }
        }

        if (resultSz == 0) {
            return EMPTY;
        }

        ByteCatchList result = new ByteCatchList(resultSz);
        for (int i = 0; i < resultSz; i++) {
            result.set(i, resultArr[i]);
        }

        result.setImmutable();
        return result;
    
public voidset(int n, com.android.dx.cf.code.ByteCatchList$Item item)
Sets the item at the given index.

param
n >= 0, < size(); which entry to set
param
item non-null; the item

        if (item == null) {
            throw new NullPointerException("item == null");
        }

        set0(n, item);
    
public voidset(int n, int startPc, int endPc, int handlerPc, com.android.dx.rop.cst.CstType exceptionClass)
Sets the item at the given index.

param
n >= 0, < size(); which entry to set
param
startPc >= 0; the start pc (inclusive) of the handler's range
param
endPc >= startPc; the end pc (exclusive) of the handler's range
param
handlerPc >= 0; the pc of the exception handler
param
exceptionClass null-ok; the exception class or null to catch all exceptions with this handler

        set0(n, new Item(startPc, endPc, handlerPc, exceptionClass));
    
public com.android.dx.rop.type.TypeListtoRopCatchList()
Returns a rop-style catches list equivalent to this one.

return
non-null; the converted instance

        int sz = size();
        if (sz == 0) {
            return StdTypeList.EMPTY;
        }

        StdTypeList result = new StdTypeList(sz);

        for (int i = 0; i < sz; i++) {
            result.set(i, get(i).getExceptionClass().getClassType());
        }

        result.setImmutable();
        return result;
    
public com.android.dx.util.IntListtoTargetList(int noException)
Returns a target list corresponding to this instance. The result is a list of all the exception handler addresses, with the given noException address appended if appropriate. The result is automatically made immutable.

param
noException >= -1; the no-exception address to append, or -1 not to append anything
return
non-null; list of exception targets, with noException appended if necessary

        if (noException < -1) {
            throw new IllegalArgumentException("noException < -1");
        }

        boolean hasDefault = (noException >= 0);
        int sz = size();

        if (sz == 0) {
            if (hasDefault) {
                /*
                 * The list is empty, but there is a no-exception
                 * address; so, the result is just that address.
                 */
                return IntList.makeImmutable(noException);
            }
            /*
             * The list is empty and there isn't even a no-exception
             * address.
             */
            return IntList.EMPTY;
        }

        IntList result = new IntList(sz + (hasDefault ? 1 : 0));

        for (int i = 0; i < sz; i++) {
            result.add(get(i).getHandlerPc());
        }

        if (hasDefault) {
            result.add(noException);
        }

        result.setImmutable();
        return result;
    
private static booleantypeNotFound(com.android.dx.cf.code.ByteCatchList$Item item, com.android.dx.cf.code.ByteCatchList$Item[] arr, int count)
Helper method for {@link #listFor}, which tells whether a match is not found for the exception type of the given item in the given array. A match is considered to be either an exact type match or the class Object which represents a catch-all.

param
item non-null; item with the exception type to look for
param
arr non-null; array to search in
param
count non-null; maximum number of elements in the array to check
return
true iff the exception type is not found

        CstType type = item.getExceptionClass();

        for (int i = 0; i < count; i++) {
            CstType one = arr[i].getExceptionClass();
            if ((one == type) || (one == CstType.OBJECT)) {
                return false;
            }
        }

        return true;