MCPcopy Create free account
hub / github.com/airlift/bytecode / TryCatch

Class TryCatch

src/main/java/io/airlift/bytecode/control/TryCatch.java:32–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30import static java.util.Objects.requireNonNull;
31
32public class TryCatch
33 implements FlowControl
34{
35 private final String comment;
36 private final BytecodeNode tryNode;
37 private final List<CatchBlock> catchBlocks;
38
39 public TryCatch(BytecodeNode tryNode, List<CatchBlock> catchBlocks)
40 {
41 this(null, tryNode, catchBlocks);
42 }
43
44 public TryCatch(String comment, BytecodeNode tryNode, List<CatchBlock> catchBlocks)
45 {
46 this.comment = comment;
47 this.tryNode = requireNonNull(tryNode, "tryNode is null");
48 this.catchBlocks = ImmutableList.copyOf(requireNonNull(catchBlocks, "catchBlocks is null"));
49 }
50
51 @Override
52 public String getComment()
53 {
54 return comment;
55 }
56
57 public BytecodeNode getTryNode()
58 {
59 return tryNode;
60 }
61
62 public List<CatchBlock> getCatchBlocks()
63 {
64 return catchBlocks;
65 }
66
67 @Override
68 public void accept(MethodVisitor visitor, MethodGenerationContext generationContext)
69 {
70 LabelNode tryStart = new LabelNode("tryStart");
71 LabelNode tryEnd = new LabelNode("tryEnd");
72 List<LabelNode> handlers = new ArrayList<>();
73 LabelNode done = new LabelNode("done");
74
75 BytecodeBlock block = new BytecodeBlock();
76
77 // try block
78 block.visitLabel(tryStart)
79 .append(tryNode)
80 .visitLabel(tryEnd)
81 .gotoLabel(done);
82
83 // catch blocks
84 for (int i = 0; i < catchBlocks.size(); i++) {
85 BytecodeNode handlerBlock = catchBlocks.get(i).getHandler();
86 LabelNode handler = new LabelNode("handler" + i);
87 handlers.add(handler);
88 block.visitLabel(handler)
89 .append(handlerBlock);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected