From fea5981599f110aaa70b89a1610c1117eceaedad Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Thu, 20 Nov 2003 18:57:40 +0000 Subject: [PATCH] Implemented [ 845348 ] UnnecessaryReturn could display line numbers of return stmts git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2409 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../sourceforge/pmd/rules/UnnecessaryReturnTest.java | 7 +++---- pmd/rulesets/basic.xml | 10 +++++++--- pmd/xdocs/credits.xml | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index ebf87787f4..4a9388e3b8 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -4,6 +4,7 @@ Fixed bug 840926 - AvoidReassigningParametersRule no longer reports a false posi Fixed bug 760520 - RuleSetFactory is less strict about whitespace in ruleset.xml files. Fixed bug 826805 - JumbledIncrementorRule no longer reports a false positive when a outer loop incrementor is used as an array index Fixed bug 845343 - AvoidDuplicateLiterals now picks up cases when a duplicate literal appears in field declarations. +Implemented RFE 845348 - UnnecessaryReturn yields more useful line numbers now Added a ruleset DTD and a ruleset XML Schema. TODO - fix it so tests and rules don't duplicate the xpath expressions diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/UnnecessaryReturnTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/UnnecessaryReturnTest.java index a610d2517c..9c85d66f8c 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/UnnecessaryReturnTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/UnnecessaryReturnTest.java @@ -12,7 +12,7 @@ public class UnnecessaryReturnTest extends SimpleAggregatorTst{ public void setUp() { rule = new XPathRule(); - rule.addProperty("xpath", "//ResultType[@Void='true' and parent::MethodDeclaration[Block/BlockStatement/Statement/ReturnStatement]]"); + rule.addProperty("xpath", "//ReturnStatement[parent::Statement[parent::BlockStatement[parent::Block[parent::MethodDeclaration/ResultType[@Void='true']]]]"); } public void testAll() { @@ -20,8 +20,8 @@ public class UnnecessaryReturnTest extends SimpleAggregatorTst{ new TestDescriptor(TEST1, "bad", 1, rule), new TestDescriptor(TEST2, "ok since method is not void", 0, rule), new TestDescriptor(TEST3, "ok since return is in sub block", 0, rule), - new TestDescriptor(TEST4, "interface methods work ok", 0, rule), - new TestDescriptor(TEST5, "abstract methods work ok", 0, rule), + new TestDescriptor(TEST4, "interface methods don't have return statements", 0, rule), + new TestDescriptor(TEST5, "abstract methods don't have return statements", 0, rule), }); } @@ -56,5 +56,4 @@ public class UnnecessaryReturnTest extends SimpleAggregatorTst{ "public class Foo {" + PMD.EOL + " abstract void bar();" + PMD.EOL + "}"; - } diff --git a/pmd/rulesets/basic.xml b/pmd/rulesets/basic.xml index 50e7105204..72943838d5 100644 --- a/pmd/rulesets/basic.xml +++ b/pmd/rulesets/basic.xml @@ -435,10 +435,14 @@ public class Bar { diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml index ee0327a3cc..c73069c413 100644 --- a/pmd/xdocs/credits.xml +++ b/pmd/xdocs/credits.xml @@ -38,7 +38,7 @@