core: inline anonymous classes with arguments
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package jadx.tests.integration.inner;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestAnonymousClass10 extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public A test() {
|
||||
Random random = new Random();
|
||||
int a2 = random.nextInt();
|
||||
int a3 = a2 + 3;
|
||||
return new A(this, a2, a3, 4, 5, random.nextDouble()) {
|
||||
@Override
|
||||
public void m() {
|
||||
System.out.println(1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public abstract class A {
|
||||
public A(TestCls a1, int a2, int a3, int a4, int a5, double a6) {
|
||||
}
|
||||
|
||||
public abstract void m();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("return new A(this, a2, a2 + 3, 4, 5, random.nextDouble()) {"));
|
||||
assertThat(code, not(containsString("synthetic")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package jadx.tests.integration.inner;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestAnonymousClass6 extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
public Runnable test(final double d) {
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
System.out.println(d);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("public Runnable test(final double d) {"));
|
||||
assertThat(code, containsOne("return new Runnable() {"));
|
||||
assertThat(code, containsOne("public void run() {"));
|
||||
assertThat(code, containsOne("System.out.println(d);"));
|
||||
assertThat(code, not(containsString("synthetic")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package jadx.tests.integration.inner;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestAnonymousClass7 extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
public static Runnable test(final double d) {
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
System.out.println(d);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("public static Runnable test(final double d) {"));
|
||||
assertThat(code, containsOne("return new Runnable() {"));
|
||||
assertThat(code, containsOne("public void run() {"));
|
||||
assertThat(code, containsOne("System.out.println(d);"));
|
||||
assertThat(code, not(containsString("synthetic")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package jadx.tests.integration.inner;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestAnonymousClass8 extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public final double d = Math.abs(4);
|
||||
|
||||
public Runnable test() {
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
System.out.println(d);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("public Runnable test() {"));
|
||||
assertThat(code, containsOne("return new Runnable() {"));
|
||||
assertThat(code, containsOne("public void run() {"));
|
||||
assertThat(code, containsOne("this.d);"));
|
||||
assertThat(code, not(containsString("synthetic")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package jadx.tests.integration.inner;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestAnonymousClass9 extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public Callable<String> c = new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return "str";
|
||||
}
|
||||
};
|
||||
|
||||
public Runnable test() {
|
||||
return new FutureTask<String>(this.c) {
|
||||
public void run() {
|
||||
System.out.println(6);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("c = new Callable<String>() {"));
|
||||
assertThat(code, containsOne("return new FutureTask<String>(this.c) {"));
|
||||
assertThat(code, not(containsString("synthetic")));
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ public class TestConstructor extends SmaliTest {
|
||||
disableCompilation();
|
||||
ClassNode cls = getClassNodeFromSmali("TestConstructor");
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsOne("new SomeObject(arg3);"));
|
||||
assertThat(code, not(containsString("= someObject")));
|
||||
|
||||
Reference in New Issue
Block a user