Skip to content

Commit

Permalink
feat: <java> add expr call
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 7, 2020
1 parent f8b705d commit 0225c31
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>())
val field = CodeField(typeTypeText, typeValue, arrayOf<String>())
fields += field

buildFieldCall(typeType, ctx)
buildFieldCall(typeTypeText, ctx)
}
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 0225c31

Please sign in to comment.