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

refactor: move more behaviro to domain

上级 f51d4103
......@@ -71,7 +71,7 @@ func (c CallGraph) AnalysisByFiles(restApis []domain.RestApi, deps []domain.JCla
results := "digraph G { \n"
for _, restApi := range restApis {
caller := restApi.PackageName + "." + restApi.ClassName + "." + restApi.MethodName
caller := restApi.BuildFullMethodPath()
loopCount = 0
chain := "\"" + restApi.HttpMethod + " " + restApi.Uri + "\" -> \"" + escapeStr(caller) + "\";\n"
......@@ -100,16 +100,11 @@ func BuildMethodMap(clzs []domain.JClassNode) map[string][]string {
var methodMap = make(map[string][]string)
for _, clz := range clzs {
for _, method := range clz.Methods {
var methodName = clz.Package + "." + clz.Class + "." + method.Name
var calls []string
for _, call := range method.MethodCalls {
if call.Class != "" {
calls = append(calls, call.Package+"."+call.Class+"."+call.MethodName)
}
}
methodMap[methodName] = calls
methodName := method.BuildFullMethodName(clz)
methodMap[methodName] = method.GetAllCallString()
}
}
return methodMap
}
......@@ -13,7 +13,7 @@ func BuildCallMap(parserDeps []domain.JClassNode) map[string]int {
for _, clz := range parserDeps {
for _, method := range clz.Methods {
for _, call := range method.MethodCalls {
callMethod := call.GetFullMethodName()
callMethod := call.BuilFullMethodName()
if _, ok := projectMethods[callMethod]; ok {
if callMap[callMethod] == 0 {
callMap[callMethod] = 1
......
......@@ -83,7 +83,7 @@ func (s Service) Evaluate(result *EvaluateModel, node domain.JClassNode) {
methodType := method.Type
if _, ok := serviceNodeMap[methodType]; ok {
returnTypeMap[methodType] = append(returnTypeMap[methodType], method.GetFullMethodName(node))
returnTypeMap[methodType] = append(returnTypeMap[methodType], method.BuildFullMethodName(node))
}
}
}
......
......@@ -43,6 +43,6 @@ func (j *JClassNode) SetMethodFromMap(methodMap map[string]JMethod) {
func (j *JClassNode) BuildStringMethodMap(projectMethods map[string]string) {
for _, method := range j.Methods {
projectMethods[method.GetFullMethodName(*j)] = method.GetFullMethodName(*j)
projectMethods[method.BuildFullMethodName(*j)] = method.BuildFullMethodName(*j)
}
}
......@@ -37,6 +37,13 @@ func NewJMethod() JMethod {
}
}
type JMethodInfo struct {
Name string
Type string
Parameters []JParameter
Length string
}
func (m *JMethod) IsJavaLangReturnType() bool {
return m.Type == "String" || m.Type == "int" || m.Type == "float" || m.Type == "void" || m.Type == "char" || m.Type == "double"
}
......@@ -49,13 +56,16 @@ func (m *JMethod) IsGetterSetter() bool {
return strings.HasPrefix(m.Name, "set") || strings.HasPrefix(m.Name, "get")
}
func (m *JMethod) GetFullMethodName(node JClassNode) string {
func (m *JMethod) BuildFullMethodName(node JClassNode) string {
return node.Package + "." + node.Class + "." + m.Name
}
type JMethodInfo struct {
Name string
Type string
Parameters []JParameter
Length string
func (m *JMethod) GetAllCallString() []string {
var calls []string
for _, call := range m.MethodCalls {
if call.Class != "" {
calls = append(calls, call.BuilFullMethodName())
}
}
return calls
}
......@@ -26,6 +26,6 @@ func NewJMethodCall() JMethodCall {
}
}
func (c *JMethodCall) GetFullMethodName() string {
func (c *JMethodCall) BuilFullMethodName() string {
return c.Package + "." + c.Class + "." + c.MethodName
}
\ No newline at end of file
......@@ -11,3 +11,7 @@ type RestApi struct {
ClassName string
}
func (r *RestApi) BuildFullMethodPath() string {
return r.PackageName + "." + r.ClassName + "." + r.MethodName
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册