Added "reportLevel" for determining when a rule violation is reported.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1384 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Don Leckie
2003-01-28 04:08:24 +00:00
parent bb30b7e839
commit 02a624bc43

View File

@ -128,25 +128,29 @@ public class CyclomaticComplexityRule extends AbstractRule
{ {
m_entryStack.push(new Entry(node)); m_entryStack.push(new Entry(node));
super.visit(node, data); super.visit(node, data);
Entry classEntry = (Entry) m_entryStack.pop();
double decisionPoints = (double) classEntry.m_decisionPoints;
double methodCount = (double) classEntry.m_methodCount;
int complexityAverage = (int) (Math.rint(decisionPoints / methodCount));
// The {0} "{1}" has a cyclomatic complexity of {2}. if ((complexityAverage >= getIntProperty("reportLevel")) ||
Entry classEntry = (Entry) m_entryStack.pop(); (classEntry.m_highestDecisionPoints >= getIntProperty("reportLevel")))
double decisionPoints = (double) classEntry.m_decisionPoints; {
double methodCount = (double) classEntry.m_methodCount; // The {0} "{1}" has a cyclomatic complexity of {2}.
int complexityAverage = (int) (Math.rint(decisionPoints / methodCount)); RuleContext ruleContext = (RuleContext) data;
RuleContext ruleContext = (RuleContext) data; String template = getMessage();
String template = getMessage(); String className = node.getImage();
String className = node.getImage(); String complexityHighest = String.valueOf(classEntry.m_highestDecisionPoints);
String complexityHighest = String.valueOf(classEntry.m_highestDecisionPoints); String complexity = String.valueOf(complexityAverage)
String complexity = String.valueOf(complexityAverage) + " (Highest = "
+ " (Highest = " + complexityHighest
+ complexityHighest + ")";
+ ")"; String[] args = {"class", className, complexity};
String[] args = {"class", className, complexity}; String message = MessageFormat.format(template, args);
String message = MessageFormat.format(template, args); int lineNumber = node.getBeginLine();
int lineNumber = node.getBeginLine(); RuleViolation ruleViolation = createRuleViolation(ruleContext, lineNumber, message);
RuleViolation ruleViolation = createRuleViolation(ruleContext, lineNumber, message); ruleContext.getReport().addRuleViolation(ruleViolation);
ruleContext.getReport().addRuleViolation(ruleViolation); }
return data; return data;
} }
@ -199,16 +203,19 @@ public class CyclomaticComplexityRule extends AbstractRule
} }
} }
// The {0} "{1}" has a cyclomatic complexity of {2}. if (methodEntry.m_decisionPoints >= getIntProperty("reportLevel"))
RuleContext ruleContext = (RuleContext) data; {
String template = getMessage(); // The {0} "{1}" has a cyclomatic complexity of {2}.
String methodName = (methodDeclarator == null) ? "" : methodDeclarator.getImage(); RuleContext ruleContext = (RuleContext) data;
String complexity = String.valueOf(methodEntry.m_decisionPoints); String template = getMessage();
String[] args = {"method", methodName, complexity}; String methodName = (methodDeclarator == null) ? "" : methodDeclarator.getImage();
String message = MessageFormat.format(template, args); String complexity = String.valueOf(methodEntry.m_decisionPoints);
int lineNumber = node.getBeginLine(); String[] args = {"method", methodName, complexity};
RuleViolation ruleViolation = createRuleViolation(ruleContext, lineNumber, message); String message = MessageFormat.format(template, args);
ruleContext.getReport().addRuleViolation(ruleViolation); int lineNumber = node.getBeginLine();
RuleViolation ruleViolation = createRuleViolation(ruleContext, lineNumber, message);
ruleContext.getReport().addRuleViolation(ruleViolation);
}
return data; return data;
} }