Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
ef0d8e6a
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 搜索 >>
未验证
提交
ef0d8e6a
编写于
1月 06, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: extract comment generates
上级
63c85126
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
86 addition
and
86 deletion
+86
-86
cmd/tbs.go
cmd/tbs.go
+2
-2
cocatest/compare.go
cocatest/compare.go
+33
-0
cocatest/generate.go
cocatest/generate.go
+22
-3
core/adapter/cocafile/file_analysis_helper.go
core/adapter/cocafile/file_analysis_helper.go
+1
-1
core/adapter/cocafile/file_analysis_helper_test.go
core/adapter/cocafile/file_analysis_helper_test.go
+1
-1
core/context/analysis/java_full_app.go
core/context/analysis/java_full_app.go
+3
-3
core/context/analysis/java_identifier_app.go
core/context/analysis/java_identifier_app.go
+3
-3
core/context/api/java_api_app.go
core/context/api/java_api_app.go
+3
-3
core/context/arch/arch_app_test.go
core/context/arch/arch_app_test.go
+4
-56
core/context/bs/bad_smell_app.go
core/context/bs/bad_smell_app.go
+3
-3
core/context/deps/dep_app_test.go
core/context/deps/dep_app_test.go
+2
-2
core/context/refactor/move_class/move_class_app.go
core/context/refactor/move_class/move_class_app.go
+3
-3
core/context/refactor/unused/remove_unused_import.go
core/context/refactor/unused/remove_unused_import.go
+3
-3
core/context/tbs/tbs_app_test.go
core/context/tbs/tbs_app_test.go
+1
-1
core/context/todo/todo_app.go
core/context/todo/todo_app.go
+2
-2
未找到文件。
cmd/tbs.go
浏览文件 @
ef0d8e6a
...
...
@@ -5,7 +5,7 @@ import (
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
"github.com/phodal/coca/core/context/analysis"
"github.com/phodal/coca/core/context/tbs"
"github.com/phodal/coca/core/domain"
...
...
@@ -28,7 +28,7 @@ var tbsCmd = &cobra.Command{
Short
:
"generate tests bad smell"
,
Long
:
``
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
files
:=
coca
_
file
.
GetJavaTestFiles
(
tbsCmdConfig
.
Path
)
files
:=
cocafile
.
GetJavaTestFiles
(
tbsCmdConfig
.
Path
)
var
identifiers
[]
domain
.
JIdentifier
identifiers
=
cmd_util
.
LoadTestIdentify
(
files
)
...
...
cocatest/compare.go
0 → 100644
浏览文件 @
ef0d8e6a
package
cocatest
import
(
"encoding/json"
"io"
"reflect"
)
// JSONBytesEqual compares the JSON in two byte slices.
func
JSONBytesEqual
(
a
,
b
[]
byte
)
(
bool
,
error
)
{
var
j
,
j2
interface
{}
if
err
:=
json
.
Unmarshal
(
a
,
&
j
);
err
!=
nil
{
return
false
,
err
}
if
err
:=
json
.
Unmarshal
(
b
,
&
j2
);
err
!=
nil
{
return
false
,
err
}
return
reflect
.
DeepEqual
(
j2
,
j
),
nil
}
func
JSONEqual
(
a
,
b
io
.
Reader
)
(
bool
,
error
)
{
var
j
,
j2
interface
{}
d
:=
json
.
NewDecoder
(
a
)
if
err
:=
d
.
Decode
(
&
j
);
err
!=
nil
{
return
false
,
err
}
d
=
json
.
NewDecoder
(
b
)
if
err
:=
d
.
Decode
(
&
j2
);
err
!=
nil
{
return
false
,
err
}
return
reflect
.
DeepEqual
(
j2
,
j
),
nil
}
cocatest/generate.go
浏览文件 @
ef0d8e6a
...
...
@@ -2,13 +2,14 @@ package cocatest
import
(
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
"github.com/phodal/coca/core/context/analysis"
"github.com/phodal/coca/core/domain"
"path/filepath"
)
func
BuildAnalysisResultsByPath
(
codePath
string
)
(
map
[
string
]
domain
.
JIdentifier
,
[]
domain
.
JClassNode
)
{
files
:=
coca
_
file
.
GetJavaTestFiles
(
codePath
)
func
Build
Test
AnalysisResultsByPath
(
codePath
string
)
(
map
[
string
]
domain
.
JIdentifier
,
[]
domain
.
JClassNode
)
{
files
:=
cocafile
.
GetJavaTestFiles
(
codePath
)
var
identifiers
[]
domain
.
JIdentifier
identifiers
=
cmd_util
.
LoadTestIdentify
(
files
)
...
...
@@ -23,3 +24,21 @@ func BuildAnalysisResultsByPath(codePath string) (map[string]domain.JIdentifier,
classNodes
:=
analysisApp
.
AnalysisFiles
(
identifiers
,
files
,
classes
)
return
identifiersMap
,
classNodes
}
func
BuildAnalysisDeps
(
codePath
string
)
([]
domain
.
JClassNode
,
map
[
string
]
domain
.
JIdentifier
)
{
codePath
=
filepath
.
FromSlash
(
codePath
)
identifierApp
:=
new
(
analysis
.
JavaIdentifierApp
)
identifiers
:=
identifierApp
.
AnalysisPath
(
codePath
)
var
classes
[]
string
=
nil
for
_
,
node
:=
range
identifiers
{
classes
=
append
(
classes
,
node
.
Package
+
"."
+
node
.
ClassName
)
}
callApp
:=
analysis
.
NewJavaFullApp
()
callNodes
:=
callApp
.
AnalysisPath
(
codePath
,
classes
,
identifiers
)
identifiersMap
:=
domain
.
BuildIdentifierMap
(
identifiers
)
return
callNodes
,
identifiersMap
}
core/adapter/coca
_
file/file_analysis_helper.go
→
core/adapter/cocafile/file_analysis_helper.go
浏览文件 @
ef0d8e6a
package
coca
_
file
package
cocafile
import
(
"fmt"
...
...
core/adapter/coca
_
file/file_analysis_helper_test.go
→
core/adapter/cocafile/file_analysis_helper_test.go
浏览文件 @
ef0d8e6a
package
coca
_
file
package
cocafile
import
(
"github.com/antlr/antlr4/runtime/Go/antlr"
...
...
core/context/analysis/java_full_app.go
浏览文件 @
ef0d8e6a
...
...
@@ -3,7 +3,7 @@ package analysis
import
(
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast/full"
"path/filepath"
...
...
@@ -17,7 +17,7 @@ func NewJavaFullApp() JavaFullApp {
}
func
(
j
*
JavaFullApp
)
AnalysisPath
(
codeDir
string
,
classes
[]
string
,
identNodes
[]
domain
.
JIdentifier
)
[]
domain
.
JClassNode
{
files
:=
coca
_
file
.
GetJavaFiles
(
codeDir
)
files
:=
cocafile
.
GetJavaFiles
(
codeDir
)
return
j
.
AnalysisFiles
(
identNodes
,
files
,
classes
)
}
...
...
@@ -33,7 +33,7 @@ func (j *JavaFullApp) AnalysisFiles(identNodes []domain.JIdentifier, files []str
displayName
:=
filepath
.
Base
(
file
)
fmt
.
Println
(
"Refactoring parse java call: "
+
displayName
)
parser
:=
coca
_
file
.
ProcessFile
(
file
)
parser
:=
cocafile
.
ProcessFile
(
file
)
context
:=
parser
.
CompilationUnit
()
listener
:=
full
.
NewJavaFullListener
(
identMap
,
file
)
...
...
core/context/analysis/java_identifier_app.go
浏览文件 @
ef0d8e6a
...
...
@@ -2,7 +2,7 @@ package analysis
import
(
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast/identifier"
)
...
...
@@ -16,7 +16,7 @@ func NewJavaIdentifierApp() JavaIdentifierApp {
}
func
(
j
*
JavaIdentifierApp
)
AnalysisPath
(
codeDir
string
)
[]
domain
.
JIdentifier
{
files
:=
coca
_
file
.
GetJavaFiles
(
codeDir
)
files
:=
cocafile
.
GetJavaFiles
(
codeDir
)
return
j
.
AnalysisFiles
(
files
)
}
...
...
@@ -24,7 +24,7 @@ func (j *JavaIdentifierApp) AnalysisFiles(files []string) []domain.JIdentifier {
var
nodeInfos
[]
domain
.
JIdentifier
=
nil
for
_
,
file
:=
range
files
{
parser
:=
coca
_
file
.
ProcessFile
(
file
)
parser
:=
cocafile
.
ProcessFile
(
file
)
context
:=
parser
.
CompilationUnit
()
listener
:=
identifier
.
NewJavaIdentifierListener
()
...
...
core/context/api/java_api_app.go
浏览文件 @
ef0d8e6a
...
...
@@ -3,7 +3,7 @@ package api
import
(
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast/api"
"path/filepath"
...
...
@@ -15,14 +15,14 @@ type JavaApiApp struct {
}
func
(
j
*
JavaApiApp
)
AnalysisPath
(
codeDir
string
,
parsedDeps
[]
domain
.
JClassNode
,
identifiersMap
map
[
string
]
domain
.
JIdentifier
,
diMap
map
[
string
]
string
)
[]
domain
.
RestApi
{
files
:=
coca
_
file
.
GetJavaFiles
(
codeDir
)
files
:=
cocafile
.
GetJavaFiles
(
codeDir
)
for
index
:=
range
files
{
file
:=
files
[
index
]
displayName
:=
filepath
.
Base
(
file
)
fmt
.
Println
(
"Refactoring parse java call: "
+
displayName
)
parser
:=
coca
_
file
.
ProcessFile
(
file
)
parser
:=
cocafile
.
ProcessFile
(
file
)
context
:=
parser
.
CompilationUnit
()
listener
:=
api
.
NewJavaApiListener
(
identifiersMap
,
diMap
)
...
...
core/context/arch/arch_app_test.go
浏览文件 @
ef0d8e6a
...
...
@@ -4,12 +4,9 @@ import (
"encoding/json"
.
"github.com/onsi/gomega"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/co
re/context/analysis
"
"github.com/phodal/coca/co
catest
"
"github.com/phodal/coca/core/context/arch/tequila"
"github.com/phodal/coca/core/domain"
"io"
"path/filepath"
"reflect"
"testing"
)
...
...
@@ -17,19 +14,7 @@ func TestConceptAnalyser_Analysis(t *testing.T) {
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/arch/step2-java"
codePath
=
filepath
.
FromSlash
(
codePath
)
identifierApp
:=
new
(
analysis
.
JavaIdentifierApp
)
identifiers
:=
identifierApp
.
AnalysisPath
(
codePath
)
var
classes
[]
string
=
nil
for
_
,
node
:=
range
identifiers
{
classes
=
append
(
classes
,
node
.
Package
+
"."
+
node
.
ClassName
)
}
callApp
:=
analysis
.
NewJavaFullApp
()
callNodes
:=
callApp
.
AnalysisPath
(
codePath
,
classes
,
identifiers
)
identifiersMap
:=
domain
.
BuildIdentifierMap
(
identifiers
)
callNodes
,
identifiersMap
:=
cocatest
.
BuildAnalysisDeps
(
codePath
)
app
:=
NewArchApp
()
results
:=
app
.
Analysis
(
callNodes
,
identifiersMap
)
...
...
@@ -50,26 +35,14 @@ func TestConceptAnalyser_Analysis(t *testing.T) {
jsonContent
,
_
:=
json
.
MarshalIndent
(
results
,
""
,
"
\t
"
)
content
:=
cmd_util
.
ReadFile
(
filepath
.
FromSlash
(
codePath
+
"/"
+
"results.json"
))
g
.
Expect
(
JSONBytesEqual
(
jsonContent
,
content
))
.
To
(
Equal
(
true
))
g
.
Expect
(
cocatest
.
JSONBytesEqual
(
jsonContent
,
content
))
.
To
(
Equal
(
true
))
}
func
TestConceptAnalyser_AnalysisWithFans
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/arch/step2-java"
codePath
=
filepath
.
FromSlash
(
codePath
)
identifierApp
:=
new
(
analysis
.
JavaIdentifierApp
)
identifiers
:=
identifierApp
.
AnalysisPath
(
codePath
)
var
classes
[]
string
=
nil
for
_
,
node
:=
range
identifiers
{
classes
=
append
(
classes
,
node
.
Package
+
"."
+
node
.
ClassName
)
}
callApp
:=
analysis
.
NewJavaFullApp
()
callNodes
:=
callApp
.
AnalysisPath
(
codePath
,
classes
,
identifiers
)
identifiersMap
:=
domain
.
BuildIdentifierMap
(
identifiers
)
callNodes
,
identifiersMap
:=
cocatest
.
BuildAnalysisDeps
(
codePath
)
app
:=
NewArchApp
()
result
:=
app
.
Analysis
(
callNodes
,
identifiersMap
)
...
...
@@ -87,28 +60,3 @@ func TestConceptAnalyser_AnalysisWithFans(t *testing.T) {
g
.
Eventually
(
fans
[
0
]
.
FanIn
)
.
Should
(
Equal
(
2
))
g
.
Eventually
(
fans
[
0
]
.
FanOut
)
.
Should
(
Equal
(
0
))
}
func
JSONEqual
(
a
,
b
io
.
Reader
)
(
bool
,
error
)
{
var
j
,
j2
interface
{}
d
:=
json
.
NewDecoder
(
a
)
if
err
:=
d
.
Decode
(
&
j
);
err
!=
nil
{
return
false
,
err
}
d
=
json
.
NewDecoder
(
b
)
if
err
:=
d
.
Decode
(
&
j2
);
err
!=
nil
{
return
false
,
err
}
return
reflect
.
DeepEqual
(
j2
,
j
),
nil
}
// JSONBytesEqual compares the JSON in two byte slices.
func
JSONBytesEqual
(
a
,
b
[]
byte
)
(
bool
,
error
)
{
var
j
,
j2
interface
{}
if
err
:=
json
.
Unmarshal
(
a
,
&
j
);
err
!=
nil
{
return
false
,
err
}
if
err
:=
json
.
Unmarshal
(
b
,
&
j2
);
err
!=
nil
{
return
false
,
err
}
return
reflect
.
DeepEqual
(
j2
,
j
),
nil
}
core/context/bs/bad_smell_app.go
浏览文件 @
ef0d8e6a
...
...
@@ -3,7 +3,7 @@ package bs
import
(
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
"github.com/phodal/coca/core/domain/bs_domain"
"github.com/phodal/coca/core/infrastructure/ast/bs"
"path/filepath"
...
...
@@ -20,7 +20,7 @@ func NewBadSmellApp() *BadSmellApp {
func
(
j
*
BadSmellApp
)
AnalysisPath
(
codeDir
string
)
*
[]
bs_domain
.
BsJClass
{
nodeInfos
=
nil
files
:=
coca
_
file
.
GetJavaFiles
(
codeDir
)
files
:=
cocafile
.
GetJavaFiles
(
codeDir
)
for
index
:=
range
files
{
nodeInfo
:=
bs_domain
.
NewJFullClassNode
()
file
:=
files
[
index
]
...
...
@@ -28,7 +28,7 @@ func (j *BadSmellApp) AnalysisPath(codeDir string) *[]bs_domain.BsJClass {
displayName
:=
filepath
.
Base
(
file
)
fmt
.
Println
(
"Refactoring parse java call: "
+
displayName
)
parser
:=
coca
_
file
.
ProcessFile
(
file
)
parser
:=
cocafile
.
ProcessFile
(
file
)
context
:=
parser
.
CompilationUnit
()
listener
:=
bs
.
NewBadSmellListener
()
...
...
core/context/deps/dep_app_test.go
浏览文件 @
ef0d8e6a
...
...
@@ -22,8 +22,8 @@ func TestAnalysis(t *testing.T) {
func
Test_ShouldCountDeps_WhenHadClassNodes
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/examples/api"
_
,
classNodes
:=
cocatest
.
BuildAnalysisResultsByPath
(
codePath
)
codePath
:=
"../../../_fixtures/examples/api
/
"
_
,
classNodes
:=
cocatest
.
Build
Test
AnalysisResultsByPath
(
codePath
)
depApp
:=
NewDepApp
()
depApp
.
CountDeps
(
classNodes
)
...
...
core/context/refactor/move_class/move_class_app.go
浏览文件 @
ef0d8e6a
...
...
@@ -4,7 +4,7 @@ import (
"bufio"
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
base2
"github.com/phodal/coca/core/context/refactor/base"
models2
"github.com/phodal/coca/core/context/refactor/base/models"
"io"
...
...
@@ -34,13 +34,13 @@ func NewMoveClassApp(config string, pPath string) *MoveClassApp {
func
(
j
*
MoveClassApp
)
Analysis
()
[]
models2
.
JMoveStruct
{
// TODO: 使用 Deps.json 来移动包
files
:=
coca
_
file
.
GetJavaFiles
(
configPath
)
files
:=
cocafile
.
GetJavaFiles
(
configPath
)
for
index
:=
range
files
{
file
:=
files
[
index
]
currentFile
,
_
=
filepath
.
Abs
(
file
)
parser
:=
coca
_
file
.
ProcessFile
(
file
)
parser
:=
cocafile
.
ProcessFile
(
file
)
context
:=
parser
.
CompilationUnit
()
node
:=
models2
.
NewJFullIdentifier
()
...
...
core/context/refactor/unused/remove_unused_import.go
浏览文件 @
ef0d8e6a
...
...
@@ -3,7 +3,7 @@ package unused
import
(
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
base2
"github.com/phodal/coca/core/context/refactor/base"
models2
"github.com/phodal/coca/core/context/refactor/base/models"
"io/ioutil"
...
...
@@ -25,7 +25,7 @@ func NewRemoveUnusedImportApp(pPath string) *RemoveUnusedImportApp {
}
func
(
j
*
RemoveUnusedImportApp
)
Analysis
()
[]
models2
.
JFullIdentifier
{
files
:=
coca
_
file
.
GetJavaFiles
(
configPath
)
files
:=
cocafile
.
GetJavaFiles
(
configPath
)
var
nodes
[]
models2
.
JFullIdentifier
=
nil
for
index
:=
range
files
{
...
...
@@ -35,7 +35,7 @@ func (j *RemoveUnusedImportApp) Analysis() []models2.JFullIdentifier {
displayName
:=
filepath
.
Base
(
file
)
fmt
.
Println
(
"Refactoring parse java call: "
+
displayName
)
parser
:=
coca
_
file
.
ProcessFile
(
file
)
parser
:=
cocafile
.
ProcessFile
(
file
)
context
:=
parser
.
CompilationUnit
()
node
:=
models2
.
NewJFullIdentifier
()
...
...
core/context/tbs/tbs_app_test.go
浏览文件 @
ef0d8e6a
...
...
@@ -129,7 +129,7 @@ func TestTbsApp_ShouldReturnMultipleResult(t *testing.T) {
}
func
buildTbsResult
(
codePath
string
)
[]
TestBadSmell
{
identifiersMap
,
classNodes
:=
cocatest
.
BuildAnalysisResultsByPath
(
codePath
)
identifiersMap
,
classNodes
:=
cocatest
.
Build
Test
AnalysisResultsByPath
(
codePath
)
app
:=
NewTbsApp
()
result
:=
app
.
AnalysisPath
(
classNodes
,
identifiersMap
)
...
...
core/context/todo/todo_app.go
浏览文件 @
ef0d8e6a
...
...
@@ -3,7 +3,7 @@ package todo
import
(
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca
_
file"
"github.com/phodal/coca/core/adapter/cocafile"
"github.com/phodal/coca/core/adapter/shell"
"github.com/phodal/coca/core/context/git"
"github.com/phodal/coca/core/context/todo/astitodo"
...
...
@@ -64,7 +64,7 @@ func (a TodoApp) BuildWithGitHistory(todos []*astitodo.TODO) []TodoDetail {
func
buildComments
(
path
string
)
[]
*
astitodo
.
TODO
{
var
todos
[]
*
astitodo
.
TODO
files
:=
coca
_
file
.
GetJavaFiles
(
path
)
files
:=
cocafile
.
GetJavaFiles
(
path
)
for
index
:=
range
files
{
file
:=
files
[
index
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录