-
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: add assign for inlined getter methods
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 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
43 changes: 43 additions & 0 deletions
43
jadx-core/src/test/java/jadx/tests/integration/inline/TestGetterInlineNegative.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,43 @@ | ||
package jadx.tests.integration.inline; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.SmaliTest; | ||
|
||
import static jadx.tests.api.utils.JadxMatchers.containsOne; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class TestGetterInlineNegative extends SmaliTest { | ||
|
||
// @formatter:off | ||
/* | ||
public class TestGetterInlineNegative { | ||
public static final String field = "some string"; | ||
public static synthetic String getter() { | ||
return field; | ||
} | ||
public void test() { | ||
getter(); // inline will produce 'field;' and fail to compile with 'not a statement' error | ||
} | ||
public String test2() { | ||
return getter(); | ||
} | ||
} | ||
*/ | ||
// @formatter:on | ||
|
||
@Test | ||
public void test() { | ||
ClassNode cls = getClassNodeFromSmali(); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, not(containsString(indent() + "field;"))); | ||
assertThat(code, containsOne("return field;")); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
jadx-core/src/test/smali/inline/TestGetterInlineNegative.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,29 @@ | ||
.class public Linline/TestGetterInlineNegative; | ||
.super Ljava/lang/Object; | ||
|
||
.field public static final field:Ljava/lang/String; = "some string" | ||
|
||
.method public static synthetic getter()Ljava/lang/String; | ||
.locals 1 | ||
|
||
sget-object v0, Linline/TestGetterInlineNegative;->field:Ljava/lang/String; | ||
|
||
return-object v0 | ||
.end method | ||
|
||
.method public test()V | ||
.locals 1 | ||
|
||
invoke-static {}, Linline/TestGetterInlineNegative;->getter()Ljava/lang/String; | ||
|
||
return-void | ||
.end method | ||
|
||
.method public test2()Ljava/lang/String; | ||
.locals 2 | ||
|
||
invoke-static {}, Linline/TestGetterInlineNegative;->getter()Ljava/lang/String; | ||
move-result-object v1 | ||
|
||
return-object v1 | ||
.end method |