You can look in the Java Java compiler (I heard that OpenJDK has one).
I think you will find that name resolution is much more complicated than you imagine, especially when you turn on generics and erase styles. I doubt that you can "easily" remove this code and use it yourself.
Most Java tools that do something semantically deep use class files, where everything is erased and resolved by this type, so they may not know how to do it. (The disadvantage only for searching class files is that these tools cannot modify the source code at all).
source share