Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
934734ee
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,发现更多精彩内容 >>
未验证
提交
934734ee
编写于
1月 14, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: set output method
上级
51b0c4e7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
30 addition
and
12 deletion
+30
-12
trial/cocago/cocago_builder.go
trial/cocago/cocago_builder.go
+2
-2
trial/cocago/cocago_parser.go
trial/cocago/cocago_parser.go
+19
-6
trial/cocago/cocago_parser_test.go
trial/cocago/cocago_parser_test.go
+2
-2
trial/pkg/application/processor/process.go
trial/pkg/application/processor/process.go
+4
-1
trial/pkg/application/processor/process_test.go
trial/pkg/application/processor/process_test.go
+2
-1
trial/tcmd/analysis_go.go
trial/tcmd/analysis_go.go
+1
-0
未找到文件。
trial/cocago/cocago_builder.go
浏览文件 @
934734ee
...
...
@@ -24,7 +24,7 @@ func BuildPropertyField(name string, field *ast.Field) *trial.CodeProperty {
case
*
ast
.
SelectorExpr
:
typeName
=
getSelectorName
(
*
typeX
)
default
:
fmt
.
Println
(
"BuildPropertyField ArrayType
"
,
reflect
.
TypeOf
(
x
.
Elt
))
fmt
.
Fprintf
(
output
,
"BuildPropertyField ArrayType %s
\n
"
,
reflect
.
TypeOf
(
x
.
Elt
))
}
case
*
ast
.
FuncType
:
typeType
=
"Function"
...
...
@@ -41,7 +41,7 @@ func BuildPropertyField(name string, field *ast.Field) *trial.CodeProperty {
case
*
ast
.
SelectorExpr
:
typeName
=
getSelectorName
(
*
x
)
default
:
fmt
.
Println
(
"BuildPropertyField
"
,
reflect
.
TypeOf
(
x
))
fmt
.
Fprintf
(
output
,
"BuildPropertyField %s
\n
"
,
reflect
.
TypeOf
(
x
))
}
property
:=
&
trial
.
CodeProperty
{
...
...
trial/cocago/cocago_parser.go
浏览文件 @
934734ee
package
cocago
import
(
"bytes"
"fmt"
"github.com/phodal/coca/pkg/domain/trial"
"go/ast"
"go/parser"
"go/token"
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
)
...
...
@@ -16,16 +19,27 @@ var currentPackage *trial.CodePackage
type
CocagoParser
struct
{
}
var
debug
=
false
var
output
io
.
Writer
func
NewCocagoParser
()
*
CocagoParser
{
currentPackage
=
&
trial
.
CodePackage
{}
output
=
os
.
Stdout
return
&
CocagoParser
{}
}
func
(
n
*
CocagoParser
)
SetOutput
(
isDebug
bool
)
io
.
Writer
{
output
=
new
(
bytes
.
Buffer
)
debug
=
isDebug
return
output
}
func
(
n
*
CocagoParser
)
ProcessFile
(
fileName
string
)
trial
.
CodeFile
{
absPath
,
_
:=
filepath
.
Abs
(
fileName
)
content
,
_
:=
ioutil
.
ReadFile
(
absPath
)
fmt
.
Println
(
"process file
"
,
fileName
)
fmt
.
Fprintf
(
output
,
"process file %s
\n
"
,
fileName
)
fset
:=
token
.
NewFileSet
()
f
,
err
:=
parser
.
ParseFile
(
fset
,
fileName
,
string
(
content
),
0
)
...
...
@@ -75,7 +89,7 @@ func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string
AddInterface
(
x
,
lastIdent
,
&
currentFile
)
default
:
if
reflect
.
TypeOf
(
x
)
!=
nil
{
fmt
.
Println
(
"Visitor case
"
,
reflect
.
TypeOf
(
x
))
fmt
.
Fprintf
(
output
,
"Visitor case %s
\n
"
,
reflect
.
TypeOf
(
x
))
}
}
return
true
...
...
@@ -146,7 +160,7 @@ func BuildReceiver(x *ast.FuncDecl, recv string) string {
case
*
ast
.
Ident
:
recv
=
x
.
Name
default
:
fmt
.
Println
(
"AddFunctionDecl
"
,
reflect
.
TypeOf
(
x
))
fmt
.
Fprintf
(
output
,
"AddFunctionDecl %s
\n
"
,
reflect
.
TypeOf
(
x
))
}
}
return
recv
...
...
@@ -157,7 +171,7 @@ func BuildMethodCall(codeFunc *trial.CodeFunction, item ast.Stmt) {
case
*
ast
.
ExprStmt
:
BuildMethodCallExprStmt
(
it
,
codeFunc
)
default
:
fmt
.
Println
(
"methodCall
"
,
reflect
.
TypeOf
(
it
))
fmt
.
Fprintf
(
output
,
"methodCall %s
\n
"
,
reflect
.
TypeOf
(
it
))
}
}
...
...
@@ -206,7 +220,7 @@ func BuildExpr(expr ast.Expr) (string, string) {
}
return
x
.
Name
,
name
default
:
fmt
.
Println
(
"BuildExpr
"
,
reflect
.
TypeOf
(
x
))
fmt
.
Fprintf
(
output
,
"BuildExpr %s
\n
"
,
reflect
.
TypeOf
(
x
))
}
return
""
,
""
}
...
...
@@ -245,4 +259,3 @@ func AddStructType(currentStruct trial.CodeDataStruct, x *ast.StructType, curren
currentFile
.
Members
=
append
(
currentFile
.
Members
,
&
member
)
currentFile
.
DataStructures
=
append
(
currentFile
.
DataStructures
,
currentStruct
)
}
trial/cocago/cocago_parser_test.go
浏览文件 @
934734ee
...
...
@@ -18,6 +18,7 @@ var testParser *CocagoParser
func
setup
()
{
testParser
=
NewCocagoParser
()
testParser
.
SetOutput
(
true
)
}
func
shutdown
()
{
...
...
@@ -60,9 +61,8 @@ func TestCocagoParser_ProcessFile(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
n
:=
&
CocagoParser
{}
filePath
:=
getFilePath
(
tt
.
fileName
)
if
got
:=
n
.
ProcessFile
(
filePath
+
".code"
);
!
cocatest
.
JSONFileBytesEqual
(
got
,
filePath
+
".json"
)
{
if
got
:=
testParser
.
ProcessFile
(
filePath
+
".code"
);
!
cocatest
.
JSONFileBytesEqual
(
got
,
filePath
+
".json"
)
{
t
.
Errorf
(
"ProcessFile() = %v, want %v"
,
got
,
tt
.
fileName
)
}
})
...
...
trial/pkg/application/processor/process.go
浏览文件 @
934734ee
...
...
@@ -8,7 +8,7 @@ import (
"sync"
)
func
ProcessPackage
(
path
string
)
[]
*
trial
.
CodeFile
{
func
ProcessPackage
(
path
string
,
debug
bool
)
[]
*
trial
.
CodeFile
{
var
wg
sync
.
WaitGroup
var
GoFileFilter
=
func
(
path
string
)
bool
{
...
...
@@ -18,6 +18,9 @@ func ProcessPackage(path string) []*trial.CodeFile {
files
:=
cocafile
.
GetFilesWithFilter
(
path
,
GoFileFilter
)
filesData
:=
make
([]
*
trial
.
CodeFile
,
len
(
files
))
parser
:=
cocago
.
NewCocagoParser
()
if
debug
{
parser
.
SetOutput
(
true
)
}
for
i
,
file
:=
range
files
{
wg
.
Add
(
1
)
go
func
(
i
int
,
file
string
)
{
...
...
trial/pkg/application/processor/process_test.go
浏览文件 @
934734ee
...
...
@@ -9,6 +9,7 @@ func Test_ProcessPackage(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
results
:=
ProcessPackage
(
"../../../../pkg/domain"
)
debug
:=
true
results
:=
ProcessPackage
(
"../../../../pkg/domain"
,
debug
)
g
.
Expect
(
len
(
results
))
.
To
(
Equal
(
27
))
}
\ No newline at end of file
trial/tcmd/analysis_go.go
浏览文件 @
934734ee
...
...
@@ -28,6 +28,7 @@ var analysisGoCmd = &cobra.Command{
files
:=
cocafile
.
GetFilesWithFilter
(
importPath
,
cocafile
.
GoFileFilter
)
for
_
,
file
:=
range
files
{
parser
:=
cocago
.
NewCocagoParser
()
parser
.
SetOutput
(
true
)
result
:=
parser
.
ProcessFile
(
file
)
results
=
append
(
results
,
result
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录