Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
4d41a2d9
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 搜索 >>
未验证
提交
4d41a2d9
编写于
7月 18, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: fix call lookup position issue
上级
94b91c6e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
13 deletion
+34
-13
cmd/call.go
cmd/call.go
+3
-1
pkg/application/call/call_graph.go
pkg/application/call/call_graph.go
+16
-6
pkg/application/call/call_graph_test.go
pkg/application/call/call_graph_test.go
+2
-1
pkg/application/rcall/rcall_graph.go
pkg/application/rcall/rcall_graph.go
+13
-5
未找到文件。
cmd/call.go
浏览文件 @
4d41a2d9
...
...
@@ -15,6 +15,7 @@ type CallCmdConfig struct {
Path
string
ClassName
string
RemoveName
string
Lookup
bool
}
var
(
...
...
@@ -38,7 +39,7 @@ var callGraphCmd = &cobra.Command{
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
content
:=
analyser
.
Analysis
(
callCmdConfig
.
ClassName
,
parsedDeps
)
content
:=
analyser
.
Analysis
(
callCmdConfig
.
ClassName
,
parsedDeps
,
callCmdConfig
.
Lookup
)
if
callCmdConfig
.
RemoveName
!=
""
{
content
=
strings
.
ReplaceAll
(
content
,
callCmdConfig
.
RemoveName
,
""
)
}
...
...
@@ -55,4 +56,5 @@ func init() {
callGraphCmd
.
PersistentFlags
()
.
StringVarP
(
&
callCmdConfig
.
ClassName
,
"className"
,
"c"
,
""
,
"class"
)
callGraphCmd
.
PersistentFlags
()
.
StringVarP
(
&
callCmdConfig
.
Path
,
"dependence"
,
"d"
,
config
.
CocaConfig
.
ReporterPath
+
"/deps.json"
,
"get dependence file"
)
callGraphCmd
.
PersistentFlags
()
.
StringVarP
(
&
callCmdConfig
.
RemoveName
,
"remove"
,
"r"
,
""
,
"remove package ParamName"
)
callGraphCmd
.
PersistentFlags
()
.
BoolVarP
(
&
callCmdConfig
.
Lookup
,
"lookup"
,
"l"
,
false
,
"call with rcall"
)
}
pkg/application/call/call_graph.go
浏览文件 @
4d41a2d9
package
call
import
(
api_domain2
"github.com/phodal/coca/pkg/domain/api_domain"
"github.com/phodal/coca/pkg/application/rcall"
apidomain2
"github.com/phodal/coca/pkg/domain/api_domain"
"github.com/phodal/coca/pkg/domain/core_domain"
"github.com/phodal/coca/pkg/infrastructure/jpackage"
"strings"
...
...
@@ -14,9 +15,18 @@ func NewCallGraph() CallGraph {
return
CallGraph
{}
}
func
(
c
CallGraph
)
Analysis
(
funcName
string
,
clzs
[]
core_domain
.
CodeDataStruct
)
string
{
func
(
c
CallGraph
)
Analysis
(
funcName
string
,
clzs
[]
core_domain
.
CodeDataStruct
,
lookup
bool
)
string
{
methodMap
:=
BuildMethodMap
(
clzs
)
chain
:=
BuildCallChain
(
funcName
,
methodMap
,
nil
)
if
lookup
{
var
projectMethodMap
=
rcall
.
BuildProjectMethodMap
(
clzs
)
rcallMap
:=
rcall
.
BuildRCallMethodMap
(
clzs
,
projectMethodMap
)
graph
:=
rcall
.
NewRCallGraph
()
rCallChain
:=
graph
.
BuildRCallChain
(
funcName
,
rcallMap
)
chain
=
chain
+
rCallChain
}
dotContent
:=
ToGraphviz
(
chain
)
return
dotContent
}
...
...
@@ -25,7 +35,7 @@ func (c CallGraph) Analysis(funcName string, clzs []core_domain.CodeDataStruct)
func
ToGraphviz
(
chain
string
)
string
{
//rankdir = LR;
var
result
=
"digraph G {
\n
"
//
result += "rankdir = LR;\n"
result
+=
"rankdir = LR;
\n
"
result
=
result
+
chain
result
=
result
+
"}
\n
"
return
result
...
...
@@ -57,9 +67,9 @@ func BuildCallChain(funcName string, methodMap map[string][]string, diMap map[st
return
"
\n
"
}
func
(
c
CallGraph
)
AnalysisByFiles
(
restApis
[]
api
_domain2
.
RestAPI
,
deps
[]
core_domain
.
CodeDataStruct
,
diMap
map
[
string
]
string
)
(
string
,
[]
api_
domain2
.
CallAPI
)
{
func
(
c
CallGraph
)
AnalysisByFiles
(
restApis
[]
api
domain2
.
RestAPI
,
deps
[]
core_domain
.
CodeDataStruct
,
diMap
map
[
string
]
string
)
(
string
,
[]
api
domain2
.
CallAPI
)
{
methodMap
:=
BuildMethodMap
(
deps
)
var
apiCallSCounts
[]
api
_
domain2
.
CallAPI
var
apiCallSCounts
[]
apidomain2
.
CallAPI
results
:=
"digraph G {
\n
"
...
...
@@ -71,7 +81,7 @@ func (c CallGraph) AnalysisByFiles(restApis []api_domain2.RestAPI, deps []core_d
apiCallChain
:=
BuildCallChain
(
caller
,
methodMap
,
diMap
)
chain
=
chain
+
apiCallChain
count
:=
&
api
_
domain2
.
CallAPI
{
count
:=
&
apidomain2
.
CallAPI
{
HTTPMethod
:
restApi
.
HttpMethod
,
Caller
:
caller
,
URI
:
restApi
.
Uri
,
...
...
pkg/application/call/call_graph_test.go
浏览文件 @
4d41a2d9
...
...
@@ -24,9 +24,10 @@ func Test_ShouldBuildSuccessDataFromJson(t *testing.T) {
file
:=
cmd_util
.
ReadFile
(
codePath
)
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
dotContent
:=
analyser
.
Analysis
(
"com.phodal.pholedge.book.BookController.createBook"
,
parsedDeps
)
dotContent
:=
analyser
.
Analysis
(
"com.phodal.pholedge.book.BookController.createBook"
,
parsedDeps
,
false
)
g
.
Expect
(
dotContent
)
.
To
(
Equal
(
`digraph G {
rankdir = LR;
"com.phodal.pholedge.book.BookService.createBook" -> "com.phodal.pholedge.book.BookFactory.create";
"com.phodal.pholedge.book.BookService.createBook" -> "com.phodal.pholedge.book.model.command.CreateBookCommand.getIsbn";
"com.phodal.pholedge.book.BookService.createBook" -> "com.phodal.pholedge.book.model.command.CreateBookCommand.getName";
...
...
pkg/application/rcall/rcall_graph.go
浏览文件 @
4d41a2d9
package
rcall
import
(
"github.com/phodal/coca/pkg/application/call"
"github.com/phodal/coca/pkg/domain/core_domain"
)
...
...
@@ -18,11 +17,20 @@ func (c RCallGraph) Analysis(funcName string, clzs []core_domain.CodeDataStruct,
writeCallback
(
rcallMap
)
chain
:=
c
.
b
uildRCallChain
(
funcName
,
rcallMap
)
dotContent
:=
call
.
ToGraphviz
(
chain
)
chain
:=
c
.
B
uildRCallChain
(
funcName
,
rcallMap
)
dotContent
:=
ToGraphviz
(
chain
)
return
dotContent
}
// TODO: be a utils
func
ToGraphviz
(
chain
string
)
string
{
var
result
=
"digraph G {
\n
"
//result += "rankdir = LR;\n"
result
=
result
+
chain
result
=
result
+
"}
\n
"
return
result
}
func
BuildProjectMethodMap
(
clzs
[]
core_domain
.
CodeDataStruct
)
map
[
string
]
int
{
var
maps
=
make
(
map
[
string
]
int
)
for
_
,
clz
:=
range
clzs
{
...
...
@@ -57,7 +65,7 @@ func BuildRCallMethodMap(parserDeps []core_domain.CodeDataStruct, projectMaps ma
var
loopCount
=
0
var
lastChild
=
""
func
(
c
RCallGraph
)
b
uildRCallChain
(
funcName
string
,
methodMap
map
[
string
][]
string
)
string
{
func
(
c
RCallGraph
)
B
uildRCallChain
(
funcName
string
,
methodMap
map
[
string
][]
string
)
string
{
if
loopCount
>=
6
{
return
"
\n
"
}
...
...
@@ -71,7 +79,7 @@ func (c RCallGraph) buildRCallChain(funcName string, methodMap map[string][]stri
}
if
len
(
methodMap
[
child
])
>
0
{
lastChild
=
child
arrayResult
=
arrayResult
+
c
.
b
uildRCallChain
(
child
,
methodMap
)
arrayResult
=
arrayResult
+
c
.
B
uildRCallChain
(
child
,
methodMap
)
}
if
funcName
==
child
{
continue
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录