Menu

#180 Some rules of JTest 4 PMD

pending
None
5
2012-10-07
2006-12-05
Ricard
No

Hello,

I am writting from ITI (www.iti.upv.es). We have developped some rules that for PMD that were in JTEST
(http://www.cs.indiana.edu/csg/links/parasoft/jtest)
and not in PMD 3.7. We would like to contribute with them to the project.

These are the rules that we've developped.

[PB.AES-3] Avoid empty statements

DESCRIPTION

This rule identifies empty statements in the code. An error
is reported for each occurrence.

[PB.AULV-3] Avoid unused loop variables [

DESCRIPTION

This rule identifies unused loop variables. An error is
reported if a loop variable is declared but unused in
the loop condition.

[PB.AWP-3] Avoid confusing assignments to constructor arguments

DESCRIPTION

This rule identifies confusing assignments to constructor arguments.
An error is reported for any write access to a parameter inside a constructor
when the parameter name matches the name of a field defined in the same enclosing class.

[PB.DCP-3] Do not use the "+" string concatenation operator to concatenate numbers; use it only to add numbers

DESCRIPTION

This rule identifies code that uses the "+" string concatenation operator when
the value being appended is a basic numeric type (e.g. int).

[PB.EQUS-2] Do not call 'equals()' methods that always return false

DESCRIPTION

This identifies equals() methods that would always return false. An error is
reported for each occurrence.

[PB.FLVA-2] Do not assign loop control variables in the body of a "for" loop

DESCRIPTION

Disallows modification of "for" loop control variables in the body of a "for"
loop.

[PB.NAMING-1] Do not give non-constructor methods the same name as the class

DESCRIPTION

This rule identifies non-constructor methods that have the same
name as the class. An error is reported for each occurrence.

[PB.PDCL-3] Place "default" as the last case of the "switch" statement

DESCRIPTION

This rule identifies any "default" case that is not the last case of
the "switch" statement. An error is reported for each occurrence.

[PB.PDS-2] Provide "default:" for each "switch" statement

DESCRIPTION

This rule identifies any "switch" statement that does not have a "default"
statement. An error is reported for each occurrence.

[PB.SAFL-2] Avoid self assignments/initializations to fields and/or local variables

DESCRIPTION

This rule identifies self assignments/initializations to fields and/or local variables. An error is reported if if a field and/or local variable is assigned to itself.

[PB.SG-1] Ensure get/set methods are accessing the correct variables

DESCRIPTION

This rule identifies 'set' and 'get' methods that do not access the intended instance fields. An error is reported when a method is named "setX" or "getX", but does not actually access field "X".

[PB.UEIC-3] Do not use '==' or '!=' to compare objects

DESCRIPTION

This rule identifies code that uses equals while comparing object.With the default rule parameters, an error is reported if "==" or "!=" is used when comparing Objects.

If u have any questions don't hesitate to contact me!!


                        ---------   ---
                       |         | |   |
                        ---   ---  |   |
             --------     |   |    |   |
            |        |    |   |    |   |
             --------      ---      ---

Ricard Roca Instituto Tecnológico de Informática
ricardroca@iti.upv.es Universitat Politècnica de València
Telf: 96 3877069 Camino de Vera s/n 46071 València


Discussion

  • Ricard

    Ricard - 2006-12-05

    some rules

     
  • Allan Caplan

    Allan Caplan - 2007-01-03

    Logged In: YES
    user_id=1127445
    Originator: NO

    Ricard
    This is some good stuff. I'm going to take a few days going through these rules - they'll need to be added to their respective rulesets, and unit tests will need to be added.

    That said, I do see some overlap with existing rules. These 5 rules already exist in PMD:
    [PB.AES-3] Avoid empty statements
    [PB.PDCL-3] Place "default" as the last case of the "switch" statement
    [PB.PDS-2] Provide "default:" for each "switch" statement
    [PB.UEIC-3] Do not use '==' or '!=' to compare objects
    [PB.AULV-3] Avoid unused loop variables

    This one I could swear was an existing rule, but maybe I'm just confused:
    [PB.DCP-3] Do not use the "+" string concatenation operator to concatenate numbers; use it only to add numbers

    On their faces, these look like new rules:
    [PB.AWP-3] Avoid confusing assignments to constructor arguments
    [PB.EQUS-2] Do not call 'equals()' methods that always return false
    [PB.FLVA-2] Do not assign loop control variables in the body of a "for" loop
    [PB.NAMING-1] Do not give non-constructor methods the same name as the class
    [PB.SAFL-2] Avoid self assignments/initializations to fields and/or local variables
    [PB.SG-1] Ensure get/set methods are accessing the correct variables

    Allan

     
  • Allan Caplan

    Allan Caplan - 2007-01-03

    Logged In: YES
    user_id=1127445
    Originator: NO

    Another one - PB.Naming-1 is the same as the existing rule MethodWithSameNameAsEnclosingClass

     

Log in to post a comment.