Skip to content

Commit

Permalink
Update java highlight mode to support 21 version features (#5343)
Browse files Browse the repository at this point in the history
* update java highlight mode to 21 version

* re-generate tokens

* allow user-defined template processors

* highlight record name as identifier
  • Loading branch information
mkslanc authored Oct 16, 2023
1 parent 3086776 commit 25d86b6
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 70 deletions.
21 changes: 21 additions & 0 deletions demo/kitchen-sink/docs/java.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@ public class InfiniteLoop {
* Taken from:
* http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/
*/
@Override
public static void main(String[] args) {
double d = Double.parseDouble("2.2250738585072012e-308");

// unreachable code
System.out.println("Value: " + d);
}
}

String name = "Joan"; String info = STR."My name is \{name}";

STR."Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature()++ } degrees \{ getUnit() }"

String nestedMultilineTemplates() {
return STR."""
{
"outerKey1": "outerValue1",
"nestedTemplate": "\{
STR."""
{
"innerKey": "\{innerValue.get()}"
}
"""
}",
"outerKey2": "outerValue2"
}
""";
}
14 changes: 7 additions & 7 deletions src/mode/_test/tokens_drools.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
["text"," "],
["identifier","a"],
["text","."],
["identifier","toString"],
["entity.name.function","toString"],
["lparen","("],
["rparen",")"],
["text",";"]
Expand All @@ -462,7 +462,7 @@
["lparen","("],
["identifier","$s"],
["text","."],
["identifier","trim"],
["entity.name.function","trim"],
["lparen","("],
["rparen","))"],
["text",";"]
Expand Down Expand Up @@ -566,7 +566,7 @@
["text","."],
["identifier","out"],
["text","."],
["identifier","println"],
["entity.name.function","println"],
["lparen","("],
["text"," "],
["identifier","$s"],
Expand Down Expand Up @@ -681,7 +681,7 @@
["text","."],
["identifier","out"],
["text","."],
["identifier","println"],
["entity.name.function","println"],
["lparen","("],
["text"," "],
["string","\"office is in the house\""],
Expand Down Expand Up @@ -734,7 +734,7 @@
["text","."],
["identifier","out"],
["text","."],
["identifier","println"],
["entity.name.function","println"],
["lparen","("],
["text"," "],
["string","\"Draw in the House\""],
Expand Down Expand Up @@ -884,7 +884,7 @@
["text","."],
["identifier","out"],
["text","."],
["identifier","println"],
["entity.name.function","println"],
["lparen","("],
["text"," "],
["string","\"monster right\""],
Expand All @@ -909,7 +909,7 @@
["text"," "],
["keyword","new"],
["text"," "],
["identifier","Direction"],
["entity.name.function","Direction"],
["lparen","("],
["identifier","$df"],
["text","."],
Expand Down
169 changes: 148 additions & 21 deletions src/mode/_test/tokens_java.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
[[
"start",
["keyword","import"],
["text"," "],
["identifier","java"],
["text","."],
["identifier","util"],
["text","."],
["identifier","ArrayList"],
["text",";"]
],[
"start",
["keyword","import"],
["text"," "],
["identifier","java"],
["text","."],
["identifier","util"],
["text","."],
["identifier","Vector"],
["text",";"]
],[
"start"
],[
"start",
["keyword","public"],
["text"," "],
["keyword","class"],
Expand Down Expand Up @@ -28,6 +50,10 @@
],[
"start",
["comment"," */"]
],[
"start",
["text"," "],
["storage.type.annotation","@Override"]
],[
"start",
["text"," "],
Expand All @@ -37,7 +63,7 @@
["text"," "],
["keyword","void"],
["text"," "],
["identifier","main"],
["entity.name.function","main"],
["lparen","("],
["support.function","String"],
["lparen","["],
Expand All @@ -58,7 +84,7 @@
["text"," "],
["support.function","Double"],
["text","."],
["identifier","parseDouble"],
["entity.name.function","parseDouble"],
["lparen","("],
["string","\"2.2250738585072012e-308\""],
["rparen",")"],
Expand All @@ -76,7 +102,7 @@
["text","."],
["identifier","out"],
["text","."],
["identifier","println"],
["entity.name.function","println"],
["lparen","("],
["string","\"Value: \""],
["text"," "],
Expand All @@ -87,42 +113,143 @@
["text",";"]
],[
"start",
["text"," "],
["keyword","int"],
["text"," "],
["rparen","}"]
],[
"start",
["rparen","}"]
],[
"start"
],[
"start",
["support.function","String"],
["text"," "],
["identifier","exports"],
["identifier","name"],
["text"," "],
["keyword.operator","="],
["text"," "],
["constant.numeric","10"],
["text",";"]
],[
"start",
["text"," "],
["keyword","int"],
["string","\"Joan\""],
["text","; "],
["support.function","String"],
["text"," "],
["identifier","requires"],
["identifier","info"],
["text"," "],
["keyword.operator","="],
["text"," "],
["constant.numeric","20"],
["identifier","STR"],
["punctuation","."],
["string","\""],
["string","My name is "],
["lparen","\\{"],
["identifier","name"],
["rparen","}"],
["string","\""],
["text",";"]
],[
"start"
],[
"start",
["text"," "],
["keyword","int"],
["identifier","STR"],
["punctuation","."],
["string","\""],
["string","Today's weather is "],
["lparen","\\{"],
["text"," "],
["entity.name.function","getFeelsLike"],
["lparen","("],
["rparen",")"],
["text"," "],
["identifier","open"],
["rparen","}"],
["string",", with a temperature of "],
["lparen","\\{"],
["text"," "],
["keyword.operator","="],
["entity.name.function","getTemperature"],
["lparen","("],
["rparen",")"],
["keyword.operator","++"],
["text"," "],
["constant.numeric","30"],
["text",";"]
["rparen","}"],
["string"," degrees "],
["lparen","\\{"],
["text"," "],
["entity.name.function","getUnit"],
["lparen","("],
["rparen",")"],
["text"," "],
["rparen","}"],
["string","\""]
],[
"start"
],[
"start",
["support.function","String"],
["text"," "],
["entity.name.function","nestedMultilineTemplates"],
["lparen","("],
["rparen",")"],
["text"," "],
["lparen","{"]
],[
"punctuation",
["text"," "],
["rparen","}"]
["keyword","return"],
["text"," "],
["identifier","STR"],
["punctuation","."],
["string","\"\"\""]
],[
"punctuation",
["string"," {"]
],[
"punctuation",
["string"," \"outerKey1\": \"outerValue1\","]
],[
["lparen","punctuation"],
["string"," \"nestedTemplate\": \""],
["lparen","\\{"]
],[
["punctuation","lparen","lparen","punctuation"],
["text"," "],
["identifier","STR"],
["punctuation","."],
["string","\"\"\""]
],[
["punctuation","lparen","lparen","punctuation"],
["string"," {"]
],[
["punctuation","lparen","lparen","punctuation"],
["string"," \"innerKey\": \""],
["lparen","\\{"],
["identifier","innerValue"],
["text","."],
["entity.name.function","get"],
["lparen","("],
["rparen",")}"],
["string","\""]
],[
["punctuation","lparen","lparen","punctuation"],
["string"," }"]
],[
["lparen","punctuation"],
["string"," \"\"\""]
],[
"punctuation",
["text"," "],
["rparen","}"],
["string","\","]
],[
"punctuation",
["string"," \"outerKey2\": \"outerValue2\""]
],[
"punctuation",
["string"," }"]
],[
"start",
["string"," \"\"\""],
["text",";"]
],[
"start",
["rparen","}"]
],[
"start"
]]
12 changes: 6 additions & 6 deletions src/mode/_test/tokens_jsp.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@
["text","."],
["identifier","util"],
["text","."],
["identifier","Date"],
["entity.name.function","Date"],
["lparen","("],
["rparen","))"],
["text","."],
["identifier","toLocaleString"],
["entity.name.function","toLocaleString"],
["lparen","("],
["rparen",")"],
["meta.tag","%>"]
Expand Down Expand Up @@ -333,7 +333,7 @@
["text"," "],
["variable.language","request"],
["text","."],
["identifier","getParameterValues"],
["entity.name.function","getParameterValues"],
["lparen","("],
["string","\"id\""],
["rparen",")"],
Expand Down Expand Up @@ -367,7 +367,7 @@
["text"," "],
["variable.language","out"],
["text","."],
["identifier","println"],
["entity.name.function","println"],
["lparen","("],
["string","\"You have selected: \""],
["rparen",")"],
Expand Down Expand Up @@ -404,7 +404,7 @@
["text"," "],
["variable.language","out"],
["text","."],
["identifier","println"],
["entity.name.function","println"],
["lparen","("],
["identifier","select"],
["lparen","["],
Expand Down Expand Up @@ -433,4 +433,4 @@
["meta.tag.punctuation.end-tag-open.xml","</"],
["meta.tag.tag-name.xml","html"],
["meta.tag.punctuation.tag-close.xml",">"]
]]
]]
Loading

0 comments on commit 25d86b6

Please sign in to comment.