Sonar

add CPD options ignoreLiterals and ignoreIdentifiers

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.12
  • Labels:
    None
  • Environment:
    all
  • Number of attachments :
    0

Description

Add these two options to the CPD options in Configuration->Settings->CPD

ignoreLiterals
if true, CPD ignores literal value differences when evaluating a duplicate block. This means that foo=42; and foo=43; will be seen as equivalent. You may want to run PMD with this option off to start with and then switch it on to see what it turns up; defaults to false.

ignoreIdentifiers
Similar to ignoreLiterals but for identifiers; i.e., variable names, methods names, and so forth; defaults to false.

see http://pmd.sourceforge.net/cpd.html and there "Ant Task".

Default values to be defined. For a first try, both false as defined by PMD-CPD ahould be OK.
Default true maybe shows up too many duplicates for some projects.

Activity

Hide
Freddy Mallet added a comment -

Those two options must be specified when creating the JavaLanguage object and are used internally by the JavaTokenizer object. I confirm that the default values are false.

The following piece of code must be added :

Properties properties = new Properties();
properties.setProperty("ignore_literals", "${desired_value}");
properties.setProperty("ignore_identifiers", "${desired_valu");
JavaLanguage javaLanguage = new JavaLanguage(properties);
Show
Freddy Mallet added a comment - Those two options must be specified when creating the JavaLanguage object and are used internally by the JavaTokenizer object. I confirm that the default values are false. The following piece of code must be added :
Properties properties = new Properties();
properties.setProperty("ignore_literals", "${desired_value}");
properties.setProperty("ignore_identifiers", "${desired_valu");
JavaLanguage javaLanguage = new JavaLanguage(properties);
Hide
Freddy Mallet added a comment -

ignoreLiterals is now activated by default.

Show
Freddy Mallet added a comment - ignoreLiterals is now activated by default.

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: