Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_39073359
jadx
提交
438b3b50
J
jadx
项目概览
qq_39073359
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
438b3b50
编写于
12月 26, 2013
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gui: fix missed nodes in hierarchical packages tree
上级
6bac5c16
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
20 deletion
+89
-20
jadx-gui/src/main/java/jadx/gui/treemodel/JPackage.java
jadx-gui/src/main/java/jadx/gui/treemodel/JPackage.java
+7
-5
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
+14
-6
jadx-gui/src/test/java/jadx/gui/treemodel/JRootTest.java
jadx-gui/src/test/java/jadx/gui/treemodel/JRootTest.java
+68
-9
未找到文件。
jadx-gui/src/main/java/jadx/gui/treemodel/JPackage.java
浏览文件 @
438b3b50
...
...
@@ -84,11 +84,13 @@ public class JPackage extends JNode implements Comparable<JPackage> {
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
JPackage
jPackage
=
(
JPackage
)
o
;
if
(!
name
.
equals
(
jPackage
.
name
))
return
false
;
return
true
;
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
return
name
.
equals
(((
JPackage
)
o
).
name
);
}
@Override
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
浏览文件 @
438b3b50
...
...
@@ -10,7 +10,7 @@ import java.io.File;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.
HashSet
;
import
java.util.
IdentityHashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -47,6 +47,12 @@ public class JRoot extends JNode {
}
}
/**
* Convert packages list to hierarchical packages representation
*
* @param packages input packages list
* @return root packages
*/
List
<
JPackage
>
getHierarchyPackages
(
List
<
JavaPackage
>
packages
)
{
Map
<
String
,
JPackage
>
pkgMap
=
new
HashMap
<
String
,
JPackage
>();
for
(
JavaPackage
pkg
:
packages
)
{
...
...
@@ -63,11 +69,11 @@ public class JRoot extends JNode {
pkg
.
getInnerPackages
().
addAll
(
innerPkg
.
getInnerPackages
());
pkg
.
getClasses
().
addAll
(
innerPkg
.
getClasses
());
pkg
.
setName
(
pkg
.
getName
()
+
"."
+
innerPkg
.
getName
());
innerPkg
.
getInnerPackages
().
clear
();
innerPkg
.
getClasses
().
clear
();
repeat
=
true
;
pkgMap
.
remove
(
innerPkg
.
getName
());
break
;
}
}
...
...
@@ -80,14 +86,16 @@ public class JRoot extends JNode {
it
.
remove
();
}
}
// find root packages
Set
<
JPackage
>
inners
=
new
HashSet
<
JPackage
>();
// use identity set for collect inner packages
Set
<
JPackage
>
innerPackages
=
Collections
.
newSetFromMap
(
new
IdentityHashMap
<
JPackage
,
Boolean
>());
for
(
JPackage
pkg
:
pkgMap
.
values
())
{
inners
.
addAll
(
pkg
.
getInnerPackages
());
inner
Package
s
.
addAll
(
pkg
.
getInnerPackages
());
}
// find root packages
List
<
JPackage
>
rootPkgs
=
new
ArrayList
<
JPackage
>();
for
(
JPackage
pkg
:
pkgMap
.
values
())
{
if
(!
inners
.
contains
(
pkg
))
{
if
(!
inner
Package
s
.
contains
(
pkg
))
{
rootPkgs
.
add
(
pkg
);
}
}
...
...
jadx-gui/src/test/java/jadx/gui/treemodel/JRootTest.java
浏览文件 @
438b3b50
...
...
@@ -8,10 +8,10 @@ import jadx.api.JavaPackage;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.gui.JadxWrapper
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -19,25 +19,84 @@ import static org.mockito.Mockito.mock;
public
class
JRootTest
{
private
JRoot
root
;
private
Decompiler
decompiler
;
@Before
public
void
init
()
{
root
=
new
JRoot
(
mock
(
JadxWrapper
.
class
));
decompiler
=
new
Decompiler
(
mock
(
IJadxArgs
.
class
));
}
@Test
public
void
testHierarchyPackages
()
{
String
pkgName
=
"a.b.c.d.e"
;
JadxWrapper
wrapper
=
mock
(
JadxWrapper
.
class
);
JRoot
root
=
new
JRoot
(
wrapper
);
List
<
JavaPackage
>
packages
=
Arrays
.
asList
(
newPkg
(
pkgName
)
);
List
<
JPackage
>
out
=
root
.
getHierarchyPackages
(
packages
);
JavaClass
cls
=
Factory
.
newClass
(
new
Decompiler
(
mock
(
IJadxArgs
.
class
)),
mock
(
ClassNode
.
class
));
JavaPackage
pkg
=
Factory
.
newPackage
(
pkgName
,
Arrays
.
asList
(
cls
));
assertEquals
(
out
.
size
(),
1
);
JPackage
jpkg
=
out
.
get
(
0
);
assertEquals
(
jpkg
.
getName
(),
pkgName
);
assertEquals
(
jpkg
.
getClasses
().
size
(),
1
);
}
List
<
JavaPackage
>
packages
=
new
ArrayList
<
JavaPackage
>();
packages
.
add
(
pkg
);
@Test
public
void
testHierarchyPackages2
()
{
List
<
JavaPackage
>
packages
=
Arrays
.
asList
(
newPkg
(
"a.b"
),
newPkg
(
"a.c"
),
newPkg
(
"a.d"
)
);
List
<
JPackage
>
out
=
root
.
getHierarchyPackages
(
packages
);
assertEquals
(
out
.
size
(),
1
);
JPackage
jpkg
=
out
.
get
(
0
);
assertEquals
(
jpkg
.
getName
(),
"a"
);
assertEquals
(
jpkg
.
getClasses
().
size
(),
0
);
assertEquals
(
jpkg
.
getInnerPackages
().
size
(),
3
);
}
@Test
public
void
testHierarchyPackages3
()
{
List
<
JavaPackage
>
packages
=
Arrays
.
asList
(
newPkg
(
"a.b.p1"
),
newPkg
(
"a.b.p2"
),
newPkg
(
"a.b.p3"
)
);
List
<
JPackage
>
out
=
root
.
getHierarchyPackages
(
packages
);
assertEquals
(
out
.
size
(),
1
);
JPackage
jpkg
=
out
.
get
(
0
);
assertEquals
(
jpkg
.
getName
(),
pkgName
);
assertEquals
(
jpkg
.
getClasses
().
size
(),
1
);
assertEquals
(
jpkg
.
getName
(),
"a.b"
);
assertEquals
(
jpkg
.
getClasses
().
size
(),
0
);
assertEquals
(
jpkg
.
getInnerPackages
().
size
(),
3
);
}
@Test
public
void
testHierarchyPackages4
()
{
List
<
JavaPackage
>
packages
=
Arrays
.
asList
(
newPkg
(
"a.p1"
),
newPkg
(
"a.b.c.p2"
),
newPkg
(
"a.b.c.p3"
),
newPkg
(
"d.e"
),
newPkg
(
"d.f.a"
)
);
List
<
JPackage
>
out
=
root
.
getHierarchyPackages
(
packages
);
assertEquals
(
out
.
size
(),
2
);
assertEquals
(
out
.
get
(
0
).
getName
(),
"a"
);
assertEquals
(
out
.
get
(
0
).
getInnerPackages
().
size
(),
2
);
assertEquals
(
out
.
get
(
1
).
getName
(),
"d"
);
assertEquals
(
out
.
get
(
1
).
getInnerPackages
().
size
(),
2
);
}
private
JavaPackage
newPkg
(
String
name
)
{
return
Factory
.
newPackage
(
name
,
Arrays
.
asList
(
newClass
()));
}
private
JavaClass
newClass
()
{
return
Factory
.
newClass
(
decompiler
,
mock
(
ClassNode
.
class
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录