Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
176adca9
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,发现更多精彩内容 >>
未验证
提交
176adca9
编写于
1月 19, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: move method call to json node
上级
3fae76a7
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
443 addition
and
78 deletion
+443
-78
pkg/infrastructure/ast/cocago/cocago_parser_test.go
pkg/infrastructure/ast/cocago/cocago_parser_test.go
+28
-78
pkg/infrastructure/ast/cocago/testdata/method_call/local_var_method_call.code
...st/cocago/testdata/method_call/local_var_method_call.code
+15
-0
pkg/infrastructure/ast/cocago/testdata/method_call/local_var_method_call.json
...st/cocago/testdata/method_call/local_var_method_call.json
+131
-0
pkg/infrastructure/ast/cocago/testdata/method_call/param_method_call.code
...re/ast/cocago/testdata/method_call/param_method_call.code
+9
-0
pkg/infrastructure/ast/cocago/testdata/method_call/param_method_call.json
...re/ast/cocago/testdata/method_call/param_method_call.json
+122
-0
pkg/infrastructure/ast/cocago/testdata/method_call/var_inside_method_with_call.code
...ago/testdata/method_call/var_inside_method_with_call.code
+13
-0
pkg/infrastructure/ast/cocago/testdata/method_call/var_inside_method_with_call.json
...ago/testdata/method_call/var_inside_method_with_call.json
+125
-0
未找到文件。
pkg/infrastructure/ast/cocago/cocago_parser_test.go
浏览文件 @
176adca9
...
...
@@ -72,6 +72,34 @@ func TestCocagoParser_ProcessFile(t *testing.T) {
}
}
func
Test_Method_Call
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
fileName
string
}{
{
"local_var_method_call"
,
"local_var_method_call"
,
},
{
"param_method_call"
,
"param_method_call"
,
},
{
"var_inside_method_with_call"
,
"var_inside_method_with_call"
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
filePath
:=
"testdata/method_call/"
+
tt
.
fileName
if
got
:=
testParser
.
ProcessFile
(
filePath
+
".code"
);
!
cocatest
.
JSONFileBytesEqual
(
got
,
filePath
+
".json"
)
{
t
.
Errorf
(
"ProcessFile() = %v, want %v"
,
got
,
tt
.
fileName
)
}
})
}
}
func
getFilePath
(
name
string
)
string
{
return
"testdata/node_infos/"
+
name
}
...
...
@@ -116,84 +144,6 @@ func Test_NestedMethod(t *testing.T) {
g
.
Expect
(
cocatest
.
JSONFileBytesEqual
(
results
,
filePath
+
".json"
))
.
To
(
Equal
(
true
))
}
// var call
func
Test_VarMethodCall
(
t
*
testing
.
T
)
{
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
results
:=
testParser
.
ProcessString
(
`
package main
import (
"fmt"
"sync"
)
var l *sync.Mutex
func main() {
l = new(sync.Mutex)
l.Lock()
defer l.Unlock()
fmt.Println("1")
}
`
,
"call"
,
nil
)
calls
:=
results
.
Members
[
0
]
.
FunctionNodes
[
0
]
.
FunctionCalls
fmt
.
Println
(
calls
)
g
.
Expect
(
len
(
results
.
Fields
))
.
To
(
Equal
(
1
))
g
.
Expect
(
calls
[
0
]
.
Package
)
.
To
(
Equal
(
"sync"
))
g
.
Expect
(
calls
[
0
]
.
Type
)
.
To
(
Equal
(
"sync.Mutex"
))
g
.
Expect
(
len
(
calls
))
.
To
(
Equal
(
3
))
}
// should call local
func
Test_LocalMethodCall
(
t
*
testing
.
T
)
{
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
results
:=
testParser
.
ProcessString
(
`
package main
import (
"fmt"
"sync"
)
func main() {
l := new(sync.Mutex)
l.Lock()
defer l.Unlock()
fmt.Println("1")
}
`
,
"call"
,
nil
)
calls
:=
results
.
Members
[
0
]
.
FunctionNodes
[
0
]
.
FunctionCalls
g
.
Expect
(
calls
[
0
]
.
Package
)
.
To
(
Equal
(
"sync"
))
g
.
Expect
(
calls
[
0
]
.
Type
)
.
To
(
Equal
(
"sync.Mutex"
))
g
.
Expect
(
calls
[
2
]
.
Package
)
.
To
(
Equal
(
"fmt"
))
g
.
Expect
(
len
(
calls
))
.
To
(
Equal
(
3
))
}
func
Test_ShouldSetParameterInterfaceToCallNodes
(
t
*
testing
.
T
)
{
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
results
:=
testParser
.
ProcessString
(
`
package api_domain
import "sort"
func SortAPIs(callAPIs []CallAPI) {
sort.Slice(callAPIs, func(i, j int) bool {
return callAPIs[i].Size < callAPIs[j].Size
})
}
`
,
"call"
,
nil
)
g
.
Expect
(
results
.
PackageName
)
.
To
(
Equal
(
"api_domain"
))
g
.
Expect
(
len
(
results
.
Members
[
0
]
.
FunctionNodes
[
0
]
.
FunctionCalls
))
.
To
(
Equal
(
3
))
}
func
Test_RelatedImport
(
t
*
testing
.
T
)
{
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
...
...
pkg/infrastructure/ast/cocago/testdata/method_call/local_var_method_call.code
0 → 100644
浏览文件 @
176adca9
package
main
import
(
"fmt"
"sync"
)
var
l
*
sync
.
Mutex
func
main
()
{
l
=
new
(
sync
.
Mutex
)
l
.
Lock
()
defer
l
.
Unlock
()
fmt
.
Println
(
"1"
)
}
pkg/infrastructure/ast/cocago/testdata/method_call/local_var_method_call.json
0 → 100644
浏览文件 @
176adca9
{
"DataStructures"
:
null
,
"Fields"
:
[
{
"Modifiers"
:
null
,
"TypeType"
:
"sync.Mutex"
,
"TypeValue"
:
"l"
}
],
"FullName"
:
"testdata.method_call"
,
"Imports"
:
[
{
"AsName"
:
""
,
"ImportName"
:
""
,
"Scope"
:
""
,
"Source"
:
"fmt"
,
"UsageName"
:
null
},
{
"AsName"
:
""
,
"ImportName"
:
""
,
"Scope"
:
""
,
"Source"
:
"sync"
,
"UsageName"
:
null
}
],
"Members"
:
[
{
"AliasPackage"
:
"main"
,
"DataStructID"
:
"default"
,
"FileID"
:
"testdata.method_call"
,
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"Extension"
:
null
,
"FunctionCalls"
:
[
{
"MethodName"
:
""
,
"NodeName"
:
"new"
,
"Package"
:
"testdata.method_call"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
""
},
{
"MethodName"
:
"Lock"
,
"NodeName"
:
"l"
,
"Package"
:
"sync"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
"sync.Mutex"
},
{
"MethodName"
:
"Unlock"
,
"NodeName"
:
"l"
,
"Package"
:
"sync"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
"sync.Mutex"
},
{
"MethodName"
:
"Println"
,
"NodeName"
:
"fmt"
,
"Package"
:
"fmt"
,
"Parameters"
:
[
{
"Modifiers"
:
null
,
"ParamName"
:
""
,
"Parameters"
:
null
,
"ReturnTypes"
:
null
,
"TypeType"
:
"STRING"
,
"TypeValue"
:
"
\"
1
\"
"
}
],
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
"fmt"
}
],
"InnerFunctions"
:
null
,
"InnerStructures"
:
null
,
"IsConstructor"
:
false
,
"IsReturnNull"
:
false
,
"Modifiers"
:
null
,
"MultipleReturns"
:
null
,
"Name"
:
"main"
,
"Override"
:
false
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"ReturnType"
:
""
}
],
"ID"
:
"main:main"
,
"Name"
:
""
,
"Namespace"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Structures"
:
null
,
"Type"
:
"method"
}
],
"PackageName"
:
"main"
}
\ No newline at end of file
pkg/infrastructure/ast/cocago/testdata/method_call/param_method_call.code
0 → 100644
浏览文件 @
176adca9
package
api_domain
import
"sort"
func
SortAPIs
(
callAPIs
[]
CallAPI
)
{
sort
.
Slice
(
callAPIs
,
func
(
i
,
j
int
)
bool
{
return
callAPIs
[
i
].
Size
<
callAPIs
[
j
].
Size
})
}
pkg/infrastructure/ast/cocago/testdata/method_call/param_method_call.json
0 → 100644
浏览文件 @
176adca9
{
"DataStructures"
:
null
,
"Fields"
:
null
,
"FullName"
:
"testdata.method_call"
,
"Imports"
:
[
{
"AsName"
:
""
,
"ImportName"
:
""
,
"Scope"
:
""
,
"Source"
:
"sort"
,
"UsageName"
:
null
}
],
"Members"
:
[
{
"AliasPackage"
:
"api_domain"
,
"DataStructID"
:
"default"
,
"FileID"
:
"testdata.method_call"
,
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"Extension"
:
null
,
"FunctionCalls"
:
[
{
"MethodName"
:
"Size"
,
"NodeName"
:
"CallAPI"
,
"Package"
:
"testdata.method_call"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
""
},
{
"MethodName"
:
"Size"
,
"NodeName"
:
"CallAPI"
,
"Package"
:
"testdata.method_call"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
""
},
{
"MethodName"
:
"Slice"
,
"NodeName"
:
"sort"
,
"Package"
:
"sort"
,
"Parameters"
:
[
{
"Modifiers"
:
null
,
"ParamName"
:
""
,
"Parameters"
:
null
,
"ReturnTypes"
:
null
,
"TypeType"
:
"var"
,
"TypeValue"
:
"callAPIs"
},
{
"Modifiers"
:
null
,
"ParamName"
:
""
,
"Parameters"
:
null
,
"ReturnTypes"
:
null
,
"TypeType"
:
""
,
"TypeValue"
:
""
}
],
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
"sort"
}
],
"InnerFunctions"
:
null
,
"InnerStructures"
:
null
,
"IsConstructor"
:
false
,
"IsReturnNull"
:
false
,
"Modifiers"
:
null
,
"MultipleReturns"
:
null
,
"Name"
:
"SortAPIs"
,
"Override"
:
false
,
"Parameters"
:
[
{
"Modifiers"
:
null
,
"ParamName"
:
"callAPIs"
,
"Parameters"
:
null
,
"ReturnTypes"
:
null
,
"TypeType"
:
"ArrayType"
,
"TypeValue"
:
"CallAPI"
}
],
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"ReturnType"
:
""
}
],
"ID"
:
"api_domain:SortAPIs"
,
"Name"
:
""
,
"Namespace"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Structures"
:
null
,
"Type"
:
"method"
}
],
"PackageName"
:
"api_domain"
}
\ No newline at end of file
pkg/infrastructure/ast/cocago/testdata/method_call/var_inside_method_with_call.code
0 → 100644
浏览文件 @
176adca9
package
main
import
(
"fmt"
"sync"
)
func
main
()
{
l
:=
new
(
sync
.
Mutex
)
l
.
Lock
()
defer
l
.
Unlock
()
fmt
.
Println
(
"1"
)
}
pkg/infrastructure/ast/cocago/testdata/method_call/var_inside_method_with_call.json
0 → 100644
浏览文件 @
176adca9
{
"DataStructures"
:
null
,
"Fields"
:
null
,
"FullName"
:
"testdata.method_call"
,
"Imports"
:
[
{
"AsName"
:
""
,
"ImportName"
:
""
,
"Scope"
:
""
,
"Source"
:
"fmt"
,
"UsageName"
:
null
},
{
"AsName"
:
""
,
"ImportName"
:
""
,
"Scope"
:
""
,
"Source"
:
"sync"
,
"UsageName"
:
null
}
],
"Members"
:
[
{
"AliasPackage"
:
"main"
,
"DataStructID"
:
"default"
,
"FileID"
:
"testdata.method_call"
,
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"Extension"
:
null
,
"FunctionCalls"
:
[
{
"MethodName"
:
""
,
"NodeName"
:
"new"
,
"Package"
:
"testdata.method_call"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
""
},
{
"MethodName"
:
"Lock"
,
"NodeName"
:
"l"
,
"Package"
:
"sync"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
"sync.Mutex"
},
{
"MethodName"
:
"Unlock"
,
"NodeName"
:
"l"
,
"Package"
:
"sync"
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
"sync.Mutex"
},
{
"MethodName"
:
"Println"
,
"NodeName"
:
"fmt"
,
"Package"
:
"fmt"
,
"Parameters"
:
[
{
"Modifiers"
:
null
,
"ParamName"
:
""
,
"Parameters"
:
null
,
"ReturnTypes"
:
null
,
"TypeType"
:
"STRING"
,
"TypeValue"
:
"
\"
1
\"
"
}
],
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
"fmt"
}
],
"InnerFunctions"
:
null
,
"InnerStructures"
:
null
,
"IsConstructor"
:
false
,
"IsReturnNull"
:
false
,
"Modifiers"
:
null
,
"MultipleReturns"
:
null
,
"Name"
:
"main"
,
"Override"
:
false
,
"Parameters"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"ReturnType"
:
""
}
],
"ID"
:
"main:main"
,
"Name"
:
""
,
"Namespace"
:
null
,
"Position"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Structures"
:
null
,
"Type"
:
"method"
}
],
"PackageName"
:
"main"
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录