-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle wildcard in invoke type resolver (#1238)
- Loading branch information
Showing
9 changed files
with
249 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver20.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package jadx.tests.integration.types; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.SmaliTest; | ||
import jadx.tests.api.extensions.profiles.TestProfile; | ||
import jadx.tests.api.extensions.profiles.TestWithProfiles; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
/** | ||
* Issue 1238 | ||
*/ | ||
public class TestTypeResolver20 extends SmaliTest { | ||
|
||
public static class TestCls { | ||
public interface Sequence<T> { | ||
Iterator<T> iterator(); | ||
} | ||
|
||
public static <T extends Comparable<? super T>> T max(Sequence<? extends T> seq) { | ||
Iterator<? extends T> it = seq.iterator(); | ||
if (!it.hasNext()) { | ||
return null; | ||
} | ||
T t = it.next(); | ||
while (it.hasNext()) { | ||
T next = it.next(); | ||
if (t.compareTo(next) < 0) { | ||
t = next; | ||
} | ||
} | ||
return t; | ||
} | ||
|
||
private static class ArraySeq<T> implements Sequence<T> { | ||
private final List<T> list; | ||
|
||
@SafeVarargs | ||
public ArraySeq(T... arr) { | ||
this.list = Arrays.asList(arr); | ||
} | ||
|
||
@Override | ||
public Iterator<T> iterator() { | ||
return list.iterator(); | ||
} | ||
} | ||
|
||
public void check() { | ||
assertThat(max(new ArraySeq<>(2, 5, 3, 4))).isEqualTo(5); | ||
} | ||
} | ||
|
||
@TestWithProfiles({ TestProfile.DX_J8, TestProfile.JAVA8 }) | ||
public void test() { | ||
noDebugInfo(); | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.doesNotContain("next = next;") | ||
.containsOne("T next = it.next();"); | ||
} | ||
|
||
@Test | ||
public void testSmali() { | ||
assertThat(getClassNodeFromSmaliFiles()) | ||
.code() | ||
.containsOne("T next = it.next();") | ||
.containsOne("T next2 = it.next();"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
jadx-core/src/test/smali/types/TestTypeResolver20/Sequence.smali
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.class public interface abstract Lkotlin/sequences/Sequence; | ||
.super Ljava/lang/Object; | ||
.source "SourceFile" | ||
|
||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"<T:", | ||
"Ljava/lang/Object;", | ||
">", | ||
"Ljava/lang/Object;" | ||
} | ||
.end annotation | ||
|
||
.method public abstract iterator()Ljava/util/Iterator; | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"()", | ||
"Ljava/util/Iterator<", | ||
"TT;>;" | ||
} | ||
.end annotation | ||
.end method |
61 changes: 61 additions & 0 deletions
61
jadx-core/src/test/smali/types/TestTypeResolver20/TestTypeResolver20.smali
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.class public Ltypes/TestTypeResolver20; | ||
.super Ljava/lang/Object; | ||
.source "SourceFile" | ||
|
||
|
||
.method public static final max(Lkotlin/sequences/Sequence;)Ljava/lang/Comparable; | ||
.registers 4 | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"<T::", | ||
"Ljava/lang/Comparable<", | ||
"-TT;>;>(", | ||
"Lkotlin/sequences/Sequence<", | ||
"+TT;>;)TT;" | ||
} | ||
.end annotation | ||
|
||
.line 1147 | ||
invoke-interface {p0}, Lkotlin/sequences/Sequence;->iterator()Ljava/util/Iterator; | ||
move-result-object p0 | ||
|
||
.line 1148 | ||
invoke-interface {p0}, Ljava/util/Iterator;->hasNext()Z | ||
move-result v0 | ||
|
||
if-nez v0, :cond_11 | ||
|
||
const/4 p0, 0x0 | ||
return-object p0 | ||
|
||
.line 1149 | ||
:cond_11 | ||
invoke-interface {p0}, Ljava/util/Iterator;->next()Ljava/lang/Object; | ||
move-result-object v0 | ||
check-cast v0, Ljava/lang/Comparable; | ||
|
||
.line 1150 | ||
:cond_17 | ||
:goto_17 | ||
invoke-interface {p0}, Ljava/util/Iterator;->hasNext()Z | ||
move-result v1 | ||
|
||
if-eqz v1, :cond_2b | ||
|
||
.line 1151 | ||
invoke-interface {p0}, Ljava/util/Iterator;->next()Ljava/lang/Object; | ||
move-result-object v1 | ||
check-cast v1, Ljava/lang/Comparable; | ||
|
||
.line 1152 | ||
invoke-interface {v0, v1}, Ljava/lang/Comparable;->compareTo(Ljava/lang/Object;)I | ||
move-result v2 | ||
|
||
if-gez v2, :cond_17 | ||
|
||
move-object v0, v1 | ||
goto :goto_17 | ||
|
||
:cond_2b | ||
return-object v0 | ||
.end method |