Applying patch [ 1958961 ] EmptyInitializer

Not really bug fix, but the patch was easy to apply so, why deprive soon to be 4.2.X user from this little addon... 

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6201 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse 2008-06-13 22:07:56 +00:00
parent 79a84939c5
commit f663b9773a
4 changed files with 83 additions and 0 deletions

View File

@ -6,6 +6,8 @@ Upgrading UselessOperationOnImmutable to detect more use cases, especially on St
Fixed bug 1988829 - Violation reported without source file name (actually a fix to ConsecutiveLiteralAppends)
Fixed bug 1989814 - false +: ConsecutiveLiteralAppends
New rule:
Basic ruleset: EmptyInitializer
May 20, 2008 - 4.2.2:

View File

@ -27,6 +27,7 @@ public class BasicRulesTest extends SimpleAggregatorTst {
addRule("basic", "EmptyCatchBlock");
addRule("basic", "EmptyFinallyBlock");
addRule("basic", "EmptyIfStmt");
addRule("basic", "EmptyInitializer");
addRule("basic", "EmptyStatementNotInLoop");
addRule("basic", "EmptyStaticInitializer");
addRule("basic", "EmptySwitchStatements");

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<test-data>
<test-code>
<description><![CDATA[
failure case (non static)
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
{}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
failure case (static)
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
static {}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
not an initializer
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public void bar() {
{ }
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
initializer not empty
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
{ System.out.print("something interesting"); }
}
]]></code>
</test-code>
</test-data>

View File

@ -1200,5 +1200,36 @@ public class Test {
</example>
</rule>
<rule name="EmptyInitializer"
since="5.0"
message="Empty initializer was found"
class="net.sourceforge.pmd.rules.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/rules/basic.html#EmptyInitializer">
<description>
An empty initializer was found.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Initializer/Block[count(*)=0]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
public class Foo {
static {} // Why ?
{} // Again, why ?
}
]]>
</example>
</rule>
</ruleset>