未验证 提交 45021389 编写于 作者: S Skylot

fix: correct method arg name if unused

上级 f674a29a
......@@ -238,10 +238,11 @@ public class MethodGen {
classGen.useType(code, argType);
}
code.add(' ');
if (code.isMetadataSupported() && ssaVar != null) {
String varName = nameGen.assignArg(var);
if (code.isMetadataSupported() && ssaVar != null /* for fallback mode */) {
code.attachDefinition(VarDeclareRef.get(mth, var));
}
code.add(nameGen.assignArg(var));
code.add(varName);
i++;
if (it.hasNext()) {
......
......@@ -99,9 +99,6 @@ public class MethodNode extends NotificationAttrNode implements IMethodDetails,
@Override
public void unload() {
loaded = false;
if (noCode) {
return;
}
// don't unload retType, argTypes, typeParameters
thisArg = null;
argsList = null;
......
......@@ -26,9 +26,6 @@ public class InitCodeVariables extends AbstractVisitor {
@Override
public void visit(MethodNode mth) throws JadxException {
if (mth.isNoCode()) {
return;
}
initCodeVars(mth);
}
......@@ -42,16 +39,24 @@ public class InitCodeVariables extends AbstractVisitor {
private static void initCodeVars(MethodNode mth) {
RegisterArg thisArg = mth.getThisArg();
if (thisArg != null) {
initCodeVar(thisArg.getSVar());
initCodeVar(mth, thisArg);
}
for (RegisterArg mthArg : mth.getArgRegs()) {
initCodeVar(mthArg.getSVar());
initCodeVar(mth, mthArg);
}
for (SSAVar ssaVar : mth.getSVars()) {
initCodeVar(ssaVar);
}
}
public static void initCodeVar(MethodNode mth, RegisterArg regArg) {
SSAVar ssaVar = regArg.getSVar();
if (ssaVar == null) {
ssaVar = mth.makeNewSVar(regArg);
}
initCodeVar(ssaVar);
}
public static void initCodeVar(SSAVar ssaVar) {
if (ssaVar.isCodeVarSet()) {
return;
......
package jadx.tests.integration.variables;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import jadx.api.data.annotations.VarDeclareRef;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.MethodNode;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestVariablesDeclAnnotation extends IntegrationTest {
public abstract static class TestCls {
public int test(String str, int i) {
return i;
}
public abstract int test2(String str);
}
@Test
public void test() {
noDebugInfo();
ClassNode cls = getClassNode(TestCls.class);
assertThat(cls).code()
.containsOne("public int test(String str, int i) {")
.containsOne("public abstract int test2(String str);");
checkArgNamesInMethod(cls, "test", "[str, i]");
checkArgNamesInMethod(cls, "test2", "[str]");
}
private static void checkArgNamesInMethod(ClassNode cls, String mthName, String expectedVars) {
MethodNode testMth = cls.searchMethodByShortName(mthName);
assertThat(testMth).isNotNull();
int mthLine = testMth.getDecompiledLine();
List<String> argNames = cls.getCode().getAnnotations().entrySet().stream()
.filter(e -> e.getKey().getLine() == mthLine && e.getValue() instanceof VarDeclareRef)
.sorted(Comparator.comparingInt(e -> e.getKey().getPos()))
.map(e -> ((VarDeclareRef) e.getValue()).getName())
.collect(Collectors.toList());
assertThat(argNames).doesNotContainNull();
assertThat(argNames.toString()).isEqualTo(expectedVars);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册