forked from phoedos/pmd
Update changelog, add license headers, add externalInfoUrl for new rules
This commit is contained in:
15
pmd-core/src/main/resources/rulesets/releases/540.xml
Normal file
15
pmd-core/src/main/resources/rulesets/releases/540.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="540"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>
|
||||
This ruleset contains links to rules that are new in PMD v5.4.0
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/java/design.xml/SingleMethodSingleton"/>
|
||||
<rule ref="rulesets/java/design.xml/SingletonClassReturningNewInstance"/>
|
||||
|
||||
</ruleset>
|
||||
|
@ -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;
|
||||
|
||||
|
||||
@ -23,7 +26,7 @@ public class SingleMethodSingletonRule extends AbstractJavaRule {
|
||||
|
||||
private static Map<String, ASTFieldDeclaration> fieldDecls = new HashMap<String, ASTFieldDeclaration>();
|
||||
private static Set<ASTFieldDeclaration> returnset = new HashSet<ASTFieldDeclaration>();
|
||||
boolean violation=false;
|
||||
private boolean violation = false;
|
||||
private static Set<String> methodset = new HashSet<String>();
|
||||
@Override
|
||||
public Object visit(ASTFieldDeclaration node, Object data) {
|
||||
|
@ -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 java.util.List;
|
||||
|
@ -1299,7 +1299,7 @@ public static Foo getFoo() {
|
||||
|
||||
<rule name="SingleMethodSingleton"
|
||||
since="5.4"
|
||||
externalInfoUrl=""
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/design.html#SingleMethodSingleton"
|
||||
message="Class contains multiple getInstance methods. Please review."
|
||||
class="net.sourceforge.pmd.lang.java.rule.design.SingleMethodSingletonRule">
|
||||
<description>
|
||||
@ -1329,7 +1329,7 @@ public static Singleton getInstance(Object obj){
|
||||
|
||||
<rule name="SingletonClassReturningNewInstance"
|
||||
since="5.4"
|
||||
externalInfoUrl=""
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/design.html#SingletonClassReturningNewInstance"
|
||||
message="getInstance method always creates a new object and hence does not comply to Singleton Design Pattern behaviour. Please review"
|
||||
class="net.sourceforge.pmd.lang.java.rule.design.SingletonClassReturningNewInstanceRule">
|
||||
<description>
|
||||
|
@ -46,8 +46,6 @@ public class DesignRulesTest extends SimpleAggregatorTst {
|
||||
addRule(RULESET, "NonCaseLabelInSwitchStatement");
|
||||
addRule(RULESET, "NonStaticInitializer");
|
||||
addRule(RULESET, "NonThreadSafeSingleton");
|
||||
addRule(RULESET,"SingleMethodSingleton");
|
||||
addRule(RULESET, "SingletonClassReturningNewInstance");
|
||||
addRule(RULESET, "OptimizableToArrayCall");
|
||||
// addRule(RULESET, "PositionalIteratorRule"); This rule does not yet
|
||||
// exist
|
||||
@ -59,6 +57,8 @@ public class DesignRulesTest extends SimpleAggregatorTst {
|
||||
addRule(RULESET, "SimplifyBooleanExpressions");
|
||||
addRule(RULESET, "SimplifyBooleanReturns");
|
||||
addRule(RULESET, "SimplifyConditional");
|
||||
addRule(RULESET, "SingleMethodSingleton");
|
||||
addRule(RULESET, "SingletonClassReturningNewInstance");
|
||||
addRule(RULESET, "SingularField");
|
||||
addRule(RULESET, "SwitchDensity");
|
||||
addRule(RULESET, "SwitchStmtsShouldHaveDefault");
|
||||
|
@ -8,8 +8,15 @@
|
||||
|
||||
**New/Modified/Deprecated Rules:**
|
||||
|
||||
* New Rule: rulesets/java/design.xml/SingleMethodSingletonRule: Verifies that there is only one method called
|
||||
"getInstance". If there are more methods that return the singleton, than it can easily happen, that these
|
||||
are not the same instances - and thus no singleton.
|
||||
* New Rule: rulesets/java/design.xml/SingletonClassReturningNewInstance: Verifies that the method called
|
||||
"getInstance" returns a cached instance not always a fresh, new instance.
|
||||
|
||||
**Pull Requests:**
|
||||
|
||||
* [#21](https://github.com/adangel/pmd/pull/21): Added PMD Rules for Singleton pattern violations.
|
||||
* [#53](https://github.com/pmd/pmd/pull/53): Fix some NullPointerExceptions
|
||||
|
||||
**Bugfixes:**
|
||||
|
Reference in New Issue
Block a user