Refactoring using sonar-java ?

273 views
Skip to first unread message

ameya ketkar

unread,
Oct 20, 2017, 8:11:36 PM10/20/17
to SonarQube

I have developed a tool to analyze the source code to find instances where misusing APIs results in auto-boxing overhead, and to find out whether they are refactorable based on a set of pre-conditions, and eventually automatically refactoring the code to alleviate the overhead (like in this pull request).
We have found, by analyzing a large amount of data, that a lot of projects suffer from such misuses. 
Such misuses are also found in projects that currently use collections and maps from libraries like fastutil and gs-collections (which are supposed to help in avoiding auto-boxing overhead).
We also have found that a lot of projects(especially Mathematical or DB domain) are full off maps using wrapper classes, and they would really benefit from migrating to such libraries (at least in their hot paths).

I personally think, this analysis is a nice fit into the type of analysis sonar does. I was wondering, are there any projects which do any refactoring using analysis results from sonar-java? 
And, in general, do you think we can bridge the analysis from sonar-java to some code editing libraries?

Ameya Ketkar

simon schrottner

unread,
Oct 21, 2017, 5:36:55 AM10/21/17
to SonarQube
hi!

Basically we are using Sonar output to find "hotspots" to refactor -> but as our project is pretty old, this is normally the biggest file, with the most issues and/or big complexity. It is quite hard to get an overview over a big code base. Tooling like that would be highly appreciated. and if you contribute to the SonarJava it normally will be also available with SonarLint -> so those changes would be "visible" during the implementation :D

Thx for your efforts - are there also some resources to your research?

Thank you
Simon

ameya ketkar

unread,
Oct 21, 2017, 2:18:31 PM10/21/17
to SonarQube
Thank you for showing interest in my work. 
But before we start making efforts towards using sonar java I have a few questions. 
Can I use sonar java to get binding information or its only AST parsing? 
And the two questions I posted in my previous post.  

I am the only resource in this project.

Nicolas Peru

unread,
Oct 23, 2017, 5:17:02 AM10/23/17
to ameya ketkar, SonarQube
Hi, 

I am not really sure what you are trying to achieve. What do you mean exactly by : "Can I use sonar java to get binding information or its only AST parsing? " ? 

Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/d3b671a5-c21d-431f-bd70-b73f4dab8d2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource

ameya ketkar

unread,
Oct 23, 2017, 11:42:12 AM10/23/17
to SonarQube
Helllo Nicolas,
 
I am trying to integrate a refactoring with sonar-java analysis. 
So my question is, if I parse code using sonar-java can I get the binding information too ? 
(will I be able to resolve variables and methods to get binding information like in eclipse JDT - https://help.eclipse.org/luna/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/IVariableBinding.html)
And also, are there any projects who perform automated refactoring of the code based on the results of Sonar ? 

Ameya Ketkar

Nicolas Peru

unread,
Oct 24, 2017, 5:12:30 AM10/24/17
to ameya ketkar, SonarQube
Hi, 

Ok, so you are talking about semantic of the language. You have access to it through API of SonarJava to some extent. We don't fully support generics in terms of API. 
As per refactoring based on the AST and semantic done by SonarJava : we do not provide anything in order to do so for the time being. This could be achieved (and we would love to at one point in time to be able to suggest "quick fixes" from SonarLint : but as for now, this is not supported in terms of API and we have no short term plan to add this feature. 

Cheers, 




For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages