From 95857a8b6250e1ff62fa4a79ac1146dc7cb79c0e Mon Sep 17 00:00:00 2001 From: Brian Remedios Date: Tue, 10 Oct 2006 05:05:00 +0000 Subject: [PATCH] optimization in preparation for new property mgmt code: retrieving report level just once at startup git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4614 51baf565-9d33-0410-a72c-fc3788e3496d --- .../sourceforge/pmd/rules/CyclomaticComplexity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexity.java b/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexity.java index 34b9d41e4b..34a2374792 100644 --- a/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexity.java +++ b/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexity.java @@ -32,6 +32,8 @@ import java.util.Stack; */ public class CyclomaticComplexity extends AbstractRule { + private int reportLevel = getIntProperty("reportLevel"); + private static class Entry { private SimpleNode node; private int decisionPoints = 1; @@ -134,7 +136,7 @@ public class CyclomaticComplexity extends AbstractRule { entryStack.push(new Entry(node)); super.visit(node, data); Entry classEntry = (Entry) entryStack.pop(); - if ((classEntry.getComplexityAverage() >= getIntProperty("reportLevel")) || (classEntry.highestDecisionPoints >= getIntProperty("reportLevel"))) { + if ((classEntry.getComplexityAverage() >= reportLevel) || (classEntry.highestDecisionPoints >= reportLevel)) { addViolation(data, node, new String[]{"class", node.getImage(), classEntry.getComplexityAverage() + " (Highest = " + classEntry.highestDecisionPoints + ')'}); } return data; @@ -162,7 +164,7 @@ public class CyclomaticComplexity extends AbstractRule { } } - if (methodEntry.decisionPoints >= getIntProperty("reportLevel")) { + if (methodEntry.decisionPoints >= reportLevel) { addViolation(data, node, new String[]{"method", (methodDeclarator == null) ? "" : methodDeclarator.getImage(), String.valueOf(methodEntry.decisionPoints)}); } @@ -173,7 +175,7 @@ public class CyclomaticComplexity extends AbstractRule { entryStack.push(new Entry(node)); super.visit(node, data); Entry classEntry = (Entry) entryStack.pop(); - if ((classEntry.getComplexityAverage() >= getIntProperty("reportLevel")) || (classEntry.highestDecisionPoints >= getIntProperty("reportLevel"))) { + if ((classEntry.getComplexityAverage() >= reportLevel) || (classEntry.highestDecisionPoints >= reportLevel)) { addViolation(data, node, new String[]{"class", node.getImage(), classEntry.getComplexityAverage() + "(Highest = " + classEntry.highestDecisionPoints + ')'}); } return data; @@ -190,7 +192,7 @@ public class CyclomaticComplexity extends AbstractRule { if (constructorDecisionPointCount > classEntry.highestDecisionPoints) { classEntry.highestDecisionPoints = constructorDecisionPointCount; } - if (constructorEntry.decisionPoints >= getIntProperty("reportLevel")) { + if (constructorEntry.decisionPoints >= reportLevel) { addViolation(data, node, new String[]{"constructor", classEntry.node.getImage(), String.valueOf(constructorDecisionPointCount)}); } return data;