未验证 提交 b4d61923 编写于 作者: P Phodal Huang

refactor: use common get java files api

上级 76fa23b7
......@@ -7,11 +7,8 @@ import (
"github.com/phodal/coca/core/context/bs"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure"
"os"
"path/filepath"
"strings"
. "github.com/phodal/coca/languages/java"
"path/filepath"
)
var nodeInfos []domain.BsJClass
......@@ -25,7 +22,7 @@ func NewBadSmellApp() *BadSmellApp {
func (j *BadSmellApp) AnalysisPath(codeDir string, ignoreRules []string) []domain.BadSmellModel {
nodeInfos = nil
files := (*BadSmellApp)(nil).javaFiles(codeDir)
files := infrastructure.GetJavaFiles(codeDir)
for index := range files {
nodeInfo := domain.NewJFullClassNode()
file := files[index]
......@@ -55,11 +52,11 @@ func (j *BadSmellApp) AnalysisPath(codeDir string, ignoreRules []string) []domai
mapIgnoreRules[ignore] = true
}
filteredBsList := filterBadsmellList(bsList, mapIgnoreRules)
filteredBsList := FilterBadSmellList(bsList, mapIgnoreRules)
return filteredBsList
}
func filterBadsmellList(models []domain.BadSmellModel, ignoreRules map[string]bool) []domain.BadSmellModel {
func FilterBadSmellList(models []domain.BadSmellModel, ignoreRules map[string]bool) []domain.BadSmellModel {
var results []domain.BadSmellModel
for _, model := range models {
if !ignoreRules[model.Bs] {
......@@ -69,17 +66,6 @@ func filterBadsmellList(models []domain.BadSmellModel, ignoreRules map[string]bo
return results
}
func (j *BadSmellApp) javaFiles(codeDir string) []string {
files := make([]string, 0)
_ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error {
if strings.HasSuffix(path, ".java") && !strings.Contains(path, "Test.java") {
files = append(files, path)
}
return nil
})
return files
}
func (j *BadSmellApp) processFile(path string) *JavaParser {
is, _ := antlr.NewFileStream(path)
lexer := NewJavaLexer(is)
......
......@@ -25,7 +25,7 @@ func (j *JavaCallApp) AnalysisFiles(identNodes []domain.JIdentifier, files []str
var identMap = make(map[string]domain.JIdentifier)
for _, ident := range identNodes {
identMap[ident.Package+"."+ident.ClassName] = ident
identMap[ident.GetClassFullName()] = ident
}
for _, file := range files {
......
......@@ -26,3 +26,8 @@ func (identifier *JIdentifier) AddMethod(method JMethod) {
func (identifier *JIdentifier) GetMethods() []JMethod {
return methods
}
func (identifier *JIdentifier) GetClassFullName() string {
return identifier.Package+"."+identifier.ClassName
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册