runtime(java): Recognise non-ASCII identifiers (#14543)

Commit: 
https://github.com/vim/vim/commit/4052474a1bd2fe756bc7dc596d29d0d7581e35ae
Author: Aliaksei Budavei <32549825+zzzyxw...@users.noreply.github.com>
Date:   Sun Apr 14 19:57:00 2024 +0300

    runtime(java): Recognise non-ASCII identifiers 
(https://github.com/vim/vim/issues/14543)
    
    * runtime(java): Recognise non-ASCII identifiers
    
    Also:
    
    - Remove the already commented out and less general in its
      definition javaFuncDef alternative.
    
    - Stop recognising some bespoke {p,trace} debugging API.
    
    Non-ASCII identifiers have been supported from the outset
    of the Java language.
    
    > An _identifier_ is an unlimited-length sequence of _Java
    > letters_ and _Java digits_, the first of which must be a
    > Java letter.  An identifier cannot have the same spelling
    > (Unicode character sequence) as a keyword . . . Boolean
    > literal . . . or the null literal . . .
    > . . . . . . . .
    > Letters and digits may be drawn from the entire Unicode
    > character set . . .
    > . . . . . . . .
    > A Java letter is a character for which the method
    > Character.isJavaLetter . . . returns true.  A Java
    > letter-or-digit is a character for which the method
    > Character.isJavaLetterOrDigit . . . returns true.
    > . . . . . . . .
    > The Java letters include . . . for historical reasons, the
    > ASCII underscore (_) . . . and dollar sign ($) . . .
    
    (Separate syntax tests will be written when particular parts
    now touched will have been further improved.)
    
    Reference:
    https://javaalmanac.io/jdk/1.0/langspec.pdf [§3.8]
    
    * Take on the maintenance of Java filetype and syntax files
    
    
    Signed-off-by: Aliaksei Budavei <0x000...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ac127f0c1..9bac8b2dd 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -156,6 +156,7 @@ runtime/ftplugin/icon.vim           @dkearns
 runtime/ftplugin/indent.vim            @dkearns
 runtime/ftplugin/ishd.vim              @dkearns
 runtime/ftplugin/j.vim                 @glts
+runtime/ftplugin/java.vim              @zzzyxwvut
 runtime/ftplugin/javascript.vim                @dkearns
 runtime/ftplugin/javascriptreact.vim   @dkearns
 runtime/ftplugin/json.vim              @dbarnett
@@ -397,7 +398,7 @@ runtime/syntax/icon.vim                     @dkearns
 runtime/syntax/indent.vim              @dkearns
 runtime/syntax/j.vim                   @glts
 runtime/syntax/jargon.vim              @h3xx
-runtime/syntax/java.vim                        @fleiner
+runtime/syntax/java.vim                        @zzzyxwvut
 runtime/syntax/javascript.vim          @fleiner
 runtime/syntax/jsonc.vim               @izhakjakov
 runtime/syntax/julia.vim               @carlobaldassi
diff --git a/runtime/ftplugin/java.vim b/runtime/ftplugin/java.vim
index bb7e7cd72..095e73371 100644
--- a/runtime/ftplugin/java.vim
+++ b/runtime/ftplugin/java.vim
@@ -1,10 +1,9 @@
 " Vim filetype plugin file
 " Language:            Java
-"
-" This runtime file is looking for a new maintainer.
-"
-" Former maintainer:   Dan Sharp
-" Last Change:         2012 Mar 11
+" Maintainer:          Aliaksei Budavei <0x000c70 AT gmail DOT com>
+" Former Maintainer:   Dan Sharp
+" Repository:          https://github.com/zzzyxwvut/java-vim.git
+" Last Change:         2024 Apr 13
 "                      2024 Jan 14 by Vim Project (browsefilter)
 
 if exists("b:did_ftplugin") | finish | endif
diff --git a/runtime/syntax/java.vim b/runtime/syntax/java.vim
index 22fc934a0..e85174e7b 100644
--- a/runtime/syntax/java.vim
+++ b/runtime/syntax/java.vim
@@ -1,8 +1,9 @@
 " Vim syntax file
-" Language:    Java
-" Maintainer:  Claudio Fleiner <clau...@fleiner.com>
-" URL:          
https://github.com/fleiner/vim/blob/master/runtime/syntax/java.vim
-" Last Change: 2024 Apr 04
+" Language:            Java
+" Maintainer:          Aliaksei Budavei <0x000c70 AT gmail DOT com>
+" Former Maintainer:   Claudio Fleiner <clau...@fleiner.com>
+" Repository:          https://github.com/zzzyxwvut/java-vim.git
+" Last Change:         2024 Apr 13
 
 " Please check :help java.vim for comments on some of the options available.
 
@@ -63,7 +64,7 @@ syn match   javaClassDecl     "\<permits\>\%(\s*(\)\@!"
 syn match   javaClassDecl      "\<record\>\%(\s*(\)\@!"
 syn match   javaClassDecl      "^class\>"
 syn match   javaClassDecl      "[^.]\s*\<class\>"ms=s+1
-syn match   javaAnnotation     
"@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>" contains=javaString
+syn match   javaAnnotation     "@\%(\K\k*\.\)*\K\k*\>"
 syn match   javaClassDecl      "@interface\>"
 syn keyword javaBranch         break continue nextgroup=javaUserLabelRef 
skipwhite
 syn match   javaUserLabelRef   "\k\+" contained
@@ -288,18 +289,24 @@ syn cluster javaTop 
add=javaString,javaStrTempl,javaCharacter,javaNumber,javaSpe
 
 if exists("java_highlight_functions")
   if java_highlight_functions == "indent"
-    syn match  javaFuncDef "^\(        \| \{8\}\)[_$a-zA-Z][_$a-zA-Z0-9_. 
\[\]<>]*([^-+*/]*)" 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
-    syn region javaFuncDef start=+^\(  \| \{8\}\)[$_a-zA-Z][$_a-zA-Z0-9_. 
\[\]<>]*([^-+*/]*,\s*+ end=+)+ 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
-    syn match  javaFuncDef "^  [$_a-zA-Z][$_a-zA-Z0-9_. \[\]<>]*([^-+*/]*)" 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
-    syn region javaFuncDef start=+^  [$_a-zA-Z][$_a-zA-Z0-9_. 
\[\]<>]*([^-+*/]*,\s*+ end=+)+ 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
+    syn match javaFuncDef "^\%(        \|  \%( \{6\}\)\=\)\K\%(\k\|[ 
.,<>\[\]]\)*([^-+*/]*)" 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
+    syn region javaFuncDef start=+^\%( \|  \%( \{6\}\)\=\)\K\%(\k\|[ 
.,<>\[\]]\)*([^-+*/]*,\s*+ end=+)+ 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
   else
-    " This line catches method declarations at any indentation>0, but it 
assumes
-    " two things:
-    "  1. class names are always capitalized (ie: Button)
-    "  2. method names are never capitalized (except constructors, of course)
-    "syn region javaFuncDef 
start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(<[^>]*>\)\=\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*([^0-9]+
 end=+)+ 
contains=javaScopeDecl,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses
-    syn region javaFuncDef 
start=+^\s\+\%(\%(public\|protected\|private\|static\|\%(abstract\|default\)\|final\|native\|synchronized\)\s\+\)*\%(<.*>\s\+\)\?\%(\%(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\%([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\%(<[^(){}]*>\)\=\%(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*(+
 end=+)+ 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses,javaAnnotation
+    " This is the "style" variant (:help ft-java-syntax).
+    "
+    " Match arbitrarily indented method and constructor declarations
+    " and some enum constants.
+    "
+    " TODO: Come back to refine and fix the parts of javaFuncDef.
+    " TODO: Request the new regexp engine for [:upper:] and [:lower:].
+    "
+    " XXX: \C\<[^a-z0-9]\k*\> rejects "type", but matches "τύπος".
+    " XXX: \C\<[^A-Z0-9]\k*\> rejects "Method", but matches "Μέθοδος".
+    "
+    " Match: [abstract] [<α, β>] [Τʬ][<γ>][[][]] [μΜ]ʭʭ(/* ... */);
+    syn region javaFuncDef 
start=+^\s\+\%(\%(public\|protected\|private\|static\|\%(abstract\|default\)\|final\|native\|synchronized\)\s\+\)*\%(<.*>\s\+\)\=\%(\%(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\%(\K\k*\.\)*\<[^a-z0-9]\k*\>\)\%(<[^(){}]*>\)\=\%(\[\]\)*\s\+\<[^A-Z0-9]\k*\>\|\<[^a-z0-9]\k*\>\)\s*(+
 end=+)+ 
contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses,javaAnnotation
   endif
+
   syn match   javaLambdaDef "\<\K\k*\>\%(\<default\>\)\@<!\s*->"
   syn match  javaBraces  "[{}]"
   syn cluster javaTop add=javaFuncDef,javaBraces,javaLambdaDef
@@ -332,11 +339,13 @@ if exists("java_highlight_debug")
   syn keyword javaDebugType            contained null this super
   syn region javaDebugParen  start=+(+ end=+)+ contained 
contains=javaDebug.*,javaDebugParen
 
-  " to make this work you must define the highlighting for these groups
-  syn match javaDebug "\<System\.\(out\|err\)\.print\(ln\)*\s*("me=e-1 
contains=javaDebug.* nextgroup=javaDebugParen
-  syn match javaDebug "\<p\s*("me=e-1 contains=javaDebug.* 
nextgroup=javaDebugParen
-  syn match javaDebug "[A-Za-z][a-zA-Z0-9_]*\.printStackTrace\s*("me=e-1 
contains=javaDebug.* nextgroup=javaDebugParen
-  syn match javaDebug "\<trace[SL]\=\s*("me=e-1 contains=javaDebug.* 
nextgroup=javaDebugParen
+  " To make this work, define the highlighting for these groups.
+  syn match javaDebug "\<System\.\%(out\|err\)\.print\%(ln\)\=\s*("me=e-1 
contains=javaDebug.* nextgroup=javaDebugParen
+" FIXME: What API does "p" belong to?
+" syn match javaDebug "\<p\s*("me=e-1 contains=javaDebug.* 
nextgroup=javaDebugParen
+  syn match javaDebug "\<\K\k*\.printStackTrace\s*("me=e-1 
contains=javaDebug.* nextgroup=javaDebugParen
+" FIXME: What API do "trace*" belong to?
+" syn match javaDebug "\<trace[SL]\=\s*("me=e-1 contains=javaDebug.* 
nextgroup=javaDebugParen
 
   syn cluster javaTop add=javaDebug
 
@@ -379,8 +388,8 @@ syn match   javaParenError   "\]"
 hi def link javaParenError     javaError
 
 if exists("java_highlight_functions")
-   syn match javaLambdaDef "([a-zA-Z0-9_<>\[\],        ]*)\s*->"
-   " needs to be defined after the parenthesis error catcher to work
+  " Make ()-matching definitions after the parenthesis error catcher.
+  syn match javaLambdaDef "\k\@4<!(\%(\k\|[[:space:]<>?\[\]@,.]\)*)\s*->"
 endif
 
 if !exists("java_minlines")

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rw3DD-00AJuh-E8%40256bit.org.

Raspunde prin e-mail lui