Skip to content

[java] Allow CPD suppression through comments#250

Merged
adangel merged 1 commit into
pmd:masterfrom
jsotuyod:cpd-suppress-comments-java
Feb 19, 2017
Merged

[java] Allow CPD suppression through comments#250
adangel merged 1 commit into
pmd:masterfrom
jsotuyod:cpd-suppress-comments-java

Conversation

@jsotuyod

@jsotuyod jsotuyod commented Feb 8, 2017

Copy link
Copy Markdown
Member

This one has been a big missing feature for quite some time. Even old comments on the code (now deleted) wondered on being able to do this.

I didn't reuse the CPD-START / CPD-STOP literals since I found them unintuitive. START is to tell CPD to stop looking, STOP is to resume analysis. This even contradicted the preexisting // NOPMD comments. Again, a negative to suppress.

The start / stop may work given it's within a @SuppressWarnings (so we get a "suppress warnings cpd start"), but certainly wouldn't be the same for stand alone comments. To avoid issues, I simply created new literals.

I also updated the docs and moved the annotation based approach to legacy due to lack of flexibility.

Porting this approach to other JavaCC based languages is still pending. I can't find a way to do it in a reusable manner, since each parser generates it's own Token class, and the specialToken is a public field, not accessible through a getter. Ideas are welcomed.

@jsotuyod jsotuyod added the an:enhancement An improvement on existing features / rules label Feb 8, 2017
@jsotuyod jsotuyod added this to the 5.6.0 milestone Feb 8, 2017
adangel added a commit to adangel/pmd that referenced this pull request Feb 19, 2017
@adangel adangel merged commit 4d7938d into pmd:master Feb 19, 2017
@jsotuyod jsotuyod deleted the cpd-suppress-comments-java branch February 19, 2017 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

an:enhancement An improvement on existing features / rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants