FileDocCategorySizeDatePackage
ByteCatchList.javaAPI DocAndroid 5.1 API9980Thu Mar 12 22:18:30 GMT 2015com.android.dexgen.rop

ByteCatchList

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

Fields Summary
public static final ByteCatchList
EMPTY
{@code 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 Code} attribute. The returned value includes the two bytes for {@code exception_table_length}.

return
{@code >= 2;} the total length, in bytes

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

param
n {@code >= 0;} which item
return
{@code null-ok;} the indicated item

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

param
pc which address
return
{@code non-null;} list of exception handlers active at {@code 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.dexgen.rop.ByteCatchList$Item item)
Sets the item at the given index.

param
n {@code >= 0, < size();} which entry to set
param
item {@code 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.dexgen.rop.cst.CstType exceptionClass)
Sets the item at the given index.

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

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

return
{@code 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.dexgen.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 {@code noException} address appended if appropriate. The result is automatically made immutable.

param
noException {@code >= -1;} the no-exception address to append, or {@code -1} not to append anything
return
{@code non-null;} list of exception targets, with {@code 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.dexgen.rop.ByteCatchList$Item item, com.android.dexgen.rop.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 {@code Object} which represents a catch-all.

param
item {@code non-null;} item with the exception type to look for
param
arr {@code non-null;} array to search in
param
count {@code non-null;} maximum number of elements in the array to check
return
{@code 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;