最近我开始使用像sonarqube和Teamscale这样的静态分析工具。
但是,它们仅显示项目/包/类级别的指标。我对评估Java方法的质量特别感兴趣,但是我发现在方法级别返回结果的唯一工具是Sourcemeter和Sonarqube的相应插件。
还有其他静态分析工具可以在方法级别提供指标吗?
您可以尝试JArchitect,它在方法级别为您提供了许多指标,包括体系结构/设计/实施指标。而且,通过使用其代码查询语言,您可以轻松地准确查询所需的指标,也可以根据现有指标计算自己的指标。
// <Name>Avoid methods too big, too complex</Name>
warnif count > 0 from m in JustMyCode.Methods where
(m.NbLinesOfCode > 35 ||
m.CyclomaticComplexity > 20)
let complexityScore = m.NbLinesOfCode/2 + m.CyclomaticComplexity
orderby complexityScore descending,
m.CyclomaticComplexity descending
select new {
m,
m.NbLinesOfCode,
m.CyclomaticComplexity,
complexityScore,
Debt = complexityScore.Linear(30, 40, 400, 8*60).ToMinutes().ToDebt(),
// The annual interest varies linearly from interest for severity minor
// to interest for severity major
AnnualInterest = complexityScore .Linear(30, Severity.Medium.AnnualInterestThreshold().Value.TotalMinutes,
200, 2*(Severity.High.AnnualInterestThreshold().Value.TotalMinutes)).ToMinutes().ToAnnualInterest()
}