FileDocCategorySizeDatePackage
PositionList.javaAPI DocAndroid 5.1 API5622Thu Mar 12 22:18:30 GMT 2015com.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
{@code 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 {@code null}.

param
size {@code >= 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 {@code NullPointerException}.

param
n {@code >= 0, < size();} which index
return
{@code 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 {@code non-null;} instructions to convert
param
howMuch how much information should be included; one of the static constants defined by this class
return
{@code 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 {@code >= 0, < size();} which index
param
entry {@code non-null;} the entry to set at {@code n}

        set0(n, entry);