Search in sources :

Example 6 with CatchIntermediate

use of org.candle.decompiler.intermediate.code.CatchIntermediate 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

AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)6 CatchIntermediate (org.candle.decompiler.intermediate.code.CatchIntermediate)6 TryIntermediate (org.candle.decompiler.intermediate.code.TryIntermediate)3 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 FinallyIntermediate (org.candle.decompiler.intermediate.code.FinallyIntermediate)2 IntermediateComparator (org.candle.decompiler.intermediate.code.IntermediateComparator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 TreeSet (java.util.TreeSet)1 TryBlock (org.candle.decompiler.ast.tcf.TryBlock)1 GoToIntermediate (org.candle.decompiler.intermediate.code.GoToIntermediate)1 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)1 Declaration (org.candle.decompiler.intermediate.expression.Declaration)1 NullIntermediate (org.candle.decompiler.intermediate.graph.context.NullIntermediate)1