diff --git a/pmd-eclipse-feature/feature.xml b/pmd-eclipse-feature/feature.xml index 1b7a59cf66..0b1efa8ac4 100644 --- a/pmd-eclipse-feature/feature.xml +++ b/pmd-eclipse-feature/feature.xml @@ -2,12 +2,12 @@ - + PMD For Eclipse @@ -33,20 +33,14 @@ + download-size="5 193 557" + install-size="5 193 728 " + version="3.0.1"/> - - + download-size="596 038" + install-size="598 016" + version="3.0.1"/> diff --git a/pmd-eclipse-pmd/.classpath b/pmd-eclipse-pmd/.classpath index 657ce090e6..21e4c30168 100644 --- a/pmd-eclipse-pmd/.classpath +++ b/pmd-eclipse-pmd/.classpath @@ -2,6 +2,7 @@ + diff --git a/pmd-eclipse-pmd/lib/xercesImpl.jar b/pmd-eclipse-pmd/lib/xercesImpl.jar new file mode 100644 index 0000000000..14c3162c0f Binary files /dev/null and b/pmd-eclipse-pmd/lib/xercesImpl.jar differ diff --git a/pmd-eclipse-pmd/plugin.xml b/pmd-eclipse-pmd/plugin.xml index c5b551b931..868075276f 100644 --- a/pmd-eclipse-pmd/plugin.xml +++ b/pmd-eclipse-pmd/plugin.xml @@ -3,7 +3,7 @@ @@ -13,13 +13,13 @@ + + + - - - diff --git a/pmd-eclipse/.project b/pmd-eclipse/.project index 23db46b1d7..dc63903401 100644 --- a/pmd-eclipse/.project +++ b/pmd-eclipse/.project @@ -22,7 +22,7 @@ - com.ibm.sse.model.structuredbuilder + net.sourceforge.pmd.eclipse.pmdBuilder @@ -30,7 +30,6 @@ org.eclipse.jdt.core.javanature org.eclipse.pde.PluginNature - com.ibm.etools.beaninfo.BeaninfoNature - com.ibm.etools.java.JavaMOFNature + net.sourceforge.pmd.eclipse.pmdNature diff --git a/pmd-eclipse/.ruleset b/pmd-eclipse/.ruleset new file mode 100644 index 0000000000..30157da627 --- /dev/null +++ b/pmd-eclipse/.ruleset @@ -0,0 +1,2827 @@ + + + PMD Plugin preferences rule set + + An explicit call was made to a finalize method. Finalize methods are meant to be executed at most once (by the garbage collector). Calling it explicitly could result in the method being executed twice for that object (once by you, once by the garbage collector). + + 3 + + + + + + + + Classes that have too many fields could be redesigned to have less fields and some nested object grouping some of the information collected on the many fields. + + 3 + + + + + + Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3). + + 3 + + + + + + + + Identifies a possible unsafe usage of a static field. + + 3 + + + + Abstract classes should be named 'AbstractXXX'. + + 3 + + + + + + + + Avoid instantiating an object just to call getClass() on it; use the .class public member instead + + 3 + + + + + + + + A high number of imports can indicate a high degree of coupling within an object. Rule counts the number of unique imports and reports a violation if the count is above the user defined threshold. + + 3 + + + + + + Exposing internal arrays directly allows the user to modify some code that could be critical. It is safer to return a copy of the array. + + 3 + + + + Non-constructor methods should not have the same name as the enclosing class. + + 3 + + + + It is a good practice to call super() in a constructor. If super() is not called but another constructor, such as an overloaded constructor, of the class is called, this rule will not report it. + + 3 + + + + + + + + A large amount of public methods and attributes declared in an object can indicate the class may need to be broken up as increased effort will be required to thoroughly test such a class. + + 3 + + + + + + When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Turkish. + + 3 + + + + + + + + Avoid using dollar signs in variable/method/class/interface names. + + 3 + + + + + + + + Avoid using 'for' statements without using curly braces + + 3 + + + + + + + + The method name and parameter number are suspiciously close to equals(Object), which may mean you are trying (and failing) to override the equals(Object) method. + + 1 + + + + + + + + This is dangerous because if a java.lang.Error, for example OutOfMemmoryError, occurs then it will be caught. The container should handle java.lang.Error. If application code will catch them, try to log them (which will probably fail) and continue silently the situation will not be desirable. + + 3 + + + + Using Exceptions as flow control leads to GOTOish code. + + 3 + + + + If a final field is assigned to a compile-time constant, it could be made static, thus saving overhead in each object + + 3 + + + + + + + + The method name and return type are suspiciously close to hashCode(), which may mean you are trying (and failing) to override the hashCode() method. + + 3 + + + + + + + + Fields in interfaces are automatically public static final, and methods are public abstract. Classes or interfaces nested in an interface are automatically public and static (all nested interfaces are automatically static). For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous. + + 3 + + + + + + + + Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object. This situation can be difficult to discern. It may leave the sub-class unable to construct its superclass or forced to replicate the construction process completely within itself, losing the ability to call super(). If the default constructor contains a call to an overridable method, the subclass may be completely uninstantiable. Note that this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls a private method bar() that calls a public method buz(), there's a problem. + + 1 + + + + The abstract class does not contain any abstract methods. An abstract class suggests an incomplete implementation, which is to be completed by subclasses implementing the abstract methods. If the class is intended to be used as a base class only (not to be instantiated direcly) a protected constructor can be provided prevent direct instantiation. + + 3 + + + + + + + + A nonstatic initializer block will be called any time a constructor is invoked (just prior to invoking the constructor). While this is a valid language construct, it is rarely used and is confusing. + + 3 + + + + + + + + Detects when a local variable is declared and/or assigned, but not used. + + 3 + + + + A high ratio of statements to labels in a switch statement implies that the switch statement is doing too much work. Consider moving the statements either into new methods, or creating subclasses based on the switch variable. + + 3 + + + + + + At some places Exception is caught and then a check with instanceof is performed. This result in messy code. It's considered better to catch all the specific exceptions instead. + + 3 + + + + Avoid empty finally blocks - these can be deleted. + + 3 + + + + + + + + Normally only one logger is used in each class. + + 1 + + + 1 +] + ]]> + + + + + Avoid returning from a finally block - this can discard exceptions. + + 3 + + + + + + + + Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Scale: 1-4 (low complexity) 5-7 (moderate complexity) 8-10 (high complexity) 10+ (very high complexity) + + 3 + + + + + + Avoid calling toString() on String objects; this is unnecessary + + 3 + + + + Each caught exception type should be handled in its own catch clause. + + 3 + + + + + + + + Avoid empty try blocks - what's the point? + + 1 + + + + + + + + The method clone() should only be implemented if the class implements Cloneable interface + + 3 + + + + + + + + Avoid unused import statements. + + 3 + + + + An empty statement (aka a semicolon by itself) that is not used as the sole body of a for loop or while loop is probably a bug. It could also be a double semicolon, which is useless and should be removed. + + 3 + + + + + + + + It is somewhat confusing to have a field name with the same name as a method. While this is totally legal, having information (field) and actions (method) is not clear naming. + + 3 + + + + The default label in a switch statement should be the last label, by convention. Most programmers will expect the default label (if present) to be the last one. + + 3 + + + + + + + + Method level synchronization can backfire when new code is added to the method. Block-level synchronization helps to ensure that only the code that needs synchronization gets it. + + 3 + + + + + + + + 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. + + 3 + + + + Detects when a private field is declared and/or assigned a value, but not used. + + 3 + + + + Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor. A factory method, or non-privitization of the constructor can eliminate this situation. The generated class file is actually an interface. It gives the accessing class the ability to invoke a new hidden package scope constructor that takes the interface as a supplementary parameter. This turns a private constructor effectively into one with package scope, though not visible to the naked eye. + + 3 + + + + Reassigning values to parameters is a questionable practice. Use a temporary local variable instead. + + 1 + + + + A class that has private constructors and does not have any static method cannot be used. + + 3 + + + 0 + and count(.//ConstructorDeclaration) = count(.//ConstructorDeclaration[@Private='true']) ) +and +count(.//MethodDeclaration[@Static='true'])=0 +] + + ]]> + + + + + Excessive Method Length usually means that the method is doing too much. There is usually quite a bit of Cut and Paste there as well. Try to reduce the method size by creating helper methods, and removing cut and paste. Default value is 2.5 sigma greater than the mean. There are three parameters available: minimum - Minimum Length before reporting. sigma - Std Deviations away from the mean before reporting. topscore - The Maximum Number of reports to generate. At this time, only one can be used at a time. + + 3 + + + + + + No need to import a type that's in the same package. + + 3 + + + + Rule counts unique attributes, local variables and return types within an object. An amount higher than specified threshold can indicate a high degree of couping with in an object + + 3 + + + + + + It is somewhat confusing to have a field name matching the declaring class name. This proabably means that type and or field names could be more precise. + + 3 + + + + Avoid idempotent operations - they are silly. + + 3 + + + + Method names should always begin with a lower case character, and should not contain underscores. + + 1 + + + + A method should have only one exit point, and that should be the last statement in the method. + 0) { + return "hey"; // oops, multiple exit points! + } + return "hi"; + } + } + + ]]> + 3 + + + + Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass. + + 3 + + + + + + + + Avoid duplicate import statements. + + 3 + + + + Avoid unnecessary temporaries when converting primitives to Strings + + 3 + + + + The method clone() should throw a CloneNotSupportedException + + 3 + + + + + + + + Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead + + 3 + + + + A non-case label (e.g. a named break/continue label) was present in a switch statement. This legal, but confusing. It is easy to mix up the case labels and the non-case labels. + + 3 + + + + + + + + A switch statement without an enclosed break statement may be a bug. + + 3 + + + + + + + + Avoid unnecessary comparisons in boolean expressions - this makes simple code seem complicated. + + 3 + + + + + + + + Avoid assigments in operands; this can make code more complicated and harder to read. + + 3 + + + + + + + + Unnecessary constructor detects when a constructor is not necessary; i.e., when there's only one constructor, it's public, has an empty body, and takes no arguments. + + 3 + + + + + + + + Long Class files are indications that the class may be trying to do too much. Try to break it down, and reduce the size to something managable. Default value is 2.5 sigma greater than the mean. NOTE: In version 0.9 and higher, their are three parameters available: minimum - Minimum Length before reporting. sigma - Std Deviations away from the mean before reporting. topscore - The Maximum Number of reports to generate. At this time, only one can be used at a time. + + 3 + + + + + + Constructors and methods receiving arrays shuold clone objects and store the copy. This prevents that future changes from the user affect the internal functionallity. + + 3 + + + + Object clone() should be implemented with super.clone() + + 1 + + + 0 +] + + ]]> + + + + + If you override finalize(), make it protected. Otherwise, subclasses may not called your implementation of finalize. + + 3 + + + + + + + + Avoid unnecessary if..then..else statements when returning a boolean + + 3 + + + + In an "if" expression with an "else" clause, avoid negation in the test. For example, rephrase: if (x != y) diff(); else same(); as: if (x == y) same(); else diff(); Most "if (x != y)" cases without an "else" are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as "does the error case go first?" or "does the common case go first?". + + 3 + + + + Avoid unnecessary return statements + + 3 + + + + + + + + In most cases, the Logger can be declared static and final. + + 1 + + + + + + + + Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change. + + 3 + + + + + + + + A suspicious octal escape sequence was found inside a String literal. The Java language specification (section 3.10.6) says an octal escape sequence inside a literal String shall consist of a backslash followed by: OctalDigit | OctalDigit OctalDigit | ZeroToThree OctalDigit OctalDigit Any octal escape sequence followed by non-octal digits can be confusing, e.g. "\038" is interpreted as the octal escape sequence "\03" followed by the literal character "8". + + 3 + + + + Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this swallows an exception which should either be acted on or reported. + + 3 + + + 1] + [count(*) = 0] + [../@Finally='false' or following-sibling::Block] + + ]]> + + + + + Some for loops can be simplified to while loops - this makes them more concise. + + 3 + + + 1][not(ForInit)][not(ForUpdate)] + ]]> + + + + + ArrayList is a much better Collection implementation than Vector. + + 3 + + + + + + + + It is very easy to confuse methods with classname with constructors. It is preferrable to name these non-constructor methods in a different way. + + 3 + + + + A field name is all in uppercase characters, which in sun's java naming conventions indicate a constant. However, the field is not final. + + 3 + + + + + + + + Code containing duplicate String literals can usually be improved by declaring the String as a constant field. + + 3 + + + + + + Unused Private Method detects when a private method is declared but is unused. + + 3 + + + + An empty static initializer was found. + + 3 + + + + + + + + If the finalize() is implemented, it should do something besides just calling super.finalize(). + + 3 + + + + + + + + A call to Collection.toArray can use the Collection's size vs an empty Array of the desired type. + + 3 + + + + + + + + Avoid using if statements without using curly braces + + 3 + + + + + + + + Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer. + + 1 + + + + + + + + If the finalize() method is empty, then it does not need to exist. + + 3 + + + + + + + + Avoid instantiating Boolean objects, instead use Boolean.valueOf(). + + 1 + + + + + + + + Avoid empty switch statements. + + 3 + + + + + + + + Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. + + 3 + + + + + + + + If you have a class that has nothing but static methods, consider making it a Singleton. Note that this doesn't apply to abstract classes, since their subclasses may well include non-static methods. Also, if you want this class to be a Singleton, remember to add a private constructor to prevent instantiation. + + 3 + + + + Be sure to specify a Locale when creating a new instance of SimpleDateFormat. + + 3 + + + + + + + + Avoid passing parameters to methods and then not using those parameters. + + 3 + + + + finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. + + 3 + + + + + + + + Do not use "if" statements that are always true or always false. + + 3 + + + + + + + + Do not use protected fields in final classes since they cannot be subclassed. Clarify your intent by using private or package access modifiers instead. + + 3 + + + + + + + + 1) Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable, Exception, or Error, use a subclassed exception or error instead. 2) Avoid throwing a NullPointerException - it's confusing because most people will assume that the VM threw NPE. Consider using InvalidArgumentException("Null parameter") which will be clearly seen as a programmer initiated exception.. Use IllegalArgumentException or IllegalStateException instead. + + 1 + + + + + + + + A method argument that is never assigned can be declared final. + + 3 + + + + Code should never throw NPE under normal circumstances. A catch block may hide the original error, causing other more subtle errors in its wake. + + 3 + + + + + + + + Deeply nested if..then statements are hard to read. + y) { + if (y>z) { + if (z==x) { + // this is officially out of control now + } + } + } + } +} + + ]]> + 3 + + + + + + This checks to make sure that the Parameter Lists in the project aren't getting too long. If there are long parameter lists, then that is generally indicative that another object is hiding around there. Basically, try to group the parameters together. Default value is 2.5 sigma greater than the mean. NOTE: In version 0.9 and higher, their are three parameters available: minimum - Minimum Length before reporting. sigma - Std Deviations away from the mean before reporting. topscore - The Maximum Number of reports to generate. At this time, only one can be used at a time. + + 3 + + + + + + Detects when a new object is created inside a loop + + 3 + + + + Assigning a "null" to a variable (outside of its declaration) is usually in bad form. Some times, the assignment is an indication that the programmer doesn't completely understand what is going on in the code. NOTE: This sort of assignment may in rare cases be useful to encourage garbage collection. If that's what you're using it for, by all means, disregard this rule :-) + + 3 + + + + Avoid using if..else statements without using curly braces + + 3 + + + + + + + + Empty If Statement finds instances where a condition is checked but nothing is done about it. + + 1 + + + + + + + + Avoid instantiating String objects; this is usually unnecessary. + + 1 + + + + + + + + Avoid using 'while' statements without using curly braces + + 3 + + + + + + + + Newbie programmers sometimes get the comparison concepts confused and use equals() to compare to null. + + 1 + + + + + + + + Ensures that Connection objects are always closed after use + + 3 + + + + Avoid equality comparisons with Double.NaN - these are likely to be logic errors. + + 3 + + + + + + + + Detects when a field, formal or local variable is declared with a long name. + + 3 + + + 32]]]> + + + + + + Class names should always begin with an upper case character. + + 1 + + + + Partially created objects can be returned by the Double Checked Locking pattern when used in Java. An optimizing JRE may assign a reference to the baz variable before it creates the object the reference is intended to point to. For more details see http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html. + + 1 + + + + notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only one is chosen. The thread chosen is arbitrary; thus it's usually safer to call notifyAll() instead. + + 3 + + + + + + + + Detects when very short method names are used. + + 3 + + + + + + + + A local variable assigned only once can be declared final. + + 3 + + + + Avoid concatenating non literals in a StringBuffer constructor or append(). + + 1 + + + + System.(out|err).println is used, consider using a logger. + + 1 + + + + + + + + If the finalize() is implemented, its last action should be to call super.finalize + + 3 + + + + + + + + Avoid empty synchronized blocks - they're useless. + + 3 + + + + + + + + Switch statements should have a default label. + + 3 + + + + + + + + When a class has the final modifier, all the methods are marked finally. + + 3 + + + + + + + + Identifies private fields whose values never change once they are initialized either in the declaration of the field or by a constructor. This aids in converting existing classes to immutable classes. + + 3 + + + + Methods named finalize() should not have parameters. It is confusing and probably a bug to overload finalize(). It will not be called by the VM. + + 3 + + + 0]] + + ]]> + + + + diff --git a/pmd-eclipse/plugin.xml b/pmd-eclipse/plugin.xml index ca0fe9a255..ff42d7c211 100644 --- a/pmd-eclipse/plugin.xml +++ b/pmd-eclipse/plugin.xml @@ -3,7 +3,7 @@ @@ -25,7 +25,6 @@ -