Skip to content

Commit 25d86b6

Browse files
authored
Update java highlight mode to support 21 version features (#5343)
* update java highlight mode to 21 version * re-generate tokens * allow user-defined template processors * highlight record name as identifier
1 parent 3086776 commit 25d86b6

File tree

5 files changed

+335
-70
lines changed

5 files changed

+335
-70
lines changed

demo/kitchen-sink/docs/java.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,31 @@ public class InfiniteLoop {
99
* Taken from:
1010
* http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/
1111
*/
12+
@Override
1213
public static void main(String[] args) {
1314
double d = Double.parseDouble("2.2250738585072012e-308");
1415

1516
// unreachable code
1617
System.out.println("Value: " + d);
1718
}
1819
}
20+
21+
String name = "Joan"; String info = STR."My name is \{name}";
22+
23+
STR."Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature()++ } degrees \{ getUnit() }"
24+
25+
String nestedMultilineTemplates() {
26+
return STR."""
27+
{
28+
"outerKey1": "outerValue1",
29+
"nestedTemplate": "\{
30+
STR."""
31+
{
32+
"innerKey": "\{innerValue.get()}"
33+
}
34+
"""
35+
}",
36+
"outerKey2": "outerValue2"
37+
}
38+
""";
39+
}

src/mode/_test/tokens_drools.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@
449449
["text"," "],
450450
["identifier","a"],
451451
["text","."],
452-
["identifier","toString"],
452+
["entity.name.function","toString"],
453453
["lparen","("],
454454
["rparen",")"],
455455
["text",";"]
@@ -462,7 +462,7 @@
462462
["lparen","("],
463463
["identifier","$s"],
464464
["text","."],
465-
["identifier","trim"],
465+
["entity.name.function","trim"],
466466
["lparen","("],
467467
["rparen","))"],
468468
["text",";"]
@@ -566,7 +566,7 @@
566566
["text","."],
567567
["identifier","out"],
568568
["text","."],
569-
["identifier","println"],
569+
["entity.name.function","println"],
570570
["lparen","("],
571571
["text"," "],
572572
["identifier","$s"],
@@ -681,7 +681,7 @@
681681
["text","."],
682682
["identifier","out"],
683683
["text","."],
684-
["identifier","println"],
684+
["entity.name.function","println"],
685685
["lparen","("],
686686
["text"," "],
687687
["string","\"office is in the house\""],
@@ -734,7 +734,7 @@
734734
["text","."],
735735
["identifier","out"],
736736
["text","."],
737-
["identifier","println"],
737+
["entity.name.function","println"],
738738
["lparen","("],
739739
["text"," "],
740740
["string","\"Draw in the House\""],
@@ -884,7 +884,7 @@
884884
["text","."],
885885
["identifier","out"],
886886
["text","."],
887-
["identifier","println"],
887+
["entity.name.function","println"],
888888
["lparen","("],
889889
["text"," "],
890890
["string","\"monster right\""],
@@ -909,7 +909,7 @@
909909
["text"," "],
910910
["keyword","new"],
911911
["text"," "],
912-
["identifier","Direction"],
912+
["entity.name.function","Direction"],
913913
["lparen","("],
914914
["identifier","$df"],
915915
["text","."],

src/mode/_test/tokens_java.json

Lines changed: 148 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
[[
22
"start",
3+
["keyword","import"],
4+
["text"," "],
5+
["identifier","java"],
6+
["text","."],
7+
["identifier","util"],
8+
["text","."],
9+
["identifier","ArrayList"],
10+
["text",";"]
11+
],[
12+
"start",
13+
["keyword","import"],
14+
["text"," "],
15+
["identifier","java"],
16+
["text","."],
17+
["identifier","util"],
18+
["text","."],
19+
["identifier","Vector"],
20+
["text",";"]
21+
],[
22+
"start"
23+
],[
24+
"start",
325
["keyword","public"],
426
["text"," "],
527
["keyword","class"],
@@ -28,6 +50,10 @@
2850
],[
2951
"start",
3052
["comment"," */"]
53+
],[
54+
"start",
55+
["text"," "],
56+
["storage.type.annotation","@Override"]
3157
],[
3258
"start",
3359
["text"," "],
@@ -37,7 +63,7 @@
3763
["text"," "],
3864
["keyword","void"],
3965
["text"," "],
40-
["identifier","main"],
66+
["entity.name.function","main"],
4167
["lparen","("],
4268
["support.function","String"],
4369
["lparen","["],
@@ -58,7 +84,7 @@
5884
["text"," "],
5985
["support.function","Double"],
6086
["text","."],
61-
["identifier","parseDouble"],
87+
["entity.name.function","parseDouble"],
6288
["lparen","("],
6389
["string","\"2.2250738585072012e-308\""],
6490
["rparen",")"],
@@ -76,7 +102,7 @@
76102
["text","."],
77103
["identifier","out"],
78104
["text","."],
79-
["identifier","println"],
105+
["entity.name.function","println"],
80106
["lparen","("],
81107
["string","\"Value: \""],
82108
["text"," "],
@@ -87,42 +113,143 @@
87113
["text",";"]
88114
],[
89115
"start",
90-
["text"," "],
91-
["keyword","int"],
116+
["text"," "],
117+
["rparen","}"]
118+
],[
119+
"start",
120+
["rparen","}"]
121+
],[
122+
"start"
123+
],[
124+
"start",
125+
["support.function","String"],
92126
["text"," "],
93-
["identifier","exports"],
127+
["identifier","name"],
94128
["text"," "],
95129
["keyword.operator","="],
96130
["text"," "],
97-
["constant.numeric","10"],
98-
["text",";"]
99-
],[
100-
"start",
101-
["text"," "],
102-
["keyword","int"],
131+
["string","\"Joan\""],
132+
["text","; "],
133+
["support.function","String"],
103134
["text"," "],
104-
["identifier","requires"],
135+
["identifier","info"],
105136
["text"," "],
106137
["keyword.operator","="],
107138
["text"," "],
108-
["constant.numeric","20"],
139+
["identifier","STR"],
140+
["punctuation","."],
141+
["string","\""],
142+
["string","My name is "],
143+
["lparen","\\{"],
144+
["identifier","name"],
145+
["rparen","}"],
146+
["string","\""],
109147
["text",";"]
148+
],[
149+
"start"
110150
],[
111151
"start",
112-
["text"," "],
113-
["keyword","int"],
152+
["identifier","STR"],
153+
["punctuation","."],
154+
["string","\""],
155+
["string","Today's weather is "],
156+
["lparen","\\{"],
157+
["text"," "],
158+
["entity.name.function","getFeelsLike"],
159+
["lparen","("],
160+
["rparen",")"],
114161
["text"," "],
115-
["identifier","open"],
162+
["rparen","}"],
163+
["string",", with a temperature of "],
164+
["lparen","\\{"],
116165
["text"," "],
117-
["keyword.operator","="],
166+
["entity.name.function","getTemperature"],
167+
["lparen","("],
168+
["rparen",")"],
169+
["keyword.operator","++"],
118170
["text"," "],
119-
["constant.numeric","30"],
120-
["text",";"]
171+
["rparen","}"],
172+
["string"," degrees "],
173+
["lparen","\\{"],
174+
["text"," "],
175+
["entity.name.function","getUnit"],
176+
["lparen","("],
177+
["rparen",")"],
178+
["text"," "],
179+
["rparen","}"],
180+
["string","\""]
181+
],[
182+
"start"
121183
],[
122184
"start",
185+
["support.function","String"],
186+
["text"," "],
187+
["entity.name.function","nestedMultilineTemplates"],
188+
["lparen","("],
189+
["rparen",")"],
190+
["text"," "],
191+
["lparen","{"]
192+
],[
193+
"punctuation",
123194
["text"," "],
124-
["rparen","}"]
195+
["keyword","return"],
196+
["text"," "],
197+
["identifier","STR"],
198+
["punctuation","."],
199+
["string","\"\"\""]
200+
],[
201+
"punctuation",
202+
["string"," {"]
203+
],[
204+
"punctuation",
205+
["string"," \"outerKey1\": \"outerValue1\","]
206+
],[
207+
["lparen","punctuation"],
208+
["string"," \"nestedTemplate\": \""],
209+
["lparen","\\{"]
210+
],[
211+
["punctuation","lparen","lparen","punctuation"],
212+
["text"," "],
213+
["identifier","STR"],
214+
["punctuation","."],
215+
["string","\"\"\""]
216+
],[
217+
["punctuation","lparen","lparen","punctuation"],
218+
["string"," {"]
219+
],[
220+
["punctuation","lparen","lparen","punctuation"],
221+
["string"," \"innerKey\": \""],
222+
["lparen","\\{"],
223+
["identifier","innerValue"],
224+
["text","."],
225+
["entity.name.function","get"],
226+
["lparen","("],
227+
["rparen",")}"],
228+
["string","\""]
229+
],[
230+
["punctuation","lparen","lparen","punctuation"],
231+
["string"," }"]
232+
],[
233+
["lparen","punctuation"],
234+
["string"," \"\"\""]
235+
],[
236+
"punctuation",
237+
["text"," "],
238+
["rparen","}"],
239+
["string","\","]
240+
],[
241+
"punctuation",
242+
["string"," \"outerKey2\": \"outerValue2\""]
243+
],[
244+
"punctuation",
245+
["string"," }"]
246+
],[
247+
"start",
248+
["string"," \"\"\""],
249+
["text",";"]
125250
],[
126251
"start",
127252
["rparen","}"]
253+
],[
254+
"start"
128255
]]

src/mode/_test/tokens_jsp.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@
9494
["text","."],
9595
["identifier","util"],
9696
["text","."],
97-
["identifier","Date"],
97+
["entity.name.function","Date"],
9898
["lparen","("],
9999
["rparen","))"],
100100
["text","."],
101-
["identifier","toLocaleString"],
101+
["entity.name.function","toLocaleString"],
102102
["lparen","("],
103103
["rparen",")"],
104104
["meta.tag","%>"]
@@ -333,7 +333,7 @@
333333
["text"," "],
334334
["variable.language","request"],
335335
["text","."],
336-
["identifier","getParameterValues"],
336+
["entity.name.function","getParameterValues"],
337337
["lparen","("],
338338
["string","\"id\""],
339339
["rparen",")"],
@@ -367,7 +367,7 @@
367367
["text"," "],
368368
["variable.language","out"],
369369
["text","."],
370-
["identifier","println"],
370+
["entity.name.function","println"],
371371
["lparen","("],
372372
["string","\"You have selected: \""],
373373
["rparen",")"],
@@ -404,7 +404,7 @@
404404
["text"," "],
405405
["variable.language","out"],
406406
["text","."],
407-
["identifier","println"],
407+
["entity.name.function","println"],
408408
["lparen","("],
409409
["identifier","select"],
410410
["lparen","["],
@@ -433,4 +433,4 @@
433433
["meta.tag.punctuation.end-tag-open.xml","</"],
434434
["meta.tag.tag-name.xml","html"],
435435
["meta.tag.punctuation.tag-close.xml",">"]
436-
]]
436+
]]

0 commit comments

Comments
 (0)