From 7989ae18631fffe62b8de642a3697064ccded484 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 19 Jan 2013 18:28:33 +0100 Subject: [PATCH] pmd: fixed #1060 GodClassRule >>> wrong method --- pmd/etc/changelog.txt | 1 + .../lang/java/rule/design/GodClassRule.java | 26 ++++++++++--------- .../java/rule/design/DesignRulesTest.java | 3 +++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 697f3ca9ab..2e4f937b7e 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -6,6 +6,7 @@ Fixed bug 1043: node.getEndLine() always returns 0 (ECMAscript) Fixed bug 1044: Unknown option: -excludemarker Fixed bug 1047: False Positive in 'for' loops for LocalVariableCouldBeFinal in 5.0.1 Fixed bug 1048: CommentContent Rule, String Index out of range Exception +Fixed bug 1060: GodClassRule >>> wrong method November 28, 2012 - 5.0.1: diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java index 939f1d7cdb..74e7560f75 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java @@ -154,18 +154,20 @@ public class GodClassRule extends AbstractJavaRule { int pairs = 0; if (methodCount > 1) { - for (int i = 0; i < methodCount - 1; i++) { - String firstMethodName = methods.get(i); - String secondMethodName = methods.get(i + 1); - Set accessesOfFirstMethod = methodAttributeAccess.get(firstMethodName); - Set accessesOfSecondMethod = methodAttributeAccess.get(secondMethodName); - Set combinedAccesses = new HashSet(); - - combinedAccesses.addAll(accessesOfFirstMethod); - combinedAccesses.addAll(accessesOfSecondMethod); - - if (combinedAccesses.size() < (accessesOfFirstMethod.size() + accessesOfSecondMethod.size())) { - pairs++; + for (int i = 0; i < methodCount; i++) { + for (int j = i + 1; j < methodCount; j++) { + String firstMethodName = methods.get(i); + String secondMethodName = methods.get(j); + Set accessesOfFirstMethod = methodAttributeAccess.get(firstMethodName); + Set accessesOfSecondMethod = methodAttributeAccess.get(secondMethodName); + Set combinedAccesses = new HashSet(); + + combinedAccesses.addAll(accessesOfFirstMethod); + combinedAccesses.addAll(accessesOfSecondMethod); + + if (combinedAccesses.size() < (accessesOfFirstMethod.size() + accessesOfSecondMethod.size())) { + pairs++; + } } } } diff --git a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java index f7cdcbb868..e56df3e0e8 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java @@ -1,3 +1,6 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ package net.sourceforge.pmd.lang.java.rule.design; import net.sourceforge.pmd.testframework.SimpleAggregatorTst;