Merge branch 'pr-2567'

[c#] Fix CPD suppression with comments doesn't work #2551 #2567
This commit is contained in:
Andreas Dangel
2020-06-12 12:49:21 +02:00
4 changed files with 17 additions and 2 deletions

View File

@ -370,7 +370,7 @@ Here's a screenshot of CPD after running on the JDK 8 java.lang package:
## Suppression
Arbitrary blocks of code can be ignored through comments on **Java**, **C/C++**, **Dart**, **Go**, **Javascript**,
**Kotlin**, **Lua**, **Matlab**, **Objective-C**, **PL/SQL**, **Python** and **Swift** by including the keywords `CPD-OFF` and `CPD-ON`.
**Kotlin**, **Lua**, **Matlab**, **Objective-C**, **PL/SQL**, **Python**, **Swift** and **C#** by including the keywords `CPD-OFF` and `CPD-ON`.
```java
public Object someParameterizedFactoryMethod(int x) throws Exception {

View File

@ -45,6 +45,8 @@ The command line version of PMD continues to use **scala 2.13**.
### Fixed Issues
* c#
* [#2551](https://github.com/pmd/pmd/issues/2551): \[c#] CPD suppression with comments doesn't work
* scala
* [#2547](https://github.com/pmd/pmd/pull/2547): \[scala] Add cross compilation for scala 2.12 and 2.13
@ -56,6 +58,7 @@ The command line version of PMD continues to use **scala 2.13**.
### External Contributions
* [#2547](https://github.com/pmd/pmd/pull/2547): \[scala] Add cross compilation for scala 2.12 and 2.13 - [João Ferreira](https://github.com/jtjeferreira)
* [#2567](https://github.com/pmd/pmd/pull/2567): \[c#] Fix CPD suppression with comments doesn't work - [Lixon Lookose](https://github.com/LixonLookose)
{% endtocmaker %}

View File

@ -77,7 +77,7 @@ public class AntlrToken implements GenericToken {
}
public boolean isHidden() {
return token.getChannel() == Lexer.HIDDEN;
return !isDefault();
}
public boolean isDefault() {

View File

@ -78,6 +78,18 @@ public class CsTokenizerTest {
assertEquals(5, tokens.size());
}
@Test
public void testIgnoreBetweenSpecialComments() {
tokenizer
.tokenize(
toSourceCode("// CPD-OFF\n" + "class Foo {\n" + " void bar() {\n" + " int a = 1 >> 2; \n"
+ " a += 1; \n" + " a++; \n" + " a /= 3e2; \n" + " float f = -3.1; \n"
+ " f *= 2; \n" + " bool b = ! (f == 2.0 || f >= 1.0 && f <= 2.0) \n"
+ " }\n" + "// CPD-ON\n" + "}"),
tokens);
assertEquals(2, tokens.size()); // "}" + EOF
}
@Test
public void testCommentsIgnored3() {
tokenizer.tokenize(toSourceCode("class Foo { /// class X /* aaa */ \n }"), tokens);