Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
957f7a15
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
957f7a15
编写于
12月 31, 2019
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bug: add test for rcall
上级
7b3464f4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
432 addition
and
3 deletion
+432
-3
_fixtures/rcall/constructor_call.json
_fixtures/rcall/constructor_call.json
+393
-0
core/context/rcall/rcall_graph.go
core/context/rcall/rcall_graph.go
+6
-2
core/context/rcall/rcall_graph_test.go
core/context/rcall/rcall_graph_test.go
+33
-1
未找到文件。
_fixtures/rcall/constructor_call.json
0 → 100644
浏览文件 @
957f7a15
[
{
"Package"
:
"com.phodal.coca.analysis"
,
"Class"
:
"JavaCallApp"
,
"Type"
:
""
,
"Path"
:
"_fixtures/examples/poly/poly.java"
,
"Fields"
:
[
{
"Type"
:
"JavaDaoParser"
,
"Value"
:
"daoParser"
}
],
"Methods"
:
[
{
"Name"
:
"parse"
,
"Type"
:
"void"
,
"StartLine"
:
57
,
"StartLinePosition"
:
16
,
"StopLine"
:
63
,
"StopLinePosition"
:
21
,
"Parameters"
:
[
{
"Name"
:
"path"
,
"Type"
:
"Path"
},
{
"Name"
:
"clzs"
,
"Type"
:
"List
\u
003cString
\u
003e"
}
],
"MethodCalls"
:
[
{
"Package"
:
"com.phodal.coca.analysis"
,
"Type"
:
""
,
"Class"
:
"System.out"
,
"MethodName"
:
"println"
,
"Parameters"
:
[
"
\"
Start parse java call:
\"
+path.getFileName()"
],
"StartLine"
:
58
,
"StartLinePosition"
:
19
,
"StopLine"
:
58
,
"StopLinePosition"
:
26
},
{
"Package"
:
"java.nio.file"
,
"Type"
:
"chain"
,
"Class"
:
"Path"
,
"MethodName"
:
"getFileName"
,
"Parameters"
:
null
,
"StartLine"
:
58
,
"StartLinePosition"
:
60
,
"StopLine"
:
58
,
"StopLinePosition"
:
71
},
{
"Package"
:
"com.phodal.coca.analysis.identifier"
,
"Type"
:
"chain"
,
"Class"
:
"JavaFileParser"
,
"MethodName"
:
"parse"
,
"Parameters"
:
[
"path"
],
"StartLine"
:
59
,
"StartLinePosition"
:
40
,
"StopLine"
:
59
,
"StopLinePosition"
:
45
},
{
"Package"
:
"java.util"
,
"Type"
:
"CreatorClass"
,
"Class"
:
"ArrayList"
,
"MethodName"
:
""
,
"Parameters"
:
null
,
"StartLine"
:
60
,
"StartLinePosition"
:
38
,
"StopLine"
:
60
,
"StopLinePosition"
:
50
},
{
"Package"
:
"com.phodal.coca.analysis.calls"
,
"Type"
:
"CreatorClass"
,
"Class"
:
"JavaCallVisitor"
,
"MethodName"
:
""
,
"Parameters"
:
null
,
"StartLine"
:
61
,
"StartLinePosition"
:
44
,
"StopLine"
:
61
,
"StopLinePosition"
:
82
},
{
"Package"
:
"com.phodal.coca.java"
,
"Type"
:
"chain"
,
"Class"
:
"JavaParserBaseVisitor"
,
"MethodName"
:
"visit"
,
"Parameters"
:
[
"tree"
],
"StartLine"
:
62
,
"StartLinePosition"
:
16
,
"StopLine"
:
62
,
"StopLinePosition"
:
21
}
],
"Override"
:
false
,
"Annotations"
:
null
,
"IsConstructor"
:
false
,
"IsReturnNull"
:
false
,
"Modifiers"
:
null
,
"Creators"
:
null
},
{
"Name"
:
"JavaCallApp"
,
"Type"
:
""
,
"StartLine"
:
26
,
"StartLinePosition"
:
11
,
"StopLine"
:
28
,
"StopLinePosition"
:
4
,
"Parameters"
:
[
{
"Name"
:
"daoParser"
,
"Type"
:
"JavaDaoParser"
}
],
"MethodCalls"
:
null
,
"Override"
:
false
,
"Annotations"
:
null
,
"IsConstructor"
:
true
,
"IsReturnNull"
:
false
,
"Modifiers"
:
null
,
"Creators"
:
null
},
{
"Name"
:
"analysisDir"
,
"Type"
:
"void"
,
"StartLine"
:
30
,
"StartLinePosition"
:
16
,
"StopLine"
:
42
,
"StopLinePosition"
:
27
,
"Parameters"
:
[
{
"Name"
:
"dir"
,
"Type"
:
"String"
},
{
"Name"
:
"clzs"
,
"Type"
:
"List
\u
003cString
\u
003e"
}
],
"MethodCalls"
:
[
{
"Package"
:
"java.nio.file"
,
"Type"
:
"chain"
,
"Class"
:
"Paths"
,
"MethodName"
:
"get"
,
"Parameters"
:
[
"dir"
],
"StartLine"
:
31
,
"StartLinePosition"
:
33
,
"StopLine"
:
31
,
"StopLinePosition"
:
36
},
{
"Package"
:
"com.phodal.coca.analysis"
,
"Type"
:
""
,
"Class"
:
"JavaCallApp"
,
"MethodName"
:
"parse"
,
"Parameters"
:
[
"clzs"
],
"StartLine"
:
32
,
"StartLinePosition"
:
38
,
"StopLine"
:
32
,
"StopLinePosition"
:
43
},
{
"Package"
:
"java.util.concurrent"
,
"Type"
:
"chain"
,
"Class"
:
"Executors"
,
"MethodName"
:
"newFixedThreadPool"
,
"Parameters"
:
[
"poolSize"
],
"StartLine"
:
34
,
"StartLinePosition"
:
41
,
"StopLine"
:
34
,
"StopLinePosition"
:
59
},
{
"Package"
:
"java.util"
,
"Type"
:
"CreatorClass"
,
"Class"
:
"ArrayList"
,
"MethodName"
:
""
,
"Parameters"
:
null
,
"StartLine"
:
35
,
"StartLinePosition"
:
35
,
"StopLine"
:
35
,
"StopLinePosition"
:
47
},
{
"Package"
:
"com.phodal.coca.analysis.utils"
,
"Type"
:
"CreatorClass"
,
"Class"
:
"ProcessFiles"
,
"MethodName"
:
""
,
"Parameters"
:
null
,
"StartLine"
:
36
,
"StartLinePosition"
:
30
,
"StopLine"
:
36
,
"StopLinePosition"
:
70
},
{
"Package"
:
"com.phodal.coca.analysis.utils"
,
"Type"
:
"chain"
,
"Class"
:
"Files"
,
"MethodName"
:
"walkFileTree"
,
"Parameters"
:
[
"startingDir"
,
"pf"
],
"StartLine"
:
37
,
"StartLinePosition"
:
14
,
"StopLine"
:
37
,
"StopLinePosition"
:
26
},
{
"Package"
:
"com.phodal.coca.analysis"
,
"Type"
:
""
,
"Class"
:
"f"
,
"MethodName"
:
"get"
,
"Parameters"
:
null
,
"StartLine"
:
39
,
"StartLinePosition"
:
14
,
"StopLine"
:
39
,
"StopLinePosition"
:
17
},
{
"Package"
:
"java.util.concurrent"
,
"Type"
:
"chain"
,
"Class"
:
"ExecutorService"
,
"MethodName"
:
"shutdown"
,
"Parameters"
:
null
,
"StartLine"
:
41
,
"StartLinePosition"
:
13
,
"StopLine"
:
41
,
"StopLinePosition"
:
21
}
],
"Override"
:
false
,
"Annotations"
:
null
,
"IsConstructor"
:
false
,
"IsReturnNull"
:
false
,
"Modifiers"
:
null
,
"Creators"
:
null
},
{
"Name"
:
"parse"
,
"Type"
:
"Consumer
\u
003cPath
\u
003e"
,
"StartLine"
:
44
,
"StartLinePosition"
:
27
,
"StopLine"
:
55
,
"StopLinePosition"
:
32
,
"Parameters"
:
[
{
"Name"
:
"clzs"
,
"Type"
:
"List
\u
003cString
\u
003e"
}
],
"MethodCalls"
:
[
{
"Package"
:
"java.nio.file"
,
"Type"
:
"chain"
,
"Class"
:
"Path"
,
"MethodName"
:
"toString"
,
"Parameters"
:
null
,
"StartLine"
:
47
,
"StartLinePosition"
:
48
,
"StopLine"
:
47
,
"StopLinePosition"
:
56
},
{
"Package"
:
"com.phodal.coca.analysis"
,
"Type"
:
""
,
"Class"
:
"path"
,
"MethodName"
:
"endsWith"
,
"Parameters"
:
[
"
\"
Tests.java
\"
"
],
"StartLine"
:
47
,
"StartLinePosition"
:
59
,
"StopLine"
:
47
,
"StopLinePosition"
:
67
},
{
"Package"
:
"java.nio.file"
,
"Type"
:
"chain"
,
"Class"
:
"Path"
,
"MethodName"
:
"toString"
,
"Parameters"
:
null
,
"StartLine"
:
47
,
"StartLinePosition"
:
91
,
"StopLine"
:
47
,
"StopLinePosition"
:
99
},
{
"Package"
:
"com.phodal.coca.analysis"
,
"Type"
:
""
,
"Class"
:
"path"
,
"MethodName"
:
"endsWith"
,
"Parameters"
:
[
"
\"
Test.java
\"
"
],
"StartLine"
:
47
,
"StartLinePosition"
:
102
,
"StopLine"
:
47
,
"StopLinePosition"
:
110
},
{
"Package"
:
"java.nio.file"
,
"Type"
:
"chain"
,
"Class"
:
"Path"
,
"MethodName"
:
"toString"
,
"Parameters"
:
null
,
"StartLine"
:
47
,
"StartLinePosition"
:
132
,
"StopLine"
:
47
,
"StopLinePosition"
:
140
},
{
"Package"
:
"com.phodal.coca.analysis"
,
"Type"
:
""
,
"Class"
:
"path"
,
"MethodName"
:
"endsWith"
,
"Parameters"
:
[
"
\"
.java
\"
"
],
"StartLine"
:
47
,
"StartLinePosition"
:
143
,
"StopLine"
:
47
,
"StopLinePosition"
:
151
},
{
"Package"
:
"com.phodal.coca.analysis"
,
"Type"
:
""
,
"Class"
:
"JavaCallApp"
,
"MethodName"
:
"parse"
,
"Parameters"
:
[
"path"
,
"clzs"
],
"StartLine"
:
49
,
"StartLinePosition"
:
20
,
"StopLine"
:
49
,
"StopLinePosition"
:
25
},
{
"Package"
:
"org.antlr.v4.runtime.tree"
,
"Type"
:
"chain"
,
"Class"
:
"e"
,
"MethodName"
:
"printStackTrace"
,
"Parameters"
:
null
,
"StartLine"
:
52
,
"StartLinePosition"
:
18
,
"StopLine"
:
52
,
"StopLinePosition"
:
33
}
],
"Override"
:
false
,
"Annotations"
:
null
,
"IsConstructor"
:
false
,
"IsReturnNull"
:
false
,
"Modifiers"
:
null
,
"Creators"
:
null
}
],
"MethodCalls"
:
[
{
"Package"
:
"com.phodal.coca.analysis.calls"
,
"Type"
:
"field"
,
"Class"
:
"JavaDaoParser"
,
"MethodName"
:
""
,
"Parameters"
:
null
,
"StartLine"
:
24
,
"StartLinePosition"
:
12
,
"StopLine"
:
24
,
"StopLinePosition"
:
35
}
],
"Extend"
:
""
,
"Implements"
:
null
,
"Annotations"
:
null
}
]
\ No newline at end of file
core/context/rcall/rcall_graph.go
浏览文件 @
957f7a15
...
...
@@ -60,7 +60,7 @@ func BuildRCallMethodMap(parserDeps []domain.JClassNode, projectMaps map[string]
var
loopCount
=
0
func
(
c
RCallGraph
)
buildRCallChain
(
funcName
string
,
methodMap
map
[
string
][]
string
)
string
{
if
loopCount
>
6
{
if
loopCount
>
=
6
{
return
"
\n
"
}
loopCount
++
...
...
@@ -71,7 +71,11 @@ func (c RCallGraph) buildRCallChain(funcName string, methodMap map[string][]stri
if
len
(
methodMap
[
child
])
>
0
{
arrayResult
=
arrayResult
+
c
.
buildRCallChain
(
child
,
methodMap
)
}
arrayResult
=
arrayResult
+
"
\"
"
+
funcName
+
"
\"
->
\"
"
+
child
+
"
\"
;
\n
"
if
funcName
==
child
{
continue
}
newCall
:=
"
\"
"
+
funcName
+
"
\"
->
\"
"
+
child
+
"
\"
;
\n
"
arrayResult
=
arrayResult
+
newCall
}
return
arrayResult
...
...
core/context/rcall/rcall_graph_test.go
浏览文件 @
957f7a15
...
...
@@ -10,6 +10,10 @@ import (
.
"github.com/onsi/gomega"
)
func
MockWriteCallMap
(
rcallMap
map
[
string
][]
string
)
{
}
func
TestRCallGraph_Analysis
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
...
...
@@ -22,11 +26,39 @@ func TestRCallGraph_Analysis(t *testing.T) {
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
content
:=
analyser
.
Analysis
(
"com.phodal.pholedge.book.BookFactory.create"
,
*&
parsedDeps
,
nil
)
content
:=
analyser
.
Analysis
(
"com.phodal.pholedge.book.BookService.createBook"
,
*&
parsedDeps
,
MockWriteCallMap
)
g
.
Expect
(
content
)
.
To
(
Equal
(
`digraph G {
rankdir = LR;
edge [dir="back"];
"com.phodal.pholedge.book.BookService.createBook" -> "com.phodal.pholedge.book.BookController.createBook";
}
`
))
}
func
TestRCallGraph_Constructor
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
var
parsedDeps
[]
domain
.
JClassNode
analyser
:=
NewRCallGraph
()
file
:=
cmd_util
.
ReadFile
(
"../../../_fixtures/rcall/constructor_call.json"
)
if
file
==
nil
{
log
.
Fatal
(
"lost file"
)
}
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
content
:=
analyser
.
Analysis
(
"com.phodal.coca.analysis.JavaCallApp.parse"
,
*&
parsedDeps
,
MockWriteCallMap
)
// Todo bug: to be fix
g
.
Expect
(
content
)
.
To
(
Equal
(
`digraph G {
rankdir = LR;
edge [dir="back"];
"com.phodal.coca.analysis.JavaCallApp.parse" -> "com.phodal.coca.analysis.JavaCallApp.analysisDir";
"com.phodal.coca.analysis.JavaCallApp.parse" -> "com.phodal.coca.analysis.JavaCallApp.analysisDir";
"com.phodal.coca.analysis.JavaCallApp.parse" -> "com.phodal.coca.analysis.JavaCallApp.analysisDir";
"com.phodal.coca.analysis.JavaCallApp.parse" -> "com.phodal.coca.analysis.JavaCallApp.analysisDir";
"com.phodal.coca.analysis.JavaCallApp.parse" -> "com.phodal.coca.analysis.JavaCallApp.analysisDir";
}
`
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录