FileDocCategorySizeDatePackage
OutputCollector.javaAPI DocAndroid 1.5 API3798Wed May 06 22:41:02 BST 2009com.android.dx.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
non-null; the associated finisher (which holds the instruction list in-progress)
private ArrayList
suffix
null-ok; suffix for the output, or 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 >= 0; initial capacity of the output list
param
suffixInitialCapacity >= 0; initial capacity of the output suffix
param
regCount >= 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 non-null; the instruction to add

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

param
insn 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
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; 0 is the most recently added instruction, 1 is the instruction before that, etc.
param
newTarget non-null; the new target for the reversed branch

        finisher.reverseBranch(which, newTarget);