diff --git a/cmd/bs.go b/cmd/bs.go index 7e2fedcecd67015e6d3148d6d43ae903bbd5fd45..c8ee16d461478b5e5e33c202a1074c46ec5b8ef5 100644 --- a/cmd/bs.go +++ b/cmd/bs.go @@ -1,7 +1,7 @@ package cmd import ( - "coca/core/domain/bs" + "coca/core/adapter/bs" "coca/core/support" "encoding/json" "github.com/spf13/cobra" diff --git a/core/domain/bs/BadSmellApp.go b/core/adapter/bs/BadSmellApp.go similarity index 94% rename from core/domain/bs/BadSmellApp.go rename to core/adapter/bs/BadSmellApp.go index 9ed27a8ccee678373497b72d821c806c4e680ef5..db9960ec1faaf4b2131cbe6de798107ebf7a043b 100644 --- a/core/domain/bs/BadSmellApp.go +++ b/core/adapter/bs/BadSmellApp.go @@ -1,7 +1,7 @@ package bs import ( - "coca/core/domain/bs/models" + models2 "coca/core/adapter/bs/models" "coca/core/support" "encoding/json" "fmt" @@ -14,7 +14,7 @@ import ( . "coca/core/languages/java" ) -var nodeInfos []models.JFullClassNode +var nodeInfos []models2.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 := models.NewJFullClassNode() + nodeInfo := models2.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 []models.JFullClassNode) []BadSmellModel { +func analysisBadSmell(nodes []models2.JFullClassNode) []BadSmellModel { var badSmellList []BadSmellModel for _, node := range nodes { // To be Defined number @@ -140,7 +140,7 @@ func analysisBadSmell(nodes []models.JFullClassNode) []BadSmellModel { return badSmellList } -func withOutGetterSetterClass(fullMethods []models.JFullMethod) int { +func withOutGetterSetterClass(fullMethods []models2.JFullMethod) int { var normalMethodSize = 0 for _, method := range fullMethods { if !strings.Contains(method.Name, "get") && !strings.Contains(method.Name, "set") { diff --git a/core/domain/bs/BadSmellListener.go b/core/adapter/bs/BadSmellListener.go similarity index 88% rename from core/domain/bs/BadSmellListener.go rename to core/adapter/bs/BadSmellListener.go index a36086a8782556889a26f33edb9fedd27ea0008d..9e8804146cf47c5917c005777038ce2381c3d8be 100644 --- a/core/domain/bs/BadSmellListener.go +++ b/core/adapter/bs/BadSmellListener.go @@ -1,7 +1,7 @@ package bs import ( - "coca/core/domain/bs/models" + models2 "coca/core/adapter/bs/models" . "coca/core/languages/java" "github.com/antlr/antlr4/runtime/Go/antlr" "reflect" @@ -17,13 +17,13 @@ var currentClzType string var currentClzExtends string var currentClzImplements []string -var methods []models.JFullMethod -var methodCalls []models.JFullMethodCall +var methods []models2.JFullMethod +var methodCalls []models2.JFullMethodCall var fields = make(map[string]string) var localVars = make(map[string]string) var formalParameters = make(map[string]string) -var currentClassBs models.ClassBadSmellInfo +var currentClassBs models2.ClassBadSmellInfo func NewBadSmellListener() *BadSmellListener { currentClz = "" @@ -39,8 +39,8 @@ type BadSmellListener struct { BaseJavaParserListener } -func (s *BadSmellListener) getNodeInfo() *models.JFullClassNode { - return &models.JFullClassNode{ +func (s *BadSmellListener) getNodeInfo() *models2.JFullClassNode { + return &models2.JFullClassNode{ currentPkg, currentClz, currentClzType, @@ -105,7 +105,7 @@ func (s *BadSmellListener) EnterInterfaceMethodDeclaration(ctx *InterfaceMethodD typeType := ctx.TypeTypeOrVoid().GetText() - var methodParams []models.JFullParameter = nil + var methodParams []models2.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, *&models.JFullParameter{paramType, paramValue}) + methodParams = append(methodParams, *&models2.JFullParameter{paramType, paramValue}) } } } - methodBSInfo := *&models.MethodBadSmellInfo{0, 0} + methodBSInfo := *&models2.MethodBadSmellInfo{0, 0} - method := &models.JFullMethod{ + method := &models2.JFullMethod{ name, typeType, startLine, @@ -168,7 +168,7 @@ func (s *BadSmellListener) EnterMethodDeclaration(ctx *MethodDeclarationContext) typeType := ctx.TypeTypeOrVoid().GetText() methodBody := ctx.MethodBody().GetText() - var methodParams []models.JFullParameter = nil + var methodParams []models2.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, *&models.JFullParameter{paramType, paramValue}) + methodParams = append(methodParams, *&models2.JFullParameter{paramType, paramValue}) localVars[paramValue] = paramType } } } - methodBSInfo := *&models.MethodBadSmellInfo{0, 0} + methodBSInfo := *&models2.MethodBadSmellInfo{0, 0} methodBadSmellInfo := buildMethodBSInfo(ctx, methodBSInfo) - method := &models.JFullMethod{ + method := &models2.JFullMethod{ name, typeType, startLine, @@ -202,7 +202,7 @@ func (s *BadSmellListener) EnterMethodDeclaration(ctx *MethodDeclarationContext) methods = append(methods, *method) } -func buildMethodBSInfo(context *MethodDeclarationContext, bsInfo models.MethodBadSmellInfo) models.MethodBadSmellInfo { +func buildMethodBSInfo(context *MethodDeclarationContext, bsInfo models2.MethodBadSmellInfo) models2.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 := &models.JFullMethodCall{removeTarget(fullType), "", targetType, callee, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models2.JFullMethodCall{removeTarget(fullType), "", targetType, callee, startLine, startLinePosition, stopLine, stopLinePosition} methodCalls = append(methodCalls, *jMethodCall) } else { if ctx.GetText() == targetType { methodName := ctx.IDENTIFIER().GetText() - jMethodCall := &models.JFullMethodCall{currentPkg, "", currentClz, methodName, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models2.JFullMethodCall{currentPkg, "", currentClz, methodName, startLine, startLinePosition, stopLine, stopLinePosition} methodCalls = append(methodCalls, *jMethodCall) } else { methodName := ctx.IDENTIFIER().GetText() - jMethodCall := &models.JFullMethodCall{currentPkg, "NEEDFIX", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models2.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 := &models.JFullMethodCall{removeTarget(fullType), "", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition} + jMethodCall := &models2.JFullMethodCall{removeTarget(fullType), "", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition} methodCalls = append(methodCalls, *jMethodCall) } } diff --git a/core/domain/bs/models/BsModel.go b/core/adapter/bs/models/BsModel.go similarity index 100% rename from core/domain/bs/models/BsModel.go rename to core/adapter/bs/models/BsModel.go