Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
51917891
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 搜索 >>
未验证
提交
51917891
编写于
1月 17, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [go] add pre extentions
上级
272e057e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
76 addition
and
11 deletion
+76
-11
cmd/analysis.go
cmd/analysis.go
+9
-1
pkg/application/analysis/app_concept/abstract_analysis_app.go
...application/analysis/app_concept/abstract_analysis_app.go
+2
-0
pkg/application/analysis/goapp/go_ident_app.go
pkg/application/analysis/goapp/go_ident_app.go
+14
-1
pkg/application/analysis/pyapp/py_ident_app.go
pkg/application/analysis/pyapp/py_ident_app.go
+9
-1
pkg/application/analysis/tsapp/ts_ident_app.go
pkg/application/analysis/tsapp/ts_ident_app.go
+9
-2
pkg/infrastructure/ast/cocago/cocago_parser.go
pkg/infrastructure/ast/cocago/cocago_parser.go
+31
-4
pkg/infrastructure/ast/cocago/cocago_parser_test.go
pkg/infrastructure/ast/cocago/cocago_parser_test.go
+2
-2
未找到文件。
cmd/analysis.go
浏览文件 @
51917891
...
...
@@ -68,10 +68,18 @@ func AnalysisGo() []core_domain.CodeDataStruct {
func
CommentAnalysis
(
path
string
,
app
app_concept
.
AbstractAnalysisApp
,
filter
func
(
path
string
)
bool
,
isFunctionBase
bool
)
[]
core_domain
.
CodeDataStruct
{
var
results
[]
core_domain
.
CodeFile
files
:=
cocafile
.
GetFilesWithFilter
(
path
,
filter
)
fmt
.
Println
(
files
)
var
imports
[]
core_domain
.
CodeImport
for
_
,
file
:=
range
files
{
content
,
_
:=
ioutil
.
ReadFile
(
file
)
codeImports
:=
app
.
AnalysisImport
(
string
(
content
),
file
)
imports
=
append
(
imports
,
codeImports
...
)
}
for
_
,
file
:=
range
files
{
fmt
.
Fprintf
(
output
,
"Process file: %s
\n
"
,
file
)
content
,
_
:=
ioutil
.
ReadFile
(
file
)
app
.
SetExtensions
(
imports
)
result
:=
app
.
Analysis
(
string
(
content
),
file
)
results
=
append
(
results
,
result
)
}
...
...
pkg/application/analysis/app_concept/abstract_analysis_app.go
浏览文件 @
51917891
...
...
@@ -4,4 +4,6 @@ import "github.com/phodal/coca/pkg/domain/core_domain"
type
AbstractAnalysisApp
interface
{
Analysis
(
code
string
,
path
string
)
core_domain
.
CodeFile
AnalysisImport
(
s
string
,
file
string
)
[]
core_domain
.
CodeImport
SetExtensions
(
extension
interface
{})
}
pkg/application/analysis/goapp/go_ident_app.go
浏览文件 @
51917891
...
...
@@ -6,10 +6,23 @@ import (
)
type
GoIdentApp
struct
{
Extensions
interface
{}
}
func
(
g
*
GoIdentApp
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
parser
:=
cocago
.
NewCocagoParser
()
return
*
parser
.
ProcessString
(
code
,
fileName
)
var
imports
[]
core_domain
.
CodeImport
if
g
.
Extensions
!=
nil
{
imports
=
g
.
Extensions
.
([]
core_domain
.
CodeImport
)
}
return
*
parser
.
ProcessString
(
code
,
fileName
,
imports
)
}
func
(
g
*
GoIdentApp
)
AnalysisImport
(
code
string
,
fileName
string
)
[]
core_domain
.
CodeImport
{
parser
:=
cocago
.
NewCocagoParser
()
return
parser
.
ProcessImports
(
code
,
fileName
)
}
func
(
g
*
GoIdentApp
)
SetExtensions
(
extension
interface
{})
{
g
.
Extensions
=
extension
}
pkg/application/analysis/pyapp/py_ident_app.go
浏览文件 @
51917891
...
...
@@ -22,7 +22,7 @@ type PythonIdentApp struct {
}
func
(
j
*
PythonIdentApp
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
func
(
p
*
PythonIdentApp
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
scriptParser
:=
ProcessTsString
(
code
)
context
:=
scriptParser
.
Root
()
...
...
@@ -31,3 +31,11 @@ func (j *PythonIdentApp) Analysis(code string, fileName string) core_domain.Code
return
listener
.
GetCodeFileInfo
()
}
func
(
p
*
PythonIdentApp
)
SetExtensions
(
extension
interface
{})
{
}
func
(
p
*
PythonIdentApp
)
AnalysisImport
(
code
string
,
fileName
string
)
[]
core_domain
.
CodeImport
{
return
nil
}
pkg/application/analysis/tsapp/ts_ident_app.go
浏览文件 @
51917891
...
...
@@ -19,10 +19,9 @@ func ProcessTsString(code string) *parser.TypeScriptParser {
}
type
TypeScriptIdentApp
struct
{
}
func
(
j
*
TypeScriptIdentApp
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
func
(
t
*
TypeScriptIdentApp
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
scriptParser
:=
ProcessTsString
(
code
)
context
:=
scriptParser
.
Program
()
...
...
@@ -31,3 +30,11 @@ func (j *TypeScriptIdentApp) Analysis(code string, fileName string) core_domain.
return
listener
.
GetNodeInfo
()
}
func
(
t
*
TypeScriptIdentApp
)
SetExtensions
(
extension
interface
{})
{
}
func
(
t
*
TypeScriptIdentApp
)
AnalysisImport
(
code
string
,
fileName
string
)
[]
core_domain
.
CodeImport
{
return
nil
}
pkg/infrastructure/ast/cocago/cocago_parser.go
浏览文件 @
51917891
...
...
@@ -18,6 +18,7 @@ import (
var
currentPackage
*
core_domain
.
CodePackage
type
CocagoParser
struct
{
Imports
[]
core_domain
.
CodeImport
}
var
output
io
.
Writer
...
...
@@ -41,11 +42,12 @@ func (n *CocagoParser) ProcessFile(fileName string) core_domain.CodeFile {
code
:=
string
(
content
)
codeFile
:=
n
.
ProcessString
(
code
,
fileName
)
codeFile
:=
n
.
ProcessString
(
code
,
fileName
,
nil
)
return
*
codeFile
}
func
(
n
*
CocagoParser
)
ProcessString
(
code
string
,
fileName
string
)
*
core_domain
.
CodeFile
{
func
(
n
*
CocagoParser
)
ProcessString
(
code
string
,
fileName
string
,
codeImports
[]
core_domain
.
CodeImport
)
*
core_domain
.
CodeFile
{
n
.
Imports
=
codeImports
fset
:=
token
.
NewFileSet
()
f
,
err
:=
parser
.
ParseFile
(
fset
,
fileName
,
code
,
0
)
if
err
!=
nil
{
...
...
@@ -57,6 +59,31 @@ func (n *CocagoParser) ProcessString(code string, fileName string) *core_domain.
return
codeFile
}
func
(
n
*
CocagoParser
)
ProcessImports
(
code
string
,
fileName
string
)
[]
core_domain
.
CodeImport
{
fset
:=
token
.
NewFileSet
()
f
,
err
:=
parser
.
ParseFile
(
fset
,
fileName
,
code
,
0
)
if
err
!=
nil
{
panic
(
err
)
}
imports
:=
n
.
VisitorImport
(
f
,
fset
,
fileName
)
return
imports
}
func
(
n
*
CocagoParser
)
VisitorImport
(
f
*
ast
.
File
,
fset
*
token
.
FileSet
,
fileName
string
)
[]
core_domain
.
CodeImport
{
var
imports
[]
core_domain
.
CodeImport
ast
.
Inspect
(
f
,
func
(
n
ast
.
Node
)
bool
{
switch
x
:=
n
.
(
type
)
{
case
*
ast
.
ImportSpec
:
imp
:=
BuildImport
(
x
)
imports
=
append
(
imports
,
*
imp
)
}
return
true
})
return
imports
}
func
(
n
*
CocagoParser
)
Visitor
(
f
*
ast
.
File
,
fset
*
token
.
FileSet
,
fileName
string
)
*
core_domain
.
CodeFile
{
var
currentStruct
core_domain
.
CodeDataStruct
var
currentFile
core_domain
.
CodeFile
...
...
@@ -246,7 +273,7 @@ func BuildExpr(expr ast.Expr) (string, string, string) {
for
_
,
arg
:=
range
x
.
Args
{
argType
,
argValue
,
argKind
:=
BuildExpr
(
arg
)
if
argType
==
"selector"
{
callArgs
=
append
(
callArgs
,
argValue
+
"."
+
argKind
)
callArgs
=
append
(
callArgs
,
argValue
+
"."
+
argKind
)
}
}
return
"call"
,
value
,
strings
.
Join
(
callArgs
,
","
)
...
...
@@ -290,7 +317,7 @@ func AddStructType(currentNodeName string, x *ast.StructType, currentFile *core_
ioproperties
=
append
(
ioproperties
,
*
property
)
}
// todo : when dsMap key-value create it
// todo : when dsMap key-value create it
if
dsMap
[
currentNodeName
]
!=
nil
{
dsMap
[
currentNodeName
]
.
InOutProperties
=
ioproperties
}
...
...
pkg/infrastructure/ast/cocago/cocago_parser_test.go
浏览文件 @
51917891
...
...
@@ -113,7 +113,7 @@ func main() {
defer l.Unlock()
fmt.Println("1")
}
`
,
"call"
)
`
,
"call"
,
nil
)
calls
:=
results
.
Members
[
0
]
.
FunctionNodes
[
0
]
.
FunctionCalls
fmt
.
Println
(
calls
)
g
.
Expect
(
len
(
results
.
Fields
))
.
To
(
Equal
(
1
))
...
...
@@ -142,7 +142,7 @@ func main() {
defer l.Unlock()
fmt.Println("1")
}
`
,
"call"
)
`
,
"call"
,
nil
)
calls
:=
results
.
Members
[
0
]
.
FunctionNodes
[
0
]
.
FunctionCalls
fmt
.
Println
(
calls
)
g
.
Expect
(
calls
[
0
]
.
Package
)
.
To
(
Equal
(
"sync"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录