Skip to content

Commit 8556e23

Browse files
zzzyxwvutchrisbra
authored andcommitted
runtime(java): Provide support for syntax preview features
Introduce a new API variable "g:java_syntax_previews" whose value must be a list of syntax preview feature numbers. Enumerate the currently supported numbers in a table at the end of the documentation entry for "ft-java-syntax". Also, disable the recognition of String Templates. Despite the withdrawal of this preview feature in its proposed form from the upcoming JDK 23 release and the fact that the JDK 22 release is coming to EOL this September, an earlier iteration of this preview feature was included in JDK 21 (LTS) whose EOL is projected to fall due in late 2028 and, therefore, retain the current implementation. Define "g:java_syntax_previews" and include number 430 in its list to enable the recognition of String Templates: ------------------------------------------------------------ let g:java_syntax_previews = [430] ------------------------------------------------------------ References: https://openjdk.org/jeps/430 (Preview) https://openjdk.org/jeps/459 (Second Preview) https://openjdk.org/jeps/465 (Third Preview) https://mail.openjdk.org/pipermail/amber-spec-experts/2024-April/004106.html closes: #15579 Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent d56c451 commit 8556e23

11 files changed

Lines changed: 152 additions & 96 deletions

runtime/doc/syntax.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 9.1. Last change: 2024 Aug 22
1+
*syntax.txt* For Vim version 9.1. Last change: 2024 Aug 26
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2164,6 +2164,22 @@ This will make the syntax synchronization start 50 lines before the first
21642164
displayed line. The default value is 10. The disadvantage of using a larger
21652165
number is that redrawing can become slow.
21662166

2167+
Significant changes to the Java platform are gradually introduced in the form
2168+
of JDK Enhancement Proposals (JEPs) that can be implemented for a release and
2169+
offered as its preview features. It may take several JEPs and a few release
2170+
cycles for such a feature to become either integrated into the platform or
2171+
withdrawn from this effort. To cater for early adopters, there is optional
2172+
support in Vim for syntax related preview features that are implemented. You
2173+
can request it by specifying a list of preview feature numbers as follows: >
2174+
:let g:java_syntax_previews = [430]
2175+
2176+
The supported JEP numbers are to be drawn from this table:
2177+
`430`: String Templates [JDK 21]
2178+
2179+
Note that as soon as the particular preview feature will have been integrated
2180+
into the Java platform, its entry will be removed from the table and related
2181+
optionality will be discontinued.
2182+
21672183

21682184
JSON *json.vim* *ft-json-syntax* *g:vim_json_conceal*
21692185
*g:vim_json_warnings*

runtime/syntax/java.vim

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
44
" Former Maintainer: Claudio Fleiner <claudio@fleiner.com>
55
" Repository: https://github.com/zzzyxwvut/java-vim.git
6-
" Last Change: 2024 Aug 22
6+
" Last Change: 2024 Aug 26
77

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

@@ -30,6 +30,10 @@ function! s:ff.RightConstant(x, y) abort
3030
return a:y
3131
endfunction
3232

33+
function! s:ff.IsRequestedPreviewFeature(n) abort
34+
return exists("g:java_syntax_previews") && index(g:java_syntax_previews, a:n) + 1
35+
endfunction
36+
3337
if !exists("*s:ReportOnce")
3438
function s:ReportOnce(message) abort
3539
echomsg 'syntax/java.vim: ' . a:message
@@ -367,9 +371,14 @@ syn match javaSpecialChar contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnf
367371
syn region javaString start=+"+ end=+"+ end=+$+ contains=javaSpecialChar,javaSpecialError,@Spell
368372
syn region javaString start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
369373
syn match javaTextBlockError +"""\s*"""+
370-
syn region javaStrTemplEmbExp contained matchgroup=javaStrTempl start="\\{" end="}" contains=TOP
371-
exec 'syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="+ end=+"+ contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,@Spell'
372-
exec 'syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell'
374+
375+
if s:ff.IsRequestedPreviewFeature(430)
376+
syn region javaStrTemplEmbExp contained matchgroup=javaStrTempl start="\\{" end="}" contains=TOP
377+
exec 'syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="+ end=+"+ contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,@Spell'
378+
exec 'syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell'
379+
hi def link javaStrTempl Macro
380+
endif
381+
373382
syn match javaCharacter "'[^']*'" contains=javaSpecialChar,javaSpecialCharError
374383
syn match javaCharacter "'\\''" contains=javaSpecialChar
375384
syn match javaCharacter "'[^\\]'"
@@ -441,11 +450,16 @@ if exists("g:java_highlight_debug")
441450
syn match javaDebugSpecial contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
442451
syn region javaDebugString contained start=+"+ end=+"+ contains=javaDebugSpecial
443452
syn region javaDebugString contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugSpecial,javaDebugTextBlockError
444-
" The highlight groups of java{StrTempl,Debug{,Paren,StrTempl}}\,
445-
" share one colour by default. Do not conflate unrelated parens.
446-
syn region javaDebugStrTemplEmbExp contained matchgroup=javaDebugStrTempl start="\\{" end="}" contains=javaComment,javaLineComment,javaDebug\%(Paren\)\@!.*
447-
exec 'syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="+ end=+"+ contains=javaDebugStrTemplEmbExp,javaDebugSpecial'
448-
exec 'syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugStrTemplEmbExp,javaDebugSpecial,javaDebugTextBlockError'
453+
454+
if s:ff.IsRequestedPreviewFeature(430)
455+
" The highlight groups of java{StrTempl,Debug{,Paren,StrTempl}}\,
456+
" share one colour by default. Do not conflate unrelated parens.
457+
syn region javaDebugStrTemplEmbExp contained matchgroup=javaDebugStrTempl start="\\{" end="}" contains=javaComment,javaLineComment,javaDebug\%(Paren\)\@!.*
458+
exec 'syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="+ end=+"+ contains=javaDebugStrTemplEmbExp,javaDebugSpecial'
459+
exec 'syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugStrTemplEmbExp,javaDebugSpecial,javaDebugTextBlockError'
460+
hi def link javaDebugStrTempl Macro
461+
endif
462+
449463
syn match javaDebugTextBlockError contained +"""\s*"""+
450464
syn match javaDebugCharacter contained "'[^\\]'"
451465
syn match javaDebugSpecialCharacter contained "'\\.'"
@@ -471,7 +485,6 @@ if exists("g:java_highlight_debug")
471485

472486
hi def link javaDebug Debug
473487
hi def link javaDebugString DebugString
474-
hi def link javaDebugStrTempl Macro
475488
hi def link javaDebugTextBlockError Error
476489
hi def link javaDebugType DebugType
477490
hi def link javaDebugBoolean DebugBoolean
@@ -580,7 +593,6 @@ hi def link javaSpecial Special
580593
hi def link javaSpecialError Error
581594
hi def link javaSpecialCharError Error
582595
hi def link javaString String
583-
hi def link javaStrTempl Macro
584596
hi def link javaCharacter Character
585597
hi def link javaSpecialChar SpecialChar
586598
hi def link javaNumber Number
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
>/+0#0000e05#ffffff0@1| |V|I|M|_|T|E|S|T|_|S|E|T|U|P| |l|e|t| |g|:|j|a|v|a|_|s|y|n|t|a|x|_|p|r|e|v|i|e|w|s| |=| |[|4|3|0|]| +0#0000000&@22
2+
@75
3+
@75
4+
@75
5+
|c+0#00e0003&|l|a|s@1| +0#0000000&|S|t|r|i|n|g|T|e|m|p|l|a|t|e|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&@3
6+
|{| @73
7+
@4|s+0#00e0003&|t|a|t|i|c| +0#0000000&|{| @62
8+
@8|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|S|T|R|.|"@2| @40
9+
| +0#e000e06&@7|"| +0#0000000&@65
10+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&| +0#0000000&@57
11+
| +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
12+
| +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
13+
| +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
14+
| +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
15+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"@1| +0#0000000&@43
16+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"@1|\|"|"+0#0000000&@2|)|;| @36
17+
@75
18+
@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
19+
@75
20+
@57|1|,|1| @10|T|o|p|
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
| +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
22
| +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
3+
| +0#e000e06&@7|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"|\|{|"+0#e000002&|\+0#e000e06&|"|\|"|"+0#e000002&|}+0#e000e06&|\|"@1|\|"|"+0#0000000&@2|)|;| @36
44
@75
55
@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
66
> @74
7-
@8|S|t|r|i|n|g| |s|6| |=| |S|T|R| @51
7+
@8|S|t|r|i|n|g| |s|1| |=| |S|T|R| @51
88
@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
9+
@8|S|t|r|i|n|g| |s|2| |=| |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
1010
@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
11+
@8|S|t|r|i|n|g| |s|3| |=| |S|T|R|.|"@2| @47
1212
| +0#e000e06&@11|A|\|s|\| +0#0000000&@58
1313
| +0#e000e06&@11|q|u|i|c|k| |\| +0#0000000&@55
1414
| +0#e000e06&@11|b|r|o|w|n|\|s|\| +0#0000000&@54
@@ -17,4 +17,4 @@
1717
| +0#e000e06&@11|o|v|e|r| |\| +0#0000000&@56
1818
| +0#e000e06&@11|t|h|e|\|s|\| +0#0000000&@56
1919
| +0#e000e06&@11|l|a|z|y| |\| +0#0000000&@56
20-
@57|5@1|,|0|-|1| @7|5|7|%|
20+
@57|1|9|,|0|-|1| @7|2|6|%|
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
| +0#e000e06#ffffff0@11|l|a|z|y| |\| +0#0000000&@56
22
| +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
3+
@8|S|t|r|i|n|g| |s|4| |=| |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
44
@12|.| @61
55
@12|"@2| @59
66
| +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
7+
@8|S|t|r|i|n|g| |s|5| |=| |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| @25
88
@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
99
@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
1010
@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
1111
@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
12+
@8|S|t|r|i|n|g| |s|6| |=| |S|T|R|.|"@2| @47
1313
| +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
1414
@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
1515
@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
1616
@8|}|)|.|a|p@1|l|y|(|w|o@1|f|)| @52
1717
@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
18+
@8|S|t|r|i|n|g| |s|7| |=| |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| @25
1919
@12|.|"@2| @58
20-
@57|7|3|,|4|-|1|3| @6|7|8|%|
20+
@57|3|7|,|4|-|1|3| @6|6|3|%|

runtime/syntax/testdir/dumps/java_string_05.dump renamed to runtime/syntax/testdir/dumps/java_previews_430_03.dump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
| +0#e000e06&@15|t|h|e|\|s|\| +0#0000000&@52
1111
| +0#e000e06&@15|\|{| +0#0000000&|"+0#e000002&|l|a|z|y|"| +0#0000000&|}+0#e000e06&| |"+0#0000000&@2|}+0#e000e06&|\| +0#0000000&@41
1212
| +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
13+
@8|S|t|r|i|n|g| |s|8| |=| |S|T|R| @51
1414
@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
1515
@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
1616
@28|.|a|p@1|l|y|(|w|o@1|f|)| @34
1717
@12|}+0#e000e06&|\|s|!|\|"@1|;+0#0000000&| @54
1818
@4|}| @69
1919
|}| @73
20-
@57|9|1|,|4|-|1|3| @6|B|o|t|
20+
@57|5@1|,|4|-|1|3| @6|B|o|t|

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| @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
1+
>c+0#00e0003#ffffff0|l|a|s@1| +0#0000000&|S|t|r|i|n|g|T|e|s|t|s| @57
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|1|5|%|
20+
@57|1|9|,|3|-|9| @7|5|2|%|

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-
@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|%|
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|
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// VIM_TEST_SETUP let g:java_syntax_previews = [430]
2+
3+
4+
5+
class StringTemplateTests // JDK 21+ (--enable-preview --release 21).
6+
{
7+
static {
8+
System.out.println(STR."""
9+
"
10+
\{"\"\""}
11+
\{"\"\""}\{"\u005c\u0022"}
12+
\{"\"\""}\{"\u005c\u0022"}"
13+
\{"\"\""}\"\{"\u005c\u0022\u005c\u0022"}
14+
\{"\"\""}\"\{"\"\""}\{"\u005c\u0022"}
15+
\{"\"\""}\"\{"\"\""}\""
16+
\{"\"\""}\"\{"\"\""}\""\"""");
17+
18+
String woof = "Woof", dog = "dog", fox = "fox";
19+
20+
String s1 = STR
21+
."A quick brown \{fox} jumps over the lazy \{dog}";
22+
String s2 = STR.process(StringTemplate.RAW
23+
."\"\{woof}\s!\"");
24+
String s3 = STR."""
25+
A\s\
26+
quick \
27+
brown\s\
28+
\{fox} \
29+
jumps\s\
30+
over \
31+
the\s\
32+
lazy \
33+
\{dog}""";
34+
String s4 = STR.process(StringTemplate.RAW
35+
.
36+
"""
37+
"\{woof}\s!\"""");
38+
String s5 = java.util.FormatProcessor.FMT
39+
. "%-14s\{"A\s" + STR . "quick" + "brown"}%s\{fox} "
40+
+ java.util.FormatProcessor.FMT
41+
. "%-20s\{"jumps\sover the\s"
42+
+ STR . "lazy"}%s\{dog}";
43+
String s6 = STR."""
44+
\"\{ // A nested comment.
45+
(new java.util.function.Function<String, String>() {
46+
public String apply(String bay) { return bay; };
47+
}).apply(woof)
48+
}\s!\"""";
49+
String s7 = java.util.FormatProcessor.FMT
50+
."""
51+
%-14s\{STR."""
52+
A\s\
53+
\{ "quick" } \
54+
brown"""}\
55+
%s\{ fox } \
56+
%-20s\{STR."""
57+
jumps\s\
58+
over \
59+
the\s\
60+
\{ "lazy" } """}\
61+
%s\{ dog }""";
62+
String s8 = STR
63+
."\"\{ /* A nested comment. */
64+
((java.util.function.Function<String, String>) bay -> bay)
65+
.apply(woof)
66+
}\s!\"";
67+
}
68+
}

0 commit comments

Comments
 (0)