-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore missing type parameter declarations (#1800)
- Loading branch information
Showing
6 changed files
with
222 additions
and
8 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
72 changes: 72 additions & 0 deletions
72
jadx-core/src/test/java/jadx/tests/integration/inline/TestInstanceLambda.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,72 @@ | ||
package jadx.tests.integration.inline; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.NotYetImplemented; | ||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.SmaliTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestInstanceLambda extends SmaliTest { | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes", "SameParameterValue" }) | ||
public static class TestCls { | ||
|
||
public <T> Map<T, T> test(List<? extends T> list) { | ||
return toMap(list, Lambda.INSTANCE); | ||
} | ||
|
||
/** | ||
* Smali test missing 'T' definition in 'Lambda<T>' | ||
*/ | ||
private static class Lambda<T> implements Function<T, T> { | ||
public static final Lambda INSTANCE = new Lambda(); | ||
|
||
@Override | ||
public T apply(T t) { | ||
return t; | ||
} | ||
} | ||
|
||
private static <T> Map<T, T> toMap(List<? extends T> list, Function<T, T> valueMap) { | ||
return list.stream().collect(Collectors.toMap(k -> k, valueMap)); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
noDebugInfo(); | ||
assertThat(getClassNode(TestCls.class)) | ||
.code(); | ||
} | ||
|
||
@Test | ||
public void testSmaliDisableInline() { | ||
args.setInlineAnonymousClasses(false); | ||
List<ClassNode> classNodes = loadFromSmaliFiles(); | ||
assertThat(searchTestCls(classNodes, "Lambda")) | ||
.code() | ||
.containsOne("class Lambda<T> implements Function<T, T> {"); | ||
assertThat(searchTestCls(classNodes, "TestCls")) | ||
.code() | ||
.containsOne("Lambda.INSTANCE"); | ||
} | ||
|
||
@NotYetImplemented("Inline lambda by instance field") | ||
@Test | ||
public void testSmali() { | ||
List<ClassNode> classNodes = loadFromSmaliFiles(); | ||
assertThat(classNodes) | ||
.describedAs("Expect lambda to be inlined") | ||
.hasSize(1); | ||
assertThat(searchTestCls(classNodes, "TestCls")) | ||
.code() | ||
.doesNotContain("Lambda.INSTANCE"); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
jadx-core/src/test/smali/inline/TestInstanceLambda/Lambda.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,40 @@ | ||
.class public Linline/Lambda; | ||
.super Ljava/lang/Object; | ||
|
||
.implements Ljava/util/function/Function; | ||
|
||
|
||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"Ljava/lang/Object;", | ||
"Ljava/util/function/Function", | ||
"<TT;TT;>;" | ||
} | ||
.end annotation | ||
|
||
.field public static final INSTANCE:Linline/Lambda; | ||
|
||
.method static constructor <clinit>()V | ||
.registers 1 | ||
new-instance v0, Linline/Lambda; | ||
invoke-direct {v0}, Linline/Lambda;-><init>()V | ||
sput-object v0, Linline/Lambda;->INSTANCE:Linline/Lambda; | ||
return-void | ||
.end method | ||
|
||
.method private constructor <init>()V | ||
.registers 1 | ||
invoke-direct {p0}, Ljava/lang/Object;-><init>()V | ||
return-void | ||
.end method | ||
|
||
.method public final apply(Ljava/lang/Object;)Ljava/lang/Object; | ||
.registers 2 | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"(TT;)TT;" | ||
} | ||
.end annotation | ||
|
||
return-object p1 | ||
.end method |
56 changes: 56 additions & 0 deletions
56
jadx-core/src/test/smali/inline/TestInstanceLambda/TestCls.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,56 @@ | ||
.class public Linline/TestCls; | ||
.super Ljava/lang/Object; | ||
|
||
.method public test(Ljava/util/List;)Ljava/util/Map; | ||
.registers 3 | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"<T:", | ||
"Ljava/lang/Object;", | ||
">(", | ||
"Ljava/util/List", | ||
"<+TT;>;)", | ||
"Ljava/util/Map", | ||
"<TT;TT;>;" | ||
} | ||
.end annotation | ||
|
||
sget-object v0, Linline/Lambda;->INSTANCE:Linline/Lambda; | ||
invoke-static {p1, v0}, Linline/TestCls;->toMap(Ljava/util/List;Ljava/util/function/Function;)Ljava/util/Map; | ||
move-result-object v0 | ||
return-object v0 | ||
.end method | ||
|
||
|
||
.method private static synthetic lambda$toMap$0(Ljava/lang/Object;)Ljava/lang/Object; | ||
.registers 1 | ||
return-object p0 | ||
.end method | ||
|
||
.method private static toMap(Ljava/util/List;Ljava/util/function/Function;)Ljava/util/Map; | ||
.registers 4 | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"<T:", | ||
"Ljava/lang/Object;", | ||
">(", | ||
"Ljava/util/List", | ||
"<+TT;>;", | ||
"Ljava/util/function/Function", | ||
"<TT;TT;>;)", | ||
"Ljava/util/Map", | ||
"<TT;TT;>;" | ||
} | ||
.end annotation | ||
|
||
invoke-interface {p0}, Ljava/util/List;->stream()Ljava/util/stream/Stream; | ||
move-result-object v0 | ||
invoke-custom {}, call_site_0("apply", ()Ljava/util/function/Function;, (Ljava/lang/Object;)Ljava/lang/Object;, invoke-static@Linline/TestCls;->lambda$toMap$0(Ljava/lang/Object;)Ljava/lang/Object;, (Ljava/lang/Object;)Ljava/lang/Object;)@Ljava/lang/invoke/LambdaMetafactory;->metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | ||
move-result-object v1 | ||
invoke-static {v1, p1}, Ljava/util/stream/Collectors;->toMap(Ljava/util/function/Function;Ljava/util/function/Function;)Ljava/util/stream/Collector; | ||
move-result-object v1 | ||
invoke-interface {v0, v1}, Ljava/util/stream/Stream;->collect(Ljava/util/stream/Collector;)Ljava/lang/Object; | ||
move-result-object v0 | ||
check-cast v0, Ljava/util/Map; | ||
return-object v0 | ||
.end method |