fix: remove redundant array type when initialized with declaration (PR #566)
This commit is contained in:
@@ -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++) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
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--) {"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user