fix: fix chain call issue

上级 8b4a1fb0
......@@ -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"))
}
......@@ -289,6 +289,6 @@ func Test_NormalChainCall(t *testing.T) {
calls := callNodes[0].Functions[0].FunctionCalls
g.Expect(len(calls)).To(Equal(2))
//g.Expect(calls[1].NodeName).To(Equal("UriComponentsBuilder"))
//g.Expect(calls[1].MethodName).To(Equal("buildAndExpand"))
g.Expect(calls[1].NodeName).To(Equal("UriComponentsBuilder"))
g.Expect(calls[1].MethodName).To(Equal("buildAndExpand"))
}
......@@ -92,37 +92,39 @@ func HandleEmptyFullType(ctx *parser.MethodCallContext, targetType string, metho
targetType = clz
} else {
targetType = buildSelfThisTarget(targetType)
targetType = buildMethodNameForBuilder(ctx, 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()
}
if strings.Contains(targetType, "this.") {
targetType = buildSelfThisTarget(targetType)
}
//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
if isChainCall(targetType) {
split := strings.Split(targetType, ".")
targetType = split[0]
targetType = ParseTargetType(targetType)
}
jMethodCall.Package = packageName
......
......@@ -518,15 +518,13 @@ func isChainCall(targetType string) bool {
}
func buildSelfThisTarget(targetType string) string {
isSelfFieldCall := strings.Contains(targetType, "this.")
if isSelfFieldCall {
targetType = strings.ReplaceAll(targetType, "this.", "")
for _, field := range fields {
if field.TypeValue == targetType {
targetType = field.TypeType
}
targetType = strings.ReplaceAll(targetType, "this.", "")
for _, field := range fields {
if field.TypeValue == targetType {
targetType = field.TypeType
}
}
return targetType
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册