质量管理工具Sonar中名词解释

Metrics are the heart of Sonar, using Sonar efficiently means perfectly understanding the definition and calculation algorithm of each one.

Name Key Description
Physical lineslinesNumber of carriage returns
Comment linescomment_linesNumber of javadoc, multi-comment and single-comment lines. Empty comment lines like, header file comments (mainly used to define the license) and commented-out lines of code are not included.
?
/**
  * This is a javadoc block
  *           <- empty comment line considered as a blank line
  */          <- empty comment line considered as a blank line
/*
  * This is a multi-comment block
  */
// This is a single-comment block
// log("Debug information"); <- commented-out line of code is not a comment line
Commented-out lines of code commented_out_code_lines Number of commented-out lines of code. Javadoc blocks are not scanned.
?
/*
* someoneCommentMeOutOneDay();
* nobodyKnowWhatAmISupposedToDo();
*/
Lines of codenclocNumber of physical lines of code - number of blank lines - number of comment lines - number of header file comments - commented-out lines of code
Density of comment linescomment_lines_densityNumber of comment lines / (lines of code + number of comments lines) * 100
PackagespackagesNumber of packages
ClassesclassesNumber of classes including nested classes, interfaces, enums and annotations
FilesfilesNumber of analyzed files
Directories directories Number of analyzed directories
AccessorsaccessorsNumber of getter and setter methods used to get(reading) or set(writing) a class' property .
?
// Getters
public String getName(){
      return this .name;
}
public boolean isParent(){
      return this .isParent;
}
// Setters
public void setName(String name){
      this .name = name;
}
public void setIsParent( boolean isParent){
      this .isParent = isParent;
}
MethodsfunctionsNumber of Methods without including accessors. A constructor is considered to be a method.
Public APIpublic_apiNumber of public classes, public methods (without accessors) and public properties (without public final static ones)
Public undocumented APIpublic_undocumented_apiNumber of public API without a Javadoc block
Density of public documented APIpublic_documented_api_density(Number of public API - Number of undocumented public API) / Number of public API * 100
Duplicated linesduplicated_linesNumber of physical lines touched by a duplication
Duplicated blocksduplicated_blocksNumber of duplicated blocks of lines
Duplicated filesduplicated_filesNumber of files involved in a duplication of lines
Density of duplicated linesduplicated_lines_densityDuplicated lines / Physical lines * 100
StatementsstatementsNumber of statements as defined in the Java Language Specification but without block definitions. Statements counter gets incremented by one each time an expression, if, else, while, do, for, switch, break, continue, return, throw, synchronized, catch, finally is encountered :
?
//
i = 0 ;
if (ok)
if (exit) {
if ( 3 == 4 );
if ( 4 == 4 ) { ; }
} else {
try {}
while ( true ){}
for (...){}
...
Statements counter is not incremented by a class, method, field, annotation definition or by a package and import declaration.
ComplexitycomplexityThe Cyclomatic Complexity Number is also known as McCabe Metric. It all comes down to simply counting 'if', 'for', 'while' statements etc. in a method. Whenever the control flow of a method splits, the Cyclomatic counter gets incremented by one.
Each method has a minimum value of 1 per default except accessors which are not considered as method and so don't increment complexity. For each of the following Java keywords/statements this value gets incremented by one:
?
if
for
while
case
catch
throw
return (that isn't the last statement of a method)
&&
||
?
Note that else, default, and finally don't increment the CCN value any further. On the other hand, a simple method with a switch statement and a huge block of case statements can have a surprisingly high CCN value (still it has the same value when converting a switch block to an equivalent sequence of if statements).
For instance the following method has a complexity of 5
?
public void process(Car myCar){          <- + 1
     if (myCar.isNotMine()){               <- + 1
          return ;                         <- + 1
     }
     car.paint( "red" );
     car.changeWheel();
     while (car.hasGazol() && car.getDriver().isNotStressed()){   <- + 2
          car.drive();
     }
     return ;
}
Average complexity by methodfunction_complexityAverage cyclomatic complexity number by method
Complexity distribution by methodfunction_complexity_distributionNumber of methods for given complexities
Average complexity by classclass_complexityAverage cyclomatic complexity by class
Complexity distribution by classclass_complexity_distributionNumber of classes for given complexities
Average complexity by filefile_complexityAverage cyclomatic complexity by file
ViolationsviolationsTotal number of rule violations
New Violationsnew_violationsTotal number of new violations
xxxxx violationsxxxxx_violationsNumber of violations with severity xxxxx, xxxxx being blocker, critical, major, minor or info
New xxxxx violationsnew_xxxxx_violationsNumber of new violations with severity xxxxx, xxxxx being blocker, critical, major, minor or info
Weighted violationsweighted_violationsSum of the violations weighted by the coefficient associated at each priority (Sum(xxxxx_violations * xxxxx_weight))
Rules compliance indexviolations_density100 - weighted_violations / Lines of code * 100
Unit teststestsNumber of unit tests
Unit tests durationtest_execution_timeTime required to execute unit tests
Unit test errortest_errorsNumber of unit tests that failed
Unit test failurestest_failuresNumber of unit tests that failed with an unexpected exception
Unit test success densitytest_success_density(Unit tests - (errors + failures))/ Unit tests * 100
Skipped unit testsskipped_testsNumber of skipped unit tests
Line Coverage line_coverage On a given line of code, line coverage simply answers the question: "Is this line of code executed during unit test execution?". At project level, this is the density of covered lines:
?
Line coverage = LC / EL
 
where
 
LC - lines covered (lines_to_cover - uncovered_lines)
EL - total number of executable lines (lines_to_cover)
New Line Coverage new_line_coverage identical to line_coverage but restricted to new / update source code
Branch coverage branch_coverage On each line of code containing some boolean expressions, the branch coverage simply answers the question: "Has each boolean expression evaluated both to true and false ?". At project level, this is the density of possible branches in flow control structures that have been followed.
?
Branch coverage = (CT + CF) / ( 2 *B)
 
where
 
CT - branches that evaluated to "true" at least once
CF - branches that evaluated to "false" at least once
(CT + CF = conditions_to_cover - uncovered_conditions)
 
B - total number of branches ( 2 *B = conditions_to_cover)
New Branch Coverage new_branch_coverage identical to branch_coverage but restricted to new / update source code
CoveragecoverageCoverage metric is a mix of the two previous line coverage and branch coverage metrics to get an even more accurate answer to the question "how much of a source-code is being executed by your unit tests?".
The Coverage is calculated with the following formula :
?
coverage = (CT + CF + LC)/( 2 *B + EL)
 
where
 
CT - branches that evaluated to "true" at least once
CF - branches that evaluated to "false" at least once
LC - lines covered (lines_to_cover - uncovered_lines)
 
B - total number of branches ( 2 *B = conditions_to_cover)
EL - total number of executable lines (lines_to_cover)
New Coverage new_coverage identical to coverage but restricted to new / update source code
Conditions to Coverconditions_to_coverTotal number of conditions which could be covered by unit tests.
New Conditions to Cover new_conditions_to_cover identical to conditions_to_cover but restricted to new / update source code
Lines to Coverlines_to_coverTotal number of lines of code which could be covered by unit tests.
New Lines to Covernew_lines_to_coveridentical to lines_to_cover but restricted to new / update source code
Uncovered Conditions uncovered_conditionsTotal number of conditions which are not covered by unit tests.
New Uncovered Conditions new_uncovered_conditionsidentical to uncovered_conditions but restricted to new / update source code
Uncovered Lines uncovered_linesTotal number of lines of code which are not covered by unit tests.
New Uncovered Lines new_uncovered_linesidentical to uncovered_lines but restricted to new / update source code
Depth of inheritance treeditThe depth of inheritance tree (DIT) metric provides for each class a measure of the inheritance levels from the object hierarchy top. In Java where all classes inherit Object the minimum value of DIT is 1.
Number of childrennocA class's number of children (NOC) metric simply measures the number of direct and indirect descendants of the class.
Response for classrfcThe response set of a class is a set of methods that can potentially be executed in response to a message received by an object of that class. RFC is simply the number of methods in the set.
Afferent couplingscaA class's afferent couplings is a measure of how many other classes use the specific class.
Efferent couplingsceA class's efferent couplings is a measure of how many different classes are used by the specific class.
Lack of cohesion of methodslcom4LCOM4 measures the number of "connected components" in a class. A connected component is a set of related methods and fields. There should be only one such component in each class. If there are 2 or more components, the class should be split into so many smaller classes.
Package cyclespackage_cyclesMinimal number of package cycles detected to be able to identify all undesired dependencies.
Package dependencies to cutpackage_feedback_edgesNumber of package dependencies to cut in order to remove all cycles between packages.
File dependencies to cutpackage_tanglesNumber of file dependencies to cut in order to remove all cycles between packages.
Package edges weightpackage_edges_weightTotal number of file dependencies between packages.
Package tangle indexpackage_tangle_indexGives the level of tangle of the packages, best value 0% meaning that there is no cycles and worst value 100% meaning that packages are really tangled. The index is calculated using : 2 * (package_tangles / package_edges_weight) * 100.
File cyclesfile_cyclesMinimal number of file cycles detected inside a package to be able to identify all undesired dependencies.
Suspect file dependenciesfile_feedback_edgesFile dependencies to cut in order to remove cycles between files inside a package. Warning : cycles are not always bad between files inside a package.
File tanglefile_tanglesfile_tangles = file_feedback_edges.
File edges weightfile_edges_weightTotal number of file dependencies inside a package.
File tangle indexfile_tangle_index2 * (file_tangles / file_edges_weight) * 100.
CommitscommitsThe number of commits
Last commit datelast_commit_dateThe latest commit date on a resource
RevisionrevisionThe latest revision of a resource
Authors by lineauthors_by_lineThe last committer on each line of code
Revisions by linerevisions_by_lineThe revision number on each line of code

From http://docs.codehaus.org/display/SONAR/Metric+definitions

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值