FileDocCategorySizeDatePackage
OutputCollector.javaAPI DocAndroid 5.1 API3836Thu Mar 12 22:18:28 GMT 2015com.android.dexgen.dex.code

OutputCollector

public final class OutputCollector extends Object
Destination for {@link DalvInsn} instances being output. This class receives and collects instructions in two pieces — a primary list and a suffix (generally consisting of adjunct data referred to by the primary list, such as switch case tables) — which it merges and emits back out in the form of a {@link DalvInsnList} instance.

Fields Summary
private final OutputFinisher
finisher
{@code non-null;} the associated finisher (which holds the instruction list in-progress)
private ArrayList
suffix
{@code null-ok;} suffix for the output, or {@code null} if the suffix has been appended to the main output (by {@link #appendSuffixToOutput})
Constructors Summary
public OutputCollector(int initialCapacity, int suffixInitialCapacity, int regCount)
Constructs an instance.

param
initialCapacity {@code >= 0;} initial capacity of the output list
param
suffixInitialCapacity {@code >= 0;} initial capacity of the output suffix
param
regCount {@code >= 0;} register count for the method

        this.finisher = new OutputFinisher(initialCapacity, regCount);
        this.suffix = new ArrayList<DalvInsn>(suffixInitialCapacity);
    
Methods Summary
public voidadd(DalvInsn insn)
Adds an instruction to the output.

param
insn {@code non-null;} the instruction to add

        finisher.add(insn);
    
public voidaddSuffix(DalvInsn insn)
Adds an instruction to the output suffix.

param
insn {@code non-null;} the instruction to add

        suffix.add(insn);
    
private voidappendSuffixToOutput()
Helper for {@link #getFinisher}, which appends the suffix to the primary output.

        int size = suffix.size();

        for (int i = 0; i < size; i++) {
            finisher.add(suffix.get(i));
        }

        suffix = null;
    
public OutputFinishergetFinisher()
Gets the results of all the calls on this instance, in the form of an {@link OutputFinisher}.

return
{@code non-null;} the output finisher
throws
UnsupportedOperationException if this method has already been called

        if (suffix == null) {
            throw new UnsupportedOperationException("already processed");
        }

        appendSuffixToOutput();
        return finisher;
    
public voidreverseBranch(int which, CodeAddress newTarget)
Reverses a branch which is buried a given number of instructions backward in the output. It is illegal to call this unless the indicated instruction really is a reversible branch.

param
which how many instructions back to find the branch; {@code 0} is the most recently added instruction, {@code 1} is the instruction before that, etc.
param
newTarget {@code non-null;} the new target for the reversed branch

        finisher.reverseBranch(which, newTarget);