Skip to content

Commit a2c6580

Browse files
authored
runtime(java): Recognise string templates (#14150)
As this is encouraged in the referenced JEPs, "to visually distinguish a string template from a string literal, and a text block template from a text block", the default colours for java\%[Debug]StrTempl are made distinct from java\%[Debug]String. According to §3.2 Lexical Translations (JLS, c. 1996 or any more recent version), line terminators, white space, and comments are discarded before tokens are accepted. Since a template expression comprises a template processor, a dot, and a template, it may be visually appealing to break up its head across a few lines whenever its tail already spans multiple lines. Curiously, no allowance for it is made in the distributed tests for OpenJDK 21; the proposed regexp patterns take in consideration a line terminator and white space after a dot. References: https://openjdk.org/jeps/430 (Preview) https://openjdk.org/jeps/459 (Second Preview) https://openjdk.org/jeps/465 Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 5d67aef commit a2c6580

9 files changed

Lines changed: 165 additions & 35 deletions

File tree

runtime/syntax/java.vim

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Java
33
" Maintainer: Claudio Fleiner <claudio@fleiner.com>
44
" URL: https://github.com/fleiner/vim/blob/master/runtime/syntax/java.vim
5-
" Last Change: 2024 Mar 02
5+
" Last Change: 2024 Mar 06
66

77
" Please check :help java.vim for comments on some of the options available.
88

@@ -187,8 +187,8 @@ if exists("java_comment_strings")
187187
syn match javaCommentCharacter contained "'\\[^']\{1,6\}'" contains=javaSpecialChar
188188
syn match javaCommentCharacter contained "'\\''" contains=javaSpecialChar
189189
syn match javaCommentCharacter contained "'[^\\]'"
190-
syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber
191-
syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber
190+
syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber,javaStrTempl
191+
syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber,javaStrTempl
192192
endif
193193

194194
syn region javaComment start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
@@ -234,6 +234,9 @@ syn match javaSpecialChar contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstn
234234
syn region javaString start=+"+ end=+"+ end=+$+ contains=javaSpecialChar,javaSpecialError,@Spell
235235
syn region javaString start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
236236
syn match javaTextBlockError +"""\s*"""+
237+
syn region javaStrTemplEmbExp contained matchgroup=javaStrTempl start="\\{" end="}" contains=TOP
238+
syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@<="+ end=+"+ contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,@Spell
239+
syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
237240
" The next line is commented out, it can cause a crash for a long line
238241
"syn match javaStringError +"\%([^"\\]\|\\.\)*$+
239242
syn match javaCharacter "'[^']*'" contains=javaSpecialChar,javaSpecialCharError
@@ -254,7 +257,7 @@ syn match javaNumber "\<0[xX]\%(\x\%(_*\x\)*\.\=\|\%(\x\%(_*\x\)*\)\=\.\x\%(
254257
" Unicode characters
255258
syn match javaSpecial "\\u\x\x\x\x"
256259

257-
syn cluster javaTop add=javaString,javaCharacter,javaNumber,javaSpecial,javaStringError,javaTextBlockError
260+
syn cluster javaTop add=javaString,javaStrTempl,javaCharacter,javaNumber,javaSpecial,javaStringError,javaTextBlockError
258261

259262
if exists("java_highlight_functions")
260263
if java_highlight_functions == "indent"
@@ -280,7 +283,12 @@ if exists("java_highlight_debug")
280283
syn match javaDebugSpecial contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
281284
syn region javaDebugString contained start=+"+ end=+"+ contains=javaDebugSpecial
282285
syn region javaDebugString contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugSpecial,javaDebugTextBlockError
283-
" The next line is commented out, it can cause a crash for a long line
286+
" The highlight groups of java{StrTempl,Debug{,Paren,StrTempl}}\,
287+
" share one colour by default. Do not conflate unrelated parens.
288+
syn region javaDebugStrTemplEmbExp contained matchgroup=javaDebugStrTempl start="\\{" end="}" contains=javaComment,javaLineComment,javaDebug\%(Paren\)\@!.*
289+
syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@<="+ end=+"+ contains=javaDebugStrTemplEmbExp,javaDebugSpecial
290+
syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugStrTemplEmbExp,javaDebugSpecial,javaDebugTextBlockError
291+
" The next line is commented out, it can cause a crash for a long line
284292
" syn match javaDebugStringError contained +"\%([^"\\]\|\\.\)*$+
285293
syn match javaDebugTextBlockError contained +"""\s*"""+
286294
syn match javaDebugCharacter contained "'[^\\]'"
@@ -307,6 +315,7 @@ if exists("java_highlight_debug")
307315

308316
hi def link javaDebug Debug
309317
hi def link javaDebugString DebugString
318+
hi def link javaDebugStrTempl Macro
310319
hi def link javaDebugStringError javaError
311320
hi def link javaDebugTextBlockError javaDebugStringError
312321
hi def link javaDebugType DebugType
@@ -376,6 +385,7 @@ hi def link javaSpecial Special
376385
hi def link javaSpecialError Error
377386
hi def link javaSpecialCharError Error
378387
hi def link javaString String
388+
hi def link javaStrTempl Macro
379389
hi def link javaCharacter Character
380390
hi def link javaSpecialChar SpecialChar
381391
hi def link javaNumber Number

runtime/syntax/testdir/dumps/java_string_00.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
>c+0#00e0003#ffffff0|l|a|s@1| +0#0000000&|S|t|r|i|n|g|T|e|s|t|s| @57
1+
>c+0#00e0003#ffffff0|l|a|s@1| +0#0000000&|S|t|r|i|n|g|T|e|s|t|s| @2|/+0#0000e05&@1| |J|D|K| |2|1|+| |(|-@1|e|n|a|b|l|e|-|p|r|e|v|i|e|w| |-@1|r|e|l|e|a|s|e| |2|1|)|.| +0#0000000&@11
22
|{| @73
33
@4|s+0#00e0003&|t|a|t|i|c| +0#0000000&|{| @62
44
@8|S|t|r|i|n|g| |s|1| |=| |"+0#e000002&|A| |q|u|i|c|k| |b|r|o|w|n| |f|o|x| |j|u|m|p|s| |o|v|e|r| |t|h|e| |l|a|z|y| |d|o|g|"|;+0#0000000&| @10

runtime/syntax/testdir/dumps/java_string_01.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
@8|/+0#0000e05&@1| |T|h|e|r|e| |a|r|e| |S|P|A|C|E|,| |F@1|,| |H|T|,| |C|R|,| |a|n|d| |L|F| |a|f|t|e|r| |"@2|.| +0#0000000&@17
1818
@8|S|t|r|i|n|g| |e|m|p|t|y| |=| |"@2| |^+0#0000e05&|L| +0#0000000&@2|^+0#0000e05&|M| +0#0000000&@40
1919
| +0#e000002&@11|"+0#0000000&@2|;| @58
20-
@57|1|9|,|3|-|9| @7|5|2|%|
20+
@57|1|9|,|3|-|9| @7|1|5|%|

runtime/syntax/testdir/dumps/java_string_02.dump

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1| +0#0000000&@48
1010
| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&| +0#0000000&@57
1111
| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&|\+0#e000e06&|"|"+0#0000000&@2|)|;| @50
12-
@4|}| @69
13-
|}| @73
14-
|~+0#4040ff13&| @73
15-
|~| @73
16-
|~| @73
17-
|~| @73
18-
|~| @73
19-
|~| @73
20-
| +0#0000000&@56|3|7|,|3|-|9| @7|B|o|t|
12+
@75
13+
@8|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|S|T|R|.|"@2| @40
14+
| +0#e000e06&@7|"| +0#0000000&@65
15+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&| +0#0000000&@57
16+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|{|"+0#e000002&|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1|"+0#e000002&|}+0#e000e06&| +0#0000000&@40
17+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|{|"+0#e000002&|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1|"+0#e000002&|}+0#e000e06&|"| +0#0000000&@39
18+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1|\|u|0@1|5|c|\|u|0@1|2@1|"+0#e000002&|}+0#e000e06&| +0#0000000&@26
19+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|{|"+0#e000002&|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1|"+0#e000002&|}+0#e000e06&| +0#0000000&@29
20+
@57|3|7|,|3|-|9| @7|3|6|%|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +0#e000e06#ffffff0@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|{|"+0#e000002&|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1|"+0#e000002&|}+0#e000e06&| +0#0000000&@29
2+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"@1| +0#0000000&@43
3+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"@1|\|"|"+0#0000000&@2|)|;| @5|/+0#0000e05&@1| |J|D|K| |2|1|+|.| +0#0000000&@19
4+
@75
5+
@8|S|t|r|i|n|g| |w|o@1|f| |=| |"+0#e000002&|W|o@1|f|"|,+0#0000000&| |d|o|g| |=| |"+0#e000002&|d|o|g|"|,+0#0000000&| |f|o|x| |=| |"+0#e000002&|f|o|x|"|;+0#0000000&| @19
6+
> @74
7+
@8|S|t|r|i|n|g| |s|6| |=| |S|T|R| @51
8+
@12|.|"+0#e000e06&|A| |q|u|i|c|k| |b|r|o|w|n| |\|{|f+0#0000000&|o|x|}+0#e000e06&| |j|u|m|p|s| |o|v|e|r| |t|h|e| |l|a|z|y| |\|{|d+0#0000000&|o|g|}+0#e000e06&|"|;+0#0000000&| @11
9+
@8|S|t|r|i|n|g| |s|7| |=| |S|T|R|.|p|r|o|c|e|s@1|(|S|t|r|i|n|g|T|e|m|p|l|a|t|e|.|R|A|W| @24
10+
@12|.|"+0#e000e06&|\|"|\|{|w+0#0000000&|o@1|f|}+0#e000e06&|\|s|!|\|"@1|)+0#0000000&|;| @43
11+
@8|S|t|r|i|n|g| |s|8| |=| |S|T|R|.|"@2| @47
12+
| +0#e000e06&@11|A|\|s|\| +0#0000000&@58
13+
| +0#e000e06&@11|q|u|i|c|k| |\| +0#0000000&@55
14+
| +0#e000e06&@11|b|r|o|w|n|\|s|\| +0#0000000&@54
15+
| +0#e000e06&@11|\|{|f+0#0000000&|o|x|}+0#e000e06&| |\| +0#0000000&@54
16+
| +0#e000e06&@11|j|u|m|p|s|\|s|\| +0#0000000&@54
17+
| +0#e000e06&@11|o|v|e|r| |\| +0#0000000&@56
18+
| +0#e000e06&@11|t|h|e|\|s|\| +0#0000000&@56
19+
| +0#e000e06&@11|l|a|z|y| |\| +0#0000000&@56
20+
@57|5@1|,|0|-|1| @7|5|7|%|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +0#e000e06#ffffff0@11|l|a|z|y| |\| +0#0000000&@56
2+
| +0#e000e06&@11|\|{|d+0#0000000&|o|g|}+0#e000e06&|"+0#0000000&@2|;| @52
3+
@8|S|t|r|i|n|g| |s|9| |=| |S|T|R|.|p|r|o|c|e|s@1|(|S|t|r|i|n|g|T|e|m|p|l|a|t|e|.|R|A|W| @24
4+
@12|.| @61
5+
@12|"@2| @59
6+
| +0#e000e06&@11>"|\|{|w+0#0000000&|o@1|f|}+0#e000e06&|\|s|!|\|"|"+0#0000000&@2|)|;| @44
7+
@8|S|t|r|i|n|g| |s|1|0| |=| |j|a|v|a|.|u|t|i|l|.|F|o|r|m|a|t|P|r|o|c|e|s@1|o|r|.|F|M|T| @24
8+
@12|.| |"+0#e000e06&|%|-|1|4|s|\|{|"+0#e000002&|A|\+0#e000e06&|s|"+0#e000002&| +0#0000000&|+| |S|T|R| |.| |"+0#e000e06&|q|u|i|c|k|"| +0#0000000&|+| |"+0#e000002&|b|r|o|w|n|"|}+0#e000e06&|%|s|\|{|f+0#0000000&|o|x|}+0#e000e06&| |"| +0#0000000&@10
9+
@12|+| |j|a|v|a|.|u|t|i|l|.|F|o|r|m|a|t|P|r|o|c|e|s@1|o|r|.|F|M|T| @31
10+
@12|.| |"+0#e000e06&|%|-|2|0|s|\|{|"+0#e000002&|j|u|m|p|s|\+0#e000e06&|s|o+0#e000002&|v|e|r| |t|h|e|\+0#e000e06&|s|"+0#e000002&| +0#0000000&@33
11+
@20|+| |S|T|R| |.| |"+0#e000e06&|l|a|z|y|"|}|%|s|\|{|d+0#0000000&|o|g|}+0#e000e06&|"|;+0#0000000&| @29
12+
@8|S|t|r|i|n|g| |s|1@1| |=| |S|T|R|.|"@2| @46
13+
| +0#e000e06&@11|\|"|\|{| +0#0000000&@11|/+0#0000e05&@1| |A| |n|e|s|t|e|d| |c|o|m@1|e|n|t|.| +0#0000000&@26
14+
@8|(|n+0#af5f00255&|e|w| +0#0000000&|j|a|v|a|.|u|t|i|l|.|f|u|n|c|t|i|o|n|.|F|u|n|c|t|i|o|n|<|S|t|r|i|n|g|,| |S|t|r|i|n|g|>|(|)| |{| @14
15+
@12|p+0#00e0003&|u|b|l|i|c| +0#0000000&|S|t|r|i|n|g| |a|p@1|l|y|(|S|t|r|i|n|g| |b|a|y|)| |{| |r+0#af5f00255&|e|t|u|r|n| +0#0000000&|b|a|y|;| |}|;| @14
16+
@8|}|)|.|a|p@1|l|y|(|w|o@1|f|)| @52
17+
@12|}+0#e000e06&|\|s|!|\|"|"+0#0000000&@2|;| @52
18+
@8|S|t|r|i|n|g| |s|1|2| |=| |j|a|v|a|.|u|t|i|l|.|F|o|r|m|a|t|P|r|o|c|e|s@1|o|r|.|F|M|T| @24
19+
@12|.|"@2| @58
20+
@57|7|3|,|4|-|1|3| @6|7|8|%|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +0&#ffffff0@11|.|"@2| @58
2+
| +0#e000e06&@11|%|-|1|4|s|\|{|S+0#0000000&|T|R|.|"@2| @48
3+
| +0#e000e06&@15|A|\|s|\| +0#0000000&@54
4+
| +0#e000e06&@15|\|{| +0#0000000&|"+0#e000002&|q|u|i|c|k|"| +0#0000000&|}+0#e000e06&| |\| +0#0000000&@44
5+
| +0#e000e06&@15|b|r|o|w|n|"+0#0000000&@2|}+0#e000e06&|\| +0#0000000&@48
6+
| +0#e000e06&@11>%|s|\|{| +0#0000000&|f|o|x| |}+0#e000e06&| |\| +0#0000000&@50
7+
| +0#e000e06&@11|%|-|2|0|s|\|{|S+0#0000000&|T|R|.|"@2| @48
8+
| +0#e000e06&@15|j|u|m|p|s|\|s|\| +0#0000000&@50
9+
| +0#e000e06&@15|o|v|e|r| |\| +0#0000000&@52
10+
| +0#e000e06&@15|t|h|e|\|s|\| +0#0000000&@52
11+
| +0#e000e06&@15|\|{| +0#0000000&|"+0#e000002&|l|a|z|y|"| +0#0000000&|}+0#e000e06&| |"+0#0000000&@2|}+0#e000e06&|\| +0#0000000&@41
12+
| +0#e000e06&@11|%|s|\|{| +0#0000000&|d|o|g| |}+0#e000e06&|"+0#0000000&@2|;| @48
13+
@8|S|t|r|i|n|g| |s|1|3| |=| |S|T|R| @50
14+
@12|.|"+0#e000e06&|\|"|\|{| +0#0000000&@9|/+0#0000e05&|*| |A| |n|e|s|t|e|d| |c|o|m@1|e|n|t|.| |*|/| +0#0000000&@23
15+
@8|(@1|j|a|v|a|.|u|t|i|l|.|f|u|n|c|t|i|o|n|.|F|u|n|c|t|i|o|n|<|S|t|r|i|n|g|,| |S|t|r|i|n|g|>|)| |b|a|y| |-|>| |b|a|y|)| @8
16+
@28|.|a|p@1|l|y|(|w|o@1|f|)| @34
17+
@12|}+0#e000e06&|\|s|!|\|"@1|;+0#0000000&| @54
18+
@4|}| @69
19+
|}| @73
20+
@57|9|1|,|4|-|1|3| @6|B|o|t|
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
| +0#e000002#ffffff0@11|t|h|e|\+0#e000e06&@1|s+0#e000002&|\+0#e000e06&@1| +0#0000000&@54
2-
| +0#e000002&@11|l|a|z|y| |\+0#e000e06&@1| +0#0000000&@55
3-
| +0#e000002&@11|d|o|g|\+0#e000e06&|"|"+0#e000002&@1|;|"+0#0000000&@2|;| @50
4-
@75
5-
@8|/+0#0000e05&@1| |T|h|e|r|e| |a|r|e| |S|P|A|C|E|,| |F@1|,| |H|T|,| |C|R|,| |a|n|d| |L|F| |a|f|t|e|r| |"@2|.| +0#0000000&@17
6-
@8|S|t|r|i|n|g| |e|m|p|t|y| |=| |"@2| |^+0#0000e05&|L| +0#0000000&@2|^+0#0000e05&|M| +0#0000000&@40
7-
| +0#e000002&@11|"+0#0000000&@2|;| @58
8-
@75
9-
@8|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"@2| @44
10-
| +0#e000002&@7|"| +0#0000000&@65
11-
| +0#e000002&@7|"@1| +0#0000000&@64
12-
| +0#e000002&@7|"@1|\+0#e000e06&|u|0@1|5|c|"+0#e000002&| +0#0000000&@57
13-
| +0#e000002&@7|"@1|\+0#e000e06&|u|0@1|5|c|"+0#e000002&@1| +0#0000000&@56
14-
| +0#e000002&@7|"@1|\+0#e000e06&|"|\|u|0@1|2@1|\|u|0@1|2@1| +0#0000000&@50
15-
| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1| +0#0000000&@48
16-
| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&| +0#0000000&@57
17-
| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&|\+0#e000e06&|"|"+0#0000000&@2|)|;| @50
1+
| +0&#ffffff0@11|.|"@2| @58
2+
| +0#e000e06&@11|%|-|1|4|s|\|{|S+0#0000000&|T|R|.|"@2| @48
3+
| +0#e000e06&@15|A|\|s|\| +0#0000000&@54
4+
| +0#e000e06&@15|\|{| +0#0000000&|"+0#e000002&|q|u|i|c|k|"| +0#0000000&|}+0#e000e06&| |\| +0#0000000&@44
5+
| +0#e000e06&@15|b|r|o|w|n|"+0#0000000&@2|}+0#e000e06&|\| +0#0000000&@48
6+
| +0#e000e06&@11|%|s|\|{| +0#0000000&|f|o|x| |}+0#e000e06&| |\| +0#0000000&@50
7+
| +0#e000e06&@11|%|-|2|0|s|\|{|S+0#0000000&|T|R|.|"@2| @48
8+
| +0#e000e06&@15|j|u|m|p|s|\|s|\| +0#0000000&@50
9+
| +0#e000e06&@15|o|v|e|r| |\| +0#0000000&@52
10+
| +0#e000e06&@15|t|h|e|\|s|\| +0#0000000&@52
11+
| +0#e000e06&@15|\|{| +0#0000000&|"+0#e000002&|l|a|z|y|"| +0#0000000&|}+0#e000e06&| |"+0#0000000&@2|}+0#e000e06&|\| +0#0000000&@41
12+
| +0#e000e06&@11|%|s|\|{| +0#0000000&|d|o|g| |}+0#e000e06&|"+0#0000000&@2|;| @48
13+
@8|S|t|r|i|n|g| |s|1|3| |=| |S|T|R| @50
14+
@12|.|"+0#e000e06&|\|"|\|{| +0#0000000&@9|/+0#0000e05&|*| |A| |n|e|s|t|e|d| |c|o|m@1|e|n|t|.| |*|/| +0#0000000&@23
15+
@8|(@1|j|a|v|a|.|u|t|i|l|.|f|u|n|c|t|i|o|n|.|F|u|n|c|t|i|o|n|<|S|t|r|i|n|g|,| |S|t|r|i|n|g|>|)| |b|a|y| |-|>| |b|a|y|)| @8
16+
@28|.|a|p@1|l|y|(|w|o@1|f|)| @34
17+
@12|}+0#e000e06&|\|s|!|\|"@1|;+0#0000000&| @54
1818
@4|}| @69
1919
>}| @73
20-
@57|4@1|,|1| @9|B|o|t|
20+
@57|1|0|4|,|1| @8|B|o|t|

runtime/syntax/testdir/input/java_string.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class StringTests
1+
class StringTests // JDK 21+ (--enable-preview --release 21).
22
{
33
static {
44
String s1 = "A quick brown fox jumps over the lazy dog";
@@ -40,5 +40,65 @@ class StringTests
4040
""\"""\u005c\u0022
4141
""\"""\""
4242
""\"""\""\"""");
43+
44+
System.out.println(STR."""
45+
"
46+
\{"\"\""}
47+
\{"\"\""}\{"\u005c\u0022"}
48+
\{"\"\""}\{"\u005c\u0022"}"
49+
\{"\"\""}\"\{"\u005c\u0022\u005c\u0022"}
50+
\{"\"\""}\"\{"\"\""}\{"\u005c\u0022"}
51+
\{"\"\""}\"\{"\"\""}\""
52+
\{"\"\""}\"\{"\"\""}\""\""""); // JDK 21+.
53+
54+
String woof = "Woof", dog = "dog", fox = "fox";
55+
56+
String s6 = STR
57+
."A quick brown \{fox} jumps over the lazy \{dog}";
58+
String s7 = STR.process(StringTemplate.RAW
59+
."\"\{woof}\s!\"");
60+
String s8 = STR."""
61+
A\s\
62+
quick \
63+
brown\s\
64+
\{fox} \
65+
jumps\s\
66+
over \
67+
the\s\
68+
lazy \
69+
\{dog}""";
70+
String s9 = STR.process(StringTemplate.RAW
71+
.
72+
"""
73+
"\{woof}\s!\"""");
74+
String s10 = java.util.FormatProcessor.FMT
75+
. "%-14s\{"A\s" + STR . "quick" + "brown"}%s\{fox} "
76+
+ java.util.FormatProcessor.FMT
77+
. "%-20s\{"jumps\sover the\s"
78+
+ STR . "lazy"}%s\{dog}";
79+
String s11 = STR."""
80+
\"\{ // A nested comment.
81+
(new java.util.function.Function<String, String>() {
82+
public String apply(String bay) { return bay; };
83+
}).apply(woof)
84+
}\s!\"""";
85+
String s12 = java.util.FormatProcessor.FMT
86+
."""
87+
%-14s\{STR."""
88+
A\s\
89+
\{ "quick" } \
90+
brown"""}\
91+
%s\{ fox } \
92+
%-20s\{STR."""
93+
jumps\s\
94+
over \
95+
the\s\
96+
\{ "lazy" } """}\
97+
%s\{ dog }""";
98+
String s13 = STR
99+
."\"\{ /* A nested comment. */
100+
((java.util.function.Function<String, String>) bay -> bay)
101+
.apply(woof)
102+
}\s!\"";
43103
}
44104
}

0 commit comments

Comments
 (0)