core: fix indent for anonymous classes
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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() {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
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--;"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user