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
c9521192
Commit
c9521192
authored
Sep 24, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: omit 'this' for methods and fields
parent
95e9da36
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
2 deletions
+62
-2
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+19
-2
TestRedundantThis.java
.../src/test/java/jadx/tests/internal/TestRedundantThis.java
+43
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
c9521192
...
...
@@ -125,7 +125,21 @@ public class InsnGen {
}
private
String
ifield
(
FieldInfo
field
,
InsnArg
arg
)
throws
CodegenException
{
return
arg
(
arg
)
+
"."
+
field
.
getName
();
String
name
=
field
.
getName
();
if
(
arg
.
isThis
())
{
boolean
useShort
=
true
;
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
false
);
for
(
RegisterArg
param
:
args
)
{
String
paramName
=
param
.
getTypedVar
().
getName
();
if
(
paramName
!=
null
&&
paramName
.
equals
(
name
))
{
useShort
=
false
;
}
}
if
(
useShort
)
{
return
name
;
// FIXME: check variable names in scope
}
}
return
arg
(
arg
)
+
"."
+
name
;
}
private
String
sfield
(
FieldInfo
field
)
{
...
...
@@ -531,7 +545,10 @@ public class InsnGen {
case
DIRECT:
case
VIRTUAL:
case
INTERFACE:
code
.
add
(
arg
(
insn
.
getArg
(
0
))).
add
(
'.'
);
InsnArg
arg
=
insn
.
getArg
(
0
);
if
(!
arg
.
isThis
())
{
// FIXME: add 'this' for equals methods in scope
code
.
add
(
arg
(
arg
)).
add
(
'.'
);
}
k
++;
break
;
...
...
jadx-core/src/test/java/jadx/tests/internal/TestRedundantThis.java
0 → 100644
View file @
c9521192
package
jadx
.
tests
.
internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestRedundantThis
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
int
field1
=
1
;
public
int
field2
=
2
;
public
boolean
f1
()
{
return
false
;
}
public
int
method
()
{
f1
();
return
field1
;
}
public
void
method2
(
int
field2
)
{
this
.
field2
=
field2
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"this.f1();"
)));
assertThat
(
code
,
not
(
containsString
(
"return this.field1;"
)));
assertThat
(
code
,
containsString
(
"this.field2 = field2;"
));
}
}
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