fix: improve type inference of type variables in method invoke (#913)

This commit is contained in:
Skylot
2020-06-01 19:59:28 +01:00
parent ae31fee8dd
commit 6192ced214
14 changed files with 325 additions and 108 deletions
@@ -64,7 +64,7 @@ public class TestCastInOverloadedInvoke extends IntegrationTest {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("call((ArrayList<String>) new ArrayList());"));
assertThat(code, containsOne("call(new ArrayList<>());"));
assertThat(code, containsOne("call((List<String>) new ArrayList());"));
assertThat(code, containsOne("call((String) obj);"));
@@ -76,9 +76,6 @@ public class TestCastInOverloadedInvoke extends IntegrationTest {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("call(new ArrayList<>());"));
assertThat(code, containsOne("call((List<String>) new ArrayList<String>());"));
assertThat(code, containsOne("call((String) obj);"));
}
}
@@ -5,7 +5,6 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import jadx.NotYetImplemented;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
@@ -83,18 +82,9 @@ public class TestHierarchyOverloadedInvoke extends IntegrationTest {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("b.call((ArrayList<String>) new ArrayList());"));
assertThat(code, containsOne("b.call(new ArrayList<>());"));
assertThat(code, containsOne("b.call((List<String>) new ArrayList());"));
assertThat(code, containsOne("b.call((String) obj);"));
}
@NotYetImplemented
@Test
public void test2() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("b.call(new ArrayList<>());"));
}
}
@@ -0,0 +1,70 @@
package jadx.tests.integration.types;
import java.util.Iterator;
import java.util.Map;
import org.junit.jupiter.api.Test;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestGenerics6 extends IntegrationTest {
public static class TestCls<K, V> implements Iterable<Map.Entry<K, V>> {
public V test(K key, V v) {
Entry<K, V> entry = get(key);
if (entry != null) {
return entry.mValue;
}
put(key, v);
return null;
}
protected Entry<K, V> get(K k) {
return null;
}
protected Entry<K, V> put(K key, V v) {
return null;
}
@Override
public Iterator<Map.Entry<K, V>> iterator() {
return null;
}
static class Entry<K, V> implements Map.Entry<K, V> {
final V mValue;
Entry(K key, V value) {
this.mValue = value;
}
@Override
public K getKey() {
return null;
}
@Override
public V getValue() {
return null;
}
@Override
public V setValue(V value) {
return null;
}
}
}
@Test
public void test() {
noDebugInfo();
assertThat(getClassNode(TestCls.class))
.code()
.doesNotContain("Entry entry = get(k);")
.containsOne("Entry<K, V> entry = get(k);");
}
}