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

LocalVariableList

public final class LocalVariableList extends com.android.dx.util.FixedSizeList
List of "local variable" entries, which are the contents of LocalVariableTable and LocalVariableTypeTable attributes, as well as combinations of the two.

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

param
count the number of elements to be in the list

        super(count);
    
Methods Summary
public static com.android.dx.cf.code.LocalVariableListconcat(com.android.dx.cf.code.LocalVariableList list1, com.android.dx.cf.code.LocalVariableList list2)
Returns an instance which is the concatenation of the two given instances. The result is immutable.

param
list1 non-null; first instance
param
list2 non-null; second instance
return
non-null; combined instance


                                        
        
                                             
        if (list1 == EMPTY) {
            // easy case
            return list2;
        }

        int sz1 = list1.size();
        int sz2 = list2.size();
        LocalVariableList result = new LocalVariableList(sz1 + sz2);

        for (int i = 0; i < sz1; i++) {
            result.set(i, list1.get(i));
        }

        for (int i = 0; i < sz2; i++) {
            result.set(sz1 + i, list2.get(i));
        }

        result.setImmutable();
        return result;
    
public com.android.dx.cf.code.LocalVariableList$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.LocalVariableList$ItemitemToLocal(com.android.dx.cf.code.LocalVariableList$Item item)
Gets the local variable information in this instance which matches the given {@link com.android.dx.cf.code.LocalVariableList.Item} in all respects but the type descriptor and signature, if any.

param
item non-null; local variable information to match
return
null-ok; the corresponding local variable information stored in this instance, or null if there is no matching information

        int sz = size();

        for (int i = 0; i < sz; i++) {
            Item one = (Item) get0(i);

            if ((one != null) && one.matchesAllButType(item)) {
                return one;
            }
        }

        return null;
    
public static com.android.dx.cf.code.LocalVariableListmergeDescriptorsAndSignatures(com.android.dx.cf.code.LocalVariableList descriptorList, com.android.dx.cf.code.LocalVariableList signatureList)
Returns an instance which is the result of merging the two given instances, where one instance should have only type descriptors and the other only type signatures. The merged result is identical to the one with descriptors, except that any element whose {name, index, start, length} matches an element in the signature list gets augmented with the corresponding signature. The result is immutable.

param
descriptorList non-null; list with descriptors
param
signatureList non-null; list with signatures
return
non-null; the merged result

        int signatureSize = signatureList.size();
        int descriptorSize = descriptorList.size();
        LocalVariableList result = new LocalVariableList(descriptorSize);

        for (int i = 0; i < descriptorSize; i++) {
            Item item = descriptorList.get(i);
            Item signatureItem = signatureList.itemToLocal(item);
            if (signatureItem != null) {
                CstUtf8 signature = signatureItem.getSignature();
                item = item.withSignature(signature);
            }
            result.set(i, item);
        }        

        result.setImmutable();
        return result;
    
public com.android.dx.cf.code.LocalVariableList$ItempcAndIndexToLocal(int pc, int index)
Gets the local variable information associated with a given address and local index, if any. Note: In standard classfiles, a variable's start point is listed as the address of the instruction just past the one that sets the variable.

param
pc >= 0; the address to look up
param
index >= 0; the local variable index
return
null-ok; the associated local variable information, or null if none is known

        int sz = size();

        for (int i = 0; i < sz; i++) {
            Item one = (Item) get0(i);

            if ((one != null) && one.matchesPcAndIndex(pc, index)) {
                return one;
            }
        }

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

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

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

        set0(n, item);
    
public voidset(int n, int startPc, int length, com.android.dx.rop.cst.CstUtf8 name, com.android.dx.rop.cst.CstUtf8 descriptor, com.android.dx.rop.cst.CstUtf8 signature, int index)
Sets the item at the given index.

Note: At least one of descriptor or signature must be passed as non-null.

param
n >= 0, < size(); which element
param
startPc >= 0; the start pc of this variable's scope
param
length >= 0; the length (in bytecodes) of this variable's scope
param
name non-null; the variable's name
param
descriptor null-ok; the variable's type descriptor
param
signature null-ok; the variable's type signature
param
index >= 0; the variable's local index

        set0(n, new Item(startPc, length, name, descriptor, signature, index));