Commit b1b49e61 authored by Ahmed Ashour's avatar Ahmed Ashour Committed by skylot

fix: remove declaration of unused variable (PR #590)

parent d23f4ac1
package jadx.core.codegen; package jadx.core.codegen;
import static jadx.core.utils.android.AndroidResourcesUtils.handleAppResField;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
...@@ -41,6 +43,7 @@ import jadx.core.dex.instructions.args.InsnWrapArg; ...@@ -41,6 +43,7 @@ import jadx.core.dex.instructions.args.InsnWrapArg;
import jadx.core.dex.instructions.args.LiteralArg; import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.Named; import jadx.core.dex.instructions.args.Named;
import jadx.core.dex.instructions.args.RegisterArg; 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.ConstructorInsn;
import jadx.core.dex.instructions.mods.TernaryInsn; import jadx.core.dex.instructions.mods.TernaryInsn;
import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.ClassNode;
...@@ -52,8 +55,6 @@ import jadx.core.utils.RegionUtils; ...@@ -52,8 +55,6 @@ import jadx.core.utils.RegionUtils;
import jadx.core.utils.exceptions.CodegenException; import jadx.core.utils.exceptions.CodegenException;
import jadx.core.utils.exceptions.JadxRuntimeException; import jadx.core.utils.exceptions.JadxRuntimeException;
import static jadx.core.utils.android.AndroidResourcesUtils.handleAppResField;
public class InsnGen { public class InsnGen {
private static final Logger LOG = LoggerFactory.getLogger(InsnGen.class); private static final Logger LOG = LoggerFactory.getLogger(InsnGen.class);
...@@ -219,9 +220,13 @@ public class InsnGen { ...@@ -219,9 +220,13 @@ public class InsnGen {
if (flag != Flags.INLINE) { if (flag != Flags.INLINE) {
code.startLineWithNum(insn.getSourceLine()); code.startLineWithNum(insn.getSourceLine());
} }
if (insn.getResult() != null && !insn.contains(AFlag.ARITH_ONEARG)) { if (insn.getResult() != null) {
assignVar(code, insn); SSAVar var = insn.getResult().getSVar();
code.add(" = "); if ((var == null || var.getUseCount() != 0 || insn.getType() != InsnType.CONSTRUCTOR)
&& !insn.contains(AFlag.ARITH_ONEARG)) {
assignVar(code, insn);
code.add(" = ");
}
} }
makeInsnBody(code, insn, state); makeInsnBody(code, insn, state);
if (flag != Flags.INLINE) { if (flag != Flags.INLINE) {
......
...@@ -10,7 +10,6 @@ import java.util.Arrays; ...@@ -10,7 +10,6 @@ import java.util.Arrays;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jadx.NotYetImplemented;
import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest; import jadx.tests.api.IntegrationTest;
...@@ -112,8 +111,7 @@ public class TestAnnotationsMix extends IntegrationTest { ...@@ -112,8 +111,7 @@ public class TestAnnotationsMix extends IntegrationTest {
} }
@Test @Test
@NotYetImplemented public void testDeclaration() {
public void testNYI() {
ClassNode cls = getClassNode(TestCls.class); ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString(); String code = cls.getCode().toString();
......
...@@ -2,7 +2,6 @@ package jadx.tests.integration.inner; ...@@ -2,7 +2,6 @@ package jadx.tests.integration.inner;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jadx.NotYetImplemented;
import jadx.tests.api.IntegrationTest; import jadx.tests.api.IntegrationTest;
public class TestAnonymousClass13 extends IntegrationTest { public class TestAnonymousClass13 extends IntegrationTest {
...@@ -16,7 +15,6 @@ public class TestAnonymousClass13 extends IntegrationTest { ...@@ -16,7 +15,6 @@ public class TestAnonymousClass13 extends IntegrationTest {
} }
@Test @Test
@NotYetImplemented
public void test() { public void test() {
getClassNode(TestCls.class); getClassNode(TestCls.class);
} }
......
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("));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment