Commit eb6d145d authored by Skylot's avatar Skylot

core: fix indent for anonymous classes

parent 63c003a0
......@@ -95,6 +95,14 @@ public class InsnGen {
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 {
addArg(code, arg, true);
}
......@@ -152,11 +160,7 @@ public class InsnGen {
return;
}
}
int len = code.length();
addArg(code, arg);
if (code.length() != len) {
code.add('.');
}
addArgDot(code, arg);
code.add(field.getName());
}
......@@ -609,10 +613,7 @@ public class InsnGen {
InsnArg arg = insn.getArg(0);
// FIXME: add 'this' for equals methods in scope
if (!arg.isThis()) {
CodeWriter argStr = arg(arg);
if (!argStr.isEmpty()) {
code.add(argStr).add('.');
}
addArgDot(code, arg);
}
k++;
break;
......
package jadx.api;
import jadx.core.Jadx;
import jadx.core.codegen.CodeWriter;
import jadx.core.dex.attributes.AttributeFlag;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.MethodNode;
......@@ -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
@Deprecated
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