forked from phoedos/pmd
Adding a new rule : GenericsNaming
Thanks to Nicolas Dordet for his inputs on this one. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@7009 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
parent
d836721675
commit
59eaa27c59
@ -21,6 +21,7 @@ New rule:
|
||||
Android: DoNotHardCodeSDCard
|
||||
Controversial : AvoidLiteralsInIfCondition (patch 2591627), UseConcurrentHashMap
|
||||
StrictExceptions : AvoidCatchingGenericException, AvoidLosingExceptionInformation
|
||||
Naming : GenericsNaming
|
||||
|
||||
February 08, 2009 - 4.2.5:
|
||||
|
||||
|
@ -26,6 +26,7 @@ public class NamingRulesTest extends SimpleAggregatorTst {
|
||||
addRule("naming", "SuspiciousEqualsMethodName");
|
||||
addRule("naming", "SuspiciousHashcodeMethodName");
|
||||
addRule("naming", "VariableNamingConventions");
|
||||
addRule("naming", "GenericsNaming");
|
||||
}
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
|
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
1 upper case/single letter
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public interface Foo <B extends Bar>
|
||||
{
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
2 upper case/single letter
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public interface Foo <B extends Bar, C extends Car>
|
||||
{
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
1 lower Case/single letter
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public interface Foo <b extends Bar>
|
||||
{
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
1 lower case/multiple letter
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public interface Foo <BA extends Bar>
|
||||
{
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
@ -507,4 +507,53 @@ public boolean getFoo(boolean bar); // ok, unless checkParameterizedMethods=true
|
||||
]]></example>
|
||||
</rule>
|
||||
|
||||
<rule name="GenericsNaming"
|
||||
since="4.2.6"
|
||||
message="Generics names should be a one letter long and upper case."
|
||||
class="net.sourceforge.pmd.rules.XPathRule"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/naming.html#GenericsNaming">
|
||||
<description>
|
||||
Generics names should be a one letter long and upper case.
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TypeDeclaration/ClassOrInterfaceDeclaration/TypeParameters/TypeParameter[
|
||||
string-length(@Image) > 1
|
||||
or
|
||||
string:upper-case(@Image) != @Image
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public interface GenericDao<E extends BaseModel, K extends Serializable> extends BaseDao
|
||||
{
|
||||
// This is ok...
|
||||
}
|
||||
|
||||
public interface GenericDao<E extends BaseModel, K extends Serializable>
|
||||
{
|
||||
// Also this
|
||||
}
|
||||
|
||||
public interface GenericDao<e extends BaseModel, K extends Serializable>
|
||||
{
|
||||
// 'e' should be an 'E'
|
||||
}
|
||||
|
||||
public interface GenericDao<EF extends BaseModel, K extends Serializable>
|
||||
{
|
||||
// 'EF' is not ok.
|
||||
}
|
||||
|
||||
|
||||
|
||||
]]></example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
Loading…
x
Reference in New Issue
Block a user