fix: remove declaration of unused variable (PR #590)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package jadx.core.codegen;
|
||||
|
||||
import static jadx.core.utils.android.AndroidResourcesUtils.handleAppResField;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
@@ -41,6 +43,7 @@ import jadx.core.dex.instructions.args.InsnWrapArg;
|
||||
import jadx.core.dex.instructions.args.LiteralArg;
|
||||
import jadx.core.dex.instructions.args.Named;
|
||||
import jadx.core.dex.instructions.args.RegisterArg;
|
||||
import jadx.core.dex.instructions.args.SSAVar;
|
||||
import jadx.core.dex.instructions.mods.ConstructorInsn;
|
||||
import jadx.core.dex.instructions.mods.TernaryInsn;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
@@ -52,8 +55,6 @@ import jadx.core.utils.RegionUtils;
|
||||
import jadx.core.utils.exceptions.CodegenException;
|
||||
import jadx.core.utils.exceptions.JadxRuntimeException;
|
||||
|
||||
import static jadx.core.utils.android.AndroidResourcesUtils.handleAppResField;
|
||||
|
||||
public class InsnGen {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InsnGen.class);
|
||||
|
||||
@@ -219,9 +220,13 @@ public class InsnGen {
|
||||
if (flag != Flags.INLINE) {
|
||||
code.startLineWithNum(insn.getSourceLine());
|
||||
}
|
||||
if (insn.getResult() != null && !insn.contains(AFlag.ARITH_ONEARG)) {
|
||||
assignVar(code, insn);
|
||||
code.add(" = ");
|
||||
if (insn.getResult() != null) {
|
||||
SSAVar var = insn.getResult().getSVar();
|
||||
if ((var == null || var.getUseCount() != 0 || insn.getType() != InsnType.CONSTRUCTOR)
|
||||
&& !insn.contains(AFlag.ARITH_ONEARG)) {
|
||||
assignVar(code, insn);
|
||||
code.add(" = ");
|
||||
}
|
||||
}
|
||||
makeInsnBody(code, insn, state);
|
||||
if (flag != Flags.INLINE) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.NotYetImplemented;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
@@ -112,8 +111,7 @@ public class TestAnnotationsMix extends IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotYetImplemented
|
||||
public void testNYI() {
|
||||
public void testDeclaration() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package jadx.tests.integration.inner;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.NotYetImplemented;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
public class TestAnonymousClass13 extends IntegrationTest {
|
||||
@@ -16,7 +15,6 @@ public class TestAnonymousClass13 extends IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotYetImplemented
|
||||
public void test() {
|
||||
getClassNode(TestCls.class);
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package jadx.tests.integration.invoke;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.NotYetImplemented;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class TestConstructorInvoke extends IntegrationTest {
|
||||
|
||||
void test(String root, String name) {
|
||||
ViewHolder holder = new ViewHolder(root, name);
|
||||
}
|
||||
|
||||
private final class ViewHolder {
|
||||
private ViewHolder(String root, String name) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotYetImplemented("Variable lost name from debug info")
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestConstructorInvoke.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne(indent() + "ViewHolder holder = new ViewHolder(root, name);"));
|
||||
}
|
||||
|
||||
// Remove after fix above @NYI
|
||||
@Test
|
||||
public void test2() {
|
||||
ClassNode cls = getClassNode(TestConstructorInvoke.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne(indent() + "ViewHolder viewHolder = new ViewHolder(root, name);"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDebug() {
|
||||
noDebugInfo();
|
||||
ClassNode cls = getClassNode(TestConstructorInvoke.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne(indent() + "ViewHolder viewHolder = new ViewHolder("));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user