fix: fix chain call issue

上级 8b4a1fb0
...@@ -221,7 +221,7 @@ func Test_BuilderCallSplitIssue(t *testing.T) { ...@@ -221,7 +221,7 @@ func Test_BuilderCallSplitIssue(t *testing.T) {
} }
} }
g.Expect(methodCallMap["assertThat"].NodeName).To(Equal("assertThat")) g.Expect(methodCallMap["assertThat"].NodeName).To(Equal(""))
g.Expect(methodCallMap["isFalse"].NodeName).To(Equal("assertThat")) g.Expect(methodCallMap["isFalse"].NodeName).To(Equal("assertThat"))
} }
...@@ -289,6 +289,6 @@ func Test_NormalChainCall(t *testing.T) { ...@@ -289,6 +289,6 @@ func Test_NormalChainCall(t *testing.T) {
calls := callNodes[0].Functions[0].FunctionCalls calls := callNodes[0].Functions[0].FunctionCalls
g.Expect(len(calls)).To(Equal(2)) g.Expect(len(calls)).To(Equal(2))
//g.Expect(calls[1].NodeName).To(Equal("UriComponentsBuilder")) g.Expect(calls[1].NodeName).To(Equal("UriComponentsBuilder"))
//g.Expect(calls[1].MethodName).To(Equal("buildAndExpand")) g.Expect(calls[1].MethodName).To(Equal("buildAndExpand"))
} }
...@@ -92,37 +92,39 @@ func HandleEmptyFullType(ctx *parser.MethodCallContext, targetType string, metho ...@@ -92,37 +92,39 @@ func HandleEmptyFullType(ctx *parser.MethodCallContext, targetType string, metho
targetType = clz targetType = clz
} else { } else {
targetType = buildSelfThisTarget(targetType) if strings.Contains(targetType, "this.") {
targetType = buildMethodNameForBuilder(ctx, targetType) targetType = buildSelfThisTarget(targetType)
}
return targetType, packageName
}
func buildMethodNameForBuilder(ctx *parser.MethodCallContext, targetType string) string {
switch parentCtx := ctx.GetParent().(type) {
case *parser.ExpressionContext:
switch parentParentCtx := parentCtx.GetParent().(type) {
case *parser.VariableInitializerContext:
switch varDeclCtx := parentParentCtx.GetParent().(type) {
case *parser.VariableDeclaratorContext:
targetType = getTargetFromVarDecl(varDeclCtx, targetType)
}
}
}
return targetType
}
func getTargetFromVarDecl(ctx *parser.VariableDeclaratorContext, targetType string) string {
switch x := ctx.GetParent().(type) {
case *parser.VariableDeclaratorsContext:
switch parentType := x.GetParent().(type) {
case *parser.LocalVariableDeclarationContext:
{
targetType = parentType.TypeType().GetText()
}
} }
//targetType = buildMethodNameForBuilder(ctx, targetType)
} }
return targetType return targetType, packageName
} }
// todo: check usecases
//func buildMethodNameForBuilder(ctx *parser.MethodCallContext, targetType string) string {
// switch parentCtx := ctx.GetParent().(type) {
// case *parser.ExpressionContext:
// switch parentParentCtx := parentCtx.GetParent().(type) {
// case *parser.VariableInitializerContext:
// switch varDeclCtx := parentParentCtx.GetParent().(type) {
// case *parser.VariableDeclaratorContext:
// targetType = getTargetFromVarDecl(varDeclCtx, targetType)
// }
// }
// }
//
// return targetType
//}
//
//func getTargetFromVarDecl(ctx *parser.VariableDeclaratorContext, targetType string) string {
// switch x := ctx.GetParent().(type) {
// case *parser.VariableDeclaratorsContext:
// switch parentType := x.GetParent().(type) {
// case *parser.LocalVariableDeclarationContext:
// {
// targetType = parentType.TypeType().GetText()
// }
// }
// }
// return targetType
//}
...@@ -45,6 +45,7 @@ func BuildMethodCallMethod(jMethodCall *core_domain.CodeCall, callee string, tar ...@@ -45,6 +45,7 @@ func BuildMethodCallMethod(jMethodCall *core_domain.CodeCall, callee string, tar
if isChainCall(targetType) { if isChainCall(targetType) {
split := strings.Split(targetType, ".") split := strings.Split(targetType, ".")
targetType = split[0] targetType = split[0]
targetType = ParseTargetType(targetType)
} }
jMethodCall.Package = packageName jMethodCall.Package = packageName
......
...@@ -518,15 +518,13 @@ func isChainCall(targetType string) bool { ...@@ -518,15 +518,13 @@ func isChainCall(targetType string) bool {
} }
func buildSelfThisTarget(targetType string) string { func buildSelfThisTarget(targetType string) string {
isSelfFieldCall := strings.Contains(targetType, "this.") targetType = strings.ReplaceAll(targetType, "this.", "")
if isSelfFieldCall { for _, field := range fields {
targetType = strings.ReplaceAll(targetType, "this.", "") if field.TypeValue == targetType {
for _, field := range fields { targetType = field.TypeType
if field.TypeValue == targetType {
targetType = field.TypeType
}
} }
} }
return targetType return targetType
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册