From 1b89d92b147faf40c28a45e2f8d117f7d12b585f Mon Sep 17 00:00:00 2001 From: Konstantin Chukharev Date: Fri, 16 Aug 2024 17:08:39 +0300 Subject: [PATCH] Improve resolution of callees --- .../jacodb/ets/graph/EtsApplicationGraph.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/jacodb-ets/src/main/kotlin/org/jacodb/ets/graph/EtsApplicationGraph.kt b/jacodb-ets/src/main/kotlin/org/jacodb/ets/graph/EtsApplicationGraph.kt index d1fbf410e..91cfdb893 100644 --- a/jacodb-ets/src/main/kotlin/org/jacodb/ets/graph/EtsApplicationGraph.kt +++ b/jacodb-ets/src/main/kotlin/org/jacodb/ets/graph/EtsApplicationGraph.kt @@ -45,10 +45,29 @@ class EtsApplicationGraphImpl( override fun callees(node: EtsStmt): Sequence { val expr = node.callExpr ?: return emptySequence() val callee = expr.method - return cp.classes + val allMethods = cp.classes .asSequence() - .flatMap { it.methods } - .filter { it.signature == callee } + .flatMap { it.methods + it.ctor } + .toList() + + val methodsWithSameName = allMethods.filter { + it.name == callee.name + } + if (methodsWithSameName.size == 1) { + return sequenceOf(methodsWithSameName.first()) + } + + val methodsWithSameClassName = methodsWithSameName.filter { + it.enclosingClass.name == callee.enclosingClass.name + } + if (methodsWithSameClassName.size == 1) { + return sequenceOf(methodsWithSameClassName.first()) + } + + // Else, return all methods with the same signature. + return allMethods.asSequence().filter { + it.signature == callee + } } override fun callers(method: EtsMethod): Sequence {