From f5431c3bb14854025dc1f0ec470b77497f79494c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 29 Aug 2014 21:58:12 +0400 Subject: java-decompiler: post-import cleanup (common fixes and optimizations) --- .../java/decompiler/code/ExceptionHandler.java | 8 +- .../java/decompiler/code/InstructionSequence.java | 2 +- .../java/decompiler/code/cfg/BasicBlock.java | 2 +- .../java/decompiler/code/cfg/ControlFlowGraph.java | 117 ++++++++++---------- .../decompiler/code/cfg/ExceptionRangeCFG.java | 8 +- .../decompiler/main/ClassReference14Processor.java | 10 +- .../java/decompiler/main/ClassWriter.java | 8 +- .../java/decompiler/main/ClassesProcessor.java | 12 +- .../jetbrains/java/decompiler/main/Fernflower.java | 4 +- .../main/decompiler/ConsoleDecompiler.java | 3 +- .../java/decompiler/main/rels/ClassWrapper.java | 38 ++----- .../java/decompiler/main/rels/LambdaProcessor.java | 6 +- .../main/rels/MethodProcessorThread.java | 26 +++-- .../decompiler/main/rels/NestedClassProcessor.java | 26 ++--- .../decompiler/main/rels/NestedMemberAccess.java | 2 +- .../decompiler/modules/code/DeadCodeHelper.java | 7 +- .../decompiler/modules/decompiler/DecHelper.java | 5 +- .../decompiler/modules/decompiler/DomHelper.java | 9 +- .../modules/decompiler/ExprProcessor.java | 20 ++-- .../modules/decompiler/FinallyProcessor.java | 121 ++++++++++++--------- .../decompiler/modules/decompiler/LabelHelper.java | 21 ++-- .../modules/decompiler/StackVarsProcessor.java | 36 +++--- .../decompiler/decompose/DominatorEngine.java | 2 +- .../decompose/GenericDominatorEngine.java | 2 +- .../deobfuscator/ExceptionDeobfuscator.java | 68 +++++++----- .../modules/decompiler/exps/AnnotationExprent.java | 4 +- .../modules/decompiler/exps/ConstExprent.java | 4 +- .../modules/decompiler/exps/FieldExprent.java | 2 +- .../modules/decompiler/exps/FunctionExprent.java | 2 +- .../modules/decompiler/exps/IfExprent.java | 6 +- .../modules/decompiler/exps/InvocationExprent.java | 6 +- .../modules/decompiler/exps/NewExprent.java | 2 +- .../modules/decompiler/exps/VarExprent.java | 2 +- .../modules/decompiler/sforms/DirectGraph.java | 2 +- .../decompiler/sforms/FlattenStatementsHelper.java | 15 ++- .../decompiler/sforms/SSAConstructorSparseEx.java | 4 +- .../decompiler/sforms/SSAUConstructorSparseEx.java | 6 +- .../decompiler/stats/CatchAllStatement.java | 18 +-- .../modules/decompiler/stats/CatchStatement.java | 13 ++- .../modules/decompiler/stats/DoStatement.java | 23 ++-- .../modules/decompiler/stats/GeneralStatement.java | 8 +- .../modules/decompiler/stats/IfStatement.java | 16 +-- .../decompiler/stats/SequenceStatement.java | 4 +- .../modules/decompiler/stats/Statement.java | 37 +++---- .../modules/decompiler/stats/SwitchStatement.java | 10 +- .../decompiler/stats/SynchronizedStatement.java | 8 +- .../modules/decompiler/vars/CheckTypesResult.java | 2 +- .../decompiler/vars/VarDefinitionHelper.java | 13 +-- .../modules/decompiler/vars/VarTypeProcessor.java | 2 +- .../modules/decompiler/vars/VarVersionsGraph.java | 4 +- .../decompiler/vars/VarVersionsProcessor.java | 6 +- .../modules/renamer/IdentifierConverter.java | 5 +- .../java/decompiler/struct/StructMethod.java | 7 +- .../decompiler/struct/consts/ConstantPool.java | 2 +- .../java/decompiler/struct/gen/VarType.java | 4 +- .../struct/gen/generics/GenericMain.java | 2 +- .../struct/gen/generics/GenericType.java | 6 +- .../java/decompiler/struct/lazy/LazyLoader.java | 2 +- .../java/decompiler/util/FastSparseSetFactory.java | 2 +- .../java/decompiler/util/InterpreterUtil.java | 3 +- .../java/decompiler/util/SFormsFastMapDirect.java | 15 +-- .../java/decompiler/util/VBStyleCollection.java | 2 +- 62 files changed, 410 insertions(+), 422 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/code/ExceptionHandler.java b/src/org/jetbrains/java/decompiler/code/ExceptionHandler.java index 5c5b659..2927294 100644 --- a/src/org/jetbrains/java/decompiler/code/ExceptionHandler.java +++ b/src/org/jetbrains/java/decompiler/code/ExceptionHandler.java @@ -54,10 +54,8 @@ public class ExceptionHandler { String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); - buf.append("from: " + from + " to: " + to + " handler: " + handler + new_line_separator); - buf.append("from_instr: " + from_instr + " to_instr: " + to_instr + " handler_instr: " + handler_instr + new_line_separator); - buf.append("exceptionClass: " + exceptionClass + new_line_separator); - return buf.toString(); + return "from: " + from + " to: " + to + " handler: " + handler + new_line_separator + + "from_instr: " + from_instr + " to_instr: " + to_instr + " handler_instr: " + handler_instr + new_line_separator + + "exceptionClass: " + exceptionClass + new_line_separator; } } diff --git a/src/org/jetbrains/java/decompiler/code/InstructionSequence.java b/src/org/jetbrains/java/decompiler/code/InstructionSequence.java index 68c2dab..709a85d 100644 --- a/src/org/jetbrains/java/decompiler/code/InstructionSequence.java +++ b/src/org/jetbrains/java/decompiler/code/InstructionSequence.java @@ -140,7 +140,7 @@ public int getOffset(int index) { String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (int i = 0; i < collinstr.size(); i++) { buf.append(InterpreterUtil.getIndentString(indent)); diff --git a/src/org/jetbrains/java/decompiler/code/cfg/BasicBlock.java b/src/org/jetbrains/java/decompiler/code/cfg/BasicBlock.java index f8bf793..61b0a63 100644 --- a/src/org/jetbrains/java/decompiler/code/cfg/BasicBlock.java +++ b/src/org/jetbrains/java/decompiler/code/cfg/BasicBlock.java @@ -169,7 +169,7 @@ public class BasicBlock implements IGraphNode { String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (int i = 0; i < seq.length(); i++) { if (i < instrOldOffsets.size()) { diff --git a/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java b/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java index 1e395ed..44c58f0 100644 --- a/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java +++ b/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java @@ -45,9 +45,9 @@ public class ControlFlowGraph implements CodeConstants { private List exceptions; - private HashMap subroutines; + private Map subroutines; - private HashSet finallyExits = new HashSet(); + private Set finallyExits = new HashSet(); // ***************************************************************************** // constructors @@ -85,16 +85,16 @@ public class ControlFlowGraph implements CodeConstants { String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (BasicBlock block : blocks) { - buf.append("----- Block " + block.id + " -----" + new_line_separator); + buf.append("----- Block ").append(block.id).append(" -----").append(new_line_separator); buf.append(block.toString()); - buf.append("----- Edges -----" + new_line_separator); + buf.append("----- Edges -----").append(new_line_separator); List suc = block.getSuccs(); for (int j = 0; j < suc.size(); j++) { - buf.append(">>>>>>>>(regular) Block " + suc.get(j).id + new_line_separator); + buf.append(">>>>>>>>(regular) Block ").append(suc.get(j).id).append(new_line_separator); } suc = block.getSuccExceptions(); for (int j = 0; j < suc.size(); j++) { @@ -102,21 +102,22 @@ public class ControlFlowGraph implements CodeConstants { ExceptionRangeCFG range = getExceptionRange(handler, block); if (range == null) { - buf.append(">>>>>>>>(exception) Block " + handler.id + "\t" + "ERROR: range not found!" + new_line_separator); + buf.append(">>>>>>>>(exception) Block ").append(handler.id).append("\t").append("ERROR: range not found!") + .append(new_line_separator); } else { List exceptionTypes = range.getExceptionTypes(); if (exceptionTypes == null) { - buf.append(">>>>>>>>(exception) Block " + handler.id + "\t" + "NULL" + new_line_separator); + buf.append(">>>>>>>>(exception) Block ").append(handler.id).append("\t").append("NULL").append(new_line_separator); } else { for (String exceptionType : exceptionTypes) { - buf.append(">>>>>>>>(exception) Block " + handler.id + "\t" + exceptionType + new_line_separator); + buf.append(">>>>>>>>(exception) Block ").append(handler.id).append("\t").append(exceptionType).append(new_line_separator); } } } } - buf.append("----- ----- -----" + new_line_separator); + buf.append("----- ----- -----").append(new_line_separator); } return buf.toString(); @@ -223,7 +224,7 @@ public class ControlFlowGraph implements CodeConstants { short[] states = findStartInstructions(instrseq); - HashMap mapInstrBlocks = new HashMap(); + Map mapInstrBlocks = new HashMap(); VBStyleCollection colBlocks = createBasicBlocks(states, instrseq, mapInstrBlocks); blocks = colBlocks; @@ -237,12 +238,12 @@ public class ControlFlowGraph implements CodeConstants { setFirstAndLastBlocks(); } - private short[] findStartInstructions(InstructionSequence seq) { + private static short[] findStartInstructions(InstructionSequence seq) { int len = seq.length(); short[] inststates = new short[len]; - HashSet excSet = new HashSet(); + Set excSet = new HashSet(); for (ExceptionHandler handler : seq.getExceptionTable().getHandlers()) { excSet.add(handler.from_instr); @@ -287,8 +288,9 @@ public class ControlFlowGraph implements CodeConstants { } - private VBStyleCollection createBasicBlocks(short[] startblock, InstructionSequence instrseq, - HashMap mapInstrBlocks) { + private VBStyleCollection createBasicBlocks(short[] startblock, + InstructionSequence instrseq, + Map mapInstrBlocks) { VBStyleCollection col = new VBStyleCollection(); @@ -329,7 +331,7 @@ public class ControlFlowGraph implements CodeConstants { } - private void connectBlocks(List lstbb, HashMap mapInstrBlocks) { + private static void connectBlocks(List lstbb, Map mapInstrBlocks) { for (int i = 0; i < lstbb.size(); i++) { @@ -365,7 +367,7 @@ public class ControlFlowGraph implements CodeConstants { } } - private void setExceptionEdges(InstructionSequence instrseq, HashMap instrBlocks) { + private void setExceptionEdges(InstructionSequence instrseq, Map instrBlocks) { exceptions = new ArrayList(); @@ -404,7 +406,7 @@ public class ControlFlowGraph implements CodeConstants { private void setSubroutineEdges() { - final HashMap subroutines = new HashMap(); + final Map subroutines = new HashMap(); for (BasicBlock block : blocks) { @@ -413,7 +415,7 @@ public class ControlFlowGraph implements CodeConstants { LinkedList stack = new LinkedList(); LinkedList> stackJsrStacks = new LinkedList>(); - HashSet setVisited = new HashSet(); + Set setVisited = new HashSet(); stack.add(block); stackJsrStacks.add(new LinkedList()); @@ -461,53 +463,64 @@ public class ControlFlowGraph implements CodeConstants { } private void processJsr() { + while (true) { + if (processJsrRanges() == 0) break; + } + } + + private static class JsrRecord { + private final BasicBlock jsr; + private final Set range; + private final BasicBlock ret; - while (processJsrRanges() != 0) ; + private JsrRecord(BasicBlock jsr, Set range, BasicBlock ret) { + this.jsr = jsr; + this.range = range; + this.ret = ret; + } } private int processJsrRanges() { - List lstJsrAll = new ArrayList(); + List lstJsrAll = new ArrayList(); // get all jsr ranges for (Entry ent : subroutines.entrySet()) { BasicBlock jsr = ent.getKey(); BasicBlock ret = ent.getValue(); - lstJsrAll.add(new Object[]{jsr, getJsrRange(jsr, ret), ret}); + lstJsrAll.add(new JsrRecord(jsr, getJsrRange(jsr, ret), ret)); } // sort ranges // FIXME: better sort order - List lstJsr = new ArrayList(); - for (Object[] arr : lstJsrAll) { + List lstJsr = new ArrayList(); + for (JsrRecord arr : lstJsrAll) { int i = 0; for (; i < lstJsr.size(); i++) { - Object[] arrJsr = lstJsr.get(i); - - if (((HashSet)arrJsr[1]).contains(arr[0])) { + JsrRecord arrJsr = lstJsr.get(i); + if (arrJsr.range.contains(arr.jsr)) { break; } } - lstJsr.add(i, arr); } // find the first intersection for (int i = 0; i < lstJsr.size(); i++) { - Object[] arr = lstJsr.get(i); - HashSet set = (HashSet)arr[1]; + JsrRecord arr = lstJsr.get(i); + Set set = arr.range; for (int j = i + 1; j < lstJsr.size(); j++) { - Object[] arr1 = lstJsr.get(j); - HashSet set1 = (HashSet)arr1[1]; + JsrRecord arr1 = lstJsr.get(j); + Set set1 = arr1.range; - if (!set.contains(arr1[0]) && !set1.contains(arr[0])) { // rang 0 doesn't contain entry 1 and vice versa - HashSet setc = new HashSet(set); + if (!set.contains(arr1.jsr) && !set1.contains(arr.jsr)) { // rang 0 doesn't contain entry 1 and vice versa + Set setc = new HashSet(set); setc.retainAll(set1); if (!setc.isEmpty()) { - splitJsrRange((BasicBlock)arr[0], (BasicBlock)arr[2], setc); + splitJsrRange(arr.jsr, arr.ret, setc); return 1; } } @@ -517,11 +530,11 @@ public class ControlFlowGraph implements CodeConstants { return 0; } - private HashSet getJsrRange(BasicBlock jsr, BasicBlock ret) { + private Set getJsrRange(BasicBlock jsr, BasicBlock ret) { - HashSet blocks = new HashSet(); + Set blocks = new HashSet(); - LinkedList lstNodes = new LinkedList(); + List lstNodes = new LinkedList(); lstNodes.add(jsr); BasicBlock dom = jsr.getSuccs().get(0); @@ -581,10 +594,10 @@ public class ControlFlowGraph implements CodeConstants { return blocks; } - private void splitJsrRange(BasicBlock jsr, BasicBlock ret, HashSet common_blocks) { + private void splitJsrRange(BasicBlock jsr, BasicBlock ret, Set common_blocks) { - LinkedList lstNodes = new LinkedList(); - HashMap mapNewNodes = new HashMap(); + List lstNodes = new LinkedList(); + Map mapNewNodes = new HashMap(); lstNodes.add(jsr); mapNewNodes.put(jsr.id, jsr); @@ -662,7 +675,7 @@ public class ControlFlowGraph implements CodeConstants { splitJsrExceptionRanges(common_blocks, mapNewNodes); } - private void splitJsrExceptionRanges(HashSet common_blocks, HashMap mapNewNodes) { + private void splitJsrExceptionRanges(Set common_blocks, Map mapNewNodes) { for (int i = exceptions.size() - 1; i >= 0; i--) { @@ -696,7 +709,7 @@ public class ControlFlowGraph implements CodeConstants { removeJsrInstructions(mt.getClassStruct().getPool(), first, DataPoint.getInitialDataPoint(mt)); } - private void removeJsrInstructions(ConstantPool pool, BasicBlock block, DataPoint data) { + private static void removeJsrInstructions(ConstantPool pool, BasicBlock block, DataPoint data) { ListStack stack = data.getStack(); @@ -765,18 +778,18 @@ public class ControlFlowGraph implements CodeConstants { public List getReversePostOrder() { - LinkedList res = new LinkedList(); + List res = new LinkedList(); addToReversePostOrderListIterative(first, res); return res; } - private void addToReversePostOrderListIterative(BasicBlock root, List lst) { + private static void addToReversePostOrderListIterative(BasicBlock root, List lst) { LinkedList stackNode = new LinkedList(); LinkedList stackIndex = new LinkedList(); - HashSet setVisited = new HashSet(); + Set setVisited = new HashSet(); stackNode.add(root); stackIndex.add(0); @@ -845,32 +858,26 @@ public class ControlFlowGraph implements CodeConstants { this.exceptions = exceptions; } - public BasicBlock getLast() { return last; } - public void setLast(BasicBlock last) { this.last = last; } - - public HashMap getSubroutines() { + public Map getSubroutines() { return subroutines; } - - public void setSubroutines(HashMap subroutines) { + public void setSubroutines(Map subroutines) { this.subroutines = subroutines; } - - public HashSet getFinallyExits() { + public Set getFinallyExits() { return finallyExits; } - public void setFinallyExits(HashSet finallyExits) { this.finallyExits = finallyExits; } diff --git a/src/org/jetbrains/java/decompiler/code/cfg/ExceptionRangeCFG.java b/src/org/jetbrains/java/decompiler/code/cfg/ExceptionRangeCFG.java index 7d83ef6..47e0e21 100644 --- a/src/org/jetbrains/java/decompiler/code/cfg/ExceptionRangeCFG.java +++ b/src/org/jetbrains/java/decompiler/code/cfg/ExceptionRangeCFG.java @@ -47,18 +47,18 @@ public class ExceptionRangeCFG { String new_line_separator = DecompilerContext.getNewLineSeparator(); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append("exceptionType:"); for (String exception_type : exceptionTypes) { - buf.append(" " + exception_type); + buf.append(" ").append(exception_type); } buf.append(new_line_separator); - buf.append("handler: " + handler.id + new_line_separator); + buf.append("handler: ").append(handler.id).append(new_line_separator); buf.append("range: "); for (int i = 0; i < protectedRange.size(); i++) { - buf.append(protectedRange.get(i).id + " "); + buf.append(protectedRange.get(i).id).append(" "); } buf.append(new_line_separator); diff --git a/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java b/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java index 060497a..937d59b 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java +++ b/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java @@ -122,9 +122,9 @@ public class ClassReference14Processor { } } - private void processClassRec(ClassNode node, - final HashMap mapClassMeths, - final HashSet setFound) { + private static void processClassRec(ClassNode node, + final HashMap mapClassMeths, + final HashSet setFound) { final ClassWrapper wrapper = node.wrapper; @@ -221,7 +221,7 @@ public class ClassReference14Processor { } - private boolean replaceInvocations(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) { + private static boolean replaceInvocations(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) { boolean res = false; @@ -250,7 +250,7 @@ public class ClassReference14Processor { } - private String isClass14Invocation(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) { + private static String isClass14Invocation(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) { if (exprent.type == Exprent.EXPRENT_FUNCTION) { FunctionExprent fexpr = (FunctionExprent)exprent; diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index 7808b26..d16c203 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -1046,7 +1046,7 @@ public class ClassWriter { return !hidemethod; } - private List getAllAnnotations(VBStyleCollection attributes) { + private static List getAllAnnotations(VBStyleCollection attributes) { String[] annattrnames = new String[]{StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS, StructGeneralAttribute.ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS}; @@ -1063,7 +1063,7 @@ public class ClassWriter { return lst; } - private List> getAllParameterAnnotations(VBStyleCollection attributes) { + private static List> getAllParameterAnnotations(VBStyleCollection attributes) { String[] annattrnames = new String[]{StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, StructGeneralAttribute.ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS}; @@ -1095,7 +1095,7 @@ public class ClassWriter { return ret; } - private String getDescriptorPrintOut(String descriptor, int element) { + private static String getDescriptorPrintOut(String descriptor, int element) { switch (element) { case 0: // class @@ -1125,7 +1125,7 @@ public class ClassWriter { } } - private String getTypePrintOut(VarType type) { + private static String getTypePrintOut(VarType type) { String strtype = ExprProcessor.getCastTypeName(type, false); if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(strtype) && DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) { diff --git a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java index 155dee0..9230c68 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java @@ -303,7 +303,7 @@ public class ClassesProcessor { } } - private void initWrappers(ClassNode node) throws IOException { + private static void initWrappers(ClassNode node) throws IOException { if (node.type == ClassNode.CLASS_LAMBDA) { return; @@ -319,7 +319,7 @@ public class ClassesProcessor { } } - private void addClassnameToImport(ClassNode node, ImportCollector imp) { + private static void addClassnameToImport(ClassNode node, ImportCollector imp) { if (node.simpleName != null && node.simpleName.length() > 0) { imp.getShortName(node.type == ClassNode.CLASS_ROOT ? node.classStruct.qualifiedName : node.simpleName, false); @@ -330,7 +330,7 @@ public class ClassesProcessor { } } - private void destroyWrappers(ClassNode node) { + private static void destroyWrappers(ClassNode node) { node.wrapper = null; node.classStruct.releaseResources(); @@ -345,7 +345,7 @@ public class ClassesProcessor { } - public class ClassNode { + public static class ClassNode { public static final int CLASS_ROOT = 0; public static final int CLASS_MEMBER = 1; @@ -436,9 +436,7 @@ public class ClassesProcessor { return null; } - public class LambdaInformation { - - + public static class LambdaInformation { public String class_name; public String method_name; public String method_descriptor; diff --git a/src/org/jetbrains/java/decompiler/main/Fernflower.java b/src/org/jetbrains/java/decompiler/main/Fernflower.java index bc0fcd4..88655a9 100644 --- a/src/org/jetbrains/java/decompiler/main/Fernflower.java +++ b/src/org/jetbrains/java/decompiler/main/Fernflower.java @@ -50,9 +50,7 @@ public class Fernflower implements IDecompiledData { public void decompileContext() { if (DecompilerContext.getOption(IFernflowerPreferences.RENAME_ENTITIES)) { - IdentifierConverter ren = new IdentifierConverter(); - ren.rename(structcontext); - ren = null; + new IdentifierConverter().rename(structcontext); } clprocessor = new ClassesProcessor(structcontext); diff --git a/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java b/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java index 0a8261f..50a55cf 100644 --- a/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java +++ b/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java @@ -311,8 +311,7 @@ public class ConsoleDecompiler implements IBytecodeProvider, IDecompilatSaver { String filename = new File(getAbsolutePath(path), archivename).getAbsolutePath(); mapArchiveEntries.remove(filename); - ZipOutputStream out = mapArchiveStreams.remove(filename); - + OutputStream out = mapArchiveStreams.remove(filename); out.flush(); out.close(); } diff --git a/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java b/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java index f0e8591..0991fa4 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java +++ b/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java @@ -67,6 +67,8 @@ public class ClassWrapper { setFieldNames.add(fd.getName()); } + int maxsec = Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString()); + for (StructMethod mt : classStruct.getMethods()) { DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor()); @@ -83,7 +85,6 @@ public class ClassWrapper { VarProcessor varproc = new VarProcessor(); DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varproc); - Thread mtthread = null; RootStatement root = null; boolean isError = false; @@ -91,28 +92,25 @@ public class ClassWrapper { try { if (mt.containsCode()) { - int maxsec = 10 * Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString()); - if (maxsec == 0) { // blocking wait root = MethodProcessorThread.codeToJava(mt, varproc); } else { MethodProcessorThread mtproc = new MethodProcessorThread(mt, varproc, DecompilerContext.getCurrentContext()); - mtthread = new Thread(mtproc); + Thread mtthread = new Thread(mtproc); + long stopAt = System.currentTimeMillis() + maxsec * 1000; mtthread.start(); - int sec = 0; while (mtthread.isAlive()) { - synchronized (mtproc) { - mtproc.wait(100); + synchronized (mtproc.lock) { + mtproc.lock.wait(100); } - if (maxsec > 0 && ++sec > maxsec) { - DecompilerContext.getLogger().writeMessage("Processing time limit (" + maxsec + " sec.) for method " + - mt.getName() + " " + mt.getDescriptor() + " exceeded, execution interrupted.", - IFernflowerLogger.ERROR); + if (System.currentTimeMillis() >= stopAt) { + String message = "Processing time limit exceeded for method " + mt.getName() + ", execution interrupted."; + DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.ERROR); mtthread.stop(); isError = true; break; @@ -120,12 +118,7 @@ public class ClassWrapper { } if (!isError) { - if (mtproc.getError() != null) { - throw mtproc.getError(); - } - else { - root = mtproc.getRoot(); - } + root = mtproc.getResult(); } } } @@ -158,17 +151,6 @@ public class ClassWrapper { } } } - catch (ThreadDeath ex) { - try { - if (mtthread != null) { - mtthread.stop(); - } - } - catch (Throwable ignored) { - } - - throw ex; - } catch (Throwable ex) { DecompilerContext.getLogger().writeMessage("Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be decompiled.", ex); isError = true; diff --git a/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java index 3d42bda..3150894 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java @@ -112,9 +112,9 @@ public class LambdaProcessor { LinkConstant content_method_handle = (LinkConstant)bootstrap_arguments.get(1); - ClassNode node_lambda = clprocessor.new ClassNode(content_method_handle.classname, content_method_handle.elementname, - content_method_handle.descriptor, content_method_handle.index1, - lambda_class_name, lambda_method_name, lambda_method_descriptor, cl); + ClassNode node_lambda = new ClassNode(content_method_handle.classname, content_method_handle.elementname, + content_method_handle.descriptor, content_method_handle.index1, + lambda_class_name, lambda_method_name, lambda_method_descriptor, cl); node_lambda.simpleName = cl.qualifiedName + "##Lambda_" + invoke_dynamic.index1 + "_" + invoke_dynamic.index2; node_lambda.enclosingMethod = InterpreterUtil.makeUniqueKey(mt.getName(), mt.getDescriptor()); diff --git a/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java b/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java index eeee352..da05640 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java +++ b/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java @@ -33,16 +33,16 @@ import java.io.IOException; public class MethodProcessorThread implements Runnable { - private StructMethod method; - private VarProcessor varproc; - private DecompilerContext parentContext; + public final Object lock = new Object(); - private RootStatement root; + private final StructMethod method; + private final VarProcessor varproc; + private final DecompilerContext parentContext; - private Throwable error; + private volatile RootStatement root; + private volatile Throwable error; - public MethodProcessorThread(StructMethod method, VarProcessor varproc, - DecompilerContext parentContext) { + public MethodProcessorThread(StructMethod method, VarProcessor varproc, DecompilerContext parentContext) { this.method = method; this.varproc = varproc; this.parentContext = parentContext; @@ -58,11 +58,13 @@ public class MethodProcessorThread implements Runnable { try { root = codeToJava(method, varproc); - synchronized (this) { - this.notify(); + synchronized (lock) { + lock.notifyAll(); } } - catch (ThreadDeath ignored) { } + catch (ThreadDeath ex) { + throw ex; + } catch (Throwable ex) { error = ex; } @@ -248,7 +250,9 @@ public class MethodProcessorThread implements Runnable { return root; } - public RootStatement getRoot() { + public RootStatement getResult() throws Throwable { + Throwable t = error; + if (t != null) throw t; return root; } diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java index 6cd2204..e637632 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java @@ -101,7 +101,7 @@ public class NestedClassProcessor { } } - private void setLambdaVars(ClassNode parent, ClassNode child) { + private static void setLambdaVars(ClassNode parent, ClassNode child) { if (child.lambda_information.is_method_reference) { // method reference, no code and no parameters return; @@ -187,7 +187,7 @@ public class NestedClassProcessor { } } - private void checkNotFoundClasses(ClassNode root, ClassNode node) { + private static void checkNotFoundClasses(ClassNode root, ClassNode node) { List lstChildren = new ArrayList(node.nested); @@ -232,7 +232,7 @@ public class NestedClassProcessor { } } - private boolean insertNestedClass(ClassNode root, ClassNode child) { + private static boolean insertNestedClass(ClassNode root, ClassNode child) { Set setEnclosing = child.enclosingClasses; @@ -258,7 +258,7 @@ public class NestedClassProcessor { } - private void computeLocalVarsAndDefinitions(final ClassNode node) { + private static void computeLocalVarsAndDefinitions(final ClassNode node) { // local var masks // class name, constructor descriptor, field mask @@ -433,7 +433,7 @@ public class NestedClassProcessor { } } - private void insertLocalVars(final ClassNode parent, final ClassNode child) { + private static void insertLocalVars(final ClassNode parent, final ClassNode child) { // enclosing method, is null iff member class MethodWrapper encmeth = parent.wrapper.getMethods().getWithKey(child.enclosingMethod); @@ -634,7 +634,7 @@ public class NestedClassProcessor { } } - private HashMap> getMaskLocalVars(ClassWrapper wrapper) { + private static HashMap> getMaskLocalVars(ClassWrapper wrapper) { HashMap> mapMasks = new HashMap>(); @@ -666,7 +666,7 @@ public class NestedClassProcessor { return mapMasks; } - private String getEnclosingVarField(StructClass cl, MethodWrapper meth, DirectGraph graph, final int index) { + private static String getEnclosingVarField(StructClass cl, MethodWrapper meth, DirectGraph graph, final int index) { String field = ""; @@ -709,7 +709,7 @@ public class NestedClassProcessor { return field; } - private void mergeListSignatures(List first, List second, boolean both) { + private static void mergeListSignatures(List first, List second, boolean both) { int i = 1; while (true) { @@ -818,7 +818,7 @@ public class NestedClassProcessor { } - private void setLocalClassDefinition(MethodWrapper meth, ClassNode node) { + private static void setLocalClassDefinition(MethodWrapper meth, ClassNode node) { RootStatement root = meth.root; @@ -862,7 +862,7 @@ public class NestedClassProcessor { } - private Statement findFirstBlock(Statement stat, HashSet setStats) { + private static Statement findFirstBlock(Statement stat, HashSet setStats) { LinkedList stack = new LinkedList(); stack.add(stat); @@ -903,7 +903,7 @@ public class NestedClassProcessor { } - private Statement getDefStatement(Statement stat, VarType classtype, HashSet setStats) { + private static Statement getDefStatement(Statement stat, VarType classtype, HashSet setStats) { List condlst = new ArrayList(); Statement retstat = null; @@ -958,7 +958,7 @@ public class NestedClassProcessor { return retstat; } - private boolean searchForClass(Exprent exprent, VarType classtype) { + private static boolean searchForClass(Exprent exprent, VarType classtype) { List lst = exprent.getAllExprents(true); lst.add(exprent); @@ -1004,7 +1004,7 @@ public class NestedClassProcessor { } - private class VarFieldPair { + private static class VarFieldPair { public String keyfield = ""; public VarVersionPaar varpaar; diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java index d8c67ac..8551856 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java +++ b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java @@ -310,7 +310,7 @@ public class NestedMemberAccess { return res; } - private boolean sameTree(ClassNode caller, ClassNode callee) { + private static boolean sameTree(ClassNode caller, ClassNode callee) { if (caller.classStruct.qualifiedName.equals(callee.classStruct.qualifiedName)) { return false; 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 setFinallyExits = graph.getFinallyExits(); + Set 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 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 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 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 entrypoints) { + private static String buildEntryPointKey(LinkedList 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 map) { + private static void collectCatchVars(Statement stat, FlattenStatementsHelper flatthelper, Map map) { List 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 finallyBlockIDs = new HashMap(); - private HashMap catchallBlockIDs = new HashMap(); + private Map finallyBlockIDs = new HashMap(); + private Map catchallBlockIDs = new HashMap(); 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 mapLast; + + private Record(int firstCode, Map 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 mapLast = new HashMap(); + Map mapLast = new HashMap(); BasicBlockStatement firstBlockStatement = fstat.getHandler().getBasichead(); BasicBlock firstBasicBlock = firstBlockStatement.getBlock(); @@ -216,7 +225,7 @@ public class FinallyProcessor { LinkedList stack = new LinkedList(); stack.add(dgraph.first); - HashSet setVisited = new HashSet(); + Set setVisited = new HashSet(); 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 setTry, - BasicBlock head, - BasicBlock handler, - int var, - Object[] information, - int bytecode_version) { + private static void insertSemaphore(ControlFlowGraph graph, + Set setTry, + BasicBlock head, + BasicBlock handler, + int var, + Record information, + int bytecode_version) { - HashSet setCopy = new HashSet(setTry); + Set setCopy = new HashSet(setTry); - int finallytype = (Integer)information[0]; - HashMap mapLast = (HashMap)information[1]; + int finallytype = information.firstCode; + Map 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 lstTemp = new ArrayList(); lstTemp.addAll(oldblock.getPreds()); @@ -501,7 +510,7 @@ public class FinallyProcessor { } } - private HashSet getAllBasicBlocks(Statement stat) { + private static HashSet getAllBasicBlocks(Statement stat) { List lst = new LinkedList(); 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 tryBlocks = getAllBasicBlocks(fstat.getFirst()); HashSet catchBlocks = getAllBasicBlocks(fstat.getHandler()); - int finallytype = (Integer)information[0]; - HashMap mapLast = (HashMap)information[1]; + int finallytype = information.firstCode; + Map 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 lstAreas = new ArrayList(); + List lstAreas = new ArrayList(); 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 catchBlocks, - BasicBlock startCatch, - int finallytype, - HashMap mapLast, - boolean skippedFirst) { + private static class Area { + private final BasicBlock start; + private final Set sample; + private final BasicBlock next; + + private Area(BasicBlock start, Set sample, BasicBlock next) { + this.start = start; + this.sample = sample; + this.next = next; + } + } + + private Area compareSubgraphsEx(ControlFlowGraph graph, + BasicBlock startSample, + HashSet catchBlocks, + BasicBlock startCatch, + int finallytype, + Map mapLast, + boolean skippedFirst) { class BlockStackEntry { public BasicBlock blockCatch; @@ -635,9 +656,9 @@ public class FinallyProcessor { List stack = new LinkedList(); - HashSet setSample = new HashSet(); + Set setSample = new HashSet(); - HashMap mapNext = new HashMap(); + Map mapNext = new HashMap(); stack.add(new BlockStackEntry(startCatch, startSample, new ArrayList())); @@ -719,7 +740,7 @@ public class FinallyProcessor { } if (isLastBlock) { - HashSet setSuccs = new HashSet(blockSample.getSuccs()); + Set setSuccs = new HashSet(blockSample.getSuccs()); setSuccs.removeAll(setSample); for (BlockStackEntry stackent : stack) { @@ -734,10 +755,10 @@ public class FinallyProcessor { } } - return new Object[]{setSample, getUniqueNext(graph, new HashSet(mapNext.values()))}; + return new Area(startSample, setSample, getUniqueNext(graph, new HashSet(mapNext.values()))); } - private BasicBlock getUniqueNext(ControlFlowGraph graph, HashSet setNext) { + private static BasicBlock getUniqueNext(ControlFlowGraph graph, Set 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 setFinallyExits = graph.getFinallyExits(); + Set 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 setCommonExceptionHandlers = new HashSet(next.getSuccExceptions()); + Set setCommonExceptionHandlers = new HashSet(next.getSuccExceptions()); for (BasicBlock pred : start.getPreds()) { setCommonExceptionHandlers.retainAll(pred.getSuccExceptions()); } boolean is_outside_range = false; - HashSet setPredecessors = new HashSet(start.getPreds()); + Set setPredecessors = new HashSet(start.getPreds()); // replace start with next for (BasicBlock pred : setPredecessors) { pred.replaceSuccessor(start, next); } - HashSet setBlocks = (HashSet)area[1]; + Set setBlocks = area.sample; - HashSet setCommonRemovedExceptionRanges = null; + Set setCommonRemovedExceptionRanges = null; // remove all the blocks inbetween for (BasicBlock block : setBlocks) { @@ -983,7 +1004,7 @@ public class FinallyProcessor { is_outside_range = true; } - HashSet setRemovedExceptionRanges = new HashSet(); + Set setRemovedExceptionRanges = new HashSet(); 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> mapEdges1 = null; if (ifstat.getElsestat() != null) { @@ -422,17 +420,14 @@ public class LabelHelper { } } - private static HashSet[] processStatementLabel(Statement stat) { - - HashSet setBreak = new HashSet(); - HashSet setContinue = new HashSet(); + private static void processStatementLabel(Statement stat) { + processStatementLabel(stat, new HashSet(), new HashSet()); + } + private static void processStatementLabel(Statement stat, Set setBreak, Set setContinue) { if (stat.getExprents() == null) { for (Statement st : stat.getStats()) { - HashSet[] 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 lst = exprent.getAllExprents(true); lst.add(exprent); @@ -236,7 +236,7 @@ public class StackVarsProcessor { } - private Exprent isReplaceableVar(Exprent exprent, HashMap mapVarValues, SSAUConstructorSparseEx ssau) { + private static Exprent isReplaceableVar(Exprent exprent, HashMap 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 getAllVersions(Exprent exprent) { + private static HashSet getAllVersions(Exprent exprent) { HashSet res = new HashSet(); @@ -455,11 +455,11 @@ public class StackVarsProcessor { return res; } - private Object[] iterateChildExprent(Exprent exprent, - Exprent parent, - Exprent next, - HashMap mapVarValues, - SSAUConstructorSparseEx ssau) { + private static Object[] iterateChildExprent(Exprent exprent, + Exprent parent, + Exprent next, + HashMap 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 res) { + private static boolean getUsedVersions(SSAUConstructorSparseEx ssa, VarVersionPaar var, List 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> mapVars, - SSAUConstructorSparseEx ssau, - VarVersionPaar leftpaar) { + private static boolean isVersionToBeReplaced(VarVersionPaar usedvar, + HashMap> mapVars, + SSAUConstructorSparseEx ssau, + VarVersionPaar leftpaar) { VarVersionsGraph ssuversions = ssau.getSsuversions(); @@ -687,9 +687,9 @@ public class StackVarsProcessor { return true; } - private HashMap> getAllVarVersions(VarVersionPaar leftvar, - Exprent exprent, - SSAUConstructorSparseEx ssau) { + private static HashMap> getAllVarVersions(VarVersionPaar leftvar, + Exprent exprent, + SSAUConstructorSparseEx ssau) { HashMap> map = new HashMap>(); 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 orderedIDoms) { + private static Integer getCommonIDom(Integer key1, Integer key2, VBStyleCollection 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 orderedIDoms) { + private static IGraphNode getCommonIDom(IGraphNode node1, IGraphNode node2, VBStyleCollection 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 protectedRange; + private final ExceptionRangeCFG rangeCFG; + + private Range(BasicBlock handler, String uniqueStr, Set protectedRange, ExceptionRangeCFG rangeCFG) { + this.handler = handler; + this.uniqueStr = uniqueStr; + this.protectedRange = protectedRange; + this.rangeCFG = rangeCFG; + } + } + public static void restorePopRanges(ControlFlowGraph graph) { - List lstRanges = new ArrayList(); + List lstRanges = new ArrayList(); // 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)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(range.getProtectedRange()), range}); + lstRanges.add(new Range(range.getHandler(), range.getUniqueExceptionsString(), new HashSet(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 setrange = new HashSet((HashSet)range[2]); + Set setrange = new HashSet(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 setrange_super = new HashSet((HashSet)range_super[2]); + Set setrange_super = new HashSet(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 setVisited = new HashSet(); + Set setVisited = new HashSet(); for (ExceptionRangeCFG range : graph.getExceptions()) { BasicBlock handler = range.getHandler(); @@ -255,7 +267,7 @@ public class ExceptionDeobfuscator { List lstRes = new ArrayList(); LinkedList stack = new LinkedList(); - HashSet setVisited = new HashSet(); + Set setVisited = new HashSet(); 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> mapRanges = new HashMap>(); + Map> mapRanges = new HashMap>(); for (ExceptionRangeCFG range : graph.getExceptions()) { - HashSet set = mapRanges.get(range.getHandler()); + Set set = mapRanges.get(range.getHandler()); if (set == null) { mapRanges.put(range.getHandler(), set = new HashSet()); } set.addAll(range.getProtectedRange()); } - for (Entry> ent : mapRanges.entrySet()) { - HashSet setEntries = new HashSet(); + for (Entry> ent : mapRanges.entrySet()) { + Set setEntries = new HashSet(); for (BasicBlock block : ent.getValue()) { - HashSet setTemp = new HashSet(block.getPreds()); + Set setTemp = new HashSet(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 lstParams, int indent) { + private static String getQualifiedNewInstance(String classname, List 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 lst) { + private static void addToReversePostOrderListIterative(DirectNode root, List lst) { LinkedList stackNode = new LinkedList(); LinkedList stackIndex = new LinkedList(); 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 mapDestinationNodes = new HashMap(); + private Map mapDestinationNodes = new HashMap(); // node.id(source), statement.id(destination), edge type private List listEdges = new ArrayList(); // node.id(exit), [node.id(source), statement.id(destination)] - public HashMap> mapShortRangeFinallyPathIds = new HashMap>(); + private Map> mapShortRangeFinallyPathIds = new HashMap>(); // node.id(exit), [node.id(source), statement.id(destination)] - public HashMap> mapLongRangeFinallyPathIds = new HashMap>(); + private Map> mapLongRangeFinallyPathIds = new HashMap>(); // positive if branches - public HashMap mapPosIfBranch = new HashMap(); - + private Map mapPosIfBranch = new HashMap(); private DirectGraph graph; @@ -99,7 +98,7 @@ public class FlattenStatementsHelper { LinkedList stackFinally = statEntry.stackFinally; int statementBreakIndex = statEntry.statementIndex; - DirectNode node = null, nd = null; + DirectNode node, nd; List lstSuccEdges = new ArrayList(); 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 getMapDestinationNodes() { + public Map 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 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 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> map : new Map[]{mapSuccEdges, mapPredEdges}) { - map.remove(StatEdge.TYPE_EXCEPTION); - - List lst = map.get(STATEDGE_DIRECT_ALL); - if (lst != null) { - map.put(STATEDGE_ALL, new ArrayList(lst)); - } - else { - map.remove(STATEDGE_ALL); - } - } + processMap(mapSuccEdges); + processMap(mapPredEdges); + processMap(mapSuccStates); + processMap(mapPredStates); + } - for (Map> map : new Map[]{mapSuccStates, mapPredStates}) { - map.remove(StatEdge.TYPE_EXCEPTION); + private static void processMap(Map> map) { + map.remove(StatEdge.TYPE_EXCEPTION); - List lst = map.get(STATEDGE_DIRECT_ALL); - if (lst != null) { - map.put(STATEDGE_ALL, new ArrayList(lst)); - } - else { - map.remove(STATEDGE_ALL); - } + List lst = map.get(STATEDGE_DIRECT_ALL); + if (lst != null) { + map.put(STATEDGE_ALL, new ArrayList(lst)); + } + else { + map.remove(STATEDGE_ALL); } } @@ -579,7 +572,7 @@ public class Statement { // private methods // ***************************************************************************** - private void addToReversePostOrderListIterative(Statement root, List lst) { + private static void addToReversePostOrderListIterative(Statement root, List lst) { LinkedList stackNode = new LinkedList(); LinkedList stackIndex = new LinkedList(); @@ -622,7 +615,7 @@ public class Statement { } - private void addToPostReversePostOrderList(Statement stat, List lst, HashSet setVisited) { + private static void addToPostReversePostOrderList(Statement stat, List lst, HashSet 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> it = mapVarDefStatements.entrySet().iterator(); - while (it.hasNext()) { - Entry en = it.next(); - + for (Entry en : mapVarDefStatements.entrySet()) { Statement stat = en.getValue(); Integer index = en.getKey(); @@ -312,9 +309,7 @@ public class VarDefinitionHelper { HashSet set = new HashSet(mapCount.keySet()); // put all variables defined in this statement into the set - Iterator> itMult = mapCount.entrySet().iterator(); - while (itMult.hasNext()) { - Entry en = itMult.next(); + for (Entry en : mapCount.entrySet()) { if (en.getValue().intValue() > 1) { mapVarDefStatements.put(en.getKey(), stat); } @@ -325,7 +320,7 @@ public class VarDefinitionHelper { return set; } - private List getAllVars(List lst) { + private static List getAllVars(List lst) { List res = new ArrayList(); List listTemp = new ArrayList(); @@ -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 getReversedPostOrder(Collection roots) { + private static LinkedList getReversedPostOrder(Collection roots) { LinkedList lst = new LinkedList(); HashSet setVisited = new HashSet(); @@ -122,7 +122,7 @@ public class VarVersionsGraph { return lst; } - private void addToReversePostOrderListIterative(VarVersionNode root, List lst, HashSet setVisited) { + private static void addToReversePostOrderListIterative(VarVersionNode root, List lst, HashSet setVisited) { HashMap> mapNodeSuccs = new HashMap>(); 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> lst = new ArrayList>(); @@ -125,7 +125,7 @@ public class VarVersionsProcessor { }); } - private void eliminateNonJavaTypes(VarTypeProcessor typeproc) { + private static void eliminateNonJavaTypes(VarTypeProcessor typeproc) { HashMap mapExprentMaxTypes = typeproc.getMapExprentMaxTypes(); HashMap 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 mapExprentMaxTypes = typeproc.getMapExprentMaxTypes(); HashMap 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 getReversePostOrderListIterative(List roots) { + private static List getReversePostOrderListIterative(List roots) { List res = new ArrayList(); diff --git a/src/org/jetbrains/java/decompiler/struct/StructMethod.java b/src/org/jetbrains/java/decompiler/struct/StructMethod.java index 08101d2..e3de510 100644 --- a/src/org/jetbrains/java/decompiler/struct/StructMethod.java +++ b/src/org/jetbrains/java/decompiler/struct/StructMethod.java @@ -216,8 +216,11 @@ public class StructMethod implements CodeConstants { } } - private void readAttribute(DataInputFullStream in, ConstantPool pool, VBStyleCollection lstAttribute, - int attr_nameindex, String attrname) throws IOException { + private static void readAttribute(DataInputFullStream in, + ConstantPool pool, + VBStyleCollection lstAttribute, + int attr_nameindex, + String attrname) throws IOException { StructGeneralAttribute attribute = StructGeneralAttribute.getMatchingAttributeInstance(attr_nameindex, attrname); diff --git a/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java b/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java index a352213..1b21828 100644 --- a/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java +++ b/src/org/jetbrains/java/decompiler/struct/consts/ConstantPool.java @@ -252,7 +252,7 @@ public class ConstantPool { buffer.append("["); } - buffer.append("L" + newname + ";"); + buffer.append("L").append(newname).append(";"); } else { buffer.append(newname); diff --git a/src/org/jetbrains/java/decompiler/struct/gen/VarType.java b/src/org/jetbrains/java/decompiler/struct/gen/VarType.java index 1b6ff99..a58898a 100644 --- a/src/org/jetbrains/java/decompiler/struct/gen/VarType.java +++ b/src/org/jetbrains/java/decompiler/struct/gen/VarType.java @@ -306,7 +306,7 @@ public class VarType { // TODO: optimize switch } } - private int getType(char c) { + private static int getType(char c) { switch (c) { case 'B': return CodeConstants.TYPE_BYTE; @@ -343,7 +343,7 @@ public class VarType { // TODO: optimize switch } } - private String getChar(int type) { + private static String getChar(int type) { switch (type) { case CodeConstants.TYPE_BYTE: return "B"; diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java index 6a4f52e..a2df8f5 100644 --- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java +++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java @@ -221,7 +221,7 @@ public class GenericMain { String res = name.replace('/', '.'); - if (res.indexOf("$") >= 0) { + if (res.contains("$")) { StructClass cl = DecompilerContext.getStructcontext().getClass(name); if (cl == null || !cl.isOwn()) { res = res.replace('$', '.'); diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java index 61d07a0..160a0ac 100644 --- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java +++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java @@ -105,7 +105,7 @@ public class GenericType { } } - private String getNextClassSignature(String value) { + private static String getNextClassSignature(String value) { int counter = 0; int index = 0; @@ -131,7 +131,7 @@ public class GenericType { return value.substring(0, index); } - private void parseArgumentsList(String value, GenericType type) { + private static void parseArgumentsList(String value, GenericType type) { if (value == null) { return; @@ -214,7 +214,7 @@ public class GenericType { return value.substring(0, index + 1); } - private int getType(char c) { + private static int getType(char c) { switch (c) { case 'B': return CodeConstants.TYPE_BYTE; diff --git a/src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java b/src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java index ad87235..8673c21 100644 --- a/src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java +++ b/src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java @@ -158,7 +158,7 @@ public class LazyLoader { return link == null ? null : getClassStream(link.externPath, link.internPath); } - private void skipAttributes(DataInputFullStream in) throws IOException { + private static void skipAttributes(DataInputFullStream in) throws IOException { int length = in.readUnsignedShort(); for (int i = 0; i < length; i++) { diff --git a/src/org/jetbrains/java/decompiler/util/FastSparseSetFactory.java b/src/org/jetbrains/java/decompiler/util/FastSparseSetFactory.java index 863dd72..bf01035 100644 --- a/src/org/jetbrains/java/decompiler/util/FastSparseSetFactory.java +++ b/src/org/jetbrains/java/decompiler/util/FastSparseSetFactory.java @@ -253,7 +253,7 @@ public class FastSparseSetFactory { } } - private void changeNext(int[] arrnext, int key, int oldnext, int newnext) { + private static void changeNext(int[] arrnext, int key, int oldnext, int newnext) { for (int i = key - 1; i >= 0; i--) { if (arrnext[i] == oldnext) { arrnext[i] = newnext; diff --git a/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java b/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java index a1da87b..89e11c0 100644 --- a/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java +++ b/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java @@ -83,9 +83,8 @@ public class InterpreterUtil { return false; } - HashSet set = new HashSet(c1); + HashSet set = new HashSet(c1); set.removeAll(c2); - return (set.size() == 0); } diff --git a/src/org/jetbrains/java/decompiler/util/SFormsFastMapDirect.java b/src/org/jetbrains/java/decompiler/util/SFormsFastMapDirect.java index 089225d..996607a 100644 --- a/src/org/jetbrains/java/decompiler/util/SFormsFastMapDirect.java +++ b/src/org/jetbrains/java/decompiler/util/SFormsFastMapDirect.java @@ -27,7 +27,7 @@ public class SFormsFastMapDirect { private int size; - private FastSparseSet[][] elements = new FastSparseSet[3][]; + @SuppressWarnings("unchecked") private FastSparseSet[][] elements = new FastSparseSet[3][]; private int[][] next = new int[3][]; @@ -38,7 +38,8 @@ public class SFormsFastMapDirect { private SFormsFastMapDirect(boolean initialize) { if (initialize) { for (int i = 2; i >= 0; i--) { - elements[i] = new FastSparseSet[0]; + @SuppressWarnings("unchecked") FastSparseSet[] empty = new FastSparseSet[0]; + elements[i] = empty; next[i] = new int[0]; } } @@ -50,7 +51,7 @@ public class SFormsFastMapDirect { int[] arrnext = map.next[i]; int length = arr.length; - FastSparseSet[] arrnew = new FastSparseSet[length]; + @SuppressWarnings("unchecked") FastSparseSet[] arrnew = new FastSparseSet[length]; int[] arrnextnew = new int[length]; System.arraycopy(arr, 0, arrnew, 0, length); @@ -78,7 +79,7 @@ public class SFormsFastMapDirect { if (length > 0) { int[] arrnext = next[i]; - FastSparseSet[] arrnew = new FastSparseSet[length]; + @SuppressWarnings("unchecked") FastSparseSet[] arrnew = new FastSparseSet[length]; int[] arrnextnew = new int[length]; System.arraycopy(arrnext, 0, arrnextnew, 0, length); @@ -174,7 +175,7 @@ public class SFormsFastMapDirect { } } - private void changeNext(int[] arrnext, int key, int oldnext, int newnext) { + private static void changeNext(int[] arrnext, int key, int oldnext, int newnext) { for (int i = key - 1; i >= 0; i--) { if (arrnext[i] == oldnext) { arrnext[i] = newnext; @@ -343,7 +344,7 @@ public class SFormsFastMapDirect { } Set set = entry.getValue().toPlainSet(); - buffer.append(entry.getKey() + "={" + set.toString() + "}"); + buffer.append(entry.getKey()).append("={").append(set.toString()).append("}"); } } @@ -399,7 +400,7 @@ public class SFormsFastMapDirect { } } - FastSparseSet[] arrnew = new FastSparseSet[minsize]; + @SuppressWarnings("unchecked") FastSparseSet[] arrnew = new FastSparseSet[minsize]; System.arraycopy(arr, 0, arrnew, 0, arr.length); int[] arrnextnew = new int[minsize]; diff --git a/src/org/jetbrains/java/decompiler/util/VBStyleCollection.java b/src/org/jetbrains/java/decompiler/util/VBStyleCollection.java index f4d5968..cdc1762 100644 --- a/src/org/jetbrains/java/decompiler/util/VBStyleCollection.java +++ b/src/org/jetbrains/java/decompiler/util/VBStyleCollection.java @@ -115,7 +115,7 @@ public class VBStyleCollection extends ArrayList { public E remove(int index) { addToListIndex(index + 1, -1); - Object obj = lstKeys.get(index); + K obj = lstKeys.get(index); if (obj != null) { map.remove(obj); } -- cgit v1.2.3