Skip to content

Commit 7f944b6

Browse files
committed
feat: add simple call type
1 parent 2a92981 commit 7f944b6

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

core/adapter/call/JavaCallListener.go

+20-14
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (s *JavaCallListener) EnterCreator(ctx *parser.CreatorContext) {
245245

246246
func buildCreatedCall(createdName string, ctx *parser.CreatorContext) {
247247
method := methodMap[getMethodMapName(currentMethod)]
248-
fullType := warpTargetFullType(createdName)
248+
fullType, _ := warpTargetFullType(createdName)
249249

250250
startLine := ctx.GetStart().GetLine()
251251
startLinePosition := ctx.GetStart().GetColumn()
@@ -254,7 +254,7 @@ func buildCreatedCall(createdName string, ctx *parser.CreatorContext) {
254254

255255
jMethodCall := &models.JMethodCall{
256256
Package: removeTarget(fullType),
257-
Type: "Creator",
257+
Type: "creator",
258258
Class: createdName,
259259
MethodName: "",
260260
StartLine: startLine,
@@ -281,7 +281,7 @@ func (s *JavaCallListener) EnterMethodCall(ctx *parser.MethodCallContext) {
281281
stopLine := ctx.GetStop().GetLine()
282282
stopLinePosition := startLinePosition + len(callee)
283283

284-
fullType := warpTargetFullType(targetType)
284+
fullType, callType := warpTargetFullType(targetType)
285285
if targetType == "super" {
286286
targetType = currentClzExtend
287287
}
@@ -293,7 +293,7 @@ func (s *JavaCallListener) EnterMethodCall(ctx *parser.MethodCallContext) {
293293
targetType = currentClz
294294
}
295295

296-
jMethodCall = &models.JMethodCall{removeTarget(fullType), "", targetType, callee, startLine, startLinePosition, stopLine, stopLinePosition}
296+
jMethodCall = &models.JMethodCall{removeTarget(fullType), callType, targetType, callee, startLine, startLinePosition, stopLine, stopLinePosition}
297297
} else {
298298
if ctx.GetText() == targetType {
299299
methodName := ctx.IDENTIFIER().GetText()
@@ -306,14 +306,14 @@ func (s *JavaCallListener) EnterMethodCall(ctx *parser.MethodCallContext) {
306306
clz = ""
307307
}
308308
}
309-
jMethodCall = &models.JMethodCall{pkg, "", clz, methodName, startLine, startLinePosition, stopLine, stopLinePosition}
309+
jMethodCall = &models.JMethodCall{pkg, callType, clz, methodName, startLine, startLinePosition, stopLine, stopLinePosition}
310310
} else {
311311
methodName := ctx.IDENTIFIER().GetText()
312312
targetType = buildSpecificTarget(targetType)
313313

314314
targetType = buildMethodNameForBuilder(ctx, targetType)
315315

316-
jMethodCall = &models.JMethodCall{currentPkg, "NEEDFIX", targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition}
316+
jMethodCall = &models.JMethodCall{currentPkg, callType, targetType, methodName, startLine, startLinePosition, stopLine, stopLinePosition}
317317
}
318318
}
319319

@@ -374,7 +374,7 @@ func (s *JavaCallListener) EnterExpression(ctx *parser.ExpressionContext) {
374374
methodName := ctx.IDENTIFIER().GetText()
375375
targetType := parseTargetType(text)
376376

377-
fullType := warpTargetFullType(targetType)
377+
fullType, _ := warpTargetFullType(targetType)
378378

379379
startLine := ctx.GetStart().GetLine()
380380
startLinePosition := ctx.GetStart().GetColumn()
@@ -424,9 +424,11 @@ func parseTargetType(targetCtx string) string {
424424
return targetType
425425
}
426426

427-
func warpTargetFullType(targetType string) string {
427+
func warpTargetFullType(targetType string) (string, string) {
428+
callType := ""
428429
if strings.EqualFold(currentClz, targetType) {
429-
return currentPkg + "." + targetType
430+
callType = "self"
431+
return currentPkg + "." + targetType, ""
430432
}
431433

432434
// TODO: update for array
@@ -437,30 +439,34 @@ func warpTargetFullType(targetType string) string {
437439
if pureTargetType != "" {
438440
for _, imp := range imports {
439441
if strings.HasSuffix(imp, pureTargetType) {
440-
return imp
442+
callType = "chain"
443+
return imp, callType
441444
}
442445
}
443446
}
444447

445448
//maybe the same package
446449
for _, clz := range clzs {
447450
if strings.HasSuffix(clz, "."+pureTargetType) {
448-
return clz
451+
callType = "same package"
452+
return clz, callType
449453
}
450454
}
451455

452456
//1. current package, 2. import by *
453457
if pureTargetType == "super" {
454458
for _, imp := range imports {
455459
if strings.HasSuffix(imp, currentClzExtend) {
456-
return imp
460+
callType = "super"
461+
return imp, callType
457462
}
458463
}
459464
}
460465

461466
if _, ok := identMap[currentPkg + "." + targetType]; ok {
462-
return currentPkg + "." + targetType
467+
callType = "same package 2"
468+
return currentPkg + "." + targetType, callType
463469
}
464470

465-
return ""
471+
return "", callType
466472
}

0 commit comments

Comments
 (0)