mirror of
https://github.com/moparisthebest/fernflower
synced 2024-11-29 04:22:22 -05:00
java-decompiler: optimization (less string buffer allocations on generating text)
This commit is contained in:
parent
f4f9e8be28
commit
1cea85e49a
File diff suppressed because it is too large
Load Diff
@ -34,15 +34,13 @@ import org.jetbrains.java.decompiler.struct.attr.StructInnerClassesAttribute;
|
|||||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class ClassesProcessor {
|
public class ClassesProcessor {
|
||||||
|
|
||||||
private HashMap<String, ClassNode> mapRootClasses = new HashMap<String, ClassNode>();
|
private Map<String, ClassNode> mapRootClasses = new HashMap<String, ClassNode>();
|
||||||
|
|
||||||
public ClassesProcessor(StructContext context) {
|
public ClassesProcessor(StructContext context) {
|
||||||
|
|
||||||
@ -96,7 +94,7 @@ public class ClassesProcessor {
|
|||||||
arr[3] = entry[3];
|
arr[3] = entry[3];
|
||||||
|
|
||||||
// enclosing class
|
// enclosing class
|
||||||
String enclClassName = null;
|
String enclClassName;
|
||||||
if (entry[1] != 0) {
|
if (entry[1] != 0) {
|
||||||
enclClassName = strentry[1];
|
enclClassName = strentry[1];
|
||||||
}
|
}
|
||||||
@ -186,9 +184,9 @@ public class ClassesProcessor {
|
|||||||
|
|
||||||
Object[] arr = mapInnerClasses.get(nestedClass);
|
Object[] arr = mapInnerClasses.get(nestedClass);
|
||||||
|
|
||||||
if ((Integer)arr[2] == ClassNode.CLASS_MEMBER) {
|
//if ((Integer)arr[2] == ClassNode.CLASS_MEMBER) {
|
||||||
// FIXME: check for consistent naming
|
// FIXME: check for consistent naming
|
||||||
}
|
//}
|
||||||
|
|
||||||
nestednode.type = (Integer)arr[2];
|
nestednode.type = (Integer)arr[2];
|
||||||
nestednode.simpleName = (String)arr[1];
|
nestednode.simpleName = (String)arr[1];
|
||||||
@ -234,56 +232,49 @@ public class ClassesProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeClass(StructClass cl, StringBuilder buffer) throws IOException {
|
||||||
public void writeClass(StructClass cl, BufferedWriter writer) throws IOException {
|
|
||||||
|
|
||||||
ClassNode root = mapRootClasses.get(cl.qualifiedName);
|
ClassNode root = mapRootClasses.get(cl.qualifiedName);
|
||||||
if (root.type != ClassNode.CLASS_ROOT) {
|
if (root.type != ClassNode.CLASS_ROOT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DecompilerContext.setImportCollector(new ImportCollector(root));
|
ImportCollector importCollector = new ImportCollector(root);
|
||||||
|
DecompilerContext.setImportCollector(importCollector);
|
||||||
DecompilerContext.setCounterContainer(new CounterContainer());
|
DecompilerContext.setCounterContainer(new CounterContainer());
|
||||||
|
|
||||||
// lambda processing
|
new LambdaProcessor().processClass(root);
|
||||||
LambdaProcessor lambda_proc = new LambdaProcessor();
|
|
||||||
lambda_proc.processClass(root);
|
|
||||||
|
|
||||||
// add simple class names to implicit import
|
// add simple class names to implicit import
|
||||||
addClassnameToImport(root, DecompilerContext.getImportCollector());
|
addClassnameToImport(root, importCollector);
|
||||||
// build wrappers for all nested classes
|
|
||||||
// that's where the actual processing takes place
|
// build wrappers for all nested classes (that's where actual processing takes place)
|
||||||
initWrappers(root);
|
initWrappers(root);
|
||||||
|
|
||||||
NestedClassProcessor nestedproc = new NestedClassProcessor();
|
new NestedClassProcessor().processClass(root, root);
|
||||||
nestedproc.processClass(root, root);
|
|
||||||
|
|
||||||
NestedMemberAccess nstmember = new NestedMemberAccess();
|
new NestedMemberAccess().propagateMemberAccess(root);
|
||||||
nstmember.propagateMemberAccess(root);
|
|
||||||
|
|
||||||
ClassWriter clwriter = new ClassWriter();
|
StringBuilder classBuffer = new StringBuilder();
|
||||||
|
new ClassWriter().classToJava(root, classBuffer, 0);
|
||||||
|
|
||||||
StringWriter strwriter = new StringWriter();
|
String lineSeparator = DecompilerContext.getNewLineSeparator();
|
||||||
clwriter.classToJava(root, new BufferedWriter(strwriter), 0);
|
|
||||||
|
|
||||||
int index = cl.qualifiedName.lastIndexOf("/");
|
int index = cl.qualifiedName.lastIndexOf("/");
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
String packageName = cl.qualifiedName.substring(0, index).replace('/', '.');
|
String packageName = cl.qualifiedName.substring(0, index).replace('/', '.');
|
||||||
writer.write("package ");
|
buffer.append("package ");
|
||||||
writer.write(packageName);
|
buffer.append(packageName);
|
||||||
writer.write(";");
|
buffer.append(";");
|
||||||
writer.write(DecompilerContext.getNewLineSeparator());
|
buffer.append(lineSeparator);
|
||||||
writer.write(DecompilerContext.getNewLineSeparator());
|
buffer.append(lineSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS_NODE, root);
|
if (importCollector.writeImports(buffer)) {
|
||||||
|
buffer.append(lineSeparator);
|
||||||
|
}
|
||||||
|
|
||||||
DecompilerContext.getImportCollector().writeImports(writer);
|
buffer.append(classBuffer);
|
||||||
writer.write(DecompilerContext.getNewLineSeparator());
|
|
||||||
|
|
||||||
writer.write(strwriter.toString());
|
|
||||||
writer.flush();
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
destroyWrappers(root);
|
destroyWrappers(root);
|
||||||
@ -327,7 +318,7 @@ public class ClassesProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, ClassNode> getMapRootClasses() {
|
public Map<String, ClassNode> getMapRootClasses() {
|
||||||
return mapRootClasses;
|
return mapRootClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +360,7 @@ public class ClassesProcessor {
|
|||||||
public ClassNode(String content_class_name,
|
public ClassNode(String content_class_name,
|
||||||
String content_method_name,
|
String content_method_name,
|
||||||
String content_method_descriptor,
|
String content_method_descriptor,
|
||||||
int content_method_invokation_type,
|
int content_method_invocation_type,
|
||||||
String lambda_class_name,
|
String lambda_class_name,
|
||||||
String lambda_method_name,
|
String lambda_method_name,
|
||||||
String lambda_method_descriptor,
|
String lambda_method_descriptor,
|
||||||
@ -386,7 +377,7 @@ public class ClassesProcessor {
|
|||||||
lambda_information.content_class_name = content_class_name;
|
lambda_information.content_class_name = content_class_name;
|
||||||
lambda_information.content_method_name = content_method_name;
|
lambda_information.content_method_name = content_method_name;
|
||||||
lambda_information.content_method_descriptor = content_method_descriptor;
|
lambda_information.content_method_descriptor = content_method_descriptor;
|
||||||
lambda_information.content_method_invokation_type = content_method_invokation_type;
|
lambda_information.content_method_invocation_type = content_method_invocation_type;
|
||||||
|
|
||||||
lambda_information.content_method_key =
|
lambda_information.content_method_key =
|
||||||
InterpreterUtil.makeUniqueKey(lambda_information.content_method_name, lambda_information.content_method_descriptor);
|
InterpreterUtil.makeUniqueKey(lambda_information.content_method_name, lambda_information.content_method_descriptor);
|
||||||
@ -401,7 +392,7 @@ public class ClassesProcessor {
|
|||||||
|
|
||||||
lambda_information.is_method_reference = is_method_reference;
|
lambda_information.is_method_reference = is_method_reference;
|
||||||
lambda_information.is_content_method_static =
|
lambda_information.is_content_method_static =
|
||||||
(lambda_information.content_method_invokation_type == CodeConstants.CONSTANT_MethodHandle_REF_invokeStatic); // FIXME: redundant?
|
(lambda_information.content_method_invocation_type == CodeConstants.CONSTANT_MethodHandle_REF_invokeStatic); // FIXME: redundant?
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassNode(int type, StructClass classStruct) {
|
public ClassNode(int type, StructClass classStruct) {
|
||||||
@ -428,7 +419,7 @@ public class ClassesProcessor {
|
|||||||
public String content_class_name;
|
public String content_class_name;
|
||||||
public String content_method_name;
|
public String content_method_name;
|
||||||
public String content_method_descriptor;
|
public String content_method_descriptor;
|
||||||
public int content_method_invokation_type; // values from CONSTANT_MethodHandle_REF_*
|
public int content_method_invocation_type; // values from CONSTANT_MethodHandle_REF_*
|
||||||
|
|
||||||
public String content_method_key;
|
public String content_method_key;
|
||||||
|
|
||||||
|
@ -26,8 +26,6 @@ import org.jetbrains.java.decompiler.struct.StructClass;
|
|||||||
import org.jetbrains.java.decompiler.struct.StructContext;
|
import org.jetbrains.java.decompiler.struct.StructContext;
|
||||||
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader;
|
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@ -81,9 +79,9 @@ public class Fernflower implements IDecompiledData {
|
|||||||
|
|
||||||
public String getClassContent(StructClass cl) {
|
public String getClassContent(StructClass cl) {
|
||||||
try {
|
try {
|
||||||
StringWriter writer = new StringWriter();
|
StringBuilder buffer = new StringBuilder();
|
||||||
classesProcessor.writeClass(cl, new BufferedWriter(writer));
|
classesProcessor.writeClass(cl, buffer);
|
||||||
return writer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
DecompilerContext.getLogger().writeMessage("Class " + cl.qualifiedName + " couldn't be fully decompiled.", ex);
|
DecompilerContext.getLogger().writeMessage("Class " + cl.qualifiedName + " couldn't be fully decompiled.", ex);
|
||||||
|
@ -20,8 +20,6 @@ import org.jetbrains.java.decompiler.main.ClassesProcessor.ClassNode;
|
|||||||
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
||||||
import org.jetbrains.java.decompiler.struct.StructContext;
|
import org.jetbrains.java.decompiler.struct.StructContext;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@ -30,12 +28,9 @@ public class ImportCollector {
|
|||||||
|
|
||||||
private static final String JAVA_LANG_PACKAGE = "java.lang";
|
private static final String JAVA_LANG_PACKAGE = "java.lang";
|
||||||
|
|
||||||
private HashMap<String, String> mapSimpleNames = new HashMap<String, String>();
|
private Map<String, String> mapSimpleNames = new HashMap<String, String>();
|
||||||
|
private Set<String> setNotImportedNames = new HashSet<String>();
|
||||||
private HashSet<String> setNotImportedNames = new HashSet<String>();
|
|
||||||
|
|
||||||
private String currentPackageSlash = "";
|
private String currentPackageSlash = "";
|
||||||
|
|
||||||
private String currentPackagePoint = "";
|
private String currentPackagePoint = "";
|
||||||
|
|
||||||
public ImportCollector(ClassNode root) {
|
public ImportCollector(ClassNode root) {
|
||||||
@ -77,7 +72,7 @@ public class ImportCollector {
|
|||||||
return retname;
|
return retname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node == null || !node.classStruct.isOwn()) {
|
else {
|
||||||
fullname = fullname.replace('$', '.');
|
fullname = fullname.replace('$', '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,18 +107,20 @@ public class ImportCollector {
|
|||||||
return retname == null ? nshort : retname;
|
return retname == null ? nshort : retname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeImports(BufferedWriter writer) throws IOException {
|
public boolean writeImports(StringBuilder buffer) {
|
||||||
|
List<String> imports = packImports();
|
||||||
|
|
||||||
for (String s : packImports()) {
|
for (String s : imports) {
|
||||||
writer.write("import ");
|
buffer.append("import ");
|
||||||
writer.write(s);
|
buffer.append(s);
|
||||||
writer.write(";");
|
buffer.append(";");
|
||||||
writer.write(DecompilerContext.getNewLineSeparator());
|
buffer.append(DecompilerContext.getNewLineSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return imports.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> packImports() {
|
private List<String> packImports() {
|
||||||
|
|
||||||
List<Entry<String, String>> lst = new ArrayList<Entry<String, String>>(mapSimpleNames.entrySet());
|
List<Entry<String, String>> lst = new ArrayList<Entry<String, String>>(mapSimpleNames.entrySet());
|
||||||
|
|
||||||
Collections.sort(lst, new Comparator<Entry<String, String>>() {
|
Collections.sort(lst, new Comparator<Entry<String, String>>() {
|
||||||
@ -138,12 +135,11 @@ public class ImportCollector {
|
|||||||
|
|
||||||
List<String> res = new ArrayList<String>();
|
List<String> res = new ArrayList<String>();
|
||||||
for (Entry<String, String> ent : lst) {
|
for (Entry<String, String> ent : lst) {
|
||||||
if (!setNotImportedNames.contains(ent.getKey()) // not the current class or one of the nested ones. Also not the empty package.
|
// exclude a current class or one of the nested ones, java.lang and empty packages
|
||||||
&& !JAVA_LANG_PACKAGE.equals(ent.getValue())
|
if (!setNotImportedNames.contains(ent.getKey()) &&
|
||||||
&& ent.getValue().length() > 0) {
|
!JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
|
||||||
|
!ent.getValue().isEmpty()) {
|
||||||
String imp = ent.getValue() + "." + ent.getKey();
|
res.add(ent.getValue() + "." + ent.getKey());
|
||||||
res.add(imp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,9 +28,6 @@ import org.jetbrains.java.decompiler.struct.gen.VarType;
|
|||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
import org.jetbrains.java.decompiler.util.ListStack;
|
import org.jetbrains.java.decompiler.util.ListStack;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -260,29 +257,16 @@ public class NewExprent extends Exprent {
|
|||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringWriter strwriter = new StringWriter();
|
if (lambda) {
|
||||||
BufferedWriter bufstrwriter = new BufferedWriter(strwriter);
|
if (!DecompilerContext.getOption(IFernflowerPreferences.LAMBDA_TO_ANONYMOUS_CLASS)) {
|
||||||
|
buf.setLength(0); // remove the usual 'new <class>()', it will be replaced with lambda style '() ->'
|
||||||
ClassWriter clwriter = new ClassWriter();
|
|
||||||
try {
|
|
||||||
if (lambda) {
|
|
||||||
clwriter.classLambdaToJava(child, bufstrwriter, (constructor == null ? null : constructor.getInstance()), indent);
|
|
||||||
}
|
}
|
||||||
else {
|
Exprent methodObject = constructor == null ? null : constructor.getInstance();
|
||||||
clwriter.classToJava(child, bufstrwriter, indent);
|
new ClassWriter().classLambdaToJava(child, buf, methodObject, indent);
|
||||||
}
|
|
||||||
bufstrwriter.flush();
|
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
else {
|
||||||
throw new RuntimeException(ex);
|
new ClassWriter().classToJava(child, buf, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lambda && !DecompilerContext.getOption(IFernflowerPreferences.LAMBDA_TO_ANONYMOUS_CLASS)) {
|
|
||||||
buf.setLength(0); // remove the usual 'new <class>()', it will
|
|
||||||
// be replaced with lambda style '() ->'
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.append(strwriter.toString());
|
|
||||||
}
|
}
|
||||||
else if (directArrayInit) {
|
else if (directArrayInit) {
|
||||||
VarType leftType = newtype.copy();
|
VarType leftType = newtype.copy();
|
||||||
@ -293,10 +277,7 @@ public class NewExprent extends Exprent {
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
}
|
}
|
||||||
StringBuilder buff = new StringBuilder();
|
ExprProcessor.getCastedExprent(lstArrayElements.get(i), leftType, buf, indent, false);
|
||||||
ExprProcessor.getCastedExprent(lstArrayElements.get(i), leftType, buff, indent, false);
|
|
||||||
|
|
||||||
buf.append(buff);
|
|
||||||
}
|
}
|
||||||
buf.append("}");
|
buf.append("}");
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPaar;
|
|||||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -84,24 +81,11 @@ public class VarExprent extends Exprent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toJava(int indent) {
|
public String toJava(int indent) {
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
if (classdef) {
|
if (classdef) {
|
||||||
|
|
||||||
ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(vartype.value);
|
ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(vartype.value);
|
||||||
|
new ClassWriter().classToJava(child, buffer, indent);
|
||||||
StringWriter strwriter = new StringWriter();
|
|
||||||
BufferedWriter bufstrwriter = new BufferedWriter(strwriter);
|
|
||||||
|
|
||||||
ClassWriter clwriter = new ClassWriter();
|
|
||||||
try {
|
|
||||||
clwriter.classToJava(child, bufstrwriter, indent);
|
|
||||||
bufstrwriter.flush();
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return strwriter.toString();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String name = null;
|
String name = null;
|
||||||
@ -109,18 +93,16 @@ public class VarExprent extends Exprent {
|
|||||||
name = processor.getVarName(new VarVersionPaar(index, version));
|
name = processor.getVarName(new VarVersionPaar(index, version));
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
|
|
||||||
if (definition) {
|
if (definition) {
|
||||||
if (processor != null && processor.getVarFinal(new VarVersionPaar(index, version)) == VarTypeProcessor.VAR_FINALEXPLICIT) {
|
if (processor != null && processor.getVarFinal(new VarVersionPaar(index, version)) == VarTypeProcessor.VAR_FINALEXPLICIT) {
|
||||||
buf.append("final ");
|
buffer.append("final ");
|
||||||
}
|
}
|
||||||
buf.append(ExprProcessor.getCastTypeName(getVartype())).append(" ");
|
buffer.append(ExprProcessor.getCastTypeName(getVartype())).append(" ");
|
||||||
}
|
}
|
||||||
buf.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name);
|
buffer.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name);
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
@ -60,14 +60,18 @@ public class InterpreterUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getIndentString(int length) {
|
public static String getIndentString(int length) {
|
||||||
String indent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING);
|
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
while (length-- > 0) {
|
appendIndent(buf, length);
|
||||||
buf.append(indent);
|
|
||||||
}
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void appendIndent(StringBuilder buffer, int length) {
|
||||||
|
String indent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING);
|
||||||
|
while (length-- > 0) {
|
||||||
|
buffer.append(indent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean equalSets(Collection<?> c1, Collection<?> c2) {
|
public static boolean equalSets(Collection<?> c1, Collection<?> c2) {
|
||||||
if (c1 == null) {
|
if (c1 == null) {
|
||||||
return c2 == null;
|
return c2 == null;
|
||||||
|
@ -28,11 +28,17 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class SingleClassesTest {
|
public class SingleClassesTest {
|
||||||
|
private File testDataDir;
|
||||||
private File tempDir;
|
private File tempDir;
|
||||||
private ConsoleDecompiler decompiler;
|
private ConsoleDecompiler decompiler;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
|
testDataDir = new File("testData");
|
||||||
|
if (!isTestDataDir(testDataDir)) testDataDir = new File("community/plugins/java-decompiler/engine/testData");
|
||||||
|
if (!isTestDataDir(testDataDir)) testDataDir = new File("plugins/java-decompiler/engine/testData");
|
||||||
|
assertTrue(isTestDataDir(testDataDir));
|
||||||
|
|
||||||
//noinspection SSBasedInspection
|
//noinspection SSBasedInspection
|
||||||
tempDir = File.createTempFile("decompiler_test_", "_dir");
|
tempDir = File.createTempFile("decompiler_test_", "_dir");
|
||||||
assertTrue(tempDir.delete());
|
assertTrue(tempDir.delete());
|
||||||
@ -52,6 +58,7 @@ public class SingleClassesTest {
|
|||||||
decompiler = null;
|
decompiler = null;
|
||||||
delete(tempDir);
|
delete(tempDir);
|
||||||
tempDir = null;
|
tempDir = null;
|
||||||
|
testDataDir = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testClassFields() { doTest("TestClassFields"); }
|
@Test public void testClassFields() { doTest("TestClassFields"); }
|
||||||
@ -69,13 +76,9 @@ public class SingleClassesTest {
|
|||||||
|
|
||||||
private void doTest(final String testName) {
|
private void doTest(final String testName) {
|
||||||
try {
|
try {
|
||||||
File testDataDir = new File("testData");
|
|
||||||
if (!isTestDataDir(testDataDir)) testDataDir = new File("community/plugins/java-decompiler/engine/testData");
|
|
||||||
if (!isTestDataDir(testDataDir)) testDataDir = new File("plugins/java-decompiler/engine/testData");
|
|
||||||
assertTrue(isTestDataDir(testDataDir));
|
|
||||||
|
|
||||||
File classFile = new File(testDataDir, "/classes/pkg/" + testName + ".class");
|
File classFile = new File(testDataDir, "/classes/pkg/" + testName + ".class");
|
||||||
assertTrue(classFile.isFile());
|
assertTrue(classFile.isFile());
|
||||||
|
|
||||||
decompiler.addSpace(classFile, true);
|
decompiler.addSpace(classFile, true);
|
||||||
File[] innerClasses = classFile.getParentFile().listFiles(new FilenameFilter() {
|
File[] innerClasses = classFile.getParentFile().listFiles(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public class TestClassFields {
|
public class TestClassFields {
|
||||||
|
|
||||||
private static int[] sizes;
|
private static int[] sizes;
|
||||||
private static String[] names = new String[]{"name1", "name2"};
|
private static String[] names = new String[]{"name1", "name2"};
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
sizes = new int[names.length];
|
sizes = new int[names.length];
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,8 @@ import java.util.function.Predicate;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class TestClassLambda {
|
public class TestClassLambda {
|
||||||
|
|
||||||
public int field = 0;
|
public int field = 0;
|
||||||
|
|
||||||
|
|
||||||
public void testLambda() {
|
public void testLambda() {
|
||||||
List var1 = Arrays.asList(new Integer[]{Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7)});
|
List var1 = Arrays.asList(new Integer[]{Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7)});
|
||||||
int var2 = (int)Math.random();
|
int var2 = (int)Math.random();
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public class TestClassLoop {
|
public class TestClassLoop {
|
||||||
|
|
||||||
public static void testSimpleInfinite() {
|
public static void testSimpleInfinite() {
|
||||||
while(true) {
|
while(true) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public class TestClassSwitch {
|
public class TestClassSwitch {
|
||||||
|
|
||||||
public void testCaseOrder(int var1) {
|
public void testCaseOrder(int var1) {
|
||||||
switch(var1) {
|
switch(var1) {
|
||||||
case 5:
|
case 5:
|
||||||
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TestClassTypes {
|
public class TestClassTypes {
|
||||||
|
|
||||||
public void testBoolean() {
|
public void testBoolean() {
|
||||||
byte var1 = 0;
|
byte var1 = 0;
|
||||||
long var2 = System.currentTimeMillis();
|
long var2 = System.currentTimeMillis();
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public class TestClassVar {
|
public class TestClassVar {
|
||||||
|
|
||||||
private boolean field_boolean = Math.random() > 0.0D;
|
private boolean field_boolean = Math.random() > 0.0D;
|
||||||
public int field_int = 0;
|
public int field_int = 0;
|
||||||
|
|
||||||
|
|
||||||
public void testFieldSSAU() {
|
public void testFieldSSAU() {
|
||||||
for(int var1 = 0; var1 < 10; ++var1) {
|
for(int var1 = 0; var1 < 10; ++var1) {
|
||||||
try {
|
try {
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
class TestCodeConstructs {
|
class TestCodeConstructs {
|
||||||
|
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
|
|
||||||
void expressions() {
|
void expressions() {
|
||||||
(new String()).hashCode();
|
(new String()).hashCode();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package pkg;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class TestConstants {
|
public class TestConstants {
|
||||||
|
|
||||||
static final boolean T = true;
|
static final boolean T = true;
|
||||||
static final boolean F = false;
|
static final boolean F = false;
|
||||||
static final char C0 = '\n';
|
static final char C0 = '\n';
|
||||||
@ -28,7 +27,6 @@ public class TestConstants {
|
|||||||
static final double DMin = 4.9E-324D;
|
static final double DMin = 4.9E-324D;
|
||||||
static final double DMax = 1.7976931348623157E308D;
|
static final double DMax = 1.7976931348623157E308D;
|
||||||
|
|
||||||
|
|
||||||
@TestConstants.A(byte.class)
|
@TestConstants.A(byte.class)
|
||||||
void m1() {
|
void m1() {
|
||||||
}
|
}
|
||||||
@ -70,7 +68,6 @@ public class TestConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@interface A {
|
@interface A {
|
||||||
|
|
||||||
Class<?> value();
|
Class<?> value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public class TestDeprecations {
|
public class TestDeprecations {
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
public int byComment;
|
public int byComment;
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int byAnno;
|
public int byAnno;
|
||||||
|
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
public void byComment() {
|
public void byComment() {
|
||||||
}
|
}
|
||||||
@ -22,11 +19,9 @@ public class TestDeprecations {
|
|||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static class ByAnno {
|
public static class ByAnno {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
public static class ByComment {
|
public static class ByComment {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public enum TestEnum {
|
public enum TestEnum {
|
||||||
|
|
||||||
E1,
|
E1,
|
||||||
E2 {
|
E2 {
|
||||||
public void m() {
|
public void m() {
|
||||||
@ -13,8 +11,8 @@ public enum TestEnum {
|
|||||||
public void m() {
|
public void m() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private String s;
|
|
||||||
|
|
||||||
|
private String s;
|
||||||
|
|
||||||
public void m() {
|
public void m() {
|
||||||
}
|
}
|
||||||
@ -26,5 +24,4 @@ public enum TestEnum {
|
|||||||
private TestEnum(@Deprecated String var3) {
|
private TestEnum(@Deprecated String var3) {
|
||||||
this.s = var3;
|
this.s = var3;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public class TestExtendsList {
|
public class TestExtendsList {
|
||||||
|
|
||||||
static <T extends Comparable<? super T>> T m1(T var0) {
|
static <T extends Comparable<? super T>> T m1(T var0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package pkg;
|
package pkg;
|
||||||
|
|
||||||
|
|
||||||
public class TestMethodParameters {
|
public class TestMethodParameters {
|
||||||
|
|
||||||
TestMethodParameters(@Deprecated int var1) {
|
TestMethodParameters(@Deprecated int var1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +12,6 @@ public class TestMethodParameters {
|
|||||||
|
|
||||||
void local() {
|
void local() {
|
||||||
class Local {
|
class Local {
|
||||||
|
|
||||||
Local(@Deprecated int var2) {
|
Local(@Deprecated int var2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +22,6 @@ public class TestMethodParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class C2 {
|
static class C2 {
|
||||||
|
|
||||||
C2(@Deprecated int var1) {
|
C2(@Deprecated int var1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +33,6 @@ public class TestMethodParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class C1 {
|
class C1 {
|
||||||
|
|
||||||
C1(@Deprecated int var2) {
|
C1(@Deprecated int var2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user