Is there a UAST approach to match top level functions via their FQ name

UAST’s CallMatcher have basically two main way to match a call, the instance CallMatcher::instanceCall and static CallMatcher::staticCall call matchers.

But they have some shortcoming when it’s about matching top level function in Kotlin, but maybe other JVM languageslike Scala.

Suppose this declaration in FooBarUtils.kt

package foo.bar

fun bazQux() {}

This function is usually imported with this statement : import foo.bar.bazQux.

However, this would be matched via CallMatcher.staticCall("foo.bar.FooBarUtilsKt", bazQux). But if the file is renamed to BarUtils.kt, or if the file has an annotation like JvmName that changes the name, then the call matcher won’t work.

Yet the fully qualified name didn’t change from a source perspective. So is tere a recommended approach there to work around this ?

No, I think there is no such as UAST is designed as common ground for all JVM languages and Java as the basic JVM bytecode representation did not have top level funs with FQNs

For sure, but I was thinking more as a general FQN feature. So with that invented feature it could work like this ?

  • package bar, FQN is foo.bar
  • class Qux, FQN is foo.bar.Qux
  • identifier foo (property or method) in class Qux, FQN is foo.bar.Qux.foo
  • identifier foo (property or method) in package bar, FQN is foo.bar.foo