-
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: support instance invoke for 'invoke-custom' instruction (#384)
- Loading branch information
Showing
5 changed files
with
207 additions
and
60 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
70 changes: 70 additions & 0 deletions
70
jadx-core/src/test/java/jadx/tests/integration/java8/TestLambdaInstance.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,70 @@ | ||
package jadx.tests.integration.java8; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestLambdaInstance extends IntegrationTest { | ||
|
||
@SuppressWarnings("Convert2MethodRef") | ||
public static class TestCls { | ||
|
||
public Function<String, Integer> test() { | ||
return str -> this.call(str); | ||
} | ||
|
||
public Function<String, Integer> testMthRef() { | ||
return this::call; | ||
} | ||
|
||
public Integer call(String str) { | ||
return Integer.parseInt(str); | ||
} | ||
|
||
public Function<Integer, String> test2() { | ||
return num -> num.toString(); | ||
} | ||
|
||
public Function<Integer, String> testMthRef2() { | ||
return Object::toString; | ||
} | ||
|
||
public void check() throws Exception { | ||
assertThat(test().apply("11")).isEqualTo(11); | ||
assertThat(testMthRef().apply("7")).isEqualTo(7); | ||
|
||
assertThat(test2().apply(15)).isEqualTo("15"); | ||
assertThat(testMthRef2().apply(13)).isEqualTo("13"); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.doesNotContain("lambda$") | ||
.doesNotContain("renamed") | ||
.containsLines(2, | ||
"return str -> {", | ||
indent() + "return call(str);", | ||
"};") | ||
// .containsOne("return Object::toString;") // TODO | ||
.containsOne("return this::call;"); | ||
} | ||
|
||
@Test | ||
public void testNoDebug() { | ||
noDebugInfo(); | ||
getClassNode(TestCls.class); | ||
} | ||
|
||
@Test | ||
public void testFallback() { | ||
setFallback(); | ||
getClassNode(TestCls.class); | ||
} | ||
} |
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