javaparser / javasymbolsolver

*old repository* --> this is now integrated in https://github.com/javaparser/javaparser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] There is a way to know which TypeSolver solved a type?

hugofmelo opened this issue · comments

Im using a CombinedTypeSolver with Reflection, Java e Jars solvers. At some point visiting nodes, I need to know if the solved ReferenceType is a Java type, a system-defined type or a library type. That's possible?

What do you mean? You mean that you want to understand from which TypeSolver it comes from? If so you need to get the connected declaration and look at its type.

From the ReferenceType you call getTypeDeclaration and you get a ReferenceTypeDeclaration. You can look at the concrete class of the ReferenceTypeDeclaration. For example if it is a JavaParserClassDeclaration then it comes from JavaParser.

Does this help?

Hi @ftomassetti,

using JavaSymbolSolver project as example, I need to know if the solved type is a Java type (Object or ArrayList), a third-party type (guava types), or a project-defined type (ReferenceType).

Your answer works to me. Thank you.

Note to others with the same question:
JavaParserTypeSolver ---> JavaParserClassDeclaration
ReflectionTypeSolver ---> ReflectionClassDeclaration
JarTypeSolver ---> JavassistClassDeclaration

Happy to hear it worked!
Please feel free to write at any time if you have other questions and thank you for using JavaSymbolSolver