JavaParser of SonarJava can not be used independently

I’m having the same problem again with missing classes, I need a parser for java and thought using the class org.sonar.java.ast.parser.JavaParser would solve my problem. It seems it’s also not available while executing. What I’m trying to achieve is: inspect a class and discover it’s superclass, inspect its superclass and find the supersuperclass and so on.

Any suggestions on working around it or getting the parser to work? I reckon copying the parser is kinda dull.

Sonar: 7.3 community
sonar-java-plugin: 5.11.0.17289

The JavaParser defined in the SonarJava plugin is not meant to be used that way. What the java plugin provide is a mechanism to execute rules, based on a file already parsed, mapped on our API.

From my point of view, the best way to achieve what you want to do would then be to rely on a custom-rule (see tutorial and examples), which would be written in a way of collecting types rather than raising issues. The SonarJava analyzer will also guarantee the computation of the semantic model, which will be much more complete than just parsing.

Tracking all types of all files doesn’t seem great.

If you are just interested in types, then inspecting a single file should be enough, as the SonarJava semantic engine will then build its semantic model and build the whole type hierarchy, relying on the available bytecode.