Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
ce7101be
Commit
ce7101be
authored
Jun 28, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: always inline 'this' (issue #10)
parent
0a241e3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
3 deletions
+48
-3
CodeShrinker.java
...re/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
+5
-1
TestInlineThis.java
...test/java/jadx/tests/internal/usethis/TestInlineThis.java
+42
-0
TestRedundantThis.java
...t/java/jadx/tests/internal/usethis/TestRedundantThis.java
+1
-2
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
View file @
ce7101be
...
...
@@ -192,7 +192,11 @@ public class CodeShrinker extends AbstractVisitor {
// continue;
// }
SSAVar
sVar
=
arg
.
getSVar
();
if
(
sVar
.
getAssign
()
==
null
||
sVar
.
getVariableUseCount
()
!=
1
)
{
if
(
sVar
.
getAssign
()
==
null
)
{
continue
;
}
// allow inline only one use arg or 'this'
if
(
sVar
.
getVariableUseCount
()
!=
1
&&
!
arg
.
isThis
())
{
continue
;
}
InsnNode
assignInsn
=
sVar
.
getAssign
().
getParentInsn
();
...
...
jadx-core/src/test/java/jadx/tests/internal/usethis/TestInlineThis.java
0 → 100644
View file @
ce7101be
package
jadx
.
tests
.
internal
.
usethis
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestInlineThis
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
int
field
;
private
void
test
()
{
TestCls
something
=
this
;
something
.
method
();
something
.
field
=
123
;
}
private
void
method
()
{
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
not
(
containsString
(
"something"
)));
assertThat
(
code
,
not
(
containsString
(
"something.method()"
)));
assertThat
(
code
,
not
(
containsString
(
"something.field"
)));
assertThat
(
code
,
not
(
containsString
(
"= this"
)));
assertThat
(
code
,
containsOne
(
"this.field = 123;"
));
assertThat
(
code
,
containsOne
(
"method();"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/TestRedundantThis.java
→
jadx-core/src/test/java/jadx/tests/internal/
usethis/
TestRedundantThis.java
View file @
ce7101be
package
jadx
.
tests
.
internal
;
package
jadx
.
tests
.
internal
.
usethis
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
...
...
@@ -30,7 +30,6 @@ public class TestRedundantThis extends InternalJadxTest {
// @Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"this.f1();"
)));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment