refactor: keep identifier & ds:

上级 6280dfc5
...@@ -32,7 +32,7 @@ var analysisCmd = &cobra.Command{ ...@@ -32,7 +32,7 @@ var analysisCmd = &cobra.Command{
var classes []string = nil var classes []string = nil
for _, node := range iNodes { for _, node := range iNodes {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
callApp := analysis.NewJavaFullApp() callApp := analysis.NewJavaFullApp()
......
...@@ -40,7 +40,7 @@ var depsCmd = &cobra.Command{ ...@@ -40,7 +40,7 @@ var depsCmd = &cobra.Command{
var classes []string = nil var classes []string = nil
for _, node := range iNodes { for _, node := range iNodes {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
callApp := analysis.NewJavaFullApp() callApp := analysis.NewJavaFullApp()
......
...@@ -31,7 +31,7 @@ var reverseCmd = &cobra.Command{ ...@@ -31,7 +31,7 @@ var reverseCmd = &cobra.Command{
remove := reverseConfig.RemovePackage remove := reverseConfig.RemovePackage
if className == "" { if className == "" {
log.Fatal("lost ClassName") log.Fatal("lost NodeName")
} }
analyser := rcall.NewRCallGraph() analyser := rcall.NewRCallGraph()
......
...@@ -33,7 +33,7 @@ var tbsCmd = &cobra.Command{ ...@@ -33,7 +33,7 @@ var tbsCmd = &cobra.Command{
var classes []string = nil var classes []string = nil
for _, node := range identifiers { for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
analysisApp := analysis.NewJavaFullApp() analysisApp := analysis.NewJavaFullApp()
......
...@@ -13,7 +13,7 @@ func BuildAnalysisDeps(codePath string) ([]core_domain.CodeDataStruct, map[strin ...@@ -13,7 +13,7 @@ func BuildAnalysisDeps(codePath string) ([]core_domain.CodeDataStruct, map[strin
identifiers := identifierApp.AnalysisPath(codePath) identifiers := identifierApp.AnalysisPath(codePath)
var classes []string = nil var classes []string = nil
for _, node := range identifiers { for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
callApp := analysis.NewJavaFullApp() callApp := analysis.NewJavaFullApp()
......
...@@ -29,5 +29,5 @@ public class DataClass { ...@@ -29,5 +29,5 @@ public class DataClass {
antlr.NewParseTreeWalker().Walk(listener, context) antlr.NewParseTreeWalker().Walk(listener, context)
identifiers := listener.GetNodes() identifiers := listener.GetNodes()
g.Expect(identifiers[0].ClassName).To(Equal("DataClass")) g.Expect(identifiers[0].NodeName).To(Equal("DataClass"))
} }
...@@ -17,7 +17,7 @@ func TestJavaCallApp_AnalysisPath(t *testing.T) { ...@@ -17,7 +17,7 @@ func TestJavaCallApp_AnalysisPath(t *testing.T) {
iNodes := identifierApp.AnalysisPath(codePath) iNodes := identifierApp.AnalysisPath(codePath)
var classes []string = nil var classes []string = nil
for _, node := range iNodes { for _, node := range iNodes {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
callApp := NewJavaFullApp() callApp := NewJavaFullApp()
...@@ -41,7 +41,7 @@ func getCallNodes(codePath string) []core_domain.CodeDataStruct { ...@@ -41,7 +41,7 @@ func getCallNodes(codePath string) []core_domain.CodeDataStruct {
iNodes := identifierApp.AnalysisPath(codePath) iNodes := identifierApp.AnalysisPath(codePath)
var classes []string = nil var classes []string = nil
for _, node := range iNodes { for _, node := range iNodes {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
callApp := NewJavaFullApp() callApp := NewJavaFullApp()
......
...@@ -13,9 +13,9 @@ func TestJavaIdentifierApp_AnalysisPath(t *testing.T) { ...@@ -13,9 +13,9 @@ func TestJavaIdentifierApp_AnalysisPath(t *testing.T) {
identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/call")) identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/call"))
g.Expect(len(identifiers)).To(Equal(1)) g.Expect(len(identifiers)).To(Equal(1))
g.Expect(identifiers[0].ClassName).To(Equal("BookController")) g.Expect(identifiers[0].NodeName).To(Equal("BookController"))
g.Expect(identifiers[0].Methods[0].Name).To(Equal("BookController")) g.Expect(identifiers[0].Functions[0].Name).To(Equal("BookController"))
g.Expect(identifiers[0].Methods[1].Name).To(Equal("createBook")) g.Expect(identifiers[0].Functions[1].Name).To(Equal("createBook"))
g.Expect(identifiers[0].Annotations[0].Name).To(Equal("RestController")) g.Expect(identifiers[0].Annotations[0].Name).To(Equal("RestController"))
} }
...@@ -27,8 +27,8 @@ func TestPolymorphism_Method(t *testing.T) { ...@@ -27,8 +27,8 @@ func TestPolymorphism_Method(t *testing.T) {
identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/suggest/polymorphism")) identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/suggest/polymorphism"))
g.Expect(len(identifiers)).To(Equal(1)) g.Expect(len(identifiers)).To(Equal(1))
g.Expect(identifiers[0].ClassName).To(Equal("Overload")) g.Expect(identifiers[0].NodeName).To(Equal("Overload"))
g.Expect(len(identifiers[0].Methods)).To(Equal(3)) g.Expect(len(identifiers[0].Functions)).To(Equal(3))
} }
func TestPolymorphism_Constructor(t *testing.T) { func TestPolymorphism_Constructor(t *testing.T) {
...@@ -38,8 +38,8 @@ func TestPolymorphism_Constructor(t *testing.T) { ...@@ -38,8 +38,8 @@ func TestPolymorphism_Constructor(t *testing.T) {
identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/suggest/factory")) identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/suggest/factory"))
g.Expect(len(identifiers)).To(Equal(2)) g.Expect(len(identifiers)).To(Equal(2))
g.Expect(identifiers[0].ClassName).To(Equal("Insect")) g.Expect(identifiers[0].NodeName).To(Equal("Insect"))
g.Expect(identifiers[1].ClassName).To(Equal("Bee")) g.Expect(identifiers[1].NodeName).To(Equal("Bee"))
} }
func TestAddReturnNull(t *testing.T) { func TestAddReturnNull(t *testing.T) {
...@@ -49,14 +49,14 @@ func TestAddReturnNull(t *testing.T) { ...@@ -49,14 +49,14 @@ func TestAddReturnNull(t *testing.T) {
identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/evaluate/null")) identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/evaluate/null"))
var returNullCount = 0 var returNullCount = 0
for _, method := range identifiers[0].Methods { for _, method := range identifiers[0].Functions {
if method.IsReturnNull { if method.IsReturnNull {
returNullCount++ returNullCount++
} }
} }
g.Expect(identifiers[0].Methods[1].IsReturnNull).To(Equal(true)) g.Expect(identifiers[0].Functions[1].IsReturnNull).To(Equal(true))
g.Expect(identifiers[0].Methods[2].IsReturnNull).To(Equal(true)) g.Expect(identifiers[0].Functions[2].IsReturnNull).To(Equal(true))
g.Expect(returNullCount).To(Equal(2)) g.Expect(returNullCount).To(Equal(2))
} }
...@@ -66,8 +66,8 @@ func TestStaticMethod(t *testing.T) { ...@@ -66,8 +66,8 @@ func TestStaticMethod(t *testing.T) {
identApp := NewJavaIdentifierApp() identApp := NewJavaIdentifierApp()
identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/suggest/static")) identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/suggest/static"))
g.Expect(identifiers[0].Methods[0].Modifiers[0]).To(Equal("public")) g.Expect(identifiers[0].Functions[0].Modifiers[0]).To(Equal("public"))
g.Expect(identifiers[0].Methods[0].Modifiers[1]).To(Equal("static")) g.Expect(identifiers[0].Functions[0].Modifiers[1]).To(Equal("static"))
} }
func TestModifierLength(t *testing.T) { func TestModifierLength(t *testing.T) {
...@@ -76,5 +76,5 @@ func TestModifierLength(t *testing.T) { ...@@ -76,5 +76,5 @@ func TestModifierLength(t *testing.T) {
identApp := NewJavaIdentifierApp() identApp := NewJavaIdentifierApp()
identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/bs/ComplexIf.java")) identifiers := identApp.AnalysisPath(filepath.FromSlash("../../../_fixtures/bs/ComplexIf.java"))
g.Expect(len(identifiers[0].Methods[0].Modifiers)).To(Equal(1)) g.Expect(len(identifiers[0].Functions[0].Modifiers)).To(Equal(1))
} }
...@@ -54,9 +54,9 @@ func SummaryMethodIdentifier(identifiers []core_domain.JIdentifier, result *eval ...@@ -54,9 +54,9 @@ func SummaryMethodIdentifier(identifiers []core_domain.JIdentifier, result *eval
for _, ident := range identifiers { for _, ident := range identifiers {
result.Summary.ClassCount++ result.Summary.ClassCount++
methodCountArray = append(methodCountArray, float64(len(ident.Methods))) methodCountArray = append(methodCountArray, float64(len(ident.Functions)))
for _, method := range ident.Methods { for _, method := range ident.Functions {
result.Summary.MethodCount++ result.Summary.MethodCount++
if method.IsStatic() { if method.IsStatic() {
......
...@@ -15,7 +15,7 @@ func (n NullPointException) EvaluateList(evaluateModel *EvaluateModel, nodes []c ...@@ -15,7 +15,7 @@ func (n NullPointException) EvaluateList(evaluateModel *EvaluateModel, nodes []c
var nullableList []string = nil var nullableList []string = nil
var nullableMap = make(map[string]string) var nullableMap = make(map[string]string)
for _, ident := range identifiers { for _, ident := range identifiers {
for _, method := range ident.Methods { for _, method := range ident.Functions {
methodName := buildMethodPath(ident, method) methodName := buildMethodPath(ident, method)
if method.IsReturnNull { if method.IsReturnNull {
nullableMap[methodName] = methodName nullableMap[methodName] = methodName
...@@ -37,5 +37,5 @@ func (n NullPointException) EvaluateList(evaluateModel *EvaluateModel, nodes []c ...@@ -37,5 +37,5 @@ func (n NullPointException) EvaluateList(evaluateModel *EvaluateModel, nodes []c
} }
func buildMethodPath(ident core_domain.JIdentifier, method core_domain.CodeFunction) string { func buildMethodPath(ident core_domain.JIdentifier, method core_domain.CodeFunction) string {
return ident.Package + "." + ident.ClassName + "." + method.Name return ident.Package + "." + ident.NodeName + "." + method.Name
} }
...@@ -21,7 +21,7 @@ func TestRenameMethodApp(t *testing.T) { ...@@ -21,7 +21,7 @@ func TestRenameMethodApp(t *testing.T) {
identifiers := identifierApp.AnalysisPath(codePath) identifiers := identifierApp.AnalysisPath(codePath)
var classes []string = nil var classes []string = nil
for _, node := range identifiers { for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
callApp := analysis.NewJavaFullApp() callApp := analysis.NewJavaFullApp()
......
...@@ -147,7 +147,7 @@ func BuildTestAnalysisResultsByPath(codePath string) (map[string]core_domain.JId ...@@ -147,7 +147,7 @@ func BuildTestAnalysisResultsByPath(codePath string) (map[string]core_domain.JId
var classes []string = nil var classes []string = nil
for _, node := range identifiers { for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName) classes = append(classes, node.Package+"."+node.NodeName)
} }
analysisApp := analysis.NewJavaFullApp() analysisApp := analysis.NewJavaFullApp()
......
...@@ -21,6 +21,16 @@ type CodeDataStruct struct { ...@@ -21,6 +21,16 @@ type CodeDataStruct struct {
Extension interface{} Extension interface{}
} }
type JIdentifier struct {
NodeName string
Package string
Type string
Extend string
Implements []string
Functions []CodeFunction
Annotations []CodeAnnotation
}
func NewDataStruct() *CodeDataStruct { func NewDataStruct() *CodeDataStruct {
return &CodeDataStruct{} return &CodeDataStruct{}
} }
...@@ -61,3 +71,36 @@ func BuildCallMethodMap(deps []CodeDataStruct) map[string]CodeFunction { ...@@ -61,3 +71,36 @@ func BuildCallMethodMap(deps []CodeDataStruct) map[string]CodeFunction {
} }
return callMethodMap return callMethodMap
} }
func NewJIdentifier() *JIdentifier {
return &JIdentifier{}
}
func (identifier *JIdentifier) GetClassFullName() string {
return identifier.Package + "." + identifier.NodeName
}
func BuildIdentifierMap(identifiers []JIdentifier) map[string]JIdentifier {
var identifiersMap = make(map[string]JIdentifier)
for _, ident := range identifiers {
identifiersMap[ident.Package+"."+ident.NodeName] = ident
}
return identifiersMap
}
func BuildDIMap(identifiers []JIdentifier, identifierMap map[string]JIdentifier) map[string]string {
var diMap = make(map[string]string)
for _, clz := range identifiers {
if len(clz.Annotations) > 0 {
for _, annotation := range clz.Annotations {
if (annotation.IsComponentOrRepository()) && len(clz.Implements) > 0 {
superClz := identifierMap[clz.Implements[0]]
diMap[superClz.GetClassFullName()] = superClz.GetClassFullName()
}
}
}
}
return diMap
}
package core_domain package core_domain
type JIdentifier struct {
Package string
ClassName string
ClassType string
ExtendsName string
Extends []string
Implements []string
Methods []CodeFunction
Annotations []CodeAnnotation
}
func NewJIdentifier() *JIdentifier {
return &JIdentifier{}
}
func (identifier *JIdentifier) GetClassFullName() string {
return identifier.Package + "." + identifier.ClassName
}
func BuildIdentifierMap(identifiers []JIdentifier) map[string]JIdentifier {
var identifiersMap = make(map[string]JIdentifier)
for _, ident := range identifiers {
identifiersMap[ident.Package+"."+ident.ClassName] = ident
}
return identifiersMap
}
func BuildDIMap(identifiers []JIdentifier, identifierMap map[string]JIdentifier) map[string]string {
var diMap = make(map[string]string)
for _, clz := range identifiers {
if len(clz.Annotations) > 0 {
for _, annotation := range clz.Annotations {
if (annotation.IsComponentOrRepository()) && len(clz.Implements) > 0 {
superClz := identifierMap[clz.Implements[0]]
diMap[superClz.GetClassFullName()] = superClz.GetClassFullName()
}
}
}
}
return diMap
}
...@@ -220,7 +220,7 @@ func buildApiForInterfaceAnnotation(methodName string) bool { ...@@ -220,7 +220,7 @@ func buildApiForInterfaceAnnotation(methodName string) bool {
} }
if _, ok := identMap[superClz]; ok { if _, ok := identMap[superClz]; ok {
for _, method := range identMap[superClz].Methods { for _, method := range identMap[superClz].Functions {
if method.Name == methodName { if method.Name == methodName {
for _, annotation := range method.Annotations { for _, annotation := range method.Annotations {
if annotation.Name == "ServiceMethod" { if annotation.Name == "ServiceMethod" {
......
...@@ -39,13 +39,13 @@ func (s *JavaIdentifierListener) EnterPackageDeclaration(ctx *parser.PackageDecl ...@@ -39,13 +39,13 @@ func (s *JavaIdentifierListener) EnterPackageDeclaration(ctx *parser.PackageDecl
func (s *JavaIdentifierListener) EnterClassDeclaration(ctx *parser.ClassDeclarationContext) { func (s *JavaIdentifierListener) EnterClassDeclaration(ctx *parser.ClassDeclarationContext) {
hasEnterClass = true hasEnterClass = true
currentNode.ClassType = "NodeName" currentNode.Type = "NodeName"
if ctx.IDENTIFIER() != nil { if ctx.IDENTIFIER() != nil {
currentNode.ClassName = ctx.IDENTIFIER().GetText() currentNode.NodeName = ctx.IDENTIFIER().GetText()
} }
if ctx.EXTENDS() != nil { if ctx.EXTENDS() != nil {
currentNode.ExtendsName = ctx.TypeType().GetText() currentNode.Extend = ctx.TypeType().GetText()
} }
if ctx.IMPLEMENTS() != nil { if ctx.IMPLEMENTS() != nil {
...@@ -65,7 +65,7 @@ func (s *JavaIdentifierListener) EnterClassDeclaration(ctx *parser.ClassDeclarat ...@@ -65,7 +65,7 @@ func (s *JavaIdentifierListener) EnterClassDeclaration(ctx *parser.ClassDeclarat
func (s *JavaIdentifierListener) ExitClassBody(ctx *parser.ClassBodyContext) { func (s *JavaIdentifierListener) ExitClassBody(ctx *parser.ClassBodyContext) {
hasEnterClass = false hasEnterClass = false
if currentNode.ClassName != "" { if currentNode.NodeName != "" {
nodes = append(nodes, *currentNode) nodes = append(nodes, *currentNode)
} }
currentNode = core_domain.NewJIdentifier() currentNode = core_domain.NewJIdentifier()
...@@ -73,7 +73,7 @@ func (s *JavaIdentifierListener) ExitClassBody(ctx *parser.ClassBodyContext) { ...@@ -73,7 +73,7 @@ func (s *JavaIdentifierListener) ExitClassBody(ctx *parser.ClassBodyContext) {
func (s *JavaIdentifierListener) ExitInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) { func (s *JavaIdentifierListener) ExitInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) {
hasEnterClass = false hasEnterClass = false
if currentNode.ClassName != "" { if currentNode.NodeName != "" {
nodes = append(nodes, *currentNode) nodes = append(nodes, *currentNode)
} }
currentNode = core_domain.NewJIdentifier() currentNode = core_domain.NewJIdentifier()
...@@ -98,7 +98,7 @@ func (s *JavaIdentifierListener) EnterConstructorDeclaration(ctx *parser.Constru ...@@ -98,7 +98,7 @@ func (s *JavaIdentifierListener) EnterConstructorDeclaration(ctx *parser.Constru
} }
func (s *JavaIdentifierListener) ExitConstructorDeclaration(ctx *parser.ConstructorDeclarationContext) { func (s *JavaIdentifierListener) ExitConstructorDeclaration(ctx *parser.ConstructorDeclarationContext) {
currentNode.Methods = append(currentNode.Methods, currentMethod) currentNode.Functions = append(currentNode.Functions, currentMethod)
} }
func (s *JavaIdentifierListener) EnterInterfaceBodyDeclaration(ctx *parser.InterfaceBodyDeclarationContext) { func (s *JavaIdentifierListener) EnterInterfaceBodyDeclaration(ctx *parser.InterfaceBodyDeclarationContext) {
...@@ -135,7 +135,7 @@ func (s *JavaIdentifierListener) EnterInterfaceMethodDeclaration(ctx *parser.Int ...@@ -135,7 +135,7 @@ func (s *JavaIdentifierListener) EnterInterfaceMethodDeclaration(ctx *parser.Int
} }
func (s *JavaIdentifierListener) ExitInterfaceMethodDeclaration(ctx *parser.InterfaceMethodDeclarationContext) { func (s *JavaIdentifierListener) ExitInterfaceMethodDeclaration(ctx *parser.InterfaceMethodDeclarationContext) {
currentNode.Methods = append(currentNode.Methods, currentMethod) currentNode.Functions = append(currentNode.Functions, currentMethod)
currentMethod = core_domain.NewJMethod() currentMethod = core_domain.NewJMethod()
} }
...@@ -184,7 +184,7 @@ func (s *JavaIdentifierListener) EnterMethodDeclaration(ctx *parser.MethodDeclar ...@@ -184,7 +184,7 @@ func (s *JavaIdentifierListener) EnterMethodDeclaration(ctx *parser.MethodDeclar
} }
func (s *JavaIdentifierListener) ExitMethodDeclaration(ctx *parser.MethodDeclarationContext) { func (s *JavaIdentifierListener) ExitMethodDeclaration(ctx *parser.MethodDeclarationContext) {
currentNode.Methods = append(currentNode.Methods, currentMethod) currentNode.Functions = append(currentNode.Functions, currentMethod)
currentMethod = core_domain.NewJMethod() currentMethod = core_domain.NewJMethod()
} }
...@@ -202,8 +202,8 @@ func (s *JavaIdentifierListener) EnterAnnotation(ctx *parser.AnnotationContext) ...@@ -202,8 +202,8 @@ func (s *JavaIdentifierListener) EnterAnnotation(ctx *parser.AnnotationContext)
func (s *JavaIdentifierListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) { func (s *JavaIdentifierListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) {
hasEnterClass = true hasEnterClass = true
currentNode.ClassType = "Interface" currentNode.Type = "Interface"
currentNode.ClassName = ctx.IDENTIFIER().GetText() currentNode.NodeName = ctx.IDENTIFIER().GetText()
} }
func (s *JavaIdentifierListener) EnterExpression(ctx *parser.ExpressionContext) { func (s *JavaIdentifierListener) EnterExpression(ctx *parser.ExpressionContext) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册