Is there any tutorial about SonarQube semantic API?

Hi~I am learning how to write my own custom rules with SonarQube semantic API.
But I don’t understand what each API can do.
So I am wondering if there is any tutorial about SonarQube semantic API.

Please help me.
I really want to learn how to use the SonarQube semantic API.
Thanks a lot!

my SonarQube version:
the language I use: Java


Are you developing for Java? I.e. are you trying to write custom for Java?

There’s no tutorial except the Java Rules 101. But if you want to come back with specific questions, we can probably get them answered.


yes, I am trying to write custom rules for Java.

Now I am trying to use custom rule to find out where there are more than 3 “if-else” in the code.
Then I can suggest the developer use strategy design pattern.
But I don’t know how to reach my goal.

Thanks a lot!


Have you tried the Java Rules 101 tutorial I linked above?


Yes, I have tried the 101 tutorial, and successfully add the example rule in 101 tutorial to my SonarQube.
But I still don’t know what each semantic API do.
I mean, there are so many details in sonar-java/java-frontend/src/main/java/org/sonar/plugins/java/api/semantic at master · SonarSource/sonar-java · GitHub

When I want to write a rule, I don’t know which API to use.
That’s why I want to find a tutorial about the SonarQube semantic API.

Thanks a lot!


Hi @Liver
There is no other tutorial at the moment. From the moment you have completed, you should be able to start exploring the code of the analyzer to look for examples of what you are trying to do.