提交 ecaa87e7 编写于 作者: A Ahmed Ashour 提交者: skylot

fix: remove redundant array type when initialized with declaration (PR #566)

上级 0a08d8b6
......@@ -532,8 +532,10 @@ public class InsnGen {
}
private void filledNewArray(FilledNewArrayNode insn, CodeWriter code) throws CodegenException {
code.add("new ");
useType(code, insn.getArrayType());
if (!insn.contains(AFlag.DECLARE_VAR)) {
code.add("new ");
useType(code, insn.getArrayType());
}
code.add('{');
int c = insn.getArgsCount();
for (int i = 0; i < c; i++) {
......
package jadx.tests.integration.arrays;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
public class TestArrayInit extends IntegrationTest {
public static class TestCls {
byte[] bytes;
@SuppressWarnings("unused")
public void test() {
byte[] arr = new byte[]{10, 20, 30};
}
public void test2() {
bytes = new byte[]{10, 20, 30};
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsString("= {10, 20, 30};"));
assertThat(code, containsString("this.bytes = new byte[]{10, 20, 30};"));
}
}
......@@ -29,7 +29,7 @@ public class TestInline2 extends IntegrationTest {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("int[] a = new int[]{1, 2, 4, 6, 8};"));
assertThat(code, containsOne("int[] a = {1, 2, 4, 6, 8};"));
assertThat(code, containsOne("for (int i = 0; i < a.length; i += 2) {"));
assertThat(code, containsOne("for (long i2 = (long) b; i2 > 0; i2--) {"));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册