From c263a3d1110fd096c2ddbcd5fe0240d8cb1dcd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 31 May 2026 21:24:49 +0900 Subject: [PATCH] lang: Update java --- languages.toml | 2 +- runtime/queries/java/highlights.scm | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/languages.toml b/languages.toml index 7135b804..e5583950 100644 --- a/languages.toml +++ b/languages.toml @@ -1492,7 +1492,7 @@ block-comment-tokens = { start = "/*", end = "*/" } [[grammar]] name = "java" -source = { git = "https://github.com/tree-sitter/tree-sitter-java", rev = "09d650def6cdf7f479f4b78f595e9ef5b58ce31e" } +source = { git = "https://github.com/tree-sitter/tree-sitter-java", rev = "e10607b45ff745f5f876bfa3e94fbcc6b44bdc11" } [[language]] name = "smali" diff --git a/runtime/queries/java/highlights.scm b/runtime/queries/java/highlights.scm index 7f62ba31..5d8958e6 100644 --- a/runtime/queries/java/highlights.scm +++ b/runtime/queries/java/highlights.scm @@ -51,11 +51,24 @@ (type_arguments (wildcard "?" @type.builtin)) +; Patterns (Java 21+): the record type name would otherwise be a @variable. +(record_pattern . (identifier) @type) +; `when` is contextual — only a guard inside a switch label, never a keyword +; elsewhere — so scope it to the guard rather than the flat keyword list. +(guard "when" @keyword.control.conditional) + ; Variables ((identifier) @constant (#match? @constant "^_*[A-Z][A-Z\\d_]+$")) +; Unnamed variable / pattern `_` (Java 22) — dim as unused, like the discard in +; other languages. It is an (underscore_pattern) in `var _ = …` and a plain +; identifier in record components / `case _`. +(underscore_pattern) @comment.unused +((identifier) @comment.unused + (#eq? @comment.unused "_")) + (this) @variable.builtin ; Literals @@ -74,10 +87,12 @@ (character_literal) @constant.character -[ - (string_literal) - (text_block) -] @string +; `string_literal` now also covers text blocks (`"""…"""`) and its fragments. +(string_literal) @string +(escape_sequence) @constant.character.escape +; Interpolated expressions in string templates (a withdrawn preview) shouldn't +; render as string; reset them rather than colour the whole literal. +(string_interpolation) @none [ (true) -- 2.51.2