SonarQube Custom Rules - Get the content of a method from a blockTree


I am writing some custom SonarQube - Rule in java language. I would like to check the content of methods/classes/etc
First I thought I can get the content in a String format from block().body().toString(), but it was something else.
Then I found that the block().body().get(i).firstToken.text - returns the first word of the “i-th line of that code-block”, and the lastToken.text the last word, which is the “;” sign.
Could you please help me how could I get the whole Line of Code?

Hello Levente,

Can you please share a bit what you try to achieve with you rule?

The whole point of writing custom rules is to benefit from the Syntax Tree which is resulting from the parsing of a file, and so in complete abstraction of the content. Getting back to the “line” is not the way of writing rules. You should rather rely on the shape of the tree and the semantic associated with nodes (type/symbols) to identify issues.