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
04ac3b2e
Commit
04ac3b2e
authored
Sep 26, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix classes import naming
parent
6bc2d332
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
15 deletions
+74
-15
ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+38
-15
TestInnerNames.java
jadx-samples/src/main/java/jadx/samples/TestInnerNames.java
+36
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
View file @
04ac3b2e
...
...
@@ -13,6 +13,7 @@ import jadx.core.dex.info.ClassInfo;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.DexNode
;
import
jadx.core.dex.nodes.FieldNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.parser.FieldValueAttr
;
...
...
@@ -314,7 +315,7 @@ public class ClassGen {
}
public
String
useClass
(
ClassInfo
classInfo
)
{
String
baseClass
=
useClassInternal
(
classInfo
);
String
baseClass
=
useClassInternal
(
cl
s
.
getClassInfo
(),
cl
assInfo
);
ArgType
[]
generics
=
classInfo
.
getType
().
getGenericTypes
();
if
(
generics
!=
null
)
{
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -338,31 +339,37 @@ public class ClassGen {
}
}
private
String
useClassInternal
(
ClassInfo
classInfo
)
{
if
(
parentGen
!=
null
)
return
parentGen
.
useClassInternal
(
classInfo
);
private
String
useClassInternal
(
ClassInfo
useCls
,
ClassInfo
classInfo
)
{
if
(
parentGen
!=
null
)
{
return
parentGen
.
useClassInternal
(
useCls
,
classInfo
);
}
String
clsStr
=
classInfo
.
getFullName
();
if
(
fallback
)
if
(
fallback
)
{
return
clsStr
;
}
String
shortName
=
classInfo
.
getShortName
();
if
(
classInfo
.
getPackage
().
equals
(
"java.lang"
)
&&
classInfo
.
getParentClass
()
==
null
)
{
return
shortName
;
}
else
{
// don't add import if this class inner for current class
if
(
is
Inner
(
classInfo
,
cls
.
getClassInfo
()))
if
(
is
ClassInnerFor
(
classInfo
,
useCls
))
{
return
shortName
;
}
// don't add import if this class from same package
if
(
classInfo
.
getPackage
().
equals
(
cls
.
getPackage
()))
if
(
classInfo
.
getPackage
().
equals
(
useCls
.
getPackage
())
&&
!
classInfo
.
isInner
())
{
return
shortName
;
}
if
(
classInfo
.
getPackage
().
equals
(
useCls
.
getPackage
()))
{
clsStr
=
classInfo
.
getNameWithoutPackage
();
}
if
(
searchCollision
(
cls
.
dex
(),
useCls
,
shortName
))
{
return
clsStr
;
}
for
(
ClassInfo
cls
:
imports
)
{
if
(!
cls
.
equals
(
classInfo
))
{
if
(
cls
.
getShortName
().
equals
(
shortName
))
if
(
cls
.
getShortName
().
equals
(
shortName
))
{
return
clsStr
;
}
}
}
imports
.
add
(
classInfo
);
...
...
@@ -370,14 +377,30 @@ public class ClassGen {
}
}
private
boolean
isInne
r
(
ClassInfo
inner
,
ClassInfo
parent
)
{
private
static
boolean
isClassInnerFo
r
(
ClassInfo
inner
,
ClassInfo
parent
)
{
if
(
inner
.
isInner
())
{
ClassInfo
p
=
inner
.
getParentClass
();
return
p
.
equals
(
parent
)
||
is
Inne
r
(
p
,
parent
);
return
p
.
equals
(
parent
)
||
is
ClassInnerFo
r
(
p
,
parent
);
}
return
false
;
}
private
static
boolean
searchCollision
(
DexNode
dex
,
ClassInfo
useCls
,
String
shortName
)
{
if
(
useCls
==
null
)
{
return
false
;
}
if
(
useCls
.
getShortName
().
equals
(
shortName
))
{
return
true
;
}
ClassNode
classNode
=
dex
.
resolveClass
(
useCls
);
for
(
ClassNode
inner
:
classNode
.
getInnerClasses
())
{
if
(
inner
.
getShortName
().
equals
(
shortName
))
{
return
true
;
}
}
return
searchCollision
(
dex
,
useCls
.
getParentClass
(),
shortName
);
}
private
void
insertSourceFileInfo
(
CodeWriter
code
,
AttrNode
node
)
{
IAttribute
sourceFileAttr
=
node
.
getAttributes
().
get
(
AttributeType
.
SOURCE_FILE
);
if
(
sourceFileAttr
!=
null
)
{
...
...
jadx-samples/src/main/java/jadx/samples/TestInnerNames.java
0 → 100644
View file @
04ac3b2e
package
jadx
.
samples
;
public
class
TestInnerNames
extends
AbstractTest
{
public
int
D
;
public
class
A
extends
TestInner
.
MyThread
{
public
A
(
String
name
)
{
super
(
name
);
}
}
public
class
B
extends
A
{
public
B
(
String
name
)
{
super
(
name
);
}
public
class
C
extends
TestInner2
.
B
{
}
}
public
class
C
extends
TestInner2
.
B
{
}
public
class
D
extends
TestInner2
.
D
{
}
@Override
public
boolean
testRun
()
throws
Exception
{
return
true
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestInnerNames
().
testRun
();
}
}
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