I am trying to create a custom rule for java, which checks if a method is invoked multiple times on an object. My problem is, that I don´t understand the structure of the Abstract Syntax Tree (AST) Sonarqube is building. I want to understand what i get when i call for example the methods symbol(), symbolType() or methodSelect() on my trees.(Compared to an AST, https://astexplorer.net/ or the ASTView in Eclipse is giving me) Or better: How do I traverse the tree, by calling these methods.
I read that i can use the sslr toolkit to show me the tree, but i do not found any tutorials which would help me to create a tree in eclipse (java).
For example how would i get the information of the package of every “get”-Method of this class. (It should be javax.persistence.criteria.Path)
Can you please provide the code of the rule you wrote already?
Without it, it’s going to be hard to explain to you what you might be doing wrong.
Our AST-api is specific to our analyzer, and not shared with eclipse or any other java AST. The visitors that we use for our rules are subscription-based (the rule subscribes to a given KIND of tree, using an IssuableSubscriptionVisitor ), or visit every node (BaseTreeVisitor).
I figured my Problem out. I made a “TestDbo.java” in the same package as my CustomRule and assumed my test can use it, without including it in my test environment.
I just got confused from the errors, because I was able to get the package from 2 of 3 get()-methods, while 1 was “!unknown”, which let me believe, that the configuration was right, but I just didn’t understand the structure of the AST.