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

fix: remove static field redundant array type when initialized (PR #580)

上级 07209929
......@@ -92,6 +92,10 @@ public class ExtractFieldInit extends AbstractVisitor {
if (initInsns.size() == 1) {
InsnNode insn = initInsns.get(0);
if (checkInsn(insn)) {
InsnArg arg = insn.getArg(0);
if (arg instanceof InsnWrapArg) {
((InsnWrapArg) arg).getWrapInsn().add(AFlag.DECLARE_VAR);
}
InsnRemover.remove(classInitMth, insn);
addFieldInitAttr(classInitMth, field, insn);
}
......
......@@ -11,7 +11,8 @@ public class TestArrayInitField extends IntegrationTest {
public static class TestCls {
byte[] bytes = new byte[]{10, 20, 30};
static byte[] a = new byte[]{10, 20, 30};
byte[] b = new byte[]{40, 50, 60};
}
@Test
......@@ -20,5 +21,6 @@ public class TestArrayInitField extends IntegrationTest {
String code = cls.getCode().toString();
assertThat(code, containsString("= {10, 20, 30};"));
assertThat(code, containsString("= {40, 50, 60};"));
}
}
......@@ -82,6 +82,6 @@ public class TestFieldInitInTryCatch extends IntegrationTest {
ClassNode cls = getClassNode(TestCls3.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("public static final String[] a = new String[]{\"a\"};"));
assertThat(code, containsOne("public static final String[] a = {\"a\"};"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册