refactor: keep identifier & ds:

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