fix: additional casts at use place to help type inference (#1002)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package jadx.tests.integration.types;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.tests.api.SmaliTest;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
/**
|
||||
* Issue 1002
|
||||
* Insertion of additional cast (at use place) needed for successful type inference
|
||||
*/
|
||||
public class TestTypeResolver16 extends SmaliTest {
|
||||
// @formatter:off
|
||||
/*
|
||||
public final <T, K> List<T> test(List<? extends T> list, Set<? extends T> set, Function<? super T, ? extends K> function) {
|
||||
checkParameterIsNotNull(function, "distinctBy");
|
||||
if (set != null) {
|
||||
List<? extends T> union = list != null ? union(list, set, function) : null;
|
||||
if (union != null) {
|
||||
list = union;
|
||||
}
|
||||
}
|
||||
return list != null ? (List<T>) list : emptyList();
|
||||
}
|
||||
*/
|
||||
// @formatter:on
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(getClassNodeFromSmali())
|
||||
.code()
|
||||
.containsOne("(List<T>) list");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
.class public Ltypes/TestTypeResolver16;
|
||||
.super Ljava/lang/Object;
|
||||
|
||||
.method public final test(Ljava/util/List;Ljava/util/Set;Ljava/util/function/Function;)Ljava/util/List;
|
||||
.locals 1
|
||||
.annotation system Ldalvik/annotation/Signature;
|
||||
value = {
|
||||
"<T:",
|
||||
"Ljava/lang/Object;",
|
||||
"K:",
|
||||
"Ljava/lang/Object;",
|
||||
">(",
|
||||
"Ljava/util/List<",
|
||||
"+TT;>;",
|
||||
"Ljava/util/Set<",
|
||||
"+TT;>;",
|
||||
"Ljava/util/function/Function<",
|
||||
"-TT;+TK;>;)",
|
||||
"Ljava/util/List<",
|
||||
"TT;>;"
|
||||
}
|
||||
.end annotation
|
||||
|
||||
const-string v0, "distinctBy"
|
||||
|
||||
invoke-static {p3, v0}, Ltypes/TestTypeResolver16;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V
|
||||
|
||||
if-eqz p2, :cond_1
|
||||
|
||||
if-eqz p1, :cond_0
|
||||
|
||||
.line 85
|
||||
move-object v0, p1
|
||||
|
||||
check-cast v0, Ljava/util/Collection;
|
||||
|
||||
check-cast p2, Ljava/lang/Iterable;
|
||||
|
||||
invoke-static {v0, p2, p3}, Ltypes/TestTypeResolver16;->union(Ljava/util/Collection;Ljava/lang/Iterable;Ljava/util/function/Function;)Ljava/util/List;
|
||||
|
||||
move-result-object p2
|
||||
|
||||
goto :goto_0
|
||||
|
||||
:cond_0
|
||||
const/4 p2, 0x0
|
||||
|
||||
:goto_0
|
||||
if-eqz p2, :cond_1
|
||||
|
||||
move-object p1, p2
|
||||
|
||||
:cond_1
|
||||
if-eqz p1, :cond_2
|
||||
|
||||
goto :goto_1
|
||||
|
||||
:cond_2
|
||||
invoke-static {}, Ltypes/TestTypeResolver16;->emptyList()Ljava/util/List;
|
||||
|
||||
move-result-object p1
|
||||
|
||||
:goto_1
|
||||
return-object p1
|
||||
.end method
|
||||
|
||||
|
||||
.method public static final union(Ljava/util/Collection;Ljava/lang/Iterable;Ljava/util/function/Function;)Ljava/util/List;
|
||||
.locals 4
|
||||
.annotation system Ldalvik/annotation/Signature;
|
||||
value = {
|
||||
"<T:",
|
||||
"Ljava/lang/Object;",
|
||||
"K:",
|
||||
"Ljava/lang/Object;",
|
||||
">(",
|
||||
"Ljava/util/Collection<",
|
||||
"+TT;>;",
|
||||
"Ljava/lang/Iterable<",
|
||||
"+TT;>;",
|
||||
"Ljava/util/function/Function<",
|
||||
"-TT;+TK;>;)",
|
||||
"Ljava/util/List<",
|
||||
"TT;>;"
|
||||
}
|
||||
.end annotation
|
||||
|
||||
const/4 v0, 0x0
|
||||
return-object v0
|
||||
.end method
|
||||
|
||||
.method public static checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V
|
||||
.locals 0
|
||||
return-void
|
||||
.end method
|
||||
|
||||
.method public static final emptyList()Ljava/util/List;
|
||||
.locals 1
|
||||
.annotation system Ldalvik/annotation/Signature;
|
||||
value = {
|
||||
"<T:",
|
||||
"Ljava/lang/Object;",
|
||||
">()",
|
||||
"Ljava/util/List<",
|
||||
"TT;>;"
|
||||
}
|
||||
.end annotation
|
||||
|
||||
const/4 v0, 0x0
|
||||
return-object v0
|
||||
.end method
|
||||
Reference in New Issue
Block a user