From 75aa5a85a6dbae142e46aaa3429677553aa01d20 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 6 Apr 2022 15:27:57 +0800 Subject: [PATCH] fix(java): fix packageName error for static import --- .../main/kotlin/chapi/ast/javaast/JavaFullIdentListener.kt | 7 +++++-- .../test/kotlin/chapi/ast/javaast/JavaIdentCallAppTest.kt | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaFullIdentListener.kt b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaFullIdentListener.kt index 15f18482..03ec4b6c 100644 --- a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaFullIdentListener.kt +++ b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaFullIdentListener.kt @@ -364,8 +364,11 @@ open class JavaFullIdentListener( pkgName = imp.Source clz = target } else if (imp.UsageName.contains(methodName)) { - pkgName = imp.Source - clz = imp.Source.split(".").last() + val splitImp = imp.Source.split(".") + clz = splitImp.last() + + val maybePackageName = splitImp.dropLast(1).joinToString(".") + pkgName = maybePackageName } } diff --git a/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentCallAppTest.kt b/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentCallAppTest.kt index 679794b2..f11faa66 100644 --- a/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentCallAppTest.kt +++ b/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentCallAppTest.kt @@ -178,5 +178,6 @@ public class BlogRepositoryImpl { val firstFunc = codeContainer.DataStructures[0].Functions[0] assertEquals(firstFunc.FunctionCalls[0].FunctionName, "generateBatchInsertSql") assertEquals(firstFunc.FunctionCalls[0].NodeName, "SqlGenerator") + assertEquals(firstFunc.FunctionCalls[0].Package, "infrastructure.utils") } }