From 32674967dee503c5edfd49f20ac5709fafac09d9 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 1 Oct 2018 15:43:04 +0700 Subject: [PATCH] 'Switch' statements with single case converted to 'if', other warnings fixed --- .../modules/decompiler/ExitHelper.java | 49 +++++++++---------- .../modules/decompiler/MergeHelper.java | 13 +++-- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/ExitHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/ExitHelper.java index 81c61d0..3b9847f 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/ExitHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/ExitHelper.java @@ -80,32 +80,31 @@ public class ExitHelper { } } - switch (stat.type) { - case Statement.TYPE_IF: - IfStatement ifst = (IfStatement)stat; - if (ifst.getIfstat() == null) { - StatEdge ifedge = ifst.getIfEdge(); - dest = isExitEdge(ifedge); - if (dest != null) { - BasicBlockStatement bstat = new BasicBlockStatement(new BasicBlock( - DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.STATEMENT_COUNTER))); - bstat.setExprents(DecHelper.copyExprentList(dest.getExprents())); - - ifst.getFirst().removeSuccessor(ifedge); - StatEdge newedge = new StatEdge(StatEdge.TYPE_REGULAR, ifst.getFirst(), bstat); - ifst.getFirst().addSuccessor(newedge); - ifst.setIfEdge(newedge); - ifst.setIfstat(bstat); - ifst.getStats().addWithKey(bstat, bstat.id); - bstat.setParent(ifst); - - StatEdge oldexitedge = dest.getAllSuccessorEdges().get(0); - StatEdge newexitedge = new StatEdge(StatEdge.TYPE_BREAK, bstat, oldexitedge.getDestination()); - bstat.addSuccessor(newexitedge); - oldexitedge.closure.addLabeledEdge(newexitedge); - ret = 1; - } + if (stat.type == Statement.TYPE_IF) { + IfStatement ifst = (IfStatement)stat; + if (ifst.getIfstat() == null) { + StatEdge ifedge = ifst.getIfEdge(); + dest = isExitEdge(ifedge); + if (dest != null) { + BasicBlockStatement bstat = new BasicBlockStatement(new BasicBlock( + DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.STATEMENT_COUNTER))); + bstat.setExprents(DecHelper.copyExprentList(dest.getExprents())); + + ifst.getFirst().removeSuccessor(ifedge); + StatEdge newedge = new StatEdge(StatEdge.TYPE_REGULAR, ifst.getFirst(), bstat); + ifst.getFirst().addSuccessor(newedge); + ifst.setIfEdge(newedge); + ifst.setIfstat(bstat); + ifst.getStats().addWithKey(bstat, bstat.id); + bstat.setParent(ifst); + + StatEdge oldexitedge = dest.getAllSuccessorEdges().get(0); + StatEdge newexitedge = new StatEdge(StatEdge.TYPE_BREAK, bstat, oldexitedge.getDestination()); + bstat.addSuccessor(newexitedge); + oldexitedge.closure.addLabeledEdge(newexitedge); + ret = 1; } + } } } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/MergeHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/MergeHelper.java index 779aeb8..ed9f368 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/MergeHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/MergeHelper.java @@ -376,14 +376,13 @@ public class MergeHelper { return stat; } - switch (stat.type) { - case Statement.TYPE_SEQUENCE: - for (int i = stat.getStats().size() - 1; i >= 0; i--) { - Statement tmp = getLastDirectData(stat.getStats().get(i)); - if (tmp == null || !tmp.getExprents().isEmpty()) { - return tmp; - } + if (stat.type == Statement.TYPE_SEQUENCE) { + for (int i = stat.getStats().size() - 1; i >= 0; i--) { + Statement tmp = getLastDirectData(stat.getStats().get(i)); + if (tmp == null || !tmp.getExprents().isEmpty()) { + return tmp; } + } } return null; }