fix: allow local variables have name same as instance fields (#1183)
This commit is contained in:
@@ -70,7 +70,9 @@ public class NameGen {
|
||||
private void addNamesUsedInClass() {
|
||||
ClassNode parentClass = mth.getParentClass();
|
||||
for (FieldNode field : parentClass.getFields()) {
|
||||
varNames.add(field.getAlias());
|
||||
if (field.isStatic()) {
|
||||
varNames.add(field.getAlias());
|
||||
}
|
||||
}
|
||||
for (ClassNode innerClass : parentClass.getInnerClasses()) {
|
||||
varNames.add(innerClass.getClassInfo().getAliasShortName());
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package jadx.tests.integration.names;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
public class TestConstructorArgNames extends IntegrationTest {
|
||||
|
||||
@SuppressWarnings({ "FieldCanBeLocal", "FieldMayBeFinal", "StaticVariableName", "ParameterName" })
|
||||
public static class TestCls {
|
||||
private static String STR = "static field";
|
||||
private final String str;
|
||||
private final String store;
|
||||
|
||||
public TestCls(String str, String STR) {
|
||||
this.str = str;
|
||||
this.store = STR;
|
||||
}
|
||||
|
||||
public TestCls() {
|
||||
this.str = "a";
|
||||
this.store = STR;
|
||||
}
|
||||
|
||||
public void check() {
|
||||
assertThat(new TestCls("a", "b").store).isEqualTo("b");
|
||||
assertThat(new TestCls().store).isEqualTo(STR);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
.containsOne("this.str = str;")
|
||||
.containsOne("this.store = STR2;")
|
||||
.containsOne("this.store = STR;");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user