Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
272e057e
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 搜索 >>
未验证
提交
272e057e
编写于
1月 17, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: [go] fix import equal source issue
上级
a91aac1a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
24 deletion
+36
-24
pkg/infrastructure/ast/cocago/cocago_builder.go
pkg/infrastructure/ast/cocago/cocago_builder.go
+31
-20
pkg/infrastructure/ast/cocago/cocago_parser_test.go
pkg/infrastructure/ast/cocago/cocago_parser_test.go
+1
-0
pkg/infrastructure/ast/cocago/testdata/node_infos/hello_world.json
...structure/ast/cocago/testdata/node_infos/hello_world.json
+2
-2
pkg/infrastructure/ast/cocago/testdata/node_infos/struct_with_func_decl.json
...ast/cocago/testdata/node_infos/struct_with_func_decl.json
+2
-2
未找到文件。
pkg/infrastructure/ast/cocago/cocago_builder.go
浏览文件 @
272e057e
...
...
@@ -110,24 +110,7 @@ func BuildMethodCall(codeFunc *CodeFunction, item ast.Stmt, fields []CodeField,
call
:=
BuildCallFromExpr
(
it
.
Call
,
fields
,
imports
,
packageName
,
localVars
)
codeFunc
.
FunctionCalls
=
append
(
codeFunc
.
FunctionCalls
,
call
)
case
*
ast
.
AssignStmt
:
var
vars
[]
CodeProperty
for
_
,
lh
:=
range
it
.
Lhs
{
var
left
string
switch
lhx
:=
lh
.
(
type
)
{
case
*
ast
.
Ident
:
left
=
lhx
.
Name
}
for
_
,
expr
:=
range
it
.
Rhs
{
_
,
_
,
kind
:=
BuildExpr
(
expr
)
property
:=
CodeProperty
{
TypeValue
:
left
,
TypeType
:
kind
,
}
vars
=
append
(
vars
,
property
)
}
}
vars
:=
BuildLocalVars
(
it
)
localVars
=
vars
default
:
...
...
@@ -137,6 +120,28 @@ func BuildMethodCall(codeFunc *CodeFunction, item ast.Stmt, fields []CodeField,
return
localVars
}
func
BuildLocalVars
(
it
*
ast
.
AssignStmt
)
[]
CodeProperty
{
var
vars
[]
CodeProperty
for
_
,
lh
:=
range
it
.
Lhs
{
var
left
string
switch
lhx
:=
lh
.
(
type
)
{
case
*
ast
.
Ident
:
left
=
lhx
.
Name
}
for
_
,
expr
:=
range
it
.
Rhs
{
_
,
_
,
kind
:=
BuildExpr
(
expr
)
property
:=
CodeProperty
{
TypeValue
:
left
,
TypeType
:
kind
,
}
vars
=
append
(
vars
,
property
)
}
}
return
vars
}
func
BuildMethodCallExprStmt
(
it
*
ast
.
ExprStmt
,
codeFunc
*
CodeFunction
,
fields
[]
CodeField
,
imports
[]
CodeImport
,
currentPackage
string
,
localVars
[]
CodeProperty
)
{
switch
expr
:=
it
.
X
.
(
type
)
{
case
*
ast
.
CallExpr
:
...
...
@@ -151,7 +156,6 @@ func BuildCallFromExpr(expr *ast.CallExpr, fields []CodeField, imports []CodeImp
_
,
selector
,
selName
:=
BuildExpr
(
expr
.
Fun
.
(
ast
.
Expr
))
target
:=
ParseTarget
(
selector
,
fields
,
localVars
)
packageName
:=
getPackageName
(
target
,
imports
)
//fmt.Println(packageName)
if
packageName
==
""
{
packageName
=
currentPackage
}
...
...
@@ -185,6 +189,12 @@ func getPackageName(target string, imports []CodeImport) string {
}
}
}
for
_
,
imp
:=
range
imports
{
if
imp
.
Source
==
target
{
return
target
}
}
return
packageName
}
...
...
@@ -200,5 +210,6 @@ func ParseTarget(selector string, fields []CodeField, localVars []CodeProperty)
return
field
.
TypeType
}
}
return
""
return
selector
}
pkg/infrastructure/ast/cocago/cocago_parser_test.go
浏览文件 @
272e057e
...
...
@@ -147,5 +147,6 @@ func main() {
fmt
.
Println
(
calls
)
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
))
}
pkg/infrastructure/ast/cocago/testdata/node_infos/hello_world.json
浏览文件 @
272e057e
...
...
@@ -23,7 +23,7 @@
{
"MethodName"
:
"Println"
,
"NodeName"
:
"fmt"
,
"Package"
:
"
main
"
,
"Package"
:
"
fmt
"
,
"Parameters"
:
[
{
"Modifiers"
:
null
,
...
...
@@ -40,7 +40,7 @@
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
""
"Type"
:
"
fmt
"
}
],
"InnerFunctions"
:
null
,
...
...
pkg/infrastructure/ast/cocago/testdata/node_infos/struct_with_func_decl.json
浏览文件 @
272e057e
...
...
@@ -15,7 +15,7 @@
{
"MethodName"
:
"Println"
,
"NodeName"
:
"fmt"
,
"Package"
:
"
testdata
"
,
"Package"
:
"
fmt
"
,
"Parameters"
:
[
{
"Modifiers"
:
null
,
...
...
@@ -32,7 +32,7 @@
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Type"
:
""
"Type"
:
"
fmt
"
}
],
"InnerFunctions"
:
null
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录