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

refactor: move build method map to jclass nod

上级 1bb86731
......@@ -3,11 +3,9 @@ package count
import "github.com/phodal/coca/core/domain"
func BuildCallMap(parserDeps []domain.JClassNode) map[string]int {
var projectMethods = make(map[string]bool)
var projectMethods = make(map[string]string)
for _, clz := range parserDeps {
for _, method := range clz.Methods {
projectMethods[clz.Package+"."+clz.Class+"."+method.Name] = true
}
clz.BuildStringMethodMap(projectMethods)
}
// TODO: support identify data class
......@@ -15,8 +13,8 @@ func BuildCallMap(parserDeps []domain.JClassNode) map[string]int {
for _, clz := range parserDeps {
for _, method := range clz.Methods {
for _, call := range method.MethodCalls {
callMethod := call.Package + "." + call.Class + "." + call.MethodName
if projectMethods[callMethod] {
callMethod := call.GetFullMethodName()
if _, ok := projectMethods[callMethod]; ok {
if callMap[callMethod] == 0 {
callMap[callMethod] = 1
} else {
......@@ -29,3 +27,4 @@ func BuildCallMap(parserDeps []domain.JClassNode) map[string]int {
return callMap
}
......@@ -2,8 +2,8 @@ package evaluator
import (
"github.com/phodal/coca/config"
"github.com/phodal/coca/core/infrastructure/apriori"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/apriori"
"strings"
)
......@@ -83,8 +83,7 @@ func (s Service) Evaluate(result *EvaluateModel, node domain.JClassNode) {
methodType := method.Type
if _, ok := serviceNodeMap[methodType]; ok {
fullMethodName := node.Package + "." + node.Class + "." + method.Name
returnTypeMap[methodType] = append(returnTypeMap[methodType], fullMethodName)
returnTypeMap[methodType] = append(returnTypeMap[methodType], method.GetFullMethodName(node))
}
}
}
......
......@@ -40,3 +40,9 @@ func (j *JClassNode) SetMethodFromMap(methodMap map[string]JMethod) {
j.Methods = methodsArray
}
func (j *JClassNode) BuildStringMethodMap(projectMethods map[string]string) {
for _, method := range j.Methods {
projectMethods[method.GetFullMethodName(*j)] = method.GetFullMethodName(*j)
}
}
......@@ -49,6 +49,10 @@ func (m *JMethod) IsGetterSetter() bool {
return strings.HasPrefix(m.Name, "set") || strings.HasPrefix(m.Name, "get")
}
func (m *JMethod) GetFullMethodName(node JClassNode) string {
return node.Package + "." + node.Class + "." + m.Name
}
type JMethodInfo struct {
Name string
Type string
......
......@@ -25,3 +25,7 @@ func NewJMethodCall() JMethodCall {
StopLinePosition: 0,
}
}
func (c *JMethodCall) GetFullMethodName() string {
return c.Package + "." + c.Class + "." + c.MethodName
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册