diff options
Diffstat (limited to 'src/org/jetbrains/java/decompiler/modules')
37 files changed, 257 insertions, 258 deletions
diff --git a/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java b/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java index e8377ae..c7dd8ca 100644 --- a/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java @@ -24,10 +24,7 @@ import org.jetbrains.java.decompiler.code.cfg.ExceptionRangeCFG; import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; +import java.util.*; public class DeadCodeHelper { @@ -177,7 +174,7 @@ public class DeadCodeHelper { } // finally exit edges - HashSet<BasicBlock> setFinallyExits = graph.getFinallyExits(); + Set<BasicBlock> setFinallyExits = graph.getFinallyExits(); if (setFinallyExits.contains(block)) { setFinallyExits.remove(block); setFinallyExits.add(setPreds.iterator().next()); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/DecHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/DecHelper.java index 50b6673..9c719db 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/DecHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/DecHelper.java @@ -83,11 +83,8 @@ public class DecHelper { boolean repeat = false; setDest.remove(post); - Iterator<Statement> it = setDest.iterator(); - - while (it.hasNext()) { - Statement stat = it.next(); + for (Statement stat : setDest) { if (stat.getLastBasicType() != Statement.LASTBASICTYPE_GENERAL) { if (post == null) { post = stat; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java index 2b911e7..422b93b 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java @@ -497,10 +497,7 @@ public class DomHelper { while (true) { boolean hdfound = false; - Iterator<Statement> itHandlers = setHandlers.iterator(); - while (itHandlers.hasNext()) { - Statement handler = itHandlers.next(); - + for (Statement handler : setHandlers) { if (setNodes.contains(handler)) { continue; } @@ -553,9 +550,7 @@ public class DomHelper { setHandlers.removeAll(setNodes); boolean excok = true; - Iterator<Statement> itt = setHandlers.iterator(); - while (itt.hasNext()) { - Statement handler = itt.next(); + for (Statement handler : setHandlers) { if (!handler.getNeighbours(StatEdge.TYPE_EXCEPTION, Statement.DIRECTION_BACKWARD).containsAll(setNodes)) { excok = false; break; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java index 1612d32..50b04a9 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java @@ -259,7 +259,7 @@ public class ExprProcessor implements CodeConstants { } // FIXME: Ugly code, to be rewritten. A tuple class is needed. - private String buildEntryPointKey(LinkedList<String> entrypoints) { + private static String buildEntryPointKey(LinkedList<String> entrypoints) { if (entrypoints.isEmpty()) { return null; } @@ -273,7 +273,7 @@ public class ExprProcessor implements CodeConstants { } } - private PrimitiveExprsList copyVarExprents(PrimitiveExprsList data) { + private static PrimitiveExprsList copyVarExprents(PrimitiveExprsList data) { ExprentStack stack = data.getStack(); for (int i = 0; i < stack.size(); i++) { stack.set(i, stack.get(i).copy()); @@ -281,7 +281,7 @@ public class ExprProcessor implements CodeConstants { return data; } - private void collectCatchVars(Statement stat, FlattenStatementsHelper flatthelper, Map<String, VarExprent> map) { + private static void collectCatchVars(Statement stat, FlattenStatementsHelper flatthelper, Map<String, VarExprent> map) { List<VarExprent> lst = null; @@ -306,7 +306,7 @@ public class ExprProcessor implements CodeConstants { } } - private void initStatementExprents(Statement stat) { + private static void initStatementExprents(Statement stat) { stat.initExprents(); for (Statement st : stat.getStats()) { @@ -754,7 +754,7 @@ public class ExprProcessor implements CodeConstants { } public static String jmpWrapper(Statement stat, int indent, boolean semicolon) { - StringBuffer buf = new StringBuffer(stat.toJava(indent)); + StringBuilder buf = new StringBuilder(stat.toJava(indent)); String new_line_separator = DecompilerContext.getNewLineSeparator(); @@ -773,14 +773,14 @@ public class ExprProcessor implements CodeConstants { } if (edge.labeled) { - buf.append(" label" + edge.closure.id); + buf.append(" label").append(edge.closure.id); } - buf.append(";" + new_line_separator); + buf.append(";").append(new_line_separator); } } if (buf.length() == 0 && semicolon) { - buf.append(InterpreterUtil.getIndentString(indent) + ";" + new_line_separator); + buf.append(InterpreterUtil.getIndentString(indent)).append(";").append(new_line_separator); } return buf.toString(); @@ -789,7 +789,7 @@ public class ExprProcessor implements CodeConstants { public static String buildJavaClassName(String name) { String res = name.replace('/', '.'); - if (res.indexOf("$") >= 0) { // attempt to invoke foreign member + if (res.contains("$")) { // attempt to invoke foreign member // classes correctly StructClass cl = DecompilerContext.getStructcontext().getClass(name); if (cl == null || !cl.isOwn()) { @@ -808,7 +808,7 @@ public class ExprProcessor implements CodeConstants { String indstr = InterpreterUtil.getIndentString(indent); String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (Exprent expr : lst) { String content = expr.toJava(indent); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java index 103b933..53be24b 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java @@ -46,9 +46,8 @@ import java.util.Map.Entry; public class FinallyProcessor { - - private HashMap<Integer, Integer> finallyBlockIDs = new HashMap<Integer, Integer>(); - private HashMap<Integer, Integer> catchallBlockIDs = new HashMap<Integer, Integer>(); + private Map<Integer, Integer> finallyBlockIDs = new HashMap<Integer, Integer>(); + private Map<Integer, Integer> catchallBlockIDs = new HashMap<Integer, Integer>(); private VarProcessor varprocessor; @@ -92,7 +91,7 @@ public class FinallyProcessor { } else { - Object[] inf = getFinallyInformation(mt, root, fin); + Record inf = getFinallyInformation(mt, root, fin); if (inf == null) { // inconsistent finally catchallBlockIDs.put(handler.id, null); @@ -181,10 +180,20 @@ public class FinallyProcessor { // return res; // } + private static class Record { + private final int firstCode; + private final Map<BasicBlock, Boolean> mapLast; + + private Record(int firstCode, Map<BasicBlock, Boolean> mapLast) { + this.firstCode = firstCode; + this.mapLast = mapLast; + } + } + - private Object[] getFinallyInformation(StructMethod mt, RootStatement root, CatchAllStatement fstat) { + private static Record getFinallyInformation(StructMethod mt, RootStatement root, CatchAllStatement fstat) { - HashMap<BasicBlock, Boolean> mapLast = new HashMap<BasicBlock, Boolean>(); + Map<BasicBlock, Boolean> mapLast = new HashMap<BasicBlock, Boolean>(); BasicBlockStatement firstBlockStatement = fstat.getHandler().getBasichead(); BasicBlock firstBasicBlock = firstBlockStatement.getBlock(); @@ -216,7 +225,7 @@ public class FinallyProcessor { LinkedList<DirectNode> stack = new LinkedList<DirectNode>(); stack.add(dgraph.first); - HashSet<DirectNode> setVisited = new HashSet<DirectNode>(); + Set<DirectNode> setVisited = new HashSet<DirectNode>(); while (!stack.isEmpty()) { @@ -356,21 +365,21 @@ public class FinallyProcessor { } } - return new Object[]{firstcode, mapLast}; + return new Record(firstcode, mapLast); } - private void insertSemaphore(ControlFlowGraph graph, - HashSet<BasicBlock> setTry, - BasicBlock head, - BasicBlock handler, - int var, - Object[] information, - int bytecode_version) { + private static void insertSemaphore(ControlFlowGraph graph, + Set<BasicBlock> setTry, + BasicBlock head, + BasicBlock handler, + int var, + Record information, + int bytecode_version) { - HashSet<BasicBlock> setCopy = new HashSet<BasicBlock>(setTry); + Set<BasicBlock> setCopy = new HashSet<BasicBlock>(setTry); - int finallytype = (Integer)information[0]; - HashMap<BasicBlock, Boolean> mapLast = (HashMap<BasicBlock, Boolean>)information[1]; + int finallytype = information.firstCode; + Map<BasicBlock, Boolean> mapLast = information.mapLast; // first and last statements removeExceptionInstructionsEx(handler, 1, finallytype); @@ -468,7 +477,7 @@ public class FinallyProcessor { } - private void insertBlockBefore(ControlFlowGraph graph, BasicBlock oldblock, BasicBlock newblock) { + private static void insertBlockBefore(ControlFlowGraph graph, BasicBlock oldblock, BasicBlock newblock) { List<BasicBlock> lstTemp = new ArrayList<BasicBlock>(); lstTemp.addAll(oldblock.getPreds()); @@ -501,7 +510,7 @@ public class FinallyProcessor { } } - private HashSet<BasicBlock> getAllBasicBlocks(Statement stat) { + private static HashSet<BasicBlock> getAllBasicBlocks(Statement stat) { List<Statement> lst = new LinkedList<Statement>(); lst.add(stat); @@ -530,13 +539,13 @@ public class FinallyProcessor { } - private boolean verifyFinallyEx(ControlFlowGraph graph, CatchAllStatement fstat, Object[] information) { + private boolean verifyFinallyEx(ControlFlowGraph graph, CatchAllStatement fstat, Record information) { HashSet<BasicBlock> tryBlocks = getAllBasicBlocks(fstat.getFirst()); HashSet<BasicBlock> catchBlocks = getAllBasicBlocks(fstat.getHandler()); - int finallytype = (Integer)information[0]; - HashMap<BasicBlock, Boolean> mapLast = (HashMap<BasicBlock, Boolean>)information[1]; + int finallytype = information.firstCode; + Map<BasicBlock, Boolean> mapLast = information.mapLast; BasicBlock first = fstat.getHandler().getBasichead().getBlock(); boolean skippedFirst = false; @@ -571,16 +580,16 @@ public class FinallyProcessor { startBlocks.remove(graph.getLast()); startBlocks.removeAll(tryBlocks); - List<Object[]> lstAreas = new ArrayList<Object[]>(); + List<Area> lstAreas = new ArrayList<Area>(); for (BasicBlock start : startBlocks) { - Object[] arr = compareSubgraphsEx(graph, start, catchBlocks, first, finallytype, mapLast, skippedFirst); + Area arr = compareSubgraphsEx(graph, start, catchBlocks, first, finallytype, mapLast, skippedFirst); if (arr == null) { return false; } - lstAreas.add(new Object[]{start, arr[0], arr[1]}); + lstAreas.add(arr); } // try { @@ -588,7 +597,7 @@ public class FinallyProcessor { // } catch(Exception ex){ex.printStackTrace();} // delete areas - for (Object[] area : lstAreas) { + for (Area area : lstAreas) { deleteArea(graph, area); } @@ -611,13 +620,25 @@ public class FinallyProcessor { return true; } - private Object[] compareSubgraphsEx(ControlFlowGraph graph, - BasicBlock startSample, - HashSet<BasicBlock> catchBlocks, - BasicBlock startCatch, - int finallytype, - HashMap<BasicBlock, Boolean> mapLast, - boolean skippedFirst) { + private static class Area { + private final BasicBlock start; + private final Set<BasicBlock> sample; + private final BasicBlock next; + + private Area(BasicBlock start, Set<BasicBlock> sample, BasicBlock next) { + this.start = start; + this.sample = sample; + this.next = next; + } + } + + private Area compareSubgraphsEx(ControlFlowGraph graph, + BasicBlock startSample, + HashSet<BasicBlock> catchBlocks, + BasicBlock startCatch, + int finallytype, + Map<BasicBlock, Boolean> mapLast, + boolean skippedFirst) { class BlockStackEntry { public BasicBlock blockCatch; @@ -635,9 +656,9 @@ public class FinallyProcessor { List<BlockStackEntry> stack = new LinkedList<BlockStackEntry>(); - HashSet<BasicBlock> setSample = new HashSet<BasicBlock>(); + Set<BasicBlock> setSample = new HashSet<BasicBlock>(); - HashMap<String, BasicBlock[]> mapNext = new HashMap<String, BasicBlock[]>(); + Map<String, BasicBlock[]> mapNext = new HashMap<String, BasicBlock[]>(); stack.add(new BlockStackEntry(startCatch, startSample, new ArrayList<int[]>())); @@ -719,7 +740,7 @@ public class FinallyProcessor { } if (isLastBlock) { - HashSet<BasicBlock> setSuccs = new HashSet<BasicBlock>(blockSample.getSuccs()); + Set<BasicBlock> setSuccs = new HashSet<BasicBlock>(blockSample.getSuccs()); setSuccs.removeAll(setSample); for (BlockStackEntry stackent : stack) { @@ -734,10 +755,10 @@ public class FinallyProcessor { } } - return new Object[]{setSample, getUniqueNext(graph, new HashSet<BasicBlock[]>(mapNext.values()))}; + return new Area(startSample, setSample, getUniqueNext(graph, new HashSet<BasicBlock[]>(mapNext.values()))); } - private BasicBlock getUniqueNext(ControlFlowGraph graph, HashSet<BasicBlock[]> setNext) { + private static BasicBlock getUniqueNext(ControlFlowGraph graph, Set<BasicBlock[]> setNext) { // precondition: there is at most one true exit path in a finally statement @@ -784,7 +805,7 @@ public class FinallyProcessor { return null; } - for (int j = 0; i < instrNext.getOperands().length; j++) { + for (int j = 0; j < instrNext.getOperands().length; j++) { if (instrNext.getOperand(j) != instrBlock.getOperand(j)) { return null; } @@ -889,7 +910,7 @@ public class FinallyProcessor { graph.getBlocks().addWithKey(newblock, newblock.id); - HashSet<BasicBlock> setFinallyExits = graph.getFinallyExits(); + Set<BasicBlock> setFinallyExits = graph.getFinallyExits(); if (setFinallyExits.contains(sample)) { setFinallyExits.remove(sample); setFinallyExits.add(newblock); @@ -939,10 +960,10 @@ public class FinallyProcessor { return true; } - private void deleteArea(ControlFlowGraph graph, Object[] area) { + private static void deleteArea(ControlFlowGraph graph, Area area) { - BasicBlock start = (BasicBlock)area[0]; - BasicBlock next = (BasicBlock)area[2]; + BasicBlock start = area.start; + BasicBlock next = area.next; if (start == next) { return; @@ -954,23 +975,23 @@ public class FinallyProcessor { } // collect common exception ranges of predecessors and successors - HashSet<BasicBlock> setCommonExceptionHandlers = new HashSet<BasicBlock>(next.getSuccExceptions()); + Set<BasicBlock> setCommonExceptionHandlers = new HashSet<BasicBlock>(next.getSuccExceptions()); for (BasicBlock pred : start.getPreds()) { setCommonExceptionHandlers.retainAll(pred.getSuccExceptions()); } boolean is_outside_range = false; - HashSet<BasicBlock> setPredecessors = new HashSet<BasicBlock>(start.getPreds()); + Set<BasicBlock> setPredecessors = new HashSet<BasicBlock>(start.getPreds()); // replace start with next for (BasicBlock pred : setPredecessors) { pred.replaceSuccessor(start, next); } - HashSet<BasicBlock> setBlocks = (HashSet<BasicBlock>)area[1]; + Set<BasicBlock> setBlocks = area.sample; - HashSet<ExceptionRangeCFG> setCommonRemovedExceptionRanges = null; + Set<ExceptionRangeCFG> setCommonRemovedExceptionRanges = null; // remove all the blocks inbetween for (BasicBlock block : setBlocks) { @@ -983,7 +1004,7 @@ public class FinallyProcessor { is_outside_range = true; } - HashSet<ExceptionRangeCFG> setRemovedExceptionRanges = new HashSet<ExceptionRangeCFG>(); + Set<ExceptionRangeCFG> setRemovedExceptionRanges = new HashSet<ExceptionRangeCFG>(); for (BasicBlock handler : block.getSuccExceptions()) { setRemovedExceptionRanges.add(graph.getExceptionRange(handler, block)); } @@ -1036,7 +1057,7 @@ public class FinallyProcessor { } } - private void removeExceptionInstructionsEx(BasicBlock block, int blocktype, int finallytype) { + private static void removeExceptionInstructionsEx(BasicBlock block, int blocktype, int finallytype) { InstructionSequence seq = block.getSeq(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/LabelHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/LabelHelper.java index 00da7ac..1f4b5ee 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/LabelHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/LabelHelper.java @@ -223,10 +223,8 @@ public class LabelHelper { processEdgesWithNext(ifstat.getFirst(), mapEdges, null); } else { - if (ifstat.getIfstat() != null) { - mapEdges = setExplicitEdges(ifstat.getIfstat()); - processEdgesWithNext(ifstat.getIfstat(), mapEdges, null); - } + mapEdges = setExplicitEdges(ifstat.getIfstat()); + processEdgesWithNext(ifstat.getIfstat(), mapEdges, null); HashMap<Statement, List<StatEdge>> mapEdges1 = null; if (ifstat.getElsestat() != null) { @@ -422,17 +420,14 @@ public class LabelHelper { } } - private static HashSet<Statement>[] processStatementLabel(Statement stat) { - - HashSet<Statement> setBreak = new HashSet<Statement>(); - HashSet<Statement> setContinue = new HashSet<Statement>(); + private static void processStatementLabel(Statement stat) { + processStatementLabel(stat, new HashSet<Statement>(), new HashSet<Statement>()); + } + private static void processStatementLabel(Statement stat, Set<Statement> setBreak, Set<Statement> setContinue) { if (stat.getExprents() == null) { for (Statement st : stat.getStats()) { - HashSet<Statement>[] arr = processStatementLabel(st); - - setBreak.addAll(arr[0]); - setContinue.addAll(arr[1]); + processStatementLabel(st, setBreak, setContinue); } boolean shieldtype = (stat.type == Statement.TYPE_DO || stat.type == Statement.TYPE_SWITCH); @@ -456,8 +451,6 @@ public class LabelHelper { setBreak.add(stat); setContinue.add(stat); - - return new HashSet[]{setBreak, setContinue}; } public static void replaceContinueWithBreak(Statement stat) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/StackVarsProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/StackVarsProcessor.java index e72c646..109490c 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/StackVarsProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/StackVarsProcessor.java @@ -110,7 +110,7 @@ public class StackVarsProcessor { setVersionsToNull(root); } - private void setVersionsToNull(Statement stat) { + private static void setVersionsToNull(Statement stat) { if (stat.getExprents() == null) { for (Object obj : stat.getSequentialObjects()) { @@ -129,7 +129,7 @@ public class StackVarsProcessor { } } - private void setExprentVersionsToNull(Exprent exprent) { + private static void setExprentVersionsToNull(Exprent exprent) { List<Exprent> lst = exprent.getAllExprents(true); lst.add(exprent); @@ -236,7 +236,7 @@ public class StackVarsProcessor { } - private Exprent isReplaceableVar(Exprent exprent, HashMap<VarVersionPaar, Exprent> mapVarValues, SSAUConstructorSparseEx ssau) { + private static Exprent isReplaceableVar(Exprent exprent, HashMap<VarVersionPaar, Exprent> mapVarValues, SSAUConstructorSparseEx ssau) { Exprent dest = null; @@ -248,7 +248,7 @@ public class StackVarsProcessor { return dest; } - private void replaceSingleVar(Exprent parent, VarExprent var, Exprent dest, SSAUConstructorSparseEx ssau) { + private static void replaceSingleVar(Exprent parent, VarExprent var, Exprent dest, SSAUConstructorSparseEx ssau) { parent.replaceExprent(var, dest); @@ -438,7 +438,7 @@ public class StackVarsProcessor { } } - private HashSet<VarVersionPaar> getAllVersions(Exprent exprent) { + private static HashSet<VarVersionPaar> getAllVersions(Exprent exprent) { HashSet<VarVersionPaar> res = new HashSet<VarVersionPaar>(); @@ -455,11 +455,11 @@ public class StackVarsProcessor { return res; } - private Object[] iterateChildExprent(Exprent exprent, - Exprent parent, - Exprent next, - HashMap<VarVersionPaar, Exprent> mapVarValues, - SSAUConstructorSparseEx ssau) { + private static Object[] iterateChildExprent(Exprent exprent, + Exprent parent, + Exprent next, + HashMap<VarVersionPaar, Exprent> mapVarValues, + SSAUConstructorSparseEx ssau) { boolean changed = false; @@ -589,7 +589,7 @@ public class StackVarsProcessor { return new Object[]{null, changed, false}; } - private boolean getUsedVersions(SSAUConstructorSparseEx ssa, VarVersionPaar var, List<VarVersionNode> res) { + private static boolean getUsedVersions(SSAUConstructorSparseEx ssa, VarVersionPaar var, List<VarVersionNode> res) { VarVersionsGraph ssuversions = ssa.getSsuversions(); VarVersionNode varnode = ssuversions.nodes.getWithKey(var); @@ -638,10 +638,10 @@ public class StackVarsProcessor { return !setNotDoms.isEmpty(); } - private boolean isVersionToBeReplaced(VarVersionPaar usedvar, - HashMap<Integer, HashSet<VarVersionPaar>> mapVars, - SSAUConstructorSparseEx ssau, - VarVersionPaar leftpaar) { + private static boolean isVersionToBeReplaced(VarVersionPaar usedvar, + HashMap<Integer, HashSet<VarVersionPaar>> mapVars, + SSAUConstructorSparseEx ssau, + VarVersionPaar leftpaar) { VarVersionsGraph ssuversions = ssau.getSsuversions(); @@ -687,9 +687,9 @@ public class StackVarsProcessor { return true; } - private HashMap<Integer, HashSet<VarVersionPaar>> getAllVarVersions(VarVersionPaar leftvar, - Exprent exprent, - SSAUConstructorSparseEx ssau) { + private static HashMap<Integer, HashSet<VarVersionPaar>> getAllVarVersions(VarVersionPaar leftvar, + Exprent exprent, + SSAUConstructorSparseEx ssau) { HashMap<Integer, HashSet<VarVersionPaar>> map = new HashMap<Integer, HashSet<VarVersionPaar>>(); SFormsFastMapDirect mapLiveVars = ssau.getLiveVarVersionsMap(leftvar); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorEngine.java b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorEngine.java index 0980bee..aeab0d2 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorEngine.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorEngine.java @@ -43,7 +43,7 @@ public class DominatorEngine { } } - private Integer getCommonIDom(Integer key1, Integer key2, VBStyleCollection<Integer, Integer> orderedIDoms) { + private static Integer getCommonIDom(Integer key1, Integer key2, VBStyleCollection<Integer, Integer> orderedIDoms) { if (key1 == null) { return key2; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/GenericDominatorEngine.java b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/GenericDominatorEngine.java index f77e950..c6eb357 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/GenericDominatorEngine.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/GenericDominatorEngine.java @@ -45,7 +45,7 @@ public class GenericDominatorEngine { } } - private IGraphNode getCommonIDom(IGraphNode node1, IGraphNode node2, VBStyleCollection<IGraphNode, IGraphNode> orderedIDoms) { + private static IGraphNode getCommonIDom(IGraphNode node1, IGraphNode node2, VBStyleCollection<IGraphNode, IGraphNode> orderedIDoms) { IGraphNode nodeOld; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/deobfuscator/ExceptionDeobfuscator.java b/src/org/jetbrains/java/decompiler/modules/decompiler/deobfuscator/ExceptionDeobfuscator.java index b015230..7614807 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/deobfuscator/ExceptionDeobfuscator.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/deobfuscator/ExceptionDeobfuscator.java @@ -32,16 +32,30 @@ import java.util.Map.Entry; public class ExceptionDeobfuscator { + private static class Range { + private final BasicBlock handler; + private final String uniqueStr; + private final Set<BasicBlock> protectedRange; + private final ExceptionRangeCFG rangeCFG; + + private Range(BasicBlock handler, String uniqueStr, Set<BasicBlock> protectedRange, ExceptionRangeCFG rangeCFG) { + this.handler = handler; + this.uniqueStr = uniqueStr; + this.protectedRange = protectedRange; + this.rangeCFG = rangeCFG; + } + } + public static void restorePopRanges(ControlFlowGraph graph) { - List<Object[]> lstRanges = new ArrayList<Object[]>(); + List<Range> lstRanges = new ArrayList<Range>(); // aggregate ranges for (ExceptionRangeCFG range : graph.getExceptions()) { boolean found = false; - for (Object[] arr : lstRanges) { - if (arr[0] == range.getHandler() && InterpreterUtil.equalObjects(range.getUniqueExceptionsString(), arr[1])) { - ((HashSet<BasicBlock>)arr[2]).addAll(range.getProtectedRange()); + for (Range arr : lstRanges) { + if (arr.handler == range.getHandler() && InterpreterUtil.equalObjects(range.getUniqueExceptionsString(), arr.uniqueStr)) { + arr.protectedRange.addAll(range.getProtectedRange()); found = true; break; } @@ -49,37 +63,36 @@ public class ExceptionDeobfuscator { if (!found) { // doesn't matter, which range chosen - lstRanges.add( - new Object[]{range.getHandler(), range.getUniqueExceptionsString(), new HashSet<BasicBlock>(range.getProtectedRange()), range}); + lstRanges.add(new Range(range.getHandler(), range.getUniqueExceptionsString(), new HashSet<BasicBlock>(range.getProtectedRange()), range)); } } // process aggregated ranges - for (Object[] range : lstRanges) { + for (Range range : lstRanges) { - if (range[1] != null) { + if (range.uniqueStr != null) { - BasicBlock handler = (BasicBlock)range[0]; + BasicBlock handler = range.handler; InstructionSequence seq = handler.getSeq(); - Instruction firstinstr = null; + Instruction firstinstr; if (seq.length() > 0) { firstinstr = seq.getInstr(0); if (firstinstr.opcode == CodeConstants.opc_pop || firstinstr.opcode == CodeConstants.opc_astore) { - HashSet<BasicBlock> setrange = new HashSet<BasicBlock>((HashSet<BasicBlock>)range[2]); + Set<BasicBlock> setrange = new HashSet<BasicBlock>(range.protectedRange); - for (Object[] range_super : lstRanges) { // finally or strict superset + for (Range range_super : lstRanges) { // finally or strict superset if (range != range_super) { - HashSet<BasicBlock> setrange_super = new HashSet<BasicBlock>((HashSet<BasicBlock>)range_super[2]); + Set<BasicBlock> setrange_super = new HashSet<BasicBlock>(range_super.protectedRange); - if (!setrange.contains(range_super[0]) && !setrange_super.contains(handler) - && (range_super[1] == null || setrange_super.containsAll(setrange))) { + if (!setrange.contains(range_super.handler) && !setrange_super.contains(handler) + && (range_super.uniqueStr == null || setrange_super.containsAll(setrange))) { - if (range_super[1] == null) { + if (range_super.uniqueStr == null) { setrange_super.retainAll(setrange); } else { @@ -129,11 +142,10 @@ public class ExceptionDeobfuscator { seq.removeInstruction(0); } + newblock.addSuccessorException(range_super.handler); + range_super.rangeCFG.getProtectedRange().add(newblock); - newblock.addSuccessorException((BasicBlock)range_super[0]); - ((ExceptionRangeCFG)range_super[3]).getProtectedRange().add(newblock); - - handler = ((ExceptionRangeCFG)range[3]).getHandler(); + handler = range.rangeCFG.getHandler(); seq = handler.getSeq(); } } @@ -147,7 +159,7 @@ public class ExceptionDeobfuscator { public static void insertEmptyExceptionHandlerBlocks(ControlFlowGraph graph) { - HashSet<BasicBlock> setVisited = new HashSet<BasicBlock>(); + Set<BasicBlock> setVisited = new HashSet<BasicBlock>(); for (ExceptionRangeCFG range : graph.getExceptions()) { BasicBlock handler = range.getHandler(); @@ -255,7 +267,7 @@ public class ExceptionDeobfuscator { List<BasicBlock> lstRes = new ArrayList<BasicBlock>(); LinkedList<BasicBlock> stack = new LinkedList<BasicBlock>(); - HashSet<BasicBlock> setVisited = new HashSet<BasicBlock>(); + Set<BasicBlock> setVisited = new HashSet<BasicBlock>(); BasicBlock handler = range.getHandler(); stack.addFirst(handler); @@ -285,22 +297,20 @@ public class ExceptionDeobfuscator { public static boolean hasObfuscatedExceptions(ControlFlowGraph graph) { - BasicBlock first = graph.getFirst(); - - HashMap<BasicBlock, HashSet<BasicBlock>> mapRanges = new HashMap<BasicBlock, HashSet<BasicBlock>>(); + Map<BasicBlock, Set<BasicBlock>> mapRanges = new HashMap<BasicBlock, Set<BasicBlock>>(); for (ExceptionRangeCFG range : graph.getExceptions()) { - HashSet<BasicBlock> set = mapRanges.get(range.getHandler()); + Set<BasicBlock> set = mapRanges.get(range.getHandler()); if (set == null) { mapRanges.put(range.getHandler(), set = new HashSet<BasicBlock>()); } set.addAll(range.getProtectedRange()); } - for (Entry<BasicBlock, HashSet<BasicBlock>> ent : mapRanges.entrySet()) { - HashSet<BasicBlock> setEntries = new HashSet<BasicBlock>(); + for (Entry<BasicBlock, Set<BasicBlock>> ent : mapRanges.entrySet()) { + Set<BasicBlock> setEntries = new HashSet<BasicBlock>(); for (BasicBlock block : ent.getValue()) { - HashSet<BasicBlock> setTemp = new HashSet<BasicBlock>(block.getPreds()); + Set<BasicBlock> setTemp = new HashSet<BasicBlock>(block.getPreds()); setTemp.removeAll(ent.getValue()); if (!setTemp.isEmpty()) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AnnotationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AnnotationExprent.java index b919548..91de531 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AnnotationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/AnnotationExprent.java @@ -65,7 +65,7 @@ public class AnnotationExprent extends Exprent { String indstr1 = InterpreterUtil.getIndentString(indent + 1); for (int i = 0; i < parnames.size(); i++) { - buffer.append(new_line_separator + indstr1); + buffer.append(new_line_separator).append(indstr1); buffer.append(parnames.get(i)); buffer.append(" = "); buffer.append(parvalues.get(i).toJava(indent + 2)); @@ -74,7 +74,7 @@ public class AnnotationExprent extends Exprent { buffer.append(","); } } - buffer.append(new_line_separator + indstr); + buffer.append(new_line_separator).append(indstr); } buffer.append(")"); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java index ae1747d..a45429a 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java @@ -116,7 +116,7 @@ public class ConstExprent extends Exprent { else { switch (consttype.type) { case CodeConstants.TYPE_BOOLEAN: - return new Boolean(((Integer)value).intValue() != 0).toString(); + return Boolean.toString(((Integer)value).intValue() != 0); case CodeConstants.TYPE_CHAR: Integer val = (Integer)value; String ret = escapes.get(val); @@ -267,7 +267,7 @@ public class ConstExprent extends Exprent { throw new RuntimeException("invalid constant type"); } - private String convertStringToJava(String value, boolean ascii) { + private static String convertStringToJava(String value, boolean ascii) { char[] arr = value.toCharArray(); StringBuilder buffer = new StringBuilder(arr.length); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java index 652f61f..d57fcac 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java @@ -94,7 +94,7 @@ public class FieldExprent extends Exprent { } public String toJava(int indent) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if (isStatic) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java index 844a7a9..4fa2ab3 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java @@ -568,7 +568,7 @@ public class FunctionExprent extends Exprent { return res; } - private VarType getMaxVarType(VarType[] arr) { + private static VarType getMaxVarType(VarType[] arr) { int[] types = new int[]{CodeConstants.TYPE_DOUBLE, CodeConstants.TYPE_FLOAT, CodeConstants.TYPE_LONG}; VarType[] vartypes = new VarType[]{VarType.VARTYPE_DOUBLE, VarType.VARTYPE_FLOAT, VarType.VARTYPE_LONG}; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java index 030fe9a..66e63c0 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java @@ -112,11 +112,7 @@ public class IfExprent extends Exprent { } public String toJava(int indent) { - StringBuffer buf = new StringBuffer("if("); - buf.append(condition.toJava(indent)); - buf.append(")"); - - return buf.toString(); + return "if(" + condition.toJava(indent) + ")"; } public boolean equals(Object o) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java index c19052d..439d331 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java @@ -277,15 +277,15 @@ public class InvocationExprent extends Exprent { VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname); if (rightType.equals(VarType.VARTYPE_OBJECT) && !leftType.equals(rightType)) { - buf.append("((" + ExprProcessor.getCastTypeName(leftType) + ")"); + buf.append("((").append(ExprProcessor.getCastTypeName(leftType)).append(")"); if (instance.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) { res = "(" + res + ")"; } - buf.append(res + ")"); + buf.append(res).append(")"); } else if (instance.getPrecedence() > getPrecedence()) { - buf.append("(" + res + ")"); + buf.append("(").append(res).append(")"); } else { buf.append(res); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java index f71df1a..cd4fbbd 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java @@ -402,7 +402,7 @@ public class NewExprent extends Exprent { return buf.toString(); } - private String getQualifiedNewInstance(String classname, List<Exprent> lstParams, int indent) { + private static String getQualifiedNewInstance(String classname, List<Exprent> lstParams, int indent) { ClassNode node = DecompilerContext.getClassprocessor().getMapRootClasses().get(classname); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java index e589494..bef3631 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java @@ -115,7 +115,7 @@ public class VarExprent extends Exprent { if (processor != null && processor.getVarFinal(new VarVersionPaar(index, version)) == VarTypeProcessor.VAR_FINALEXPLICIT) { buf.append("final "); } - buf.append(ExprProcessor.getCastTypeName(getVartype()) + " "); + buf.append(ExprProcessor.getCastTypeName(getVartype())).append(" "); } buf.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/DirectGraph.java b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/DirectGraph.java index 2f4ed80..b24b72c 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/DirectGraph.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/DirectGraph.java @@ -53,7 +53,7 @@ public class DirectGraph { } } - private void addToReversePostOrderListIterative(DirectNode root, List<DirectNode> lst) { + private static void addToReversePostOrderListIterative(DirectNode root, List<DirectNode> lst) { LinkedList<DirectNode> stackNode = new LinkedList<DirectNode>(); LinkedList<Integer> stackIndex = new LinkedList<Integer>(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/FlattenStatementsHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/FlattenStatementsHelper.java index 27d3c9a..05d2f33 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/FlattenStatementsHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/FlattenStatementsHelper.java @@ -26,20 +26,19 @@ import java.util.Map.Entry; public class FlattenStatementsHelper { // statement.id, node.id(direct), node.id(continue) - private HashMap<Integer, String[]> mapDestinationNodes = new HashMap<Integer, String[]>(); + private Map<Integer, String[]> mapDestinationNodes = new HashMap<Integer, String[]>(); // node.id(source), statement.id(destination), edge type private List<Edge> listEdges = new ArrayList<Edge>(); // node.id(exit), [node.id(source), statement.id(destination)] - public HashMap<String, List<String[]>> mapShortRangeFinallyPathIds = new HashMap<String, List<String[]>>(); + private Map<String, List<String[]>> mapShortRangeFinallyPathIds = new HashMap<String, List<String[]>>(); // node.id(exit), [node.id(source), statement.id(destination)] - public HashMap<String, List<String[]>> mapLongRangeFinallyPathIds = new HashMap<String, List<String[]>>(); + private Map<String, List<String[]>> mapLongRangeFinallyPathIds = new HashMap<String, List<String[]>>(); // positive if branches - public HashMap<String, String> mapPosIfBranch = new HashMap<String, String>(); - + private Map<String, Integer> mapPosIfBranch = new HashMap<String, Integer>(); private DirectGraph graph; @@ -99,7 +98,7 @@ public class FlattenStatementsHelper { LinkedList<StackEntry> stackFinally = statEntry.stackFinally; int statementBreakIndex = statEntry.statementIndex; - DirectNode node = null, nd = null; + DirectNode node, nd; List<StatEdge> lstSuccEdges = new ArrayList<StatEdge>(); DirectNode sourcenode = null; @@ -133,7 +132,7 @@ public class FlattenStatementsHelper { // 'if' statement: record positive branch if (stat.getLastBasicType() == Statement.LASTBASICTYPE_IF) { - mapPosIfBranch.put(sourcenode.id, lstSuccEdges.get(0).getDestination().id.toString()); + mapPosIfBranch.put(sourcenode.id, lstSuccEdges.get(0).getDestination().id); } break; @@ -485,7 +484,7 @@ public class FlattenStatementsHelper { } } - public HashMap<Integer, String[]> getMapDestinationNodes() { + public Map<Integer, String[]> getMapDestinationNodes() { return mapDestinationNodes; } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAConstructorSparseEx.java b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAConstructorSparseEx.java index 5a6cb9d..2150f86 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAConstructorSparseEx.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAConstructorSparseEx.java @@ -416,7 +416,7 @@ public class SSAConstructorSparseEx { return mapNew; } - private SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) { + private static SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) { if (map2 != null && !map2.isEmpty()) { mapTo.union(map2); @@ -425,7 +425,7 @@ public class SSAConstructorSparseEx { return mapTo; } - private boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) { + private static boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) { if (map1 == null) { return map2 == null; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAUConstructorSparseEx.java b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAUConstructorSparseEx.java index 9b1ce0e..97b6448 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAUConstructorSparseEx.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/sforms/SSAUConstructorSparseEx.java @@ -683,7 +683,7 @@ public class SSAUConstructorSparseEx { return mapNew; } - private SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) { + private static SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) { if (map2 != null && !map2.isEmpty()) { mapTo.union(map2); @@ -692,7 +692,7 @@ public class SSAUConstructorSparseEx { return mapTo; } - private boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) { + private static boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) { if (map1 == null) { return map2 == null; @@ -789,7 +789,7 @@ public class SSAUConstructorSparseEx { return map; } - private Integer getFirstProtectedRange(Statement stat) { + private static Integer getFirstProtectedRange(Statement stat) { while (true) { Statement parent = stat.getParent(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java index f2b6bc4..cf57d98 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java @@ -116,13 +116,13 @@ public class CatchAllStatement extends Statement { String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append(ExprProcessor.listToJava(varDefinitions, indent)); boolean labeled = isLabeled(); if (labeled) { - buf.append(indstr + "label" + this.id + ":" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); } List<StatEdge> lstSuccs = first.getSuccessorEdges(STATEDGE_DIRECT_ALL); @@ -134,26 +134,26 @@ public class CatchAllStatement extends Statement { buf.append(content); } else { - buf.append(indstr + "try {" + new_line_separator); + buf.append(indstr).append("try {").append(new_line_separator); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true)); - buf.append(indstr + "}"); + buf.append(indstr).append("}"); } - buf.append((isFinally ? " finally" : - " catch (" + vars.get(0).toJava(indent) + ")") + " {" + new_line_separator); + buf.append(isFinally ? " finally" : + " catch (" + vars.get(0).toJava(indent) + ")").append(" {").append(new_line_separator); if (monitor != null) { indstr1 = InterpreterUtil.getIndentString(indent + 1); - buf.append(indstr1 + "if(" + monitor.toJava(indent) + ") {" + new_line_separator); + buf.append(indstr1).append("if(").append(monitor.toJava(indent)).append(") {").append(new_line_separator); } buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true)); if (monitor != null) { - buf.append(indstr1 + "}" + new_line_separator); + buf.append(indstr1).append("}").append(new_line_separator); } - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); return buf.toString(); } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java index 17f5636..c251d05 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java @@ -151,19 +151,19 @@ public class CatchStatement extends Statement { public String toJava(int indent) { String indstr = InterpreterUtil.getIndentString(indent); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); String new_line_separator = DecompilerContext.getNewLineSeparator(); buf.append(ExprProcessor.listToJava(varDefinitions, indent)); if (isLabeled()) { - buf.append(indstr + "label" + this.id + ":" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); } - buf.append(indstr + "try {" + new_line_separator); + buf.append(indstr).append("try {").append(new_line_separator); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true)); - buf.append(indstr + "}"); + buf.append(indstr).append("}"); for (int i = 1; i < stats.size(); i++) { List<String> exception_types = exctstrings.get(i - 1); @@ -174,11 +174,12 @@ public class CatchStatement extends Statement { VarType exc_type = new VarType(CodeConstants.TYPE_OBJECT, 0, exception_types.get(exc_index)); String exc_type_name = ExprProcessor.getCastTypeName(exc_type); - buf.append(exc_type_name + " | "); + buf.append(exc_type_name).append(" | "); } } buf.append(vars.get(i - 1).toJava(indent)); - buf.append(") {" + new_line_separator + ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true) + indstr + "}"); + buf.append(") {").append(new_line_separator).append(ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true)).append(indstr) + .append("}"); } buf.append(new_line_separator); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java index 2bd8e3a..7c152c2 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java @@ -93,37 +93,38 @@ public class DoStatement extends Statement { public String toJava(int indent) { String indstr = InterpreterUtil.getIndentString(indent); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); String new_line_separator = DecompilerContext.getNewLineSeparator(); buf.append(ExprProcessor.listToJava(varDefinitions, indent)); if (isLabeled()) { - buf.append(indstr + "label" + this.id + ":" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); } switch (looptype) { case LOOP_DO: - buf.append(indstr + "while(true) {" + new_line_separator); + buf.append(indstr).append("while(true) {").append(new_line_separator); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true)); - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); break; case LOOP_DOWHILE: - buf.append(indstr + "do {" + new_line_separator); + buf.append(indstr).append("do {").append(new_line_separator); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true)); - buf.append(indstr + "} while(" + conditionExprent.get(0).toJava(indent) + ");" + new_line_separator); + buf.append(indstr).append("} while(").append(conditionExprent.get(0).toJava(indent)).append(");").append(new_line_separator); break; case LOOP_WHILE: - buf.append(indstr + "while(" + conditionExprent.get(0).toJava(indent) + ") {" + new_line_separator); + buf.append(indstr).append("while(").append(conditionExprent.get(0).toJava(indent)).append(") {").append(new_line_separator); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true)); - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); break; case LOOP_FOR: - buf.append(indstr + "for(" + (initExprent.get(0) == null ? "" : initExprent.get(0).toJava(indent)) + - "; " + conditionExprent.get(0).toJava(indent) + "; " + incExprent.get(0).toJava(indent) + ") {" + new_line_separator); + buf.append(indstr).append("for(").append(initExprent.get(0) == null ? "" : initExprent.get(0).toJava(indent)).append("; ") + .append(conditionExprent.get(0).toJava(indent)).append("; ").append(incExprent.get(0).toJava(indent)).append(") {") + .append(new_line_separator); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true)); - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); } return buf.toString(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java index 9988881..a11171e 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java @@ -55,19 +55,19 @@ public class GeneralStatement extends Statement { public String toJava(int indent) { String indstr = InterpreterUtil.getIndentString(indent); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); String new_line_separator = DecompilerContext.getNewLineSeparator(); if (isLabeled()) { - buf.append(indstr + "label" + this.id + ":" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); } - buf.append(indstr + "abstract statement {" + new_line_separator); + buf.append(indstr).append("abstract statement {").append(new_line_separator); for (int i = 0; i < stats.size(); i++) { buf.append(stats.get(i).toJava(indent + 1)); } - buf.append(indstr + "}"); + buf.append(indstr).append("}"); return buf.toString(); } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java index 0b05981..9ad8125 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java @@ -201,7 +201,7 @@ public class IfStatement extends Statement { public String toJava(int indent) { String indstr = InterpreterUtil.getIndentString(indent); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); String new_line_separator = DecompilerContext.getNewLineSeparator(); @@ -209,10 +209,10 @@ public class IfStatement extends Statement { buf.append(first.toJava(indent)); if (isLabeled()) { - buf.append(indstr + "label" + this.id + ":" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); } - buf.append(indstr + headexprent.get(0).toJava(indent) + " {" + new_line_separator); + buf.append(indstr).append(headexprent.get(0).toJava(indent)).append(" {").append(new_line_separator); if (ifstat == null) { buf.append(InterpreterUtil.getIndentString(indent + 1)); @@ -228,10 +228,10 @@ public class IfStatement extends Statement { } if (ifedge.labeled) { - buf.append(" label" + ifedge.closure.id); + buf.append(" label").append(ifedge.closure.id); } } - buf.append(";" + new_line_separator); + buf.append(";").append(new_line_separator); } else { buf.append(ExprProcessor.jmpWrapper(ifstat, indent + 1, true)); @@ -248,7 +248,7 @@ public class IfStatement extends Statement { String content = ExprProcessor.jmpWrapper(elsestat, indent, false); content = content.substring(indstr.length()); - buf.append(indstr + "} else "); + buf.append(indstr).append("} else "); buf.append(content); elseif = true; @@ -257,14 +257,14 @@ public class IfStatement extends Statement { String content = ExprProcessor.jmpWrapper(elsestat, indent + 1, false); if (content.length() > 0) { - buf.append(indstr + "} else {" + new_line_separator); + buf.append(indstr).append("} else {").append(new_line_separator); buf.append(content); } } } if (!elseif) { - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); } return buf.toString(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SequenceStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SequenceStatement.java index d561b9e..eccce91 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SequenceStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SequenceStatement.java @@ -112,7 +112,7 @@ public class SequenceStatement extends Statement { if (islabeled) { indstr = InterpreterUtil.getIndentString(indent); indent++; - buf.append(indstr + "label" + this.id + ": {" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(": {").append(new_line_separator); } boolean notempty = false; @@ -132,7 +132,7 @@ public class SequenceStatement extends Statement { } if (islabeled) { - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); } return buf.toString(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java index 52118d2..d707258 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java @@ -126,28 +126,21 @@ public class Statement { isMonitorEnter = false; containsMonitorExit = false; - for (Map<Integer, List<StatEdge>> map : new Map[]{mapSuccEdges, mapPredEdges}) { - map.remove(StatEdge.TYPE_EXCEPTION); - - List<StatEdge> lst = map.get(STATEDGE_DIRECT_ALL); - if (lst != null) { - map.put(STATEDGE_ALL, new ArrayList<StatEdge>(lst)); - } - else { - map.remove(STATEDGE_ALL); - } - } + processMap(mapSuccEdges); + processMap(mapPredEdges); + processMap(mapSuccStates); + processMap(mapPredStates); + } - for (Map<Integer, List<Statement>> map : new Map[]{mapSuccStates, mapPredStates}) { - map.remove(StatEdge.TYPE_EXCEPTION); + private static <T> void processMap(Map<Integer, List<T>> map) { + map.remove(StatEdge.TYPE_EXCEPTION); - List<Statement> lst = map.get(STATEDGE_DIRECT_ALL); - if (lst != null) { - map.put(STATEDGE_ALL, new ArrayList<Statement>(lst)); - } - else { - map.remove(STATEDGE_ALL); - } + List<T> lst = map.get(STATEDGE_DIRECT_ALL); + if (lst != null) { + map.put(STATEDGE_ALL, new ArrayList<T>(lst)); + } + else { + map.remove(STATEDGE_ALL); } } @@ -579,7 +572,7 @@ public class Statement { // private methods // ***************************************************************************** - private void addToReversePostOrderListIterative(Statement root, List<Statement> lst) { + private static void addToReversePostOrderListIterative(Statement root, List<Statement> lst) { LinkedList<Statement> stackNode = new LinkedList<Statement>(); LinkedList<Integer> stackIndex = new LinkedList<Integer>(); @@ -622,7 +615,7 @@ public class Statement { } - private void addToPostReversePostOrderList(Statement stat, List<Statement> lst, HashSet<Statement> setVisited) { + private static void addToPostReversePostOrderList(Statement stat, List<Statement> lst, HashSet<Statement> setVisited) { if (setVisited.contains(stat)) { // because of not considered exception edges, s. isExitComponent. Should be rewritten, if possible. return; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java index 379d00d..3d409f8 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java @@ -117,10 +117,10 @@ public class SwitchStatement extends Statement { buf.append(first.toJava(indent)); if (isLabeled()) { - buf.append(indstr + "label" + this.id + ":" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); } - buf.append(indstr + headexprent.get(0).toJava(indent) + " {" + new_line_separator); + buf.append(indstr).append(headexprent.get(0).toJava(indent)).append(" {").append(new_line_separator); VarType switch_type = headexprent.get(0).getExprType(); @@ -132,20 +132,20 @@ public class SwitchStatement extends Statement { for (int j = 0; j < edges.size(); j++) { if (edges.get(j) == default_edge) { - buf.append(indstr + "default:" + new_line_separator); + buf.append(indstr).append("default:").append(new_line_separator); } else { ConstExprent value = (ConstExprent)values.get(j).copy(); value.setConsttype(switch_type); - buf.append(indstr + "case " + value.toJava(indent) + ":" + new_line_separator); + buf.append(indstr).append("case ").append(value.toJava(indent)).append(":").append(new_line_separator); } } buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, false)); } - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); return buf.toString(); } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java index 3fcb042..6e3dc47 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java @@ -73,17 +73,17 @@ public class SynchronizedStatement extends Statement { String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append(ExprProcessor.listToJava(varDefinitions, indent)); buf.append(first.toJava(indent)); if (isLabeled()) { - buf.append(indstr + "label" + this.id + ":" + new_line_separator); + buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator); } - buf.append(indstr + headexprent.get(0).toJava(indent) + " {" + new_line_separator); + buf.append(indstr).append(headexprent.get(0).toJava(indent)).append(" {").append(new_line_separator); buf.append(ExprProcessor.jmpWrapper(body, indent + 1, true)); - buf.append(indstr + "}" + new_line_separator); + buf.append(indstr).append("}").append(new_line_separator); return buf.toString(); } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/CheckTypesResult.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/CheckTypesResult.java index 6e7c967..08c32ec 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/CheckTypesResult.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/CheckTypesResult.java @@ -43,7 +43,7 @@ public class CheckTypesResult { return lstMinTypeExprents; } - public class ExprentTypePair { + public static class ExprentTypePair { public Exprent exprent; public VarType type; public VarType desttype; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java index 1c52517..9582bfb 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java @@ -125,10 +125,7 @@ public class VarDefinitionHelper { VarNamesCollector vc = DecompilerContext.getVarncollector(); - Iterator<Entry<Integer, Statement>> it = mapVarDefStatements.entrySet().iterator(); - while (it.hasNext()) { - Entry<Integer, Statement> en = it.next(); - + for (Entry<Integer, Statement> en : mapVarDefStatements.entrySet()) { Statement stat = en.getValue(); Integer index = en.getKey(); @@ -312,9 +309,7 @@ public class VarDefinitionHelper { HashSet<Integer> set = new HashSet<Integer>(mapCount.keySet()); // put all variables defined in this statement into the set - Iterator<Entry<Integer, Integer>> itMult = mapCount.entrySet().iterator(); - while (itMult.hasNext()) { - Entry<Integer, Integer> en = itMult.next(); + for (Entry<Integer, Integer> en : mapCount.entrySet()) { if (en.getValue().intValue() > 1) { mapVarDefStatements.put(en.getKey(), stat); } @@ -325,7 +320,7 @@ public class VarDefinitionHelper { return set; } - private List<VarExprent> getAllVars(List<Exprent> lst) { + private static List<VarExprent> getAllVars(List<Exprent> lst) { List<VarExprent> res = new ArrayList<VarExprent>(); List<Exprent> listTemp = new ArrayList<Exprent>(); @@ -344,7 +339,7 @@ public class VarDefinitionHelper { return res; } - private boolean setDefinition(Exprent expr, Integer index) { + private static boolean setDefinition(Exprent expr, Integer index) { if (expr.type == Exprent.EXPRENT_ASSIGNMENT) { Exprent left = ((AssignmentExprent)expr).getLeft(); if (left.type == Exprent.EXPRENT_VAR) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarTypeProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarTypeProcessor.java index 8792f3e..d7d3d2e 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarTypeProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarTypeProcessor.java @@ -102,7 +102,7 @@ public class VarTypeProcessor { while (!processVarTypes(dgraph)) ; } - private void resetExprentTypes(DirectGraph dgraph) { + private static void resetExprentTypes(DirectGraph dgraph) { dgraph.iterateExprents(new DirectGraph.ExprentIterator() { public int processExprent(Exprent exprent) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsGraph.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsGraph.java index ce05071..f839a05 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsGraph.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsGraph.java @@ -106,7 +106,7 @@ public class VarVersionsGraph { engine.initialize(); } - private LinkedList<VarVersionNode> getReversedPostOrder(Collection<VarVersionNode> roots) { + private static LinkedList<VarVersionNode> getReversedPostOrder(Collection<VarVersionNode> roots) { LinkedList<VarVersionNode> lst = new LinkedList<VarVersionNode>(); HashSet<VarVersionNode> setVisited = new HashSet<VarVersionNode>(); @@ -122,7 +122,7 @@ public class VarVersionsGraph { return lst; } - private void addToReversePostOrderListIterative(VarVersionNode root, List<VarVersionNode> lst, HashSet<VarVersionNode> setVisited) { + private static void addToReversePostOrderListIterative(VarVersionNode root, List<VarVersionNode> lst, HashSet<VarVersionNode> setVisited) { HashMap<VarVersionNode, List<VarVersionEdge>> mapNodeSuccs = new HashMap<VarVersionNode, List<VarVersionEdge>>(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java index 4093992..46c6a03 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java @@ -66,7 +66,7 @@ public class VarVersionsProcessor { setNewVarIndices(typeproc, dgraph); } - private void mergePhiVersions(SSAConstructorSparseEx ssa, DirectGraph dgraph) { + private static void mergePhiVersions(SSAConstructorSparseEx ssa, DirectGraph dgraph) { // collect phi versions List<HashSet<VarVersionPaar>> lst = new ArrayList<HashSet<VarVersionPaar>>(); @@ -125,7 +125,7 @@ public class VarVersionsProcessor { }); } - private void eliminateNonJavaTypes(VarTypeProcessor typeproc) { + private static void eliminateNonJavaTypes(VarTypeProcessor typeproc) { HashMap<VarVersionPaar, VarType> mapExprentMaxTypes = typeproc.getMapExprentMaxTypes(); HashMap<VarVersionPaar, VarType> mapExprentMinTypes = typeproc.getMapExprentMinTypes(); @@ -152,7 +152,7 @@ public class VarVersionsProcessor { } } - private void simpleMerge(VarTypeProcessor typeproc, DirectGraph dgraph, StructMethod mt) { + private static void simpleMerge(VarTypeProcessor typeproc, DirectGraph dgraph, StructMethod mt) { HashMap<VarVersionPaar, VarType> mapExprentMaxTypes = typeproc.getMapExprentMaxTypes(); HashMap<VarVersionPaar, VarType> mapExprentMinTypes = typeproc.getMapExprentMinTypes(); diff --git a/src/org/jetbrains/java/decompiler/modules/renamer/IdentifierConverter.java b/src/org/jetbrains/java/decompiler/modules/renamer/IdentifierConverter.java index c8ec379..546ece3 100644 --- a/src/org/jetbrains/java/decompiler/modules/renamer/IdentifierConverter.java +++ b/src/org/jetbrains/java/decompiler/modules/renamer/IdentifierConverter.java @@ -193,11 +193,12 @@ public class IdentifierConverter { } String classOldFullName = cl.qualifiedName; - String classNewFullName = classOldFullName; // TODO: rename packages String clsimplename = ConverterHelper.getSimpleClassName(classOldFullName); if (helper.toBeRenamed(IIdentifierRenamer.ELEMENT_CLASS, clsimplename, null, null)) { + String classNewFullName; + do { classNewFullName = ConverterHelper.replaceSimpleClassName(classOldFullName, helper.getNextClassname(classOldFullName, ConverterHelper @@ -339,7 +340,7 @@ public class IdentifierConverter { return descriptor; } - private List<ClassWrapperNode> getReversePostOrderListIterative(List<ClassWrapperNode> roots) { + private static List<ClassWrapperNode> getReversePostOrderListIterative(List<ClassWrapperNode> roots) { List<ClassWrapperNode> res = new ArrayList<ClassWrapperNode>(); |