FileDocCategorySizeDatePackage
PositionList.javaAPI DocAndroid 1.5 API5559Wed May 06 22:41:02 BST 2009com.android.dx.dex.code

PositionList

public final class PositionList extends com.android.dx.util.FixedSizeList
List of source position entries. This class includes a utility method to extract an instance out of a {@link DalvInsnList}.

Fields Summary
public static final PositionList
EMPTY
non-null; empty instance
public static final int
NONE
constant for {@link #make} to indicate that no actual position information should be returned
public static final int
LINES
constant for {@link #make} to indicate that only line number transitions should be returned
public static final int
IMPORTANT
constant for {@link #make} to indicate that only "important" position information should be returned. This includes block starts and instructions that might throw.
Constructors Summary
public PositionList(int size)
Constructs an instance. All indices initially contain null.

param
size >= 0; the size of the list

        super(size);
    
Methods Summary
public com.android.dx.dex.code.PositionList$Entryget(int n)
Gets the element at the given index. It is an error to call this with the index for an element which was never set; if you do that, this will throw NullPointerException.

param
n >= 0, < size(); which index
return
non-null; element at that index

        return (Entry) get0(n);
    
public static com.android.dx.dex.code.PositionListmake(DalvInsnList insns, int howMuch)
Extracts and returns the source position information out of an instruction list.

param
insns non-null; instructions to convert
param
howMuch how much information should be included; one of the static constants defined by this class
return
non-null; the positions list


                                                  
           
        switch (howMuch) {
            case NONE: {
                return EMPTY;
            }
            case LINES:
            case IMPORTANT: {
                // Valid.
                break;
            }
            default: {
                throw new IllegalArgumentException("bogus howMuch");
            }
        }

        SourcePosition noInfo = SourcePosition.NO_INFO;
        SourcePosition cur = noInfo;
        int sz = insns.size();
        PositionList.Entry[] arr = new PositionList.Entry[sz];
        boolean lastWasTarget = false;
        int at = 0;

        for (int i = 0; i < sz; i++) {
            DalvInsn insn = insns.get(i);

            if (insn instanceof CodeAddress) {
                lastWasTarget = true;;
                continue;
            }

            SourcePosition pos = insn.getPosition();

            if (pos.equals(noInfo) || pos.sameLine(cur)) {
                continue;
            }

            if ((howMuch == IMPORTANT) && !lastWasTarget) {
                continue;
            }

            cur = pos;
            arr[at] = new PositionList.Entry(insn.getAddress(), pos);
            at++;

            lastWasTarget = false;
        }

        PositionList result = new PositionList(at);
        for (int i = 0; i < at; i++) {
            result.set(i, arr[i]);
        }

        result.setImmutable();
        return result;
    
public voidset(int n, com.android.dx.dex.code.PositionList$Entry entry)
Sets the entry at the given index.

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

        set0(n, entry);