diff --git a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt index 6d3e474a..692366ef 100644 --- a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt +++ b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt @@ -433,14 +433,14 @@ class JavaIdentListener(fileName: String) : JavaParserBaseListener() { continue } - val typeType = typeCtx.IDENTIFIER(0).text + val typeTypeText = typeCtx.IDENTIFIER(0).text val typeValue = declCtx.variableDeclaratorId().IDENTIFIER().text - fieldsMap[typeValue] = typeType + fieldsMap[typeValue] = typeTypeText - val field = CodeField(typeType, typeValue, arrayOf()) + val field = CodeField(typeTypeText, typeValue, arrayOf()) fields += field - buildFieldCall(typeType, ctx) + buildFieldCall(typeTypeText, ctx) } } @@ -540,6 +540,30 @@ class JavaIdentListener(fileName: String) : JavaParserBaseListener() { } } + override fun enterExpression(ctx: JavaParser.ExpressionContext?) { + if (ctx!!.COLONCOLON() != null) { + if (ctx.expression(0) == null) { + return + } + + val text = ctx.expression(0).text + val methodName = ctx.IDENTIFIER().text + val targetType = parseTargetType(text) + + val fullType = warpTargetFullType(targetType).targetType + val position = buildPosition(ctx) + val codeCall = CodeCall( + Package = removeTarget(fullType), + Type = "lambda", + NodeName = targetType!!, + FunctionName = methodName, + Position = position + ) + + sendResultToMethodCallMap(codeCall) + } + } + fun getNodeInfo(): CodeFile { codeFile.DataStructures = classNodes return codeFile 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 aa15e9ad..40122ec4 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 @@ -120,4 +120,26 @@ public class PublishedBlogResource { assertEquals(functionCalls[2].NodeName, "UriComponents") assertEquals(functionCalls[2].FunctionName, "toUri") } + + @Test + fun shouldIdentifyLambdaCall() { + var code = """ +package hello; + +import domain.BlogPO; + +@Component +public class BlogRepositoryImpl { + public BlogPo getDomainModel() { + return BlogPO::toDomainModel; + } +} + """ + val codeFile = JavaIdentApp().analysis(code, "") + + val functionCalls = codeFile.DataStructures[0].Functions[0].FunctionCalls + assertEquals(functionCalls.size, 1) + assertEquals(functionCalls[0].NodeName, "BlogPO") + assertEquals(functionCalls[0].FunctionName, "toDomainModel") + } }