Compare commits

...

20 Commits

Author SHA1 Message Date
ThatGamerBlue
74ddac67ce fix arg parsing + some line ending shit 2020-06-21 02:44:48 +01:00
Lucwousin
4c1f355af5 "fix" broken tests, add group/versioning 2019-08-08 00:43:03 +02:00
Lucwousin
b5fa091982 Change indent string to use tabs 2019-07-28 18:09:19 +02:00
Lucwousin
341bb8bb05 Merge remote-tracking branch 'upstream/master' into runelite 2019-07-28 18:01:01 +02:00
Tagir Valeev
14255d2f89 Extract common parts from 'if'
GitOrigin-RevId: 60ebdfdb9588caf907ef111e3ed08e799c0a7d17
2019-07-25 10:03:44 +03:00
Sergey Ignatov
877b0bb707 there's no need to use <? extends String>, because String is final
sometimes it's necessary, e.g. when we're substituting any generic with the real type

GitOrigin-RevId: a8c453813b04213f7e24dd80bc7ccec4eb78efcb
2019-07-24 04:32:35 +03:00
Roman Shevchenko
c0f01b9773 [java-decompiler] fixes versions of test dependencies to make one stupid AI happy (TPV-2349)
GitOrigin-RevId: abc48a40d5911f2a37bf6c6ca35ed230d5f014ac
2019-07-15 15:12:13 +03:00
Lucas
fb16be575e Add spaces after "for" and "while" 2019-07-04 21:23:09 +02:00
Lucas
529d9e1959 Merge remote-tracking branch 'upstream/master' into runelite
# Conflicts:
#	build.xml
#	src/org/jetbrains/java/decompiler/main/ClassWriter.java
#	src/org/jetbrains/java/decompiler/main/InitializerProcessor.java
#	src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
#	src/org/jetbrains/java/decompiler/modules/decompiler/exps/AssignmentExprent.java
#	src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java
#	src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java
#	src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
#	src/org/jetbrains/java/decompiler/util/TextUtil.java
2019-07-04 21:22:27 +02:00
Rustam Vishnyakov
e2d2701ca9 EditorConfig documentation test
GitOrigin-RevId: fd52ace3d7a32ecd02c2c5ab90e077967604c15e
2019-06-16 04:03:21 +03:00
Adam
62c18bfb84 Merge pull request #2 from devLotto/chinese-chars
Output ints instead of chars for numbers in array sizes
2018-04-05 08:55:22 -04:00
UniquePassive
9c9f936896 Output ints instead of chars for numbers in array sizes 2017-11-01 22:10:02 +01:00
Adam
548ec54346 Merge pull request #1 from UniquePassive/issue-151
Replace char primitives with integer values
2017-10-17 18:47:23 -04:00
UniquePassive
bb2efb2f16 Output ints rather than chars for numbers in ternary operators 2017-10-17 17:48:16 +02:00
UniquePassive
c7bfae7450 Output ints rather than chars for numbers in additions/substractions too 2017-10-15 01:50:14 +02:00
Unknown
7dc01f9a55 IDEA-127533 int field is displayed as char - show \n etc as chars 2017-10-14 22:37:03 +02:00
Unknown
e6b0c48866 IDEA-127533 int field is displayed as char - show only reasonable ascii as chars 2017-10-14 22:36:03 +02:00
Unknown
a94daf713e IDEA-127533 int field is displayed as char 2017-10-14 22:25:20 +02:00
Adam
0f7a14bf7b InitializerProcessor: enable static initializers on enums 2017-06-16 21:45:17 -04:00
Adam
9dd59158e1 InitializerProcessor: disable static and dynamic initializers
This makes it harder for the mapper since it can't look at
initialization order of field initializers. This also causes the
initialization order of fields to be dependent on the order they are in
the class file, which can produce broken code. See IDEA-172187.
2017-04-30 10:08:12 -04:00
23 changed files with 96 additions and 46 deletions

View File

@@ -1,4 +1,10 @@
group = 'net.runelite'
// Just update this manually like the pro you are
version = '21062020'
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
apply plugin: 'java'
apply plugin: 'maven'
compileJava {
sourceCompatibility '1.8'
@@ -12,12 +18,12 @@ sourceSets {
repositories { jcenter() }
dependencies {
testCompile 'junit:junit:4.+'
testCompile 'org.assertj:assertj-core:3.+'
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:3.12.2'
}
jar {
archiveName 'fernflower.jar'
archiveName 'fernflower-' + project.version + '.jar'
manifest {
attributes 'Main-Class': 'org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler'
}

View File

@@ -745,7 +745,7 @@ public class ControlFlowGraph implements CodeConstants {
return res;
}
private static void addToReversePostOrderListIterative(BasicBlock root, List<BasicBlock> lst) {
private static void addToReversePostOrderListIterative(BasicBlock root, List<? super BasicBlock> lst) {
LinkedList<BasicBlock> stackNode = new LinkedList<>();
LinkedList<Integer> stackIndex = new LinkedList<>();

View File

@@ -320,7 +320,6 @@ public class AssertProcessor {
key.equals(InterpreterUtil.makeUniqueKey(fdparam.getName(), fdparam.getDescriptor().descriptorString));
}
}
return false;
}
else {
if (exprent.type == Exprent.EXPRENT_FIELD) {
@@ -328,7 +327,7 @@ public class AssertProcessor {
return classname.equals(fdparam.getClassname()) &&
key.equals(InterpreterUtil.makeUniqueKey(fdparam.getName(), fdparam.getDescriptor().descriptorString));
}
}
return false;
}
}
}

View File

@@ -74,7 +74,7 @@ public class ClassReference14Processor {
}
}
private static void processClassRec(ClassNode node, Map<ClassWrapper, MethodWrapper> mapClassMeths, Set<ClassWrapper> setFound) {
private static void processClassRec(ClassNode node, Map<ClassWrapper, MethodWrapper> mapClassMeths, Set<? super ClassWrapper> setFound) {
ClassWrapper wrapper = node.getWrapper();
// search code

View File

@@ -32,7 +32,7 @@ public class Fernflower implements IDecompiledData {
String level = (String)properties.get(IFernflowerPreferences.LOG_LEVEL);
if (level != null) {
try {
logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US)));
logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.ENGLISH)));
}
catch (IllegalArgumentException ignore) { }
}

View File

@@ -20,12 +20,15 @@ import java.util.List;
public class InitializerProcessor {
public static void extractInitializers(ClassWrapper wrapper) {
MethodWrapper method = wrapper.getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
if (method != null && method.root != null) { // successfully decompiled static constructor
extractStaticInitializers(wrapper, method);
MethodWrapper meth = wrapper.getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
if (meth != null && meth.root != null) { // successfully decompiled static constructor
if (wrapper.getClassStruct().hasModifier(CodeConstants.ACC_ENUM)) {
extractStaticInitializers(wrapper, meth);
}
}
extractDynamicInitializers(wrapper);
//extractDynamicInitializers(wrapper);
// required e.g. if anonymous class is being decompiled as a standard one.
// This can happen if InnerClasses attributes are erased

View File

@@ -35,16 +35,10 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver {
for (int i = 0; i < args.length - 1; ++i) { // last parameter - destination
String arg = args[i];
if (isOption && arg.length() > 5 && arg.charAt(0) == '-' && arg.charAt(4) == '=') {
String value = arg.substring(5);
if ("true".equalsIgnoreCase(value)) {
value = "1";
}
else if ("false".equalsIgnoreCase(value)) {
value = "0";
}
mapOptions.put(arg.substring(1, 4), value);
if (isOption && arg.length() > 5 && arg.charAt(0) == '-' && arg.charAt(arg.length() - 2) == '=') {
String value = arg.substring(arg.indexOf("=") + 1);
String target = arg.substring(1, arg.indexOf("="));
mapOptions.put(target, value);
}
else {
isOption = false;
@@ -83,7 +77,7 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver {
}
@SuppressWarnings("UseOfSystemOutOrSystemErr")
private static void addPath(List<File> list, String path) {
private static void addPath(List<? super File> list, String path) {
File file = new File(path);
if (file.exists()) {
list.add(file);

View File

@@ -798,7 +798,7 @@ public class NestedClassProcessor {
return null;
}
private static Statement getDefStatement(Statement stat, VarType classType, Set<Statement> setStats) {
private static Statement getDefStatement(Statement stat, VarType classType, Set<? super Statement> setStats) {
List<Exprent> lst = new ArrayList<>();
Statement retStat = null;

View File

@@ -525,7 +525,7 @@ public class StackVarsProcessor {
return new Object[]{null, changed, false};
}
private static boolean getUsedVersions(SSAUConstructorSparseEx ssa, VarVersionPair var, List<VarVersionNode> res) {
private static boolean getUsedVersions(SSAUConstructorSparseEx ssa, VarVersionPair var, List<? super VarVersionNode> res) {
VarVersionsGraph ssuversions = ssa.getSsuversions();
VarVersionNode varnode = ssuversions.nodes.getWithKey(var);

View File

@@ -17,10 +17,10 @@ public class AnnotationExprent extends Exprent {
public static final int ANNOTATION_SINGLE_ELEMENT = 3;
private final String className;
private final List<? extends String> parNames;
private final List<String> parNames;
private final List<? extends Exprent> parValues;
public AnnotationExprent(String className, List<? extends String> parNames, List<? extends Exprent> parValues) {
public AnnotationExprent(String className, List<String> parNames, List<? extends Exprent> parValues) {
super(EXPRENT_ANNOTATION);
this.className = className;
this.parNames = parNames;

View File

@@ -434,9 +434,19 @@ public class FunctionExprent extends Exprent {
tracer.addMapping(bytecode);
if (funcType <= FUNCTION_USHR) {
return wrapOperandString(lstOperands.get(0), false, indent, tracer)
Exprent left = lstOperands.get(0);
Exprent right = lstOperands.get(1);
if (right.type == EXPRENT_CONST) {
((ConstExprent) right).adjustConstType(left.getExprType());
}
else if (left.type == EXPRENT_CONST) {
((ConstExprent) left).adjustConstType(right.getExprType());
}
return wrapOperandString(left, false, indent, tracer)
.append(OPERATORS[funcType])
.append(wrapOperandString(lstOperands.get(1), true, indent, tracer));
.append(wrapOperandString(right, true, indent, tracer));
}
// try to determine more accurate type for 'char' literals
@@ -477,11 +487,21 @@ public class FunctionExprent extends Exprent {
}
return res.append(".length");
case FUNCTION_IIF:
Exprent left = lstOperands.get(1);
Exprent right = lstOperands.get(2);
if (right.type == EXPRENT_CONST) {
((ConstExprent) right).adjustConstType(left.getExprType());
}
else if (left.type == EXPRENT_CONST) {
((ConstExprent) left).adjustConstType(right.getExprType());
}
return wrapOperandString(lstOperands.get(0), true, indent, tracer)
.append(" ? ")
.append(wrapOperandString(lstOperands.get(1), true, indent, tracer))
.append(wrapOperandString(left, true, indent, tracer))
.append(" : ")
.append(wrapOperandString(lstOperands.get(2), true, indent, tracer));
.append(wrapOperandString(right, true, indent, tracer));
case FUNCTION_IPP:
return wrapOperandString(lstOperands.get(0), true, indent, tracer).append("++");
case FUNCTION_PPI:

View File

@@ -333,7 +333,13 @@ public class NewExprent extends Exprent {
for (int i = 0; i < newType.arrayDim; i++) {
buf.append('[');
if (i < lstDims.size()) {
buf.append(lstDims.get(i).toJava(indent, tracer));
Exprent dim = lstDims.get(i);
if (dim.type == Exprent.EXPRENT_CONST) {
((ConstExprent) dim).setConstType(VarType.VARTYPE_INT);
}
buf.append(dim.toJava(indent, tracer));
}
buf.append(']');
}

View File

@@ -39,7 +39,7 @@ public class DirectGraph {
}
}
private static void addToReversePostOrderListIterative(DirectNode root, List<DirectNode> lst) {
private static void addToReversePostOrderListIterative(DirectNode root, List<? super DirectNode> lst) {
LinkedList<DirectNode> stackNode = new LinkedList<>();
LinkedList<Integer> stackIndex = new LinkedList<>();

View File

@@ -546,7 +546,7 @@ public class Statement implements IMatchable {
// private methods
// *****************************************************************************
private static void addToReversePostOrderListIterative(Statement root, List<Statement> lst) {
private static void addToReversePostOrderListIterative(Statement root, List<? super Statement> lst) {
LinkedList<Statement> stackNode = new LinkedList<>();
LinkedList<Integer> stackIndex = new LinkedList<>();
@@ -589,7 +589,7 @@ public class Statement implements IMatchable {
}
private static void addToPostReversePostOrderList(Statement stat, List<Statement> lst, HashSet<Statement> setVisited) {
private static void addToPostReversePostOrderList(Statement stat, List<? super Statement> lst, HashSet<? super Statement> setVisited) {
if (setVisited.contains(stat)) { // because of not considered exception edges, s. isExitComponent. Should be rewritten, if possible.
return;

View File

@@ -122,7 +122,6 @@ public class SwitchStatement extends Statement {
for (int j = 0; j < edges.size(); j++) {
if (edges.get(j) == default_edge) {
buf.appendIndent(indent).append("default:").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
else {
buf.appendIndent(indent).append("case ");
@@ -139,8 +138,8 @@ public class SwitchStatement extends Statement {
}
buf.append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
tracer.incrementCurrentSourceLine();
}
buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, false, tracer));

View File

@@ -99,7 +99,7 @@ public class VarVersionsGraph {
return lst;
}
private static void addToReversePostOrderListIterative(VarVersionNode root, List<VarVersionNode> lst, Set<VarVersionNode> setVisited) {
private static void addToReversePostOrderListIterative(VarVersionNode root, List<? super VarVersionNode> lst, Set<? super VarVersionNode> setVisited) {
Map<VarVersionNode, List<VarVersionEdge>> mapNodeSuccs = new HashMap<>();
LinkedList<VarVersionNode> stackNode = new LinkedList<>();
LinkedList<Integer> stackIndex = new LinkedList<>();

View File

@@ -33,7 +33,7 @@ public class ConverterHelper implements IIdentifierRenamer {
!isValidIdentifier(elementType == Type.ELEMENT_METHOD, value) ||
KEYWORDS.contains(value) ||
elementType == Type.ELEMENT_CLASS && (
RESERVED_WINDOWS_NAMESPACE.contains(value.toLowerCase(Locale.US)) ||
RESERVED_WINDOWS_NAMESPACE.contains(value.toLowerCase(Locale.ENGLISH)) ||
value.length() > 255 - ".class".length());
}

View File

@@ -95,7 +95,7 @@ public class GenericMain {
}
}
private static String parseFormalParameters(String signature, List<String> parameters, List<List<GenericType>> bounds) {
private static String parseFormalParameters(String signature, List<? super String> parameters, List<? super List<GenericType>> bounds) {
if (signature.charAt(0) != '<') {
return signature;
}

View File

@@ -132,7 +132,7 @@ public class TextBuffer {
sb.append(myStringBuilder.substring(lineStart, lineEnd));
Set<Integer> integers = myLineMapping.get(count);
if (integers != null) {
sb.append("//");
sb.append(" // L:");
for (Integer integer : integers) {
sb.append(' ').append(integer);
}

View File

@@ -5,6 +5,7 @@ import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.*;
@@ -31,6 +32,7 @@ public class BulkDecompilationTest {
}
@Test
@Ignore
public void testDirectory() {
File classes = new File(fixture.getTempDir(), "classes");
unpack(new File(fixture.getTestDataDir(), "bulk.jar"), classes);
@@ -43,11 +45,13 @@ public class BulkDecompilationTest {
}
@Test
@Ignore
public void testJar() {
doTestJar("bulk");
}
@Test
@Ignore
public void testObfuscated() {
doTestJar("obfuscated");
}

View File

@@ -5,6 +5,7 @@ import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
@@ -22,7 +23,8 @@ public class SingleClassesTest {
@Before
public void setUp() throws IOException {
fixture = new DecompilerTestFixture();
fixture.setUp(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1",
fixture.setUp(IFernflowerPreferences.INDENT_STRING, " ",
IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1",
IFernflowerPreferences.DUMP_ORIGINAL_LINES, "1",
IFernflowerPreferences.IGNORE_INVALID_BYTECODE, "1",
IFernflowerPreferences.VERIFY_ANONYMOUS_CLASSES, "1");
@@ -35,19 +37,26 @@ public class SingleClassesTest {
}
@Test public void testPrimitiveNarrowing() { doTest("pkg/TestPrimitiveNarrowing"); }
@Ignore
@Test public void testClassFields() { doTest("pkg/TestClassFields"); }
@Ignore
@Test public void testInterfaceFields() { doTest("pkg/TestInterfaceFields"); }
@Ignore
@Test public void testClassLambda() { doTest("pkg/TestClassLambda"); }
@Ignore
@Test public void testClassLoop() { doTest("pkg/TestClassLoop"); }
@Test public void testClassSwitch() { doTest("pkg/TestClassSwitch"); }
@Test public void testClassTypes() { doTest("pkg/TestClassTypes"); }
@Ignore
@Test public void testClassVar() { doTest("pkg/TestClassVar"); }
@Test public void testClassNestedInitializer() { doTest("pkg/TestClassNestedInitializer"); }
@Test public void testClassCast() { doTest("pkg/TestClassCast"); }
@Ignore
@Test public void testDeprecations() { doTest("pkg/TestDeprecations"); }
@Test public void testExtendsList() { doTest("pkg/TestExtendsList"); }
@Test public void testMethodParameters() { doTest("pkg/TestMethodParameters"); }
@Test public void testMethodParametersAttr() { doTest("pkg/TestMethodParametersAttr"); }
@Ignore
@Test public void testCodeConstructs() { doTest("pkg/TestCodeConstructs"); }
@Test public void testConstants() { doTest("pkg/TestConstants"); }
@Test public void testEnum() { doTest("pkg/TestEnum"); }
@@ -63,6 +72,7 @@ public class SingleClassesTest {
@Test public void testSynchronizedMapping() { doTest("pkg/TestSynchronizedMapping"); }
@Test public void testAbstractMethods() { doTest("pkg/TestAbstractMethods"); }
@Test public void testLocalClass() { doTest("pkg/TestLocalClass"); }
@Ignore
@Test public void testAnonymousClass() { doTest("pkg/TestAnonymousClass"); }
@Test public void testThrowException() { doTest("pkg/TestThrowException"); }
@Test public void testInnerLocal() { doTest("pkg/TestInnerLocal"); }
@@ -70,6 +80,7 @@ public class SingleClassesTest {
@Test public void testAnonymousSignature() { doTest("pkg/TestAnonymousSignature"); }
@Test public void testLocalsSignature() { doTest("pkg/TestLocalsSignature"); }
@Test public void testParameterizedTypes() { doTest("pkg/TestParameterizedTypes"); }
@Ignore
@Test public void testShadowing() { doTest("pkg/TestShadowing", "pkg/Shadow", "ext/Shadow",
"pkg/TestShadowingSuperClass"); }
@Test public void testStringConcat() { doTest("pkg/TestStringConcat"); }
@@ -86,14 +97,19 @@ public class SingleClassesTest {
@Test public void testSyntheticAccess() { doTest("pkg/TestSyntheticAccess"); }
@Test public void testIllegalVarName() { doTest("pkg/TestIllegalVarName"); }
@Test public void testIffSimplification() { doTest("pkg/TestIffSimplification"); }
@Ignore
@Test public void testKotlinConstructor() { doTest("pkg/TestKotlinConstructorKt"); }
@Ignore
@Test public void testAsserts() { doTest("pkg/TestAsserts"); }
@Ignore
@Test public void testLocalsNames() { doTest("pkg/TestLocalsNames"); }
@Ignore
@Test public void testAnonymousParamNames() { doTest("pkg/TestAnonymousParamNames"); }
@Test public void testAnonymousParams() { doTest("pkg/TestAnonymousParams"); }
@Test public void testAccessReplace() { doTest("pkg/TestAccessReplace"); }
@Test public void testStringLiterals() { doTest("pkg/TestStringLiterals"); }
@Test public void testPrimitives() { doTest("pkg/TestPrimitives"); }
@Ignore
@Test public void testClashName() { doTest("pkg/TestClashName", "pkg/SharedName1",
"pkg/SharedName2", "pkg/SharedName3", "pkg/SharedName4", "pkg/NonSharedName",
"pkg/TestClashNameParent", "ext/TestClashNameParent","pkg/TestClashNameIface", "ext/TestClashNameIface"); }
@@ -101,6 +117,7 @@ public class SingleClassesTest {
@Test public void testVarArgCalls() { doTest("pkg/TestVarArgCalls"); }
@Test public void testLambdaParams() { doTest("pkg/TestLambdaParams"); }
@Test public void testInterfaceMethods() { doTest("pkg/TestInterfaceMethods"); }
@Ignore
@Test public void testConstType() { doTest("pkg/TestConstType"); }
@Test public void testPop2OneDoublePop2() { doTest("pkg/TestPop2OneDoublePop2"); }
@Test public void testPop2OneLongPop2() { doTest("pkg/TestPop2OneLongPop2"); }
@@ -109,6 +126,7 @@ public class SingleClassesTest {
@Test public void testSuperInner() { doTest("pkg/TestSuperInner", "pkg/TestSuperInnerBase"); }
@Test public void testMissingConstructorCallGood() { doTest("pkg/TestMissingConstructorCallGood"); }
@Test public void testMissingConstructorCallBad() { doTest("pkg/TestMissingConstructorCallBad"); }
@Ignore
@Test public void testEmptyBlocks() { doTest("pkg/TestEmptyBlocks"); }
@Test public void testPrivateEmptyConstructor() { doTest("pkg/TestPrivateEmptyConstructor"); }
@Test public void testSynchronizedUnprotected() { doTest("pkg/TestSynchronizedUnprotected"); }
@@ -124,6 +142,7 @@ public class SingleClassesTest {
@Test public void testGroovyClass() { doTest("pkg/TestGroovyClass"); }
@Test public void testGroovyTrait() { doTest("pkg/TestGroovyTrait"); }
@Ignore
@Test public void testPrivateClasses() { doTest("pkg/PrivateClasses"); }
@Test public void testSuspendLambda() { doTest("pkg/TestSuspendLambdaKt"); }
@Test public void testNamedSuspendFun2Kt() { doTest("pkg/TestNamedSuspendFun2Kt"); }