diff --git a/core/adapter/api/JavaApiApp.go b/core/adapter/api/JavaApiApp.go index c21f5b62db3bc2fcdaf7fa8eea53636466f24674..92ba05a30ff21155ec61dbe16d6c4781ad17ee8f 100644 --- a/core/adapter/api/JavaApiApp.go +++ b/core/adapter/api/JavaApiApp.go @@ -1,15 +1,12 @@ package api import ( - parser2 "coca/core/languages/java" "coca/core/models" "coca/core/support" "encoding/json" "fmt" "github.com/antlr/antlr4/runtime/Go/antlr" - "os" "path/filepath" - "strings" ) var parsedDeps []models.JClassNode @@ -28,14 +25,14 @@ func (j *JavaApiApp) AnalysisPath(codeDir string, depPath string) []RestApi { _ = json.Unmarshal(file, &parsedDeps) - files := (*JavaApiApp)(nil).JavaFiles(codeDir) + files := support.GetJavaFiles(codeDir) for index := range files { file := files[index] displayName := filepath.Base(file) fmt.Println("Start parse java call: " + displayName) - parser := (*JavaApiApp)(nil).ProcessFile(file) + parser := support.ProcessFile(file) context := parser.CompilationUnit() listener := NewJavaApiListener() @@ -49,21 +46,3 @@ func (j *JavaApiApp) AnalysisPath(codeDir string, depPath string) []RestApi { return allApis } -func (j *JavaApiApp) 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 *JavaApiApp) ProcessFile(path string) *parser2.JavaParser { - is, _ := antlr.NewFileStream(path) - lexer := parser2.NewJavaLexer(is) - stream := antlr.NewCommonTokenStream(lexer, 0); - parser := parser2.NewJavaParser(stream) - return parser -} diff --git a/core/adapter/call/JavaCallApp.go b/core/adapter/call/JavaCallApp.go index 2a7560eaebac6745cb4644f2cd8a90cbf395d2f5..bfdc9dd82b451138a546e59622c874e6f6abfa70 100644 --- a/core/adapter/call/JavaCallApp.go +++ b/core/adapter/call/JavaCallApp.go @@ -1,13 +1,11 @@ package call import ( - parser2 "coca/core/languages/java" "coca/core/models" + "coca/core/support" "fmt" "github.com/antlr/antlr4/runtime/Go/antlr" - "os" "path/filepath" - "strings" ) var nodeInfos []models.JClassNode @@ -17,7 +15,7 @@ type JavaCallApp struct { func (j *JavaCallApp) AnalysisPath(codeDir string, classes []string, identNodes []models.JsonIdentifier) []models.JClassNode { nodeInfos = nil - files := (*JavaCallApp)(nil).javaFiles(codeDir) + files := support.GetJavaFiles(codeDir) for index := range files { nodeInfo := models.NewClassNode() file := files[index] @@ -25,7 +23,7 @@ func (j *JavaCallApp) AnalysisPath(codeDir string, classes []string, identNodes displayName := filepath.Base(file) fmt.Println("Start parse java call: " + displayName) - parser := (*JavaCallApp)(nil).processFile(file) + parser := support.ProcessFile(file) context := parser.CompilationUnit() listener := NewJavaCallListener(identNodes) @@ -40,22 +38,3 @@ func (j *JavaCallApp) AnalysisPath(codeDir string, classes []string, identNodes return nodeInfos } - -func (j *JavaCallApp) 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") && !strings.Contains(path, "Tests.java") { - files = append(files, path) - } - return nil - }) - return files -} - -func (j *JavaCallApp) processFile(path string) *parser2.JavaParser { - is, _ := antlr.NewFileStream(path) - lexer := parser2.NewJavaLexer(is) - stream := antlr.NewCommonTokenStream(lexer, 0) - parser := parser2.NewJavaParser(stream) - return parser -} diff --git a/core/adapter/identifier/JavaIdentifierApp.go b/core/adapter/identifier/JavaIdentifierApp.go index 1f5a432d41d8663ad37b79ef04b1e32560e92c50..29c028d62059412880eb40c6bf75114cce1f2bde 100644 --- a/core/adapter/identifier/JavaIdentifierApp.go +++ b/core/adapter/identifier/JavaIdentifierApp.go @@ -3,10 +3,8 @@ package identifier import ( parser2 "coca/core/languages/java" "coca/core/models" + "coca/core/support" "github.com/antlr/antlr4/runtime/Go/antlr" - "os" - "path/filepath" - "strings" ) var nodeInfos []models.JsonIdentifier = nil @@ -16,12 +14,12 @@ type JavaIdentifierApp struct { func (j *JavaIdentifierApp) AnalysisPath(codeDir string) []models.JsonIdentifier { nodeInfos = nil - files := (*JavaIdentifierApp)(nil).javaFiles(codeDir) + files := support.GetJavaFiles(codeDir) for index := range files { file := files[index] node := models.NewJsonIdentifier() - parser := (*JavaIdentifierApp)(nil).processFile(file) + parser := support.ProcessFile(file) context := parser.CompilationUnit() clzInfo := models.NewJIdentifier() @@ -38,22 +36,3 @@ func (j *JavaIdentifierApp) AnalysisPath(codeDir string) []models.JsonIdentifier return nodeInfos } - -func (j *JavaIdentifierApp) 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 *JavaIdentifierApp) processFile(path string) *parser2.JavaParser { - is, _ := antlr.NewFileStream(path) - lexer := parser2.NewJavaLexer(is) - stream := antlr.NewCommonTokenStream(lexer, 0); - parser := parser2.NewJavaParser(stream) - return parser -} diff --git a/core/domain/refactor/move_class/move_class_app.go b/core/domain/refactor/move_class/move_class_app.go index 94f2515560aeb1a6945e2e85ceba90d674ecb3c0..a6584c1db57e9110f26f5e78fc1ec376b5614a11 100644 --- a/core/domain/refactor/move_class/move_class_app.go +++ b/core/domain/refactor/move_class/move_class_app.go @@ -4,7 +4,6 @@ import ( "bufio" base2 "coca/core/domain/refactor/base" models2 "coca/core/domain/refactor/base/models" - utils3 "coca/core/domain/refactor/utils" utils2 "coca/core/support" "fmt" "github.com/antlr/antlr4/runtime/Go/antlr" @@ -35,7 +34,7 @@ func NewMoveClassApp(config string, pPath string) *MoveClassApp { func (j *MoveClassApp) Analysis() { // TODO: 使用 Deps.json 来移动包 - files := utils3.GetJavaFiles(configPath) + files := utils2.GetJavaFiles(configPath) fmt.Println(files) for index := range files { file := files[index] @@ -43,7 +42,7 @@ func (j *MoveClassApp) Analysis() { currentFile, _ = filepath.Abs(file) //displayName := filepath.Base(file) - parser := utils3.ProcessFile(file) + parser := utils2.ProcessFile(file) context := parser.CompilationUnit() node := models2.NewJFullIdentifier() diff --git a/core/domain/refactor/unused/remove_unused_import.go b/core/domain/refactor/unused/remove_unused_import.go index b049e84fc0488fca1f5625e4c0d2194d981fe18a..1f2273a93040f5a2e1f1a17e96acdf9f10505214 100644 --- a/core/domain/refactor/unused/remove_unused_import.go +++ b/core/domain/refactor/unused/remove_unused_import.go @@ -3,7 +3,7 @@ package unused import ( base2 "coca/core/domain/refactor/base" models2 "coca/core/domain/refactor/base/models" - utils2 "coca/core/domain/refactor/utils" + "coca/core/support" "fmt" "github.com/antlr/antlr4/runtime/Go/antlr" "io/ioutil" @@ -30,7 +30,7 @@ func NewRemoveUnusedImportApp(config string, pPath string) *RemoveUnusedImportAp } func (j *RemoveUnusedImportApp) Analysis() { - files := utils2.GetJavaFiles(configPath) + files := support.GetJavaFiles(configPath) for index := range files { file := files[index] @@ -38,7 +38,7 @@ func (j *RemoveUnusedImportApp) Analysis() { displayName := filepath.Base(file) fmt.Println("Start parse java call: " + displayName) - parser := utils2.ProcessFile(file) + parser := support.ProcessFile(file) context := parser.CompilationUnit() node := models2.NewJFullIdentifier() diff --git a/core/domain/refactor/utils/file_analysis_helper.go b/core/support/file_analysis_helper.go similarity index 97% rename from core/domain/refactor/utils/file_analysis_helper.go rename to core/support/file_analysis_helper.go index 3ebddf0c70500f0280a1c49948dcc6b60ca7d07b..05a56fee21b49c1826c8410b86e296752a917f8a 100644 --- a/core/domain/refactor/utils/file_analysis_helper.go +++ b/core/support/file_analysis_helper.go @@ -1,4 +1,4 @@ -package utils +package support import ( "github.com/antlr/antlr4/runtime/Go/antlr" @@ -13,7 +13,6 @@ func GetJavaFiles(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")&& !strings.Contains(path, "Tests.java"){ - files = append(files, path) } return nil