diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 57f3408a69..f63f9a529b 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -17,6 +17,7 @@ Fixed bug 1064: Exception running PrematureDeclaration Fixed bug 1068: CPD fails on broken symbolic links Fixed bug 1073: Hard coded violation messages CommentSize Fixed bug 1074: rule priority doesn't work on group definitions +Fixed bug 1076: Report.treeIterator() does not return all violations Merged pull request #14: fix Nullpointer Exception when using -l jsp diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/dfa/report/ViolationNode.java b/pmd/src/main/java/net/sourceforge/pmd/lang/dfa/report/ViolationNode.java index 36a85d1761..08737c57b8 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/dfa/report/ViolationNode.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/dfa/report/ViolationNode.java @@ -1,3 +1,6 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ package net.sourceforge.pmd.lang.dfa.report; import net.sourceforge.pmd.RuleViolation; diff --git a/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java b/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java index 063fddff2d..19f7199397 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java @@ -218,6 +218,33 @@ public class ReportTest extends RuleTst implements ReportListener { assertTrue(summary.values().contains(Integer.valueOf(1))); assertTrue(summary.values().contains(Integer.valueOf(2))); } + + @Test + public void testTreeIterator() { + Report r = new Report(); + RuleContext ctx = new RuleContext(); + Rule rule = new MockRule("name", "desc", "msg", "rulesetname"); + JavaNode node1 = getNode(5, 5, ctx.getSourceCodeFilename(), true); + r.addRuleViolation(new JavaRuleViolation(rule, ctx, node1, rule.getMessage())); + JavaNode node2 = getNode(5, 6, ctx.getSourceCodeFilename(), true); + r.addRuleViolation(new JavaRuleViolation(rule, ctx, node2, rule.getMessage())); + + Iterator violations = r.iterator(); + int violationCount = 0; + while (violations.hasNext()) { + violations.next(); + violationCount++; + } + assertEquals(2, violationCount); + + Iterator treeIterator = r.treeIterator(); + int treeCount = 0; + while (treeIterator.hasNext()) { + treeIterator.next(); + treeCount++; + } + assertEquals(2, treeCount); + } public static JavaNode getNode(int line, int column, String scopeName){ DummyJavaNode s = new DummyJavaNode(2); @@ -231,6 +258,15 @@ public class ReportTest extends RuleTst implements ReportListener { return s; } + public static JavaNode getNode(int line, int column, String scopeName, boolean nextLine) { + DummyJavaNode s = (DummyJavaNode)getNode(line, column, scopeName); + if (nextLine) { + s.testingOnly__setBeginLine(line + 1); + s.testingOnly__setBeginColumn(column + 4); + } + return s; + } + public static String render(Renderer renderer, Report report) throws IOException { StringWriter writer = new StringWriter(); renderer.setWriter(writer); diff --git a/pmd/src/test/java/net/sourceforge/pmd/lang/dfa/report/ViolationNodeTest.java b/pmd/src/test/java/net/sourceforge/pmd/lang/dfa/report/ViolationNodeTest.java index 0653987396..64c808443d 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/lang/dfa/report/ViolationNodeTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/lang/dfa/report/ViolationNodeTest.java @@ -1,3 +1,6 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ package net.sourceforge.pmd.lang.dfa.report; import static org.junit.Assert.assertFalse;