diff --git a/runtime/syntax/java.vim b/runtime/syntax/java.vim index 149f5fd5a7..bc874904f6 100644 --- a/runtime/syntax/java.vim +++ b/runtime/syntax/java.vim @@ -3,7 +3,7 @@ " Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com> " Former Maintainer: Claudio Fleiner " Repository: https://github.com/zzzyxwvut/java-vim.git -" Last Change: 2025 Oct 08 +" Last Change: 2026 Feb 06 " Please check ":help java.vim" for comments on some of the options " available. @@ -37,6 +37,8 @@ set cpo&vim """" STRIVE TO REMAIN COMPATIBLE FOR AT LEAST VIM 7.0. let s:ff = {} +let s:vv = {} +let s:vv.ignore_folding = get(g:, 'java_ignore_folding', '') function! s:ff.LeftConstant(x, y) abort return a:x @@ -60,7 +62,7 @@ else endif function! s:ff.QueryFoldArgForSyntaxItems(kind) abort - return stridx(s:java_ignore_folding, a:kind) < 0 ? "fold" : "" + return stridx(s:vv.ignore_folding, a:kind) < 0 ? "fold" : "" endfunction if !exists("*s:ReportOnce") @@ -94,8 +96,6 @@ if exists("g:java_foldtext_show_first_or_second_line") setlocal foldtext=JavaSyntaxFoldTextExpr() endif -let s:java_ignore_folding = get(g:, 'java_ignore_folding', '') - " Admit the ASCII dollar sign to keyword characters (JLS-17, §3.8): try exec 'syntax iskeyword ' . &l:iskeyword . ',$' @@ -211,6 +211,15 @@ let s:with_html = !exists("g:java_ignore_html") let s:with_markdown = !exists("g:java_ignore_markdown") lockvar s:with_html s:with_markdown +" Note that the delimiting angle brackets are omitted. +let s:vv.type_param_list = '\%([^(){}]\|\n\)\+[[:space:]-]\@' . s:ff.Peek('1', '') . '\.\)*%s\<' . s:ff.UpperCase('[$_[:upper:]]', '[^a-z0-9]') . '\k*\>' +" Allow for org.example.TopLevelType.MemberType return types. +let s:vv.void_or_param_type = 'void\|\%(' . printf(s:vv.param_type_head, '\%(') . '\%(<' . s:vv.type_param_list . '>\.\=\)\=\)\+\)\%(\[\]\)*' +let s:vv.param_type_head = printf(s:vv.param_type_head, '') + " Java module declarations (JLS-17, §7.7). " " Note that a "module-info" file will be recognised with an arbitrary @@ -344,13 +353,13 @@ if exists("g:java_highlight_generics") " Match sections of generic methods and constructors and their " parameterised use. - exec 'syn region javaTypeParamSection transparent matchgroup=javaGenericsCX start=/' . s:ff.Engine('\%#=2', '') . '\%(^\|\s\)\@' . s:ff.Peek('1', '') . '<=<\%(\%([^(){}]\|\n\)\+[[:space:]-]\@' . s:ff.Peek('1', '') . '\_s\+\%(\%(void\|\%(b\%(oolean\|yte\)\|char\|short\|int\|long\|float\|double\|\%(\<\K\k*\>\.\)*\<' . s:ff.UpperCase('[$_[:upper:]]', '[^a-z0-9]') . '\k*\>\%(<\%([^(){}]\|\n\)\+[[:space:]-]\@' . s:ff.Peek('1', '') . '\)\=\)\%(\[\]\)*\)\_s\+\)\=\<\K\k*\>\s*(\)\@=/ end=/>/ contains=javaGenerics,@javaTypeParams' + exec 'syn region javaTypeParamSection transparent matchgroup=javaGenericsCX start=/' . s:ff.Engine('\%#=2', '') . '\%(^\|\s\)\@' . s:ff.Peek('1', '') . '<=<\%(' . s:vv.type_param_list . '>\_s\+\%(\%(' . s:vv.void_or_param_type . '\)\_s\+\)\=\<\K\k*\>\s*(\)\@=/ end=/>/ contains=javaGenerics,@javaTypeParams' exec 'syn region javaTypeParamSection transparent matchgroup=javaGenericsCX start=/\%(\%(\\@!/ end=/>/ contains=javaGenerics,@javaTypeParams' for s:ctx in [{'gsg': 'javaGenerics', 'ghg': 'javaGenericsC1', 'csg': 'javaGenericsX', 'c': ''}, \ {'gsg': 'javaGenericsX', 'ghg': 'javaGenericsC2', 'csg': 'javaGenerics', 'c': ' contained'}] " Match sections of generic types and their parameterised use. - exec 'syn region ' . s:ctx.gsg . s:ctx.c . ' transparent matchgroup=' . s:ctx.ghg . ' start=/' . s:ff.Engine('\%#=2', '') . '\%(\<\K\k*\>\.\)*\<' . s:ff.UpperCase('[$_[:upper:]]', '[^a-z0-9]') . '\k*\><\%([[:space:]\n]*\%([?@]\|\<\%(b\%(oolean\|yte\)\|char\|short\|int\|long\|float\|double\)\|\%(\<\K\k*\>\.\)*\<' . s:ff.UpperCase('[$_[:upper:]]', '[^a-z0-9]') . '\k*\>\)\)\@=/ end=/>/ contains=' . s:ctx.csg . ',@javaTypeParams' + exec 'syn region ' . s:ctx.gsg . s:ctx.c . ' transparent matchgroup=' . s:ctx.ghg . ' start=/' . s:ff.Engine('\%#=2', '') . '\%(\<\K\k*\>\.\)*\<' . s:ff.UpperCase('[$_[:upper:]]', '[^a-z0-9]') . '\k*\><\%([[:space:]\n]*\%([?@]\|' . s:vv.param_type_head . '\)\)\@=/ end=/>/ contains=' . s:ctx.csg . ',@javaTypeParams' endfor unlet s:ctx @@ -745,8 +754,8 @@ if exists("g:java_highlight_functions") " "[^=]*", all records with "\\)\s\+\)*\K\k*\s*\%((.*)\)\=\s*[,;({]\s*\)\+/ contains=@javaEnumConstants' - " (2) Define a syntax group for top level enumerations and tell - " apart their constants from method declarations. - exec 'syn region javaTopEnumDeclaration transparent start=/\%(^\%(\%(@\%(\K\k*\.\)*\K\k*\>\)\s\+\)*\%(p\%(ublic\|rotected\|rivate\)\s\+\)\=\%(strictfp\s\+\)\=\\)\s\+\)*\%(p\%(ublic\|rotected\|rivate\)\s\+\)\=\%(strictfp\s\+\)\=\] Τʬ[<γ>][[][]] μʭʭ(/* ... */); - exec 'syn region javaFuncDef ' . s:ff.GroupArgs('transparent matchgroup=javaFuncDefStart', '') . ' start=/' . s:ff.Engine('\%#=2', '') . s:ff.PeekTo('\%(', '') . '^\s\+\%(\%(@\%(\K\k*\.\)*\K\k*\>\)\s\+\)*\%(p\%(ublic\|rotected\|rivate\)\s\+\)\=\%(\%(abstract\|default\)\s\+\|\%(\%(final\|\%(native\|strictfp\)\|s\%(tatic\|ynchronized\)\)\s\+\)*\)\=\%(<\%([^(){}]\|\n\)\+[[:space:]-]\@' . s:ff.Peek('1', '') . '\s\+\)\=\%(void\|\%(b\%(oolean\|yte\)\|char\|short\|int\|long\|float\|double\|\%(\<\K\k*\>\.\)*\<' . s:ff.UpperCase('[$_[:upper:]]', '[^a-z0-9]') . '\k*\>\%(<\%([^(){}]\|\n\)\+[[:space:]-]\@' . s:ff.Peek('1', '') . '\)\=\)\%(\[\]\)*\)\s\+' . s:ff.PeekFrom('\)\@' . s:ff.PeekFor('javaFuncDef', 120) . '<=', '') . '\<' . s:ff.LowerCase('[$_[:lower:]]', '[^A-Z0-9]') . '\k*\>\s*(/ end=/)/ skip=/\/\*.\{-}\*\/\|\/\/.*$/ contains=@javaFuncParams' + exec 'syn region javaFuncDef ' . s:ff.GroupArgs('transparent matchgroup=javaFuncDefStart', '') . ' start=/' . s:ff.Engine('\%#=2', '') . s:ff.PeekTo('\%(', '') . '^\s\+\%(\%(@\%(\K\k*\.\)*\K\k*\>\)\s\+\)*\%(p\%(ublic\|rotected\|rivate\)\s\+\)\=\%(\%(abstract\|default\)\s\+\|\%(\%(final\|\%(native\|strictfp\)\|s\%(tatic\|ynchronized\)\)\s\+\)*\)\=\%(<' . s:vv.type_param_list . '>\s\+\)\=\%(' . s:vv.void_or_param_type . '\)\s\+' . s:ff.PeekFrom('\)\@' . s:ff.PeekFor('javaFuncDef', 120) . '<=', '') . '\<' . s:ff.LowerCase('[$_[:lower:]]', '[^A-Z0-9]') . '\k*\>\s*(/ end=/)/ skip=/\/\*.\{-}\*\/\|\/\/.*$/ contains=@javaFuncParams' endif endif @@ -977,7 +987,7 @@ endif let b:spell_options = "contained" let &cpo = s:cpo_save -unlet s:cpo_save s:ff s:java_ignore_folding s:with_html s:with_markdown +unlet s:cpo_save s:ff s:vv s:with_html s:with_markdown " See ":help vim9-mix". if !has("vim9script")