Commit eb6d145d authored by Skylot's avatar Skylot

core: fix indent for anonymous classes

parent 63c003a0
...@@ -95,6 +95,14 @@ public class InsnGen { ...@@ -95,6 +95,14 @@ public class InsnGen {
return code; return code;
} }
public void addArgDot(CodeWriter code, InsnArg arg) throws CodegenException {
int len = code.length();
addArg(code, arg, true);
if (len != code.length()) {
code.add('.');
}
}
public void addArg(CodeWriter code, InsnArg arg) throws CodegenException { public void addArg(CodeWriter code, InsnArg arg) throws CodegenException {
addArg(code, arg, true); addArg(code, arg, true);
} }
...@@ -152,11 +160,7 @@ public class InsnGen { ...@@ -152,11 +160,7 @@ public class InsnGen {
return; return;
} }
} }
int len = code.length(); addArgDot(code, arg);
addArg(code, arg);
if (code.length() != len) {
code.add('.');
}
code.add(field.getName()); code.add(field.getName());
} }
...@@ -609,10 +613,7 @@ public class InsnGen { ...@@ -609,10 +613,7 @@ public class InsnGen {
InsnArg arg = insn.getArg(0); InsnArg arg = insn.getArg(0);
// FIXME: add 'this' for equals methods in scope // FIXME: add 'this' for equals methods in scope
if (!arg.isThis()) { if (!arg.isThis()) {
CodeWriter argStr = arg(arg); addArgDot(code, arg);
if (!argStr.isEmpty()) {
code.add(argStr).add('.');
}
} }
k++; k++;
break; break;
......
package jadx.api; package jadx.api;
import jadx.core.Jadx; import jadx.core.Jadx;
import jadx.core.codegen.CodeWriter;
import jadx.core.dex.attributes.AttributeFlag; import jadx.core.dex.attributes.AttributeFlag;
import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
...@@ -149,6 +150,14 @@ public abstract class InternalJadxTest { ...@@ -149,6 +150,14 @@ public abstract class InternalJadxTest {
} }
} }
protected String makeIndent(int indent) {
StringBuilder sb = new StringBuilder(indent * CodeWriter.INDENT.length());
for (int i = 0; i < indent; i++) {
sb.append(CodeWriter.INDENT);
}
return sb.toString();
}
// Use only for debug purpose // Use only for debug purpose
@Deprecated @Deprecated
protected void setOutputCFG() { protected void setOutputCFG() {
......
package jadx.tests.internal.inner;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
public class TestAnonymousClass3 extends InternalJadxTest {
public static class TestCls {
public static class Inner {
private int f;
private double d;
public void test() {
new Thread() {
@Override
public void run() {
int a = f--;
p(a);
f += 2;
f *= 2;
a = ++f;
p(a);
d /= 3;
}
public void p(int a) {
}
}.start();
}
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsString(makeIndent(4) + "public void run() {"));
assertThat(code, containsString(makeIndent(3) + "}.start();"));
// assertThat(code, not(containsString("synthetic")));
// assertThat(code, not(containsString("AnonymousClass_")));
// assertThat(code, containsString("a = f--;"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment