Skip to content

Commit

Permalink
match can be static
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Sep 11, 2024
1 parent 3148a9d commit 188472b
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public class ZelixUselessTryCatchRemoverTransformer extends Transformer {
OpcodeMatch.of(ARETURN)
);

private static final Match INVOKE_AND_RETURN =
SequenceMatch.of(
MethodMatch.invokeStatic().save("invocation"),
OpcodeMatch.of(ATHROW)
);

@Override
protected void transform(ClassWrapper scope, Context context) throws Exception {
context.classes(scope).forEach(classWrapper -> {
Expand All @@ -56,12 +62,6 @@ protected void transform(ClassWrapper scope, Context context) throws Exception {
}
});

Match invokeAndReturnMatch =
SequenceMatch.of(
MethodMatch.invokeStatic().save("invocation"),
OpcodeMatch.of(ATHROW)
);

List<MethodRef> toRemove = new ArrayList<>();

// Remove try-catches with these instant return exception methods
Expand All @@ -70,7 +70,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception {

methodNode.tryCatchBlocks.removeIf(tryBlock -> {
InstructionContext start = framelessContext.newInsnContext(tryBlock.handler.getNext());
MatchContext result = invokeAndReturnMatch.matchResult(start);
MatchContext result = INVOKE_AND_RETURN.matchResult(start);
if (result != null) {
MethodRef methodRef = MethodRef.of((MethodInsnNode) result.insn());

Expand Down

0 comments on commit 188472b

Please sign in to comment.