简体   繁体   中英

Does SONAR implementation consider accompanying classes as part of the public class - metrics

Introduction

I'm thinking how I can get past specific critical/major issues without making major refactoring and breaking the comparison with previous revisions (diff etc).

I know I can split my class into multiple classes that are in the same file without breaking the comparisons. I have done this already. (Will provide an example tonight).

However, question is: does SONAR consider accompanying classes in the same .java file when running it's algorithms? Does it consider nested classes?

More importantly does it consider them as part of the key 'public class' that has the same name as the file name. Do the calculations for the various metrics consider them as the public class when generating the warnings?

Example

of how to refactor code so diff is not majorly broken

I had the following code in a very long chain of if, else if :

}else if ("cdbStreet".equals(paramKey)) {

And converted it into:

}else{
        setSearchDataByRequestParametersPart2(searchData, ...);
      }
    }
    return queryString.toString();
  }

  private static void setSearchDataByRequestParametersPart2(SearchRequestData searchData, ...) {
    if ("cdbStreet".equals(paramKey)) {

Sonar is doing code analysis for nested (inner) classes. It works well for my commercial project (I cannot share example). Violations are reported for inner static and non-static classes.

There are some rules specific to inner classes https://sonarqube.com/coding_rules#q=inner|languages=java

For available example see https://sonarqube.com/component_measures/metric/lines/list?id=com.icegreen%3Agreenmail-parent

From line 358 you have inner class FetchCommandParser that is analysed. There are a few warnings reported for code in that class.

Internally, sonar plugin works with source code and bytecode. By default all code you have is submitted for analysis (you may configure exclusions if you want to).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM