From 4bfe6bc7c3f612bda8e550e48a358feba8ec38e6 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 17 Dec 2019 13:06:35 +0800 Subject: [PATCH] refactor: refactor path --- cmd/api.go | 2 +- cmd/bs.go | 2 +- cmd/call_graph.go | 2 +- cmd/concept.go | 2 +- cmd/git_cmd.go | 2 +- cmd/refactor.go | 6 +-- gitt_test.go | 2 +- src/{ => domain}/bs/BadSmellApp.go | 10 ++--- src/{ => domain}/bs/BadSmellListener.go | 38 +++++++++---------- src/{ => domain}/bs/models/BsModel.go | 0 src/{ => domain}/call_graph/call_graph.go | 0 src/{ => domain}/call_graph/call_model.go | 0 src/{ => domain}/call_graph/stop_words/it.go | 0 .../call_graph/stop_words/languages/en.go | 0 src/{ => domain}/concept/concept_analyser.go | 4 +- src/{ => domain}/gitt/README.md | 0 src/{ => domain}/gitt/apriori/apriori.go | 0 src/{ => domain}/gitt/gitt.go | 8 ++-- src/{ => domain}/gitt/models.go | 0 .../refactor/base/JavaRefactorListener.go | 36 +++++++++--------- .../refactor/base/models/JFullIdentifier.go | 0 .../refactor/base/models/JMoveStruct.go | 0 src/{ => domain}/refactor/main.go | 0 .../refactor/move_class/move_class_app.go | 22 +++++------ .../refactor/rename/rename_method.go | 18 ++++----- .../rename/support/package_info_helper.go | 0 .../rename/support/refactor_change_model.go | 0 .../refactor/rename/support/related_parser.go | 0 .../refactor/unused/remove_unused_import.go | 20 +++++----- .../unused_classes/UnusedClassesApp.go | 0 .../refactor/utils/file_analysis_helper.go | 0 31 files changed, 87 insertions(+), 87 deletions(-) rename src/{ => domain}/bs/BadSmellApp.go (94%) rename src/{ => domain}/bs/BadSmellListener.go (88%) rename src/{ => domain}/bs/models/BsModel.go (100%) rename src/{ => domain}/call_graph/call_graph.go (100%) rename src/{ => domain}/call_graph/call_model.go (100%) rename src/{ => domain}/call_graph/stop_words/it.go (100%) rename src/{ => domain}/call_graph/stop_words/languages/en.go (100%) rename src/{ => domain}/concept/concept_analyser.go (94%) rename src/{ => domain}/gitt/README.md (100%) rename src/{ => domain}/gitt/apriori/apriori.go (100%) rename src/{ => domain}/gitt/gitt.go (97%) rename src/{ => domain}/gitt/models.go (100%) rename src/{ => domain}/refactor/base/JavaRefactorListener.go (80%) rename src/{ => domain}/refactor/base/models/JFullIdentifier.go (100%) rename src/{ => domain}/refactor/base/models/JMoveStruct.go (100%) rename src/{ => domain}/refactor/main.go (100%) rename src/{ => domain}/refactor/move_class/move_class_app.go (85%) rename src/{ => domain}/refactor/rename/rename_method.go (82%) rename src/{ => domain}/refactor/rename/support/package_info_helper.go (100%) rename src/{ => domain}/refactor/rename/support/refactor_change_model.go (100%) rename src/{ => domain}/refactor/rename/support/related_parser.go (100%) rename src/{ => domain}/refactor/unused/remove_unused_import.go (81%) rename src/{ => domain}/refactor/unused_classes/UnusedClassesApp.go (100%) rename src/{ => domain}/refactor/utils/file_analysis_helper.go (100%) diff --git a/cmd/api.go b/cmd/api.go index 313f3b7..fdafbab 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -3,7 +3,7 @@ package cmd import ( . "coca/src/adapter/api" "coca/src/adapter/models" - "coca/src/call_graph" + "coca/src/domain/call_graph" . "coca/src/support" "encoding/json" "github.com/olekukonko/tablewriter" diff --git a/cmd/bs.go b/cmd/bs.go index d19bf7b..6127281 100644 --- a/cmd/bs.go +++ b/cmd/bs.go @@ -1,7 +1,7 @@ package cmd import ( - "coca/src/bs" + "coca/src/domain/bs" "coca/src/support" "encoding/json" "github.com/spf13/cobra" diff --git a/cmd/call_graph.go b/cmd/call_graph.go index 98ae936..c03d09d 100644 --- a/cmd/call_graph.go +++ b/cmd/call_graph.go @@ -2,7 +2,7 @@ package cmd import ( "coca/src/adapter/models" - . "coca/src/call_graph" + . "coca/src/domain/call_graph" . "coca/src/support" "encoding/json" "github.com/spf13/cobra" diff --git a/cmd/concept.go b/cmd/concept.go index 6d4cf57..2c93667 100644 --- a/cmd/concept.go +++ b/cmd/concept.go @@ -2,7 +2,7 @@ package cmd import ( "coca/src/adapter/models" - "coca/src/concept" + "coca/src/domain/concept" . "coca/src/support" "encoding/json" "github.com/spf13/cobra" diff --git a/cmd/git_cmd.go b/cmd/git_cmd.go index ea3858b..fdc5585 100644 --- a/cmd/git_cmd.go +++ b/cmd/git_cmd.go @@ -1,7 +1,7 @@ package cmd import ( - . "coca/src/gitt" + . "coca/src/domain/gitt" "fmt" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" diff --git a/cmd/refactor.go b/cmd/refactor.go index fa0aaa5..28fc310 100644 --- a/cmd/refactor.go +++ b/cmd/refactor.go @@ -1,9 +1,9 @@ package cmd import ( - . "coca/src/refactor/move_class" - . "coca/src/refactor/rename" - . "coca/src/refactor/unused" + . "coca/src/domain/refactor/move_class" + . "coca/src/domain/refactor/rename" + . "coca/src/domain/refactor/unused" "github.com/spf13/cobra" ) diff --git a/gitt_test.go b/gitt_test.go index c89f9ce..68d7b70 100644 --- a/gitt_test.go +++ b/gitt_test.go @@ -2,7 +2,7 @@ package main_test import ( - "coca/src/gitt" + "coca/src/domain/gitt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/src/bs/BadSmellApp.go b/src/domain/bs/BadSmellApp.go similarity index 94% rename from src/bs/BadSmellApp.go rename to src/domain/bs/BadSmellApp.go index a17fbe4..14bb51b 100644 --- a/src/bs/BadSmellApp.go +++ b/src/domain/bs/BadSmellApp.go @@ -1,6 +1,7 @@ package bs import ( + "coca/src/domain/bs/models" "coca/src/support" "encoding/json" "fmt" @@ -10,11 +11,10 @@ import ( "strconv" "strings" - . "coca/src/bs/models" . "coca/src/language/java" ) -var nodeInfos []JFullClassNode +var nodeInfos []models.JFullClassNode type BadSmellModel struct { File string `json:"File,omitempty"` @@ -30,7 +30,7 @@ func (j *BadSmellApp) AnalysisPath(codeDir string, ignoreRules []string) []BadSm nodeInfos = nil files := (*BadSmellApp)(nil).javaFiles(codeDir) for index := range files { - nodeInfo := NewJFullClassNode() + nodeInfo := models.NewJFullClassNode() file := files[index] displayName := filepath.Base(file) @@ -72,7 +72,7 @@ func filterBadsmellList(models []BadSmellModel, ignoreRules map[string]bool) []B return results } -func analysisBadSmell(nodes []JFullClassNode) []BadSmellModel { +func analysisBadSmell(nodes []models.JFullClassNode) []BadSmellModel { var badSmellList []BadSmellModel for _, node := range nodes { // To be Defined number @@ -140,7 +140,7 @@ func analysisBadSmell(nodes []JFullClassNode) []BadSmellModel { return badSmellList } -func withOutGetterSetterClass(fullMethods []JFullMethod) int { +func withOutGetterSetterClass(fullMethods []models.JFullMethod) int { var normalMethodSize = 0 for _, method := range fullMethods { if !strings.Contains(method.Name, "get") && !strings.Contains(method.Name, "set") { diff --git a/src/bs/BadSmellListener.go b/src/domain/bs/BadSmellListener.go similarity index 88% rename from src/bs/BadSmellListener.go rename to src/domain/bs/BadSmellListener.go index b59c346..a18194a 100644 --- a/src/bs/BadSmellListener.go +++ b/src/domain/bs/BadSmellListener.go @@ -1,7 +1,7 @@ package bs import ( - . "coca/src/bs/models" + "coca/src/domain/bs/models" . "coca/src/language/java" "github.com/antlr/antlr4/runtime/Go/antlr" "reflect" @@ -17,13 +17,13 @@ var currentClzType string var currentClzExtends string var currentClzImplements []string -var methods []JFullMethod -var methodCalls []JFullMethodCall +var methods []models.JFullMethod +var methodCalls []models.JFullMethodCall var fields = make(map[string]string) var localVars = make(map[string]string) var formalParameters = make(map[string]string) -var currentClassBs ClassBadSmellInfo +var currentClassBs models.ClassBadSmellInfo func NewBadSmellListener() *BadSmellListener { currentClz = "" @@ -39,8 +39,8 @@ type BadSmellListener struct { BaseJavaParserListener } -func (s *BadSmellListener) getNodeInfo() *JFullClassNode { - return &JFullClassNode{ +func (s *BadSmellListener) getNodeInfo() *models.JFullClassNode { + return &models.JFullClassNode{ currentPkg, currentClz, currentClzType, @@ -105,7 +105,7 @@ func (s *BadSmellListener) EnterInterfaceMethodDeclaration(ctx *InterfaceMethodD typeType := ctx.TypeTypeOrVoid().GetText() - var methodParams []JFullParameter = nil + var methodParams []models.JFullParameter = nil parameters := ctx.FormalParameters() if parameters != nil { if reflect.TypeOf(parameters.GetChild(1)).String() == "*parser.FormalParameterListContext" { @@ -115,14 +115,14 @@ func (s *BadSmellListener) EnterInterfaceMethodDeclaration(ctx *InterfaceMethodD paramContext := param.(*FormalParameterContext) paramType := paramContext.TypeType().GetText() paramValue := paramContext.VariableDeclaratorId().(*VariableDeclaratorIdContext).IDENTIFIER().GetText() - methodParams = append(methodParams, *&JFullParameter{paramType, paramValue}) + methodParams = append(methodParams, *&models.JFullParameter{paramType, paramValue}) } } } - methodBSInfo := *&MethodBadSmellInfo{0, 0} + methodBSInfo := *&models.MethodBadSmellInfo{0, 0} - method := &JFullMethod{ + method := &models.JFullMethod{ name, typeType, startLine, @@ -168,7 +168,7 @@ func (s *BadSmellListener) EnterMethodDeclaration(ctx *MethodDeclarationContext) typeType := ctx.TypeTypeOrVoid().GetText() methodBody := ctx.MethodBody().GetText() - var methodParams []JFullParameter = nil + var methodParams []models.JFullParameter = nil parameters := ctx.FormalParameters() if parameters != nil { if reflect.TypeOf(parameters.GetChild(1)).String() == "*parser.FormalParameterListContext" { @@ -178,17 +178,17 @@ func (s *BadSmellListener) EnterMethodDeclaration(ctx *MethodDeclarationContext) paramContext := param.(*FormalParameterContext) paramType := paramContext.TypeType().GetText() paramValue := paramContext.VariableDeclaratorId().(*VariableDeclaratorIdContext).IDENTIFIER().GetText() - methodParams = append(methodParams, *&JFullParameter{paramType, paramValue}) + methodParams = append(methodParams, *&models.JFullParameter{paramType, paramValue}) localVars[paramValue] = paramType } } } - methodBSInfo := *&MethodBadSmellInfo{0, 0} + methodBSInfo := *&models.MethodBadSmellInfo{0, 0} methodBadSmellInfo := buildMethodBSInfo(ctx, methodBSInfo) - method := &JFullMethod{ + method := &models.JFullMethod{ name, typeType, startLine, @@ -202,7 +202,7 @@ func (s *BadSmellListener) EnterMethodDeclaration(ctx *MethodDeclarationContext) methods = append(methods, *method) } -func buildMethodBSInfo(context *MethodDeclarationContext, bsInfo MethodBadSmellInfo) MethodBadSmellInfo { +func buildMethodBSInfo(context *MethodDeclarationContext, bsInfo models.MethodBadSmellInfo) models.MethodBadSmellInfo { methodBody := context.MethodBody() blockContext := methodBody.GetChild(0) if reflect.TypeOf(blockContext).String() == "*parser.BlockContext" { @@ -275,16 +275,16 @@ func (s *BadSmellListener) EnterMethodCall(ctx *MethodCallContext) { targetType = currentClzExtends } if fullType != "" { - jMethodCall := &JFullMethodCall{removeTarget(fullType), "", targetType, callee, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models.JFullMethodCall{removeTarget(fullType), "", targetType, callee, startLine, startLinePosition, stopLine, stopLinePosition} methodCalls = append(methodCalls, *jMethodCall) } else { if ctx.GetText() == targetType { methodName := ctx.IDENTIFIER().GetText() - jMethodCall := &JFullMethodCall{currentPkg, "", currentClz, methodName, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models.JFullMethodCall{currentPkg, "", currentClz, methodName, startLine, startLinePosition, stopLine, stopLinePosition} methodCalls = append(methodCalls, *jMethodCall) } else { methodName := ctx.IDENTIFIER().GetText() - jMethodCall := &JFullMethodCall{currentPkg, "NEEDFIX", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models.JFullMethodCall{currentPkg, "NEEDFIX", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition} methodCalls = append(methodCalls, *jMethodCall) } } @@ -303,7 +303,7 @@ func (s *BadSmellListener) EnterExpression(ctx *ExpressionContext) { stopLine := ctx.GetStop().GetLine() stopLinePosition := startLinePosition + len(text) - jMethodCall := &JFullMethodCall{removeTarget(fullType), "", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models.JFullMethodCall{removeTarget(fullType), "", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition} methodCalls = append(methodCalls, *jMethodCall) } } diff --git a/src/bs/models/BsModel.go b/src/domain/bs/models/BsModel.go similarity index 100% rename from src/bs/models/BsModel.go rename to src/domain/bs/models/BsModel.go diff --git a/src/call_graph/call_graph.go b/src/domain/call_graph/call_graph.go similarity index 100% rename from src/call_graph/call_graph.go rename to src/domain/call_graph/call_graph.go diff --git a/src/call_graph/call_model.go b/src/domain/call_graph/call_model.go similarity index 100% rename from src/call_graph/call_model.go rename to src/domain/call_graph/call_model.go diff --git a/src/call_graph/stop_words/it.go b/src/domain/call_graph/stop_words/it.go similarity index 100% rename from src/call_graph/stop_words/it.go rename to src/domain/call_graph/stop_words/it.go diff --git a/src/call_graph/stop_words/languages/en.go b/src/domain/call_graph/stop_words/languages/en.go similarity index 100% rename from src/call_graph/stop_words/languages/en.go rename to src/domain/call_graph/stop_words/languages/en.go diff --git a/src/concept/concept_analyser.go b/src/domain/concept/concept_analyser.go similarity index 94% rename from src/concept/concept_analyser.go rename to src/domain/concept/concept_analyser.go index 60e6418..83a7c28 100644 --- a/src/concept/concept_analyser.go +++ b/src/domain/concept/concept_analyser.go @@ -2,7 +2,7 @@ package concept import ( "coca/src/adapter/models" - "coca/src/call_graph/stop_words/languages" + languages2 "coca/src/domain/call_graph/stop_words/languages" "coca/src/support" "fmt" ) @@ -116,7 +116,7 @@ var itStopWords = []string{ func removeNormalWords(words map[string]int) map[string]int { var newWords = words - var stopwords = languages.ENGLISH_STOP_WORDS + var stopwords = languages2.ENGLISH_STOP_WORDS stopwords = append(stopwords, itStopWords...) for _, normalWord := range stopwords { if newWords[normalWord] > 0 { diff --git a/src/gitt/README.md b/src/domain/gitt/README.md similarity index 100% rename from src/gitt/README.md rename to src/domain/gitt/README.md diff --git a/src/gitt/apriori/apriori.go b/src/domain/gitt/apriori/apriori.go similarity index 100% rename from src/gitt/apriori/apriori.go rename to src/domain/gitt/apriori/apriori.go diff --git a/src/gitt/gitt.go b/src/domain/gitt/gitt.go similarity index 97% rename from src/gitt/gitt.go rename to src/domain/gitt/gitt.go index 73584ac..ae51bcc 100644 --- a/src/gitt/gitt.go +++ b/src/domain/gitt/gitt.go @@ -2,7 +2,7 @@ package gitt import ( "bytes" - . "coca/src/gitt/apriori" + "coca/src/domain/gitt/apriori" "encoding/json" "fmt" "log" @@ -103,7 +103,7 @@ type TopAuthor struct { LineCount int } -func GetRelatedFiles(commitMessages []CommitMessage, relatedConfig []byte) []RelationRecord { +func GetRelatedFiles(commitMessages []CommitMessage, relatedConfig []byte) []apriori.RelationRecord { var dataset [][]string for _, commitMessage := range commitMessages { var set []string @@ -123,7 +123,7 @@ func GetRelatedFiles(commitMessages []CommitMessage, relatedConfig []byte) []Rel } } - var newOptions Options = NewOptions(0.1, 0.9, 0, 0) + var newOptions apriori.Options = apriori.NewOptions(0.1, 0.9, 0, 0) decoder := json.NewDecoder(bytes.NewReader(relatedConfig)) decoder.UseNumber() @@ -134,7 +134,7 @@ func GetRelatedFiles(commitMessages []CommitMessage, relatedConfig []byte) []Rel } fmt.Println(newOptions) - apriori := NewApriori(dataset) + apriori := apriori.NewApriori(dataset) result := apriori.Calculate(newOptions) for _, res := range result { diff --git a/src/gitt/models.go b/src/domain/gitt/models.go similarity index 100% rename from src/gitt/models.go rename to src/domain/gitt/models.go diff --git a/src/refactor/base/JavaRefactorListener.go b/src/domain/refactor/base/JavaRefactorListener.go similarity index 80% rename from src/refactor/base/JavaRefactorListener.go rename to src/domain/refactor/base/JavaRefactorListener.go index b53533d..177be7a 100644 --- a/src/refactor/base/JavaRefactorListener.go +++ b/src/domain/refactor/base/JavaRefactorListener.go @@ -1,13 +1,13 @@ package base import ( + models2 "coca/src/domain/refactor/base/models" . "coca/src/language/java" - "coca/src/refactor/base/models" "strings" "unicode" ) -var node *models.JFullIdentifier; +var node *models2.JFullIdentifier; type JavaRefactorListener struct { BaseJavaParserListener @@ -19,7 +19,7 @@ func (s *JavaRefactorListener) EnterPackageDeclaration(ctx *PackageDeclarationCo startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - pkgInfo := &models.JPkgInfo{node.Pkg, startLine, stopLine} + pkgInfo := &models2.JPkgInfo{node.Pkg, startLine, stopLine} node.SetPkgInfo(*pkgInfo) } @@ -31,7 +31,7 @@ func (s *JavaRefactorListener) EnterImportDeclaration(ctx *ImportDeclarationCont startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - jImport := &models.JImport{importText, startLine, stopLine} + jImport := &models2.JImport{importText, startLine, stopLine} node.AddImport(*jImport) } @@ -46,7 +46,7 @@ func (s *JavaRefactorListener) EnterQualifiedNameList(ctx *QualifiedNameListCont for _, qualified := range ctx.AllQualifiedName() { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{qualified.GetText(), node.Pkg, startLine, stopLine} + field := &models2.JField{qualified.GetText(), node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -55,7 +55,7 @@ func (s *JavaRefactorListener) EnterCatchType(ctx *CatchTypeContext) { for _, qualified := range ctx.AllQualifiedName() { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{qualified.GetText(), node.Pkg, startLine, stopLine} + field := &models2.JField{qualified.GetText(), node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -68,7 +68,7 @@ func (s *JavaRefactorListener) EnterInterfaceMethodDeclaration(ctx *InterfaceMet stopLinePosition := ctx.GetStop().GetColumn() name := ctx.IDENTIFIER().GetText() //XXX: find the start position of {, not public - method := &models.JFullMethod{name, startLine, startLinePosition, stopLine, stopLinePosition} + method := &models2.JFullMethod{name, startLine, startLinePosition, stopLine, stopLinePosition} node.AddMethod(*method) } @@ -80,7 +80,7 @@ func (s *JavaRefactorListener) EnterInterfaceDeclaration(ctx *InterfaceDeclarati func (s *JavaRefactorListener) EnterTypeType(ctx *TypeTypeContext) { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{ctx.GetText(), node.Pkg, startLine, stopLine} + field := &models2.JField{ctx.GetText(), node.Pkg, startLine, stopLine} node.AddField(*field) } @@ -92,7 +92,7 @@ func (s *JavaRefactorListener) EnterClassOrInterfaceType(ctx *ClassOrInterfaceTy startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{name, node.Pkg, startLine, stopLine} + field := &models2.JField{name, node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -103,7 +103,7 @@ func (s *JavaRefactorListener) EnterAnnotation(ctx *AnnotationContext) { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{annotation, node.Pkg, startLine, stopLine} + field := &models2.JField{annotation, node.Pkg, startLine, stopLine} node.AddField(*field) } @@ -115,7 +115,7 @@ func (s *JavaRefactorListener) EnterLambdaParameters(ctx *LambdaParametersContex startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{name, node.Pkg, startLine, stopLine} + field := &models2.JField{name, node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -124,7 +124,7 @@ func (s *JavaRefactorListener) EnterMethodCall(ctx *MethodCallContext) { text := ctx.IDENTIFIER().GetText() startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{text, node.Pkg, startLine, stopLine} + field := &models2.JField{text, node.Pkg, startLine, stopLine} node.AddField(*field) } @@ -134,7 +134,7 @@ func (s *JavaRefactorListener) EnterExpressionList(ctx *ExpressionListContext) { if isUppercaseText(expText) { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{expText, node.Pkg, startLine, stopLine} + field := &models2.JField{expText, node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -146,7 +146,7 @@ func (s *JavaRefactorListener) EnterStatement(ctx *StatementContext) { if isUppercaseText(expText) { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{expText, node.Pkg, startLine, stopLine} + field := &models2.JField{expText, node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -160,7 +160,7 @@ func (s *JavaRefactorListener) EnterCreatedName(ctx *CreatedNameContext) { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{name, node.Pkg, startLine, stopLine} + field := &models2.JField{name, node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -172,7 +172,7 @@ func (s *JavaRefactorListener) EnterExpression(ctx *ExpressionContext) { if isUppercaseText(expText) { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{expText, node.Pkg, startLine, stopLine} + field := &models2.JField{expText, node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -192,7 +192,7 @@ func (s *JavaRefactorListener) EnterExpression(ctx *ExpressionContext) { if isUppercaseText(expText) { startLine := ctx.GetStart().GetLine() stopLine := ctx.GetStop().GetLine() - field := &models.JField{expText, node.Pkg, startLine, stopLine} + field := &models2.JField{expText, node.Pkg, startLine, stopLine} node.AddField(*field) } } @@ -203,6 +203,6 @@ func isUppercaseText(text string) bool { return !strings.Contains(text, ".") && unicode.IsUpper([]rune(text)[0]) } -func (s *JavaRefactorListener) InitNode(identifier *models.JFullIdentifier) { +func (s *JavaRefactorListener) InitNode(identifier *models2.JFullIdentifier) { node = identifier } diff --git a/src/refactor/base/models/JFullIdentifier.go b/src/domain/refactor/base/models/JFullIdentifier.go similarity index 100% rename from src/refactor/base/models/JFullIdentifier.go rename to src/domain/refactor/base/models/JFullIdentifier.go diff --git a/src/refactor/base/models/JMoveStruct.go b/src/domain/refactor/base/models/JMoveStruct.go similarity index 100% rename from src/refactor/base/models/JMoveStruct.go rename to src/domain/refactor/base/models/JMoveStruct.go diff --git a/src/refactor/main.go b/src/domain/refactor/main.go similarity index 100% rename from src/refactor/main.go rename to src/domain/refactor/main.go diff --git a/src/refactor/move_class/move_class_app.go b/src/domain/refactor/move_class/move_class_app.go similarity index 85% rename from src/refactor/move_class/move_class_app.go rename to src/domain/refactor/move_class/move_class_app.go index 6788b91..8473c2d 100644 --- a/src/refactor/move_class/move_class_app.go +++ b/src/domain/refactor/move_class/move_class_app.go @@ -2,9 +2,9 @@ package move_class import ( "bufio" - "coca/src/refactor/base" - "coca/src/refactor/base/models" - "coca/src/refactor/utils" + base2 "coca/src/domain/refactor/base" + models2 "coca/src/domain/refactor/base/models" + utils3 "coca/src/domain/refactor/utils" utils2 "coca/src/support" "fmt" "github.com/antlr/antlr4/runtime/Go/antlr" @@ -20,7 +20,7 @@ var currentFile string var moveConfig string var configPath string -var nodes []models.JMoveStruct +var nodes []models2.JMoveStruct type MoveClassApp struct { } @@ -35,7 +35,7 @@ func NewMoveClassApp(config string, pPath string) *MoveClassApp { func (j *MoveClassApp) Analysis() { // TODO: 使用 Deps.json 来移动包 - files := utils.GetJavaFiles(configPath) + files := utils3.GetJavaFiles(configPath) fmt.Println(files) for index := range files { file := files[index] @@ -43,16 +43,16 @@ func (j *MoveClassApp) Analysis() { currentFile, _ = filepath.Abs(file) //displayName := filepath.Base(file) - parser := utils.ProcessFile(file) + parser := utils3.ProcessFile(file) context := parser.CompilationUnit() - node := models.NewJFullIdentifier() - listener := new(base.JavaRefactorListener) + node := models2.NewJFullIdentifier() + listener := new(base2.JavaRefactorListener) listener.InitNode(node) antlr.NewParseTreeWalker().Walk(listener, context) - moveStruct := &models.JMoveStruct{node, currentFile, node.GetImports()} + moveStruct := &models2.JMoveStruct{node, currentFile, node.GetImports()} nodes = append(nodes, *moveStruct) } @@ -87,8 +87,8 @@ func parseRename() { } } -func updatePackageInfo(structs []models.JMoveStruct, originImport string, newImport string) { - var originNode models.JMoveStruct +func updatePackageInfo(structs []models2.JMoveStruct, originImport string, newImport string) { + var originNode models2.JMoveStruct for index := range nodes { node := nodes[index] if originImport == node.Pkg + "." + node.Name { diff --git a/src/refactor/rename/rename_method.go b/src/domain/refactor/rename/rename_method.go similarity index 82% rename from src/refactor/rename/rename_method.go rename to src/domain/refactor/rename/rename_method.go index bdace0f..3b984bc 100644 --- a/src/refactor/rename/rename_method.go +++ b/src/domain/refactor/rename/rename_method.go @@ -2,8 +2,8 @@ package unused import ( . "coca/src/adapter/models" - "coca/src/refactor/base/models" - support2 "coca/src/refactor/rename/support" + models2 "coca/src/domain/refactor/base/models" + support3 "coca/src/domain/refactor/rename/support" "coca/src/support" "encoding/json" "io/ioutil" @@ -11,8 +11,8 @@ import ( "strings" ) -var parsedChange []support2.RefactorChangeRelate -var nodes []models.JMoveStruct +var parsedChange []support3.RefactorChangeRelate +var nodes []models2.JMoveStruct type RemoveMethodApp struct { } @@ -44,17 +44,17 @@ func (j *RemoveMethodApp) Start() { conf = string(configBytes) - parsedChange = support2.ParseRelates(conf) + parsedChange = support3.ParseRelates(conf) startParse(parsedDeps, parsedChange) } -func startParse(nodes []JClassNode, relates []support2.RefactorChangeRelate) { +func startParse(nodes []JClassNode, relates []support3.RefactorChangeRelate) { for _, pkgNode := range nodes { for _, related := range relates { - oldInfo := support2.BuildMethodPackageInfo(related.OldObj) - newInfo := support2.BuildMethodPackageInfo(related.NewObj) + oldInfo := support3.BuildMethodPackageInfo(related.OldObj) + newInfo := support3.BuildMethodPackageInfo(related.NewObj) if pkgNode.Package+pkgNode.Class == oldInfo.Package+oldInfo.Class { for _, method := range pkgNode.Methods { @@ -79,7 +79,7 @@ func methodCallToMethodModel(call JMethodCall) *JMethod { return &JMethod{call.MethodName, call.Type, call.StartLine, call.StartLinePosition, call.StopLine, call.StopLinePosition, nil, nil, false} } -func updateSelfRefs(node JClassNode, method JMethod, info *support2.PackageClassInfo) { +func updateSelfRefs(node JClassNode, method JMethod, info *support3.PackageClassInfo) { path := node.Path input, err := ioutil.ReadFile(path) if err != nil { diff --git a/src/refactor/rename/support/package_info_helper.go b/src/domain/refactor/rename/support/package_info_helper.go similarity index 100% rename from src/refactor/rename/support/package_info_helper.go rename to src/domain/refactor/rename/support/package_info_helper.go diff --git a/src/refactor/rename/support/refactor_change_model.go b/src/domain/refactor/rename/support/refactor_change_model.go similarity index 100% rename from src/refactor/rename/support/refactor_change_model.go rename to src/domain/refactor/rename/support/refactor_change_model.go diff --git a/src/refactor/rename/support/related_parser.go b/src/domain/refactor/rename/support/related_parser.go similarity index 100% rename from src/refactor/rename/support/related_parser.go rename to src/domain/refactor/rename/support/related_parser.go diff --git a/src/refactor/unused/remove_unused_import.go b/src/domain/refactor/unused/remove_unused_import.go similarity index 81% rename from src/refactor/unused/remove_unused_import.go rename to src/domain/refactor/unused/remove_unused_import.go index 68f1002..77e1fbc 100644 --- a/src/refactor/unused/remove_unused_import.go +++ b/src/domain/refactor/unused/remove_unused_import.go @@ -1,9 +1,9 @@ package unused import ( - "coca/src/refactor/base" - "coca/src/refactor/base/models" - "coca/src/refactor/utils" + base2 "coca/src/domain/refactor/base" + models2 "coca/src/domain/refactor/base/models" + utils2 "coca/src/domain/refactor/utils" "fmt" "github.com/antlr/antlr4/runtime/Go/antlr" "io/ioutil" @@ -19,7 +19,7 @@ var configPath string type RemoveUnusedImportApp struct { } -var nodes []models.JMoveStruct +var nodes []models2.JMoveStruct func NewRemoveUnusedImportApp(config string, pPath string) *RemoveUnusedImportApp { moveConfig = config @@ -30,7 +30,7 @@ func NewRemoveUnusedImportApp(config string, pPath string) *RemoveUnusedImportAp } func (j *RemoveUnusedImportApp) Analysis() { - files := utils.GetJavaFiles(configPath) + files := utils2.GetJavaFiles(configPath) for index := range files { file := files[index] @@ -38,11 +38,11 @@ func (j *RemoveUnusedImportApp) Analysis() { displayName := filepath.Base(file) fmt.Println("Start parse java call: " + displayName) - parser := utils.ProcessFile(file) + parser := utils2.ProcessFile(file) context := parser.CompilationUnit() - node := models.NewJFullIdentifier() - listener := new(base.JavaRefactorListener) + node := models2.NewJFullIdentifier() + listener := new(base2.JavaRefactorListener) listener.InitNode(node) antlr.NewParseTreeWalker().Walk(listener, context) @@ -53,7 +53,7 @@ func (j *RemoveUnusedImportApp) Analysis() { } } -func handleNode(node *models.JFullIdentifier) { +func handleNode(node *models2.JFullIdentifier) { var fields = node.GetFields() var imports = node.GetImports() @@ -87,7 +87,7 @@ func removeImportByLines(file string, errorLines []int) { } } -func removeImportByLineNum(imp models.JImport, line int) { +func removeImportByLineNum(imp models2.JImport, line int) { removeLine(currentFile, line) } diff --git a/src/refactor/unused_classes/UnusedClassesApp.go b/src/domain/refactor/unused_classes/UnusedClassesApp.go similarity index 100% rename from src/refactor/unused_classes/UnusedClassesApp.go rename to src/domain/refactor/unused_classes/UnusedClassesApp.go diff --git a/src/refactor/utils/file_analysis_helper.go b/src/domain/refactor/utils/file_analysis_helper.go similarity index 100% rename from src/refactor/utils/file_analysis_helper.go rename to src/domain/refactor/utils/file_analysis_helper.go -- GitLab