Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
a199c540
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 搜索 >>
未验证
提交
a199c540
编写于
1月 17, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: refactor cmd analysis app
上级
9fcd3b57
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
92 addition
and
105 deletion
+92
-105
cmd/analysis.go
cmd/analysis.go
+12
-44
cmd/testdata/analysis_go.txt
cmd/testdata/analysis_go.txt
+1
-1
cmd/testdata/analysis_python.txt
cmd/testdata/analysis_python.txt
+1
-1
cmd/testdata/analysis_typescript.txt
cmd/testdata/analysis_typescript.txt
+1
-1
pkg/application/analysis/app_concept/abstract_analysis_app.go
...application/analysis/app_concept/abstract_analysis_app.go
+7
-0
pkg/application/analysis/goapp/go_ident_app.go
pkg/application/analysis/goapp/go_ident_app.go
+15
-0
pkg/application/analysis/goapp/go_ident_app_test.go
pkg/application/analysis/goapp/go_ident_app_test.go
+17
-0
pkg/application/analysis/goapp/process.go
pkg/application/analysis/goapp/process.go
+0
-29
pkg/application/analysis/pyapp/py_ident_app.go
pkg/application/analysis/pyapp/py_ident_app.go
+3
-2
pkg/application/analysis/pyapp/py_ident_app_test.go
pkg/application/analysis/pyapp/py_ident_app_test.go
+8
-8
pkg/application/analysis/tsapp/ts_ident_app.go
pkg/application/analysis/tsapp/ts_ident_app.go
+3
-2
pkg/application/analysis/tsapp/ts_ident_app_regression_test.go
...pplication/analysis/tsapp/ts_ident_app_regression_test.go
+2
-2
pkg/application/analysis/tsapp/ts_ident_app_test.go
pkg/application/analysis/tsapp/ts_ident_app_test.go
+13
-13
pkg/infrastructure/ast/cocago/cocago_parser.go
pkg/infrastructure/ast/cocago/cocago_parser.go
+9
-2
未找到文件。
cmd/analysis.go
浏览文件 @
a199c540
...
...
@@ -5,11 +5,12 @@ import (
"fmt"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/pkg/adapter/cocafile"
"github.com/phodal/coca/pkg/application/analysis/app_concept"
"github.com/phodal/coca/pkg/application/analysis/goapp"
"github.com/phodal/coca/pkg/application/analysis/javaapp"
"github.com/phodal/coca/pkg/application/analysis/pyapp"
"github.com/phodal/coca/pkg/application/analysis/tsapp"
"github.com/phodal/coca/pkg/domain/core_domain"
"github.com/phodal/coca/pkg/infrastructure/ast/cocago"
"github.com/spf13/cobra"
"io/ioutil"
)
...
...
@@ -52,58 +53,25 @@ var analysisCmd = &cobra.Command{
}
func
AnalysisTypeScript
()
[]
core_domain
.
CodeDataStruct
{
importPath
:=
analysisCmdConfig
.
Path
var
results
[]
core_domain
.
CodeFile
files
:=
cocafile
.
GetFilesWithFilter
(
importPath
,
cocafile
.
TypeScriptFileFilter
)
fmt
.
Println
(
files
)
for
_
,
file
:=
range
files
{
fmt
.
Fprintf
(
output
,
"Process TypeScript file: %s
\n
"
,
file
)
app
:=
new
(
tsapp
.
TypeScriptApiApp
)
content
,
_
:=
ioutil
.
ReadFile
(
file
)
result
:=
app
.
Analysis
(
string
(
content
),
""
)
results
=
append
(
results
,
result
)
}
var
ds
[]
core_domain
.
CodeDataStruct
for
_
,
result
:=
range
results
{
ds
=
append
(
ds
,
result
.
DataStructures
...
)
}
return
ds
return
CommentAnalysis
(
analysisCmdConfig
.
Path
,
new
(
tsapp
.
TypeScriptIdentApp
),
cocafile
.
TypeScriptFileFilter
)
}
func
AnalysisPython
()
[]
core_domain
.
CodeDataStruct
{
importPath
:=
analysisCmdConfig
.
Path
var
results
[]
core_domain
.
CodeFile
files
:=
cocafile
.
GetFilesWithFilter
(
importPath
,
cocafile
.
PythonFileFilter
)
for
_
,
file
:=
range
files
{
fmt
.
Fprintf
(
output
,
"Process Python file: %s
\n
"
,
file
)
app
:=
new
(
pyapp
.
PythonApiApp
)
content
,
_
:=
ioutil
.
ReadFile
(
file
)
result
:=
app
.
Analysis
(
string
(
content
),
""
)
results
=
append
(
results
,
result
)
}
var
ds
[]
core_domain
.
CodeDataStruct
for
_
,
result
:=
range
results
{
ds
=
append
(
ds
,
result
.
DataStructures
...
)
}
return
ds
return
CommentAnalysis
(
analysisCmdConfig
.
Path
,
new
(
pyapp
.
PythonIdentApp
),
cocafile
.
PythonFileFilter
)
}
func
AnalysisGo
()
[]
core_domain
.
CodeDataStruct
{
importPath
:=
analysisCmdConfig
.
Path
return
CommentAnalysis
(
analysisCmdConfig
.
Path
,
new
(
goapp
.
GoIdentApp
),
cocafile
.
GoFileFilter
)
}
func
CommentAnalysis
(
path
string
,
app
app_concept
.
AbstractAnalysisApp
,
filter
func
(
path
string
)
bool
)
[]
core_domain
.
CodeDataStruct
{
var
results
[]
core_domain
.
CodeFile
files
:=
cocafile
.
GetFilesWithFilter
(
importPath
,
cocafile
.
GoFileFilter
)
files
:=
cocafile
.
GetFilesWithFilter
(
path
,
filter
)
fmt
.
Println
(
files
)
for
_
,
file
:=
range
files
{
parser
:=
cocago
.
NewCocagoParser
()
parser
.
SetOutput
(
output
)
result
:=
parser
.
ProcessFile
(
file
)
fmt
.
Fprintf
(
output
,
"Process file: %s
\n
"
,
file
)
content
,
_
:=
ioutil
.
ReadFile
(
file
)
result
:=
app
.
Analysis
(
string
(
content
),
file
)
results
=
append
(
results
,
result
)
}
...
...
cmd/testdata/analysis_go.txt
浏览文件 @
a199c540
process file
config/cmd_config.go
Process file:
config/cmd_config.go
cmd/testdata/analysis_python.txt
浏览文件 @
a199c540
Process
Python
file: ../_fixtures/grammar/python/blog_entity.py
Process file: ../_fixtures/grammar/python/blog_entity.py
cmd/testdata/analysis_typescript.txt
浏览文件 @
a199c540
Process
TypeScript
file: ../_fixtures/grammar/typescript/Class.ts
Process file: ../_fixtures/grammar/typescript/Class.ts
pkg/application/analysis/app_concept/abstract_analysis_app.go
0 → 100644
浏览文件 @
a199c540
package
app_concept
import
"github.com/phodal/coca/pkg/domain/core_domain"
type
AbstractAnalysisApp
interface
{
Analysis
(
code
string
,
path
string
)
core_domain
.
CodeFile
}
pkg/application/analysis/goapp/go_ident_app.go
0 → 100644
浏览文件 @
a199c540
package
goapp
import
(
"github.com/phodal/coca/pkg/domain/core_domain"
"github.com/phodal/coca/pkg/infrastructure/ast/cocago"
)
type
GoIdentApp
struct
{
}
func
(
g
*
GoIdentApp
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
parser
:=
cocago
.
NewCocagoParser
()
return
*
parser
.
ProcessString
(
code
,
fileName
)
}
pkg/application/analysis/goapp/
process
_test.go
→
pkg/application/analysis/goapp/
go_ident_app
_test.go
浏览文件 @
a199c540
...
...
@@ -2,6 +2,7 @@ package goapp
import
(
.
"github.com/onsi/gomega"
"io/ioutil"
"testing"
)
...
...
@@ -9,6 +10,8 @@ func Test_ProcessPackage(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
results
:=
ProcessPackage
(
"../../../../pkg/domain"
,
true
)
g
.
Expect
(
len
(
results
))
.
To
(
Equal
(
21
))
code
,
_
:=
ioutil
.
ReadFile
(
"../../../../pkg/domain/core_domain/code_data_struct.go"
)
app
:=
&
GoIdentApp
{}
results
:=
app
.
Analysis
(
string
(
code
),
"domain"
)
g
.
Expect
(
len
(
results
.
DataStructures
))
.
To
(
Equal
(
2
))
}
\ No newline at end of file
pkg/application/analysis/goapp/process.go
已删除
100644 → 0
浏览文件 @
9fcd3b57
package
goapp
import
(
"bytes"
"github.com/phodal/coca/pkg/adapter/cocafile"
"github.com/phodal/coca/pkg/domain/core_domain"
"github.com/phodal/coca/pkg/infrastructure/ast/cocago"
"strings"
)
func
ProcessPackage
(
path
string
,
debug
bool
)
[]
*
core_domain
.
CodeFile
{
var
GoFileFilter
=
func
(
path
string
)
bool
{
return
strings
.
HasSuffix
(
path
,
".go"
)
}
files
:=
cocafile
.
GetFilesWithFilter
(
path
,
GoFileFilter
)
filesData
:=
make
([]
*
core_domain
.
CodeFile
,
len
(
files
))
parser
:=
cocago
.
NewCocagoParser
()
if
debug
{
buf
:=
new
(
bytes
.
Buffer
)
parser
.
SetOutput
(
buf
)
}
for
i
,
file
:=
range
files
{
processFile
:=
parser
.
ProcessFile
(
file
)
filesData
[
i
]
=
&
processFile
}
return
filesData
}
pkg/application/analysis/pyapp/py_ident_app.go
浏览文件 @
a199c540
...
...
@@ -18,10 +18,11 @@ func ProcessTsString(code string) *parser.PythonParser {
return
streamToParser
(
is
)
}
type
PythonApiApp
struct
{
type
PythonIdentApp
struct
{
}
func
(
j
*
Python
Api
App
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
func
(
j
*
Python
Ident
App
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
scriptParser
:=
ProcessTsString
(
code
)
context
:=
scriptParser
.
Root
()
...
...
pkg/application/analysis/pyapp/py_ident_app_test.go
浏览文件 @
a199c540
...
...
@@ -19,7 +19,7 @@ func Test_AllPythonGrammar(t *testing.T) {
for
_
,
file
:=
range
files
{
file
,
_
:=
ioutil
.
ReadFile
(
file
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
app
.
Analysis
(
string
(
file
),
""
)
}
...
...
@@ -29,7 +29,7 @@ func Test_AllPythonGrammar(t *testing.T) {
func
Test_PythonClassForLexer
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/class.py"
)
app
.
Analysis
(
string
(
file
),
""
)
...
...
@@ -40,7 +40,7 @@ func Test_PythonClassForLexer(t *testing.T) {
func
Test_PythonArgumentsForLexer
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/argument.py"
)
app
.
Analysis
(
string
(
file
),
""
)
...
...
@@ -51,7 +51,7 @@ func Test_PythonArgumentsForLexer(t *testing.T) {
func
Test_PythonArgumentsForTryStmt
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/try_stmt.py"
)
app
.
Analysis
(
string
(
file
),
""
)
...
...
@@ -62,7 +62,7 @@ func Test_PythonArgumentsForTryStmt(t *testing.T) {
func
Test_PythonClassDef
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/class.py"
)
codeFile
:=
app
.
Analysis
(
string
(
file
),
"testdata/grammar/class.py"
)
...
...
@@ -77,7 +77,7 @@ func Test_PythonClassDef(t *testing.T) {
func
Test_PythonClassWithDecorator
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/class_or_func_def_stmt.py"
)
codeFile
:=
app
.
Analysis
(
string
(
file
),
"testdata/grammar/class_or_func_def_stmt.py"
)
...
...
@@ -92,7 +92,7 @@ func Test_PythonClassWithDecorator(t *testing.T) {
func
Test_PythonImport
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/import_stmt.py"
)
codeFile
:=
app
.
Analysis
(
string
(
file
),
"import_stmt"
)
...
...
@@ -105,7 +105,7 @@ func Test_PythonImport(t *testing.T) {
func
Test_PythonClassWithFunctionDef
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
Python
Api
App
)
app
:=
new
(
Python
Ident
App
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/compare/blog_entity.py"
)
codeFile
:=
app
.
Analysis
(
string
(
file
),
"testdata/compare/blog_entity.py"
)
...
...
pkg/application/analysis/tsapp/ts_ident_app.go
浏览文件 @
a199c540
...
...
@@ -18,10 +18,11 @@ func ProcessTsString(code string) *parser.TypeScriptParser {
return
processStream
(
is
)
}
type
TypeScriptApiApp
struct
{
type
TypeScriptIdentApp
struct
{
}
func
(
j
*
TypeScript
Api
App
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
func
(
j
*
TypeScript
Ident
App
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
scriptParser
:=
ProcessTsString
(
code
)
context
:=
scriptParser
.
Program
()
...
...
pkg/application/analysis/tsapp/ts_ident_app_regression_test.go
浏览文件 @
a199c540
...
...
@@ -9,7 +9,7 @@ import (
func
Test_Regression
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
code
,
_
:=
ioutil
.
ReadFile
(
"../../../../_fixtures/ts/regressions/import_comma_issue.ts"
)
results
:=
app
.
Analysis
(
string
(
code
),
""
)
...
...
@@ -21,7 +21,7 @@ func Test_Regression(t *testing.T) {
//func Test_ProcessErrorGrammar(t *testing.T) {
// g := NewGomegaWithT(t)
//
// app := new(TypeScript
Api
App)
// app := new(TypeScript
Ident
App)
// code, _ := ioutil.ReadFile("../../../../../_fixtures/ts/regressions/callback_hell.ts")
//
// results := app.Analysis(string(code), "")
...
...
pkg/application/analysis/tsapp/ts_ident_app_test.go
浏览文件 @
a199c540
...
...
@@ -9,7 +9,7 @@ import (
func
Test_TypeScriptClassNode
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
codefile
:=
app
.
Analysis
(
`
interface IPerson {
name: string;
...
...
@@ -38,7 +38,7 @@ func Test_TypeScriptMultipleClass(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
code
,
_
:=
ioutil
.
ReadFile
(
"../../../../_fixtures/ts/grammar/Class.ts"
)
codeFile
:=
app
.
Analysis
(
string
(
code
),
""
)
...
...
@@ -52,7 +52,7 @@ func Test_TypeScriptAbstractClass(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
code
,
_
:=
ioutil
.
ReadFile
(
"../../../../_fixtures/ts/grammar/AbstractClass.ts"
)
codeFile
:=
app
.
Analysis
(
string
(
code
),
""
)
...
...
@@ -67,7 +67,7 @@ func Test_ShouldGetClassFromModule(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
code
,
_
:=
ioutil
.
ReadFile
(
"../../../../_fixtures/ts/grammar/Module.ts"
)
results
:=
app
.
Analysis
(
string
(
code
),
""
)
...
...
@@ -80,7 +80,7 @@ func Test_ShouldEnableGetClassMethod(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
codefile
:=
app
.
Analysis
(
`
class Employee {
...
...
@@ -97,7 +97,7 @@ func Test_ShouldGetInterfaceImplements(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
results
:=
app
.
Analysis
(
`
export interface IPerson {
...
...
@@ -121,7 +121,7 @@ func Test_ShouldGetInterfaceProperty(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
codeFile
:=
app
.
Analysis
(
`
export interface IPerson {
name: string;
...
...
@@ -148,7 +148,7 @@ func Test_ShouldGetDefaultFunctionName(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
codeFile
:=
app
.
Analysis
(
`
function Sum(x: number, y: number) : void {
...
...
@@ -171,7 +171,7 @@ func Test_ShouldHandleRestParameters(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
codeFile
:=
app
.
Analysis
(
`
function buildName(firstName: string, ...restOfName: string[]) {
...
...
@@ -190,7 +190,7 @@ func Test_ShouldGetClassFields(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
code
,
_
:=
ioutil
.
ReadFile
(
"../../../../_fixtures/ts/grammar/Class.ts"
)
codeFile
:=
app
.
Analysis
(
string
(
code
),
""
)
...
...
@@ -204,7 +204,7 @@ func Test_ShouldReturnBlockImports(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
results
:=
app
.
Analysis
(
`
import { ZipCodeValidator } from "./ZipCodeValidator";
...
...
@@ -219,7 +219,7 @@ func Test_ShouldReturnAsImports(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
results
:=
app
.
Analysis
(
`
import zip = require("./ZipCodeValidator");
...
...
@@ -235,7 +235,7 @@ func Test_ShouldReturnAllImports(t *testing.T) {
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
TypeScript
Api
App
)
app
:=
new
(
TypeScript
Ident
App
)
code
,
_
:=
ioutil
.
ReadFile
(
"../../../../_fixtures/ts/grammar/Import.ts"
)
results
:=
app
.
Analysis
(
string
(
code
),
""
)
...
...
pkg/infrastructure/ast/cocago/cocago_parser.go
浏览文件 @
a199c540
...
...
@@ -38,15 +38,22 @@ func (n *CocagoParser) ProcessFile(fileName string) core_domain.CodeFile {
fmt
.
Fprintf
(
output
,
"process file %s
\n
"
,
fileName
)
code
:=
string
(
content
)
codeFile
:=
n
.
ProcessString
(
code
,
fileName
)
return
*
codeFile
}
func
(
n
*
CocagoParser
)
ProcessString
(
code
string
,
fileName
string
)
*
core_domain
.
CodeFile
{
fset
:=
token
.
NewFileSet
()
f
,
err
:=
parser
.
ParseFile
(
fset
,
fileName
,
string
(
content
)
,
0
)
f
,
err
:=
parser
.
ParseFile
(
fset
,
fileName
,
code
,
0
)
if
err
!=
nil
{
panic
(
err
)
}
codeFile
:=
n
.
Visitor
(
f
,
fset
,
fileName
)
currentPackage
.
CodeFiles
=
append
(
currentPackage
.
CodeFiles
,
*
codeFile
)
return
*
codeFile
return
codeFile
}
func
(
n
*
CocagoParser
)
Visitor
(
f
*
ast
.
File
,
fset
*
token
.
FileSet
,
fileName
string
)
*
core_domain
.
CodeFile
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录