Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
e9c7f90e
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 搜索 >>
未验证
提交
e9c7f90e
编写于
12月 28, 2019
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: make first map
上级
d43da88b
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
112 addition
and
17 deletion
+112
-17
_fixtures/tbs/code/AssertionRouletteTest.java
_fixtures/tbs/code/AssertionRouletteTest.java
+1
-1
_fixtures/tbs/code/ConstructorInitializationTest.java
_fixtures/tbs/code/ConstructorInitializationTest.java
+1
-1
_fixtures/tbs/code/DuplicateAssertTest.java
_fixtures/tbs/code/DuplicateAssertTest.java
+1
-1
_fixtures/tbs/code/MysteryGuestTest.java
_fixtures/tbs/code/MysteryGuestTest.java
+1
-1
_fixtures/tbs/code/RedundantPrintTest.java
_fixtures/tbs/code/RedundantPrintTest.java
+1
-1
cmd/tbs.go
cmd/tbs.go
+25
-7
core/adapter/helper.go
core/adapter/helper.go
+17
-0
core/domain/tbs/tbs_app.go
core/domain/tbs/tbs_app.go
+41
-3
core/support/file_analysis_helper.go
core/support/file_analysis_helper.go
+24
-2
未找到文件。
_fixtures/tbs/code/AssertionRoulette.java
→
_fixtures/tbs/code/AssertionRoulette
Test
.java
浏览文件 @
e9c7f90e
...
...
@@ -5,7 +5,7 @@ import org.junit.Test;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
AssertionRoulette
{
public
class
AssertionRoulette
Test
{
@Test
public
void
testCloneNonBareRepoFromLocalTestServer
()
throws
Exception
{
Calculate
calculate
=
new
Calculate
();
...
...
_fixtures/tbs/code/ConstructorInitialization.java
→
_fixtures/tbs/code/ConstructorInitialization
Test
.java
浏览文件 @
e9c7f90e
...
...
@@ -5,7 +5,7 @@ import org.junit.Test;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
ConstructorInitialization
{
public
class
ConstructorInitialization
Test
{
@Before
public
void
init
()
throws
Exception
{
...
...
_fixtures/tbs/code/DuplicateAssert.java
→
_fixtures/tbs/code/DuplicateAssert
Test
.java
浏览文件 @
e9c7f90e
...
...
@@ -4,7 +4,7 @@ import org.junit.Test;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
DuplicateAssert
{
public
class
DuplicateAssert
Test
{
@Test
public
void
testXmlSanitizer
()
{
boolean
valid
=
XmlSanitizer
.
isValid
(
"Fritzbox"
);
...
...
_fixtures/tbs/code/MysteryGuest.java
→
_fixtures/tbs/code/MysteryGuest
Test
.java
浏览文件 @
e9c7f90e
...
...
@@ -6,7 +6,7 @@ import java.io.FileNotFoundException;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
public
class
MysteryGuest
{
public
class
MysteryGuest
Test
{
@Test
public
void
testPersistence
()
throws
Exception
{
try
(
FileOutputStream
out
=
new
FileOutputStream
(
"people.bin"
);)
{
...
...
_fixtures/tbs/code/RedundantPrint.java
→
_fixtures/tbs/code/RedundantPrint
Test
.java
浏览文件 @
e9c7f90e
...
...
@@ -2,7 +2,7 @@ package tbs;
import
org.junit.Test
;
public
class
RedundantPrint
{
public
class
RedundantPrint
Test
{
@Test
public
void
testTransform10mNEUAndBack
()
{
String
result
=
"a, b, c"
;
...
...
cmd/tbs.go
浏览文件 @
e9c7f90e
package
cmd
import
(
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/config"
"encoding/json"
"github.com/phodal/coca/core/adapter"
"github.com/phodal/coca/core/adapter/call"
"github.com/phodal/coca/core/domain/tbs"
"github.com/phodal/coca/core/models"
"github.com/phodal/coca/core/support"
"github.com/spf13/cobra"
)
type
TbsCmdConfig
struct
{
Dependence
Path
string
Path
string
}
var
(
...
...
@@ -21,17 +23,33 @@ var tbsCmd = &cobra.Command{
Short
:
"test bad smell"
,
Long
:
``
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
identifiers
=
adapter
.
LoadIdentify
(
apiCmdConfig
.
DependencePath
)
files
:=
support
.
GetJavaTestFiles
(
tbsCmdConfig
.
Path
)
var
identifiers
[]
models
.
JIdentifier
identifiers
=
adapter
.
LoadTestIdentify
(
files
)
identifiersMap
=
adapter
.
BuildIdentifierMap
(
identifiers
)
parsedDeps
:=
cmd_util
.
GetDepsFromJson
(
tbsCmdConfig
.
DependencePath
)
var
classes
[]
string
=
nil
for
_
,
node
:=
range
identifiers
{
classes
=
append
(
classes
,
node
.
Package
+
"."
+
node
.
ClassName
)
}
analysisApp
:=
call
.
NewJavaCallApp
()
classNodes
:=
analysisApp
.
AnalysisFiles
(
identifiers
,
files
,
classes
)
nodeContent
,
_
:=
json
.
MarshalIndent
(
classNodes
,
""
,
"
\t
"
)
support
.
WriteToCocaFile
(
"tdeps.json"
,
string
(
nodeContent
))
app
:=
tbs
.
NewTbsApp
()
app
.
AnalysisPath
(
parsedDeps
,
identifiersMap
)
result
:=
app
.
AnalysisPath
(
classNodes
,
identifiersMap
)
resultContent
,
_
:=
json
.
MarshalIndent
(
result
,
""
,
"
\t
"
)
support
.
WriteToCocaFile
(
"tbs.json"
,
string
(
resultContent
))
},
}
func
init
()
{
rootCmd
.
AddCommand
(
tbsCmd
)
tbsCmd
.
PersistentFlags
()
.
StringVarP
(
&
tbsCmdConfig
.
DependencePath
,
"dependence"
,
"d"
,
config
.
CocaConfig
.
ReporterPath
+
"/deps.json"
,
"get dependence file
"
)
tbsCmd
.
PersistentFlags
()
.
StringVarP
(
&
tbsCmdConfig
.
Path
,
"path"
,
"p"
,
"."
,
"example -p core/main
"
)
}
core/adapter/helper.go
浏览文件 @
e9c7f90e
...
...
@@ -34,6 +34,23 @@ func LoadIdentify(importPath string) []models.JIdentifier {
return
*&
identifiers
}
func
LoadTestIdentify
(
files
[]
string
)
[]
models
.
JIdentifier
{
var
identifiers
[]
models
.
JIdentifier
apiContent
:=
support
.
ReadCocaFile
(
"tidentify.json"
)
if
apiContent
==
nil
{
identifierApp
:=
new
(
identifier
.
JavaIdentifierApp
)
ident
:=
identifierApp
.
AnalysisFiles
(
files
)
identModel
,
_
:=
json
.
MarshalIndent
(
ident
,
""
,
"
\t
"
)
support
.
WriteToCocaFile
(
"tidentify.json"
,
string
(
identModel
))
return
*&
ident
}
_
=
json
.
Unmarshal
(
apiContent
,
&
identifiers
)
return
*&
identifiers
}
func
BuildDIMap
(
identifiers
[]
models
.
JIdentifier
,
identifierMap
map
[
string
]
models
.
JIdentifier
)
map
[
string
]
string
{
var
diMap
=
make
(
map
[
string
]
string
)
...
...
core/domain/tbs/tbs_app.go
浏览文件 @
e9c7f90e
package
tbs
import
"github.com/phodal/coca/core/models"
import
(
"github.com/phodal/coca/core/models"
)
type
TbsApp
struct
{
}
func
NewTbsApp
()
*
TbsApp
{
return
&
TbsApp
{}
}
func
(
a
TbsApp
)
AnalysisPath
(
deps
[]
models
.
JClassNode
,
identifiersMap
map
[
string
]
models
.
JIdentifier
)
{
type
TestBadSmell
struct
{
FileName
string
Type
string
Description
string
Line
int
}
func
(
a
TbsApp
)
AnalysisPath
(
deps
[]
models
.
JClassNode
,
identifiersMap
map
[
string
]
models
.
JIdentifier
)
[]
TestBadSmell
{
var
results
[]
TestBadSmell
=
nil
var
identMethodMap
=
make
(
map
[
string
]
models
.
JMethod
)
for
key
,
clzMap
:=
range
identifiersMap
{
for
_
,
method
:=
range
clzMap
.
Methods
{
identMethodMap
[
key
+
"."
+
method
.
Name
]
=
method
}
}
for
_
,
clz
:=
range
deps
{
// TODO refactoring identify & annotation
for
_
,
method
:=
range
clz
.
Methods
{
fullName
:=
clz
.
Package
+
"."
+
clz
.
Class
+
"."
+
method
.
Name
checkIgnoreTest
(
clz
,
identMethodMap
[
fullName
],
&
results
)
}
}
return
results
}
func
checkIgnoreTest
(
clz
models
.
JClassNode
,
method
models
.
JMethod
,
results
*
[]
TestBadSmell
)
{
for
_
,
annotation
:=
range
method
.
Annotations
{
if
annotation
.
QualifiedName
==
"Ignore"
{
tbs
:=
*&
TestBadSmell
{
FileName
:
clz
.
Path
,
Type
:
"IgnoreTest"
,
Description
:
""
,
Line
:
0
,
}
*
results
=
append
(
*
results
,
tbs
)
}
}
}
core/support/file_analysis_helper.go
浏览文件 @
e9c7f90e
...
...
@@ -24,7 +24,29 @@ func GetJavaFiles(codeDir string) []string {
}
}
if
strings
.
HasSuffix
(
path
,
".java"
)
&&
!
strings
.
Contains
(
path
,
"Test.java"
)
&&
!
strings
.
Contains
(
path
,
"Tests.java"
){
if
strings
.
HasSuffix
(
path
,
".java"
)
&&
!
strings
.
Contains
(
path
,
"Test.java"
)
&&
!
strings
.
Contains
(
path
,
"Tests.java"
)
{
files
=
append
(
files
,
path
)
}
return
nil
})
return
files
}
func
GetJavaTestFiles
(
codeDir
string
)
[]
string
{
files
:=
make
([]
string
,
0
)
gitIgnore
,
err
:=
ignore
.
CompileIgnoreFile
(
".gitignore"
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
_
=
filepath
.
Walk
(
codeDir
,
func
(
path
string
,
fi
os
.
FileInfo
,
err
error
)
error
{
if
gitIgnore
!=
nil
{
if
gitIgnore
.
MatchesPath
(
path
)
{
return
nil
}
}
if
strings
.
Contains
(
path
,
"Test.java"
)
||
strings
.
Contains
(
path
,
"Tests.java"
)
{
files
=
append
(
files
,
path
)
}
return
nil
...
...
@@ -35,7 +57,7 @@ func GetJavaFiles(codeDir string) []string {
func
ProcessFile
(
path
string
)
*
JavaParser
{
is
,
_
:=
antlr
.
NewFileStream
(
path
)
lexer
:=
NewJavaLexer
(
is
)
stream
:=
antlr
.
NewCommonTokenStream
(
lexer
,
0
)
;
stream
:=
antlr
.
NewCommonTokenStream
(
lexer
,
0
)
parser
:=
NewJavaParser
(
stream
)
return
parser
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录