<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="PMD-ATPCO-RuleSet_V7">
<description>PMD Plugin preferences rule set</description>
<rule class="net.sourceforge.pmd.rules.strings.AvoidDuplicateLiteralsRule" message="The String literal {0} appears {1} times in this file; the first occurrence is on line {2}" name="AvoidDuplicateLiterals">
<description>
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
</description>
<example><![CDATA[
public class Foo {
private void bar() {
buz("Howdy");
buz("Howdy");
buz("Howdy");
buz("Howdy");
}
private void buz(String x) {}
}
]]></example>
<priority>1</priority>
<properties>
<property name="threshold" value="4"/>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.strings.StringInstantiation" message="Avoid instantiating String objects; this is usually unnecessary." name="StringInstantiation">
<description>
Avoid instantiating String objects; this is usually unnecessary.
</description>
<example><![CDATA[
public class Foo {
private String bar = new String("bar"); // just do a String bar = "bar";
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.strings.StringToStringRule" message="Avoid calling toString() on String objects; this is unnecessary" name="StringToString">
<description>
Avoid calling toString() on String objects; this is unnecessary
</description>
<example><![CDATA[
public class Foo {
private String baz() {
String bar = "howdy";
return bar.toString();
}
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.strings.InefficientStringBuffering" message="Avoid concatenating nonliterals in a StringBuffer constructor or append()" name="InefficientStringBuffering">
<description>
Avoid concatenating non literals in a StringBuffer constructor or append().
</description>
<example><![CDATA[
public class Foo {
void bar() {
// Avoid this
StringBuffer sb=new StringBuffer("tmp = "+System.getProperty("java.io.tmpdir"));
// use instead something like this
StringBuffer sb = new StringBuffer("tmp = ");
sb.append(System.getProperty("java.io.tmpdir"));
}
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.strings.UnnecessaryCaseChange" message="Using equalsIgnoreCase() is cleaner than using toUpperCase/toLowerCase().equals()" name="UnnecessaryCaseChange">
<description>
Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()
</description>
<example><![CDATA[
public class Foo {
public boolean bar(String buz) {
// should be buz.equalsIgnoreCase("baz")
return buz.toUpperCase().equals("baz");
// another unnecessary toUpperCase()
// return buz.toUpperCase().equalsIgnoreCase("baz");
}
}
]]></example>
<priority>2</priority> <!-- Priority 1 to 2. Changed by ATP3RXS -->
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.strings.ConsecutiveLiteralAppends" message="StringBuffer.append is called {0} consecutive times with literal Strings. Use a single append with a single String." name="ConsecutiveLiteralAppends">
<description>
Consecutively calling StringBuffer.append with String literals
</description>
<example><![CDATA[
public class Foo {
private void bar() {
StringBuffer buf = new StringBuffer();
buf.append("Hello").append(" ").append("World"); //bad
buf.append("Hello World");//good
}
}
]]></example>
<priority>1</priority>
<properties>
<property name="threshold" value="1"/>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.strings.UseIndexOfChar" message="String.indexOf(char) is faster than String.indexOf(String)" name="UseIndexOfChar">
<description>
Use String.indexOf(char) when checking for the index of a single character; it's faster.
</description>
<example><![CDATA[
public class Foo {
void bar() {
String s = "hello world";
// avoid this
if (s.indexOf("d") {}
// instead do this
if (s.indexOf('d') {}
}
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.strings.InsufficientStringBufferDeclaration" message="StringBuffer constructor is initialized with size {0},but has at least {1} characters appended" name="InsufficientStringBufferDeclaration">
<description>
Failing to pre-size a StringBuffer properly could cause it to re-size many times
during runtime. This rule checks the characters that are actually passed into
StringBuffer.append(),but represents a best guess "worst case" scenario. An
empty StringBuffer constructor initializes the object to 16 characters. This default
is assumed if the length of the constructor can not be determined.
</description>
<example><![CDATA[
public class Foo {
void bar() {
StringBuffer bad = new StringBuffer();
bad.append("This is a long string,will exceed the default 16 characters");//bad
StringBuffer good = new StringBuffer(41);
good.append("This is a long string,which is pre-sized");//good
}
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.imports.UnusedImportsRule" message="Avoid unused imports such as ''{0}''" name="UnusedImports">
<description>
Avoid unused import statements.
</description>
<example><![CDATA[
// this is bad
import java.io.File;
public class Foo {}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.UnusedPrivateFieldRule" message="Avoid unused private fields such as ''{0}''" name="UnusedPrivateField">
<description>
Detects when a private field is declared and/or assigned a value,but not used.
</description>
<example><![CDATA[
public class Something {
private static int FOO = 2; // Unused
private int i = 5; // Unused
private int j = 6;
public int addOne() {
return j++;
}
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.UnusedLocalVariableRule" message="Avoid unused local variables such as ''{0}''" name="UnusedLocalVariable">
<description>
Detects when a local variable is declared and/or assigned,but not used.
</description>
<example><![CDATA[
public class Foo {
public void doSomething() {
int i = 5; // Unused
}
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.UnusedPrivateMethodRule" message="Avoid unused private methods such as ''{0}''" name="UnusedPrivateMethod">
<description>
Unused Private Method detects when a private method is declared but is unused.
</description>
<example><![CDATA[
public class Something {
private void foo() {} // unused
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.UnusedFormalParameterRule" message="Avoid unused {0} parameters such as ''{1}''" name="UnusedFormalParameter">
<description>
Avoid passing parameters to methods or constructors and then not using those parameters.
</description>
<example><![CDATA[
public class Foo {
private void bar(String howdy) {
// howdy is not used
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.strictexception.AvoidCatchingThrowable" message="A catch statement should never catch throwable since it includes errors" name="AvoidCatchingThrowable">
<description>
This is dangerous because it casts too wide a net; it can catch things like OutOfMemoryError.
</description>
<example><![CDATA[
public class Foo {
public void bar() {
try {
// do something
} catch (Throwable th) { //Should not catch throwable
th.printStackTrace();
}
}
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.strictexception.ExceptionSignatureDeclaration" message="A signature (constructor or method) shouldn't have Exception in throws declaration" name="SignatureDeclareThrowsException">
<description>
It is unclear which exceptions that can be thrown from the methods.
It might be difficult to document and understand the vague interfaces.
Use either a class derived from RuntimeException or a checked exception.
</description>
<example><![CDATA[
public void methodThrowingException() throws Exception {
}
]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid catching NullPointerException; consider removing the cause of the NPE." name="AvoidCatchingNPE">
<description>
Code should never throw NPE under normal circumstances. A catch block may hide the original error,causing other more subtle errors in its wake.
</description>
<example><![CDATA[
public class Foo {
void bar() {
try {
// do something
} catch (NullPointerException npe) {
}
}
}
]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//CatchStatement/FormalParameter/Type
/ReferenceType/ClassOrInterfaceType[@Image='NullPointerException']
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid throwing raw exception types" name="AvoidThrowingRawExceptionTypes">
<description>
Avoid throwing certain exception types. Rather than throw a raw RuntimeException,Throwable,
Exception,or Error,use a subclassed exception or error instead.
</description>
<example><![CDATA[
public class Foo {
public void bar() throws Exception {
throw new Exception();
}
}
]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//AllocationExpression
/ClassOrInterfaceType[
@Image='Throwable' or
@Image='Exception' or
@Image='Error' or
@Image='RuntimeException']
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Consider replacing this Vector with the newer java.util.List" name="ReplaceVectorWithList">
<description>
Consider replacing this Vector with the newer java.util.List
</description>
<example><![CDATA[
public class Foo {
void bar() {
Vector v = new Vector();
}
}
]]></example>
<priority>1</priority> <!-- Priority 5 to 1. Changed by ATP1AXR -->
<properties>
<property name="xpath">
<value><![CDATA[
//Type/ReferenceType/ClassOrInterfaceType[@Image='Vector']
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Consider replacing this Hashtable with the newer java.util.Map" name="ReplaceHashtableWithMap">
<description>
Consider replacing this Hashtable with the newer java.util.Map
</description>
<example><![CDATA[
public class Foo {
void bar() {
Hashtable h = new Hashtable();
}
}
]]></example>
<priority>1</priority> <!-- Priority 5 to 1. Changed by ATP1AXR -->
<properties>
<property name="xpath">
<value><![CDATA[
//Type/ReferenceType/ClassOrInterfaceType[@Image='Hashtable']
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using enum as an identifier; it's a reserved word in JDK 1.5" name="AvoidEnumAsIdentifier">
<description>Finds all places 'enum' is used as an identifier is used</description>
<example><![CDATA[
public class A {
public class foo {
String enum = "foo";
}
}
]]></example>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//VariableDeclaratorId[@Image='enum']
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using 'while' statements without curly braces" name="WhileLoopsMustUseBraces">
<description>
Avoid using 'while' statements without using curly braces
</description>
<example><![CDATA[
public void doSomething() {
while (true)
x++;
}
]]></example>
<priority>1</priority> <!-- Priority 5 to 1. Changed by ATP3RXS -->
<properties>
<property name="xpath">
<value><![CDATA[
//WhileStatement[not(Statement/Block)]
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using 'for' statements without curly braces" name="ForLoopsMustUseBraces">
<description>
Avoid using 'for' statements without using curly braces
</description>
<example><![CDATA[
public void foo() {
for (int i=0; i<42;i++)
foo();
}
]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ForStatement[not(Statement/Block)]
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.SimplifyBooleanReturns" message="Avoid unnecessary if..then..else statements when returning a boolean" name="SimplifyBooleanReturns">
<description>
Avoid unnecessary if..then..else statements when returning a boolean
</description>
<example><![CDATA[
public class Foo {
private int bar =2;
public boolean isBarEqualsTo(int x) {
// this bit of code
if (bar == x) {
return true;
} else {
return false;
}
// can be replaced with a simple
// return bar == x;
}
}
]]></example>
<priority>2</priority> <!-- Priority 1 to 2. Changed by ATP3RXS -->
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Switch statements should have a default label" name="SwitchStmtsShouldHaveDefault">
<description>
Switch statements should have a default label.
</description>
<example><![CDATA[
public class Foo {
public void bar() {
int x = 2;
switch (x) {
case 2: int j = 8;
}
}
}
]]></example> <priority>1</priority> <properties> <property name="xpath"> <value><![CDATA[ //SwitchStatement[not(SwitchLabel[@Default='true'])] ]]></value> </property> </properties> </rule> <rule class="net.sourceforge.pmd.rules.ConstructorCallsOverridableMethod" message="Overridable {0} called during object construction" name="ConstructorCallsOverridableMethod"> <description>Calling overridable methods during construction poses a risk of invoking methods on anincompletely constructed object. This situation can be difficult to discern.It may leave the sub-class unable to construct its superclass or forced toreplicate the construction process completely within itself,losing the ability to callsuper(). If the default constructor contains a call to an overridable method,the subclass may be completely uninstantiable. Note that this includes method callsthroughout the control flow graph - i.e.,if a constructor Foo() calls a private methodbar() that calls a public method buz(),there's a problem. </description> <example><![CDATA[ public class SeniorClass { public SeniorClass(){ toString(); //may throw NullPointerException if overridden } public String toString(){ return "IAmSeniorClass"; }}public class JuniorClass extends SeniorClass { private String name; public JuniorClass(){ super(); //Automatic call leads to NullPointerException name = "JuniorClass"; } public String toString(){ return name.toUpperCase(); }} ]]></example> <priority>1</priority> <properties/> </rule> <rule class="net.sourceforge.pmd.rules.XPathRule" message="This final field could be made static" name="FinalFieldCouldBeStatic"> <description>
If a final field is assigned to a compile-time constant,it could be
made static,thus saving overhead in each object
 </description> <example><![CDATA[ public class Foo {public final int BAR = 42; // this could be static and save some space} ]]></example> <priority>1</priority> <properties> <property name="xpath"> <value><![CDATA[ //FieldDeclaration[@Final='true' and @Static='false'][not (../../../../ClassOrInterfaceDeclaration[@Interface='true'])] /VariableDeclarator/VariableInitializer/Expression /PrimaryExpression/PrimaryPrefix/Literal ]]></value> </property> </properties> </rule>
原文链接:https://www.f2er.com/xml/297876.html