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

refactor: move bs to adapter

上级 6e3235ac
package cmd
import (
"coca/core/domain/bs"
"coca/core/adapter/bs"
"coca/core/support"
"encoding/json"
"github.com/spf13/cobra"
......
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") {
......
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)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册