Search code examples
javascopeabstract-syntax-treejavaparser

How to get class name from a methodCallExpr without invoking reolve()


Using javaparser library in Java, I have a Visitor class that extracts methodCallExpr. now I want to get the class name of the objects on which they are invoked. For instance:

a.sayHi();

when I call getScope() on the 'sayHi' method, I get 'a'. How can I get the class name of the 'a' object in java parser without resolving it? because calling resolve() for the methodCallExpr seems so memory-consuming, I want to extract it from another way.


Solution

  • You can't get it other than by using the symbol resolution. Symbol resolution is actually relatively expensive because the processing is particularly complex and depends on the configuration of your project. For example, if your project uses a lot of libraries, the resolution can be expensive the first time you resolve a symbol.