Search in sources :

Example 1 with TryBlock

use of org.candle.decompiler.ast.tcf.TryBlock in project candle-decompiler by bradsdavis.

the class BlockVisitor method visitTryIntermediate.

@Override
public void visitTryIntermediate(TryIntermediate line) {
    if (seen.contains(line)) {
        // do nothing.
        return;
    } else {
        seen.add(line);
    }
    // set current block...
    TryBlock tryBlock = new TryBlock(line);
    // add it as a child of current..
    this.current.addChild(tryBlock);
    // set the current...
    this.current = tryBlock;
    // now, get the nested blocks...
    List<AbstractIntermediate> successors = getUnseenSuccessors(line);
    AbstractIntermediate inner = null;
    List<AbstractIntermediate> catchBlocks = new LinkedList<AbstractIntermediate>();
    AbstractIntermediate finallyIntermediate = null;
    // find the non-catch/finally...
    for (AbstractIntermediate successor : successors) {
        if (successor instanceof CatchIntermediate) {
            catchBlocks.add(successor);
        } else if (successor instanceof FinallyIntermediate) {
            finallyIntermediate = successor;
        } else {
            if (inner != null) {
                throw new IllegalStateException("Inner direction already set.");
            }
            inner = successor;
        }
    }
    Collections.sort(catchBlocks, new IntermediateComparator());
    if (inner == null) {
        throw new IllegalStateException("Inner is not set.");
    }
    inner.accept(this);
    // set the current up.
    moveUp();
    for (AbstractIntermediate catchBlock : catchBlocks) {
        current = tryBlock;
        catchBlock.accept(this);
    }
    if (finallyIntermediate != null) {
        current = tryBlock;
        finallyIntermediate.accept(this);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) CatchIntermediate(org.candle.decompiler.intermediate.code.CatchIntermediate) FinallyIntermediate(org.candle.decompiler.intermediate.code.FinallyIntermediate) TryBlock(org.candle.decompiler.ast.tcf.TryBlock) IntermediateComparator(org.candle.decompiler.intermediate.code.IntermediateComparator) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 TryBlock (org.candle.decompiler.ast.tcf.TryBlock)1 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)1 CatchIntermediate (org.candle.decompiler.intermediate.code.CatchIntermediate)1 FinallyIntermediate (org.candle.decompiler.intermediate.code.FinallyIntermediate)1 IntermediateComparator (org.candle.decompiler.intermediate.code.IntermediateComparator)1