Skip to content

Commit

Permalink
Merge pull request #4366 from Monits:fix-4346
Browse files Browse the repository at this point in the history
[java] Fix broken TextBlock grammar #4366
  • Loading branch information
adangel committed Jan 27, 2023
2 parents 30a01c4 + 3e29407 commit 8d6068b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 39 deletions.
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ See [the example report](report-examples/html-report-v2.html).
* [#4279](https://github.com/pmd/pmd/issues/4279): \[core] Can not set ruleset property value to empty
* [#4329](https://github.com/pmd/pmd/pull/4329): \[core] Refactor usage of snakeyaml
* [#4340](https://github.com/pmd/pmd/issues/4340): \[core] Allow to filter found matches in CPDReport
* java
* [#4364](https://github.com/pmd/pmd/issues/4364): \[java] Parsing error with textblock containing quote followed by two backslashes
* testing
* [#4236](https://github.com/pmd/pmd/issues/4236): \[test] kotest logs look broken

Expand Down
24 changes: 18 additions & 6 deletions pmd-java/etc/grammar/Java.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -936,12 +936,24 @@ TOKEN :
)*
"\""
>
|
< TEXT_BLOCK_LITERAL:
"\"\"\"" (<HORIZONTAL_WHITESPACE>)* <LINE_TERMINATOR>
( ~["\"", "\\"] | "\"" ~["\""] | "\"\"" ~["\""] | <STRING_ESCAPE> | "\\" <LINE_TERMINATOR> )*
"\"\"\""
>
}

/* TEXT BLOCKS */
MORE :
{
< "\"\"\"" (<HORIZONTAL_WHITESPACE>)* <LINE_TERMINATOR> > : IN_TEXT_BLOCK_LITERAL
}

<IN_TEXT_BLOCK_LITERAL>
TOKEN :
{
<TEXT_BLOCK_LITERAL: "\"\"\"" > : DEFAULT
}

<IN_TEXT_BLOCK_LITERAL>
MORE :
{
< ~["\\"] | <STRING_ESCAPE> | ("\\")? <LINE_TERMINATOR> >
}

/* IDENTIFIERS */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ParserCornersTest {
private final JavaParsingHelper java4 = java.withDefaultVersion("1.4");
private final JavaParsingHelper java5 = java.withDefaultVersion("1.5");
private final JavaParsingHelper java7 = java.withDefaultVersion("1.7");
private final JavaParsingHelper java15 = java.withDefaultVersion("15");

@Rule
public ExpectedException expect = ExpectedException.none();

Expand Down Expand Up @@ -118,6 +120,16 @@ public final void testTryWithResourcesThis() {
+ "}");
}

@Test
public final void testTextBlockWithQuotes() {
// https://github.com/pmd/pmd/issues/4364
java15.parse("public class Foo {\n"
+ " private String content = \"\"\"\n"
+ " <div class=\"invalid-class></div>\n"
+ " \"\"\";\n"
+ "}");
}

/**
* Tests a specific generic notation for calling methods. See:
* https://jira.codehaus.org/browse/MPMD-139
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
L2
[public] 1 6
[class] 8 12
[72] 14 16
[74] 14 16
[{] 18 18
L3
[Foo] 5 7
Expand All @@ -14,16 +14,16 @@ L4
L5
[public] 5 10
[void] 12 15
[72] 17 19
[74] 17 19
[(] 20 20
[)] 21 21
[{] 23 23
L6
[72] 9 11
[74] 9 11
[.] 12 12
[72] 13 15
[74] 13 15
[(] 16 16
[72] 17 19
[74] 17 19
[.] 20 20
[class] 21 25
[Foo] 26 26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,83 @@
L2
[public] 1 6
[class] 8 12
[72] 14 16
[74] 14 16
[extends] 18 24
[72] 26 28
[74] 26 28
[{] 30 30
L4
[private] 5 11
[72] 13 15
[72] 17 31
[74] 13 15
[74] 17 31
L6
[public] 5 10
[Foo] 12 14
[(] 15 15
[int] 16 18
[72] 20 20
[74] 20 20
[)] 21 21
[{] 23 23
[super] 25 29
[(] 30 30
[72] 31 31
[74] 31 31
[)] 32 32
[}] 35 35
L8
[private] 5 11
[Foo] 13 15
[(] 16 16
[int] 17 19
[72] 21 21
[74] 21 21
[,] 22 22
[72] 24 29
[72] 31 31
[74] 24 29
[74] 31 31
[)] 32 32
[{] 34 34
[super] 36 40
[(] 41 41
[72] 42 42
[74] 42 42
[,] 43 43
[72] 45 45
[74] 45 45
[)] 46 46
[}] 49 49
L10
[Foo] 19 21
[(] 22 22
[int] 23 25
[72] 27 27
[74] 27 27
[,] 28 28
[72] 30 35
[72] 37 37
[74] 30 35
[74] 37 37
[,] 38 38
[72] 40 45
[72] 47 47
[74] 40 45
[74] 47 47
[)] 48 48
[{] 50 50
[super] 52 56
[(] 57 57
[72] 58 58
[74] 58 58
[,] 59 59
[72] 61 61
[74] 61 61
[,] 62 62
[72] 64 64
[74] 64 64
[)] 65 65
[}] 68 68
L12
[private] 5 11
[static] 13 18
[class] 20 24
[72] 26 30
[74] 26 30
[{] 32 32
L14
[Inner] 9 13
[(] 14 14
[)] 15 15
[{] 17 17
[72] 19 24
[74] 19 24
[.] 25 25
[72] 26 28
[74] 26 28
[.] 29 29
[72] 30 36
[74] 30 36
[(] 37 37
["Guess who?"] 38 49
[)] 50 50
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[Image] or [Truncated image[ Bcol Ecol
L2
[public] 1 6
[72] 8 11
[72] 13 15
[74] 8 11
[74] 13 15
[{] 17 17
L3
[72] 5 7
[74] 5 7
[(] 8 8
[1] 9 9
[)] 10 10
[,] 11 11
L4
[72] 5 7
[74] 5 7
[(] 8 8
[2] 9 9
[)] 10 10
L6
[Foo] 5 7
[(] 8 8
[int] 9 11
[72] 13 15
[74] 13 15
[)] 16 16
[{] 18 18
L7
Expand Down

0 comments on commit 8d6068b

Please sign in to comment.