Merge branch 'pr-2495'

[c#] Support for interpolated verbatim strings #2495
This commit is contained in:
Andreas Dangel
2020-05-22 19:53:10 +02:00
3 changed files with 15 additions and 1 deletions

View File

@ -45,6 +45,8 @@ This is useful to find duplicated sections in XML files.
* core
* [#2444](https://github.com/pmd/pmd/pull/2444): \[core] Support reproducible builds
* [#2484](https://github.com/pmd/pmd/issues/2484): \[core] Update maven-enforcer-plugin to require Java 118
* c#
* [#2495](https://github.com/pmd/pmd/pull/2495): \[c#] Support for interpolated verbatim strings
* java
* [#2472](https://github.com/pmd/pmd/issues/2472): \[java] JavaCharStream throws an Error on invalid escape
* java-bestpractices
@ -89,6 +91,7 @@ definitive API.
* [#2479](https://github.com/pmd/pmd/pull/2479): \[java] False positive with Hamcrest's assertThat - [andreoss](https://github.com/andreoss)
* [#2481](https://github.com/pmd/pmd/pull/2481): \[java] Fix JUnitSpellingRule false positive - [Artem Krosheninnikov](https://github.com/KroArtem)
* [#2493](https://github.com/pmd/pmd/pull/2493): \[java] Deprecate redundant String Comparison rules - [John-Teng](https://github.com/John-Teng)
* [#2495](https://github.com/pmd/pmd/pull/2495): \[c#] Support for interpolated verbatim strings - [Maikel Steneker](https://github.com/maikelsteneker)
{% endtocmaker %}

View File

@ -148,7 +148,7 @@ REGULAR_STRING: '"' (~["\\\r\n\u0085\u2028\u2029] | Common
VERBATIUM_STRING: '@"' (~'"' | '""')* '"';
INTERPOLATED_REGULAR_STRING_START: '$"'
{ interpolatedStringLevel++; interpolatedVerbatiums.push(false); verbatium = false; } -> pushMode(INTERPOLATION_STRING);
INTERPOLATED_VERBATIUM_STRING_START: '$@"'
INTERPOLATED_VERBATIUM_STRING_START: ('$@"' | '@$"')
{ interpolatedStringLevel++; interpolatedVerbatiums.push(true); verbatium = true; } -> pushMode(INTERPOLATION_STRING);
//B.1.9 Operators And Punctuators

View File

@ -162,6 +162,17 @@ public class CsTokenizerTest {
assertEquals("using", tokens.getTokens().get(0).toString());
}
@Test
public void testInterpolatedVerbatimStrings() {
tokenizer.setIgnoreUsings(true);
tokenizer.tokenize(toSourceCode(
"var test = $@\"test\";\n"
+ "var test2 = @$\"test\";"),
tokens
);
assertEquals(15, tokens.size());
}
private SourceCode toSourceCode(String source) {
return new SourceCode(new SourceCode.StringCodeLoader(source));
}