Skip to first unread message

Ali el ghourassi

unread,
Dec 28, 2017, 4:07:29 AM12/28/17
to SonarQube
Hello everybody

in  Rule's class sometime we find method visitFile(@Nullable AstNode astNode) this method can analyse one file by one and give the result of every file  but i want analyse all the files in same time with one result  ,there's other method how do that ?

Thanks.

Ali el ghourassi

unread,
Dec 28, 2017, 10:39:15 AM12/28/17
to SonarQube
Example

@Override
public void visitFile(@Nullable AstNode astNode) {

lines = Collections.emptyList();
try {
lines = Files.readLines(getContext().getFile(), charset);

dinesh.bo...@gmail.com

unread,
Dec 29, 2017, 4:12:40 AM12/29/17
to SonarQube
Hello Ali

In your example you're reading all the lines but of just one file, not of every files.

Can you perhaps explain what you are trying to achieve, and also on which language?

That way we can give you the best solution

Ali el ghourassi

unread,
Dec 29, 2017, 5:38:28 AM12/29/17
to SonarQube
Thanks Dinesh for your response

 yes in my example i achieve one file  ,
i am trying to find functions unused ,

for example i can find declaration of function or multiple functions in file and it's  used in other file
so whene i achieve the first file i find the declartion but i can't find the apple of the function in same file so he say the function is unused  

the language is ncl


Le jeudi 28 décembre 2017 09:07:29 UTC, Ali el ghourassi a écrit :

Ali el ghourassi

unread,
Dec 29, 2017, 5:41:02 AM12/29/17
to SonarQube
what i am trying to do is to achieve all the files in one time


Le jeudi 28 décembre 2017 09:07:29 UTC, Ali el ghourassi a écrit :

dinesh.bo...@gmail.com

unread,
Dec 29, 2017, 5:50:41 AM12/29/17
to SonarQube
I see, so this is on your own custom language plugin.

If you do not need the Abstract Syntax Tree (and so there is no requirement to use SSLR), then you can iterate on all "InputFiles" in your plugin sensor.

If you do need to access the AST, then you can process each file one by one using visitFile() etc.

Your unused function rule should keep track of all functions which have been declared and all functions that have been invoked.

Then, you need at the very end to compute the diff between these two sets to create your unused function issues.
To do so, you can add a method in your check class that you invoke from your plugin only after all files will have been scanned.

Does this make sense?

On Thursday, December 28, 2017 at 10:07:29 AM UTC+1, Ali el ghourassi wrote:

Ali el ghourassi

unread,
Jan 3, 2018, 6:35:32 AM1/3/18
to SonarQube
hi Dinesh
but how can i add a method to my check class that will be execute after all files will have been scanned .

Thanks.

Le jeudi 28 décembre 2017 09:07:29 UTC, Ali el ghourassi a écrit :

Ali el ghourassi

unread,
Jan 3, 2018, 12:30:56 PM1/3/18
to SonarQube
Hello everybody

i wonder if there is any method of how can scan all files one time .

Thanks


Le jeudi 28 décembre 2017 09:07:29 UTC, Ali el ghourassi a écrit :

dinesh.bo...@sonarsource.com

unread,
Jan 4, 2018, 5:20:40 AM1/4/18
to SonarQube
No there is not such method provided out of the box.

The way to go is to keep a state between the analysis of multiple files, and process it at the end.
If you think about it, that's what a method that scans multiple files "at once" would end up doing behind the scene anyway

As this is your plugin, you have control over your code, and you should be able to find a way to do this :-)

On Thursday, December 28, 2017 at 10:07:29 AM UTC+1, Ali el ghourassi wrote:
Reply all
Reply to author
Forward
0 new messages