0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

runtime(java): Tidy up the syntax file

- Prefix all global variables with "g:".
- Add spaces around each variable assignment operator.
- Remove extraneous whitespace characters.
- Remove a spurious _serializable_ Java keyword (since v1.1,
  java.io.Serializable and java.io.Externalizable interfaces
  provide an API for object serialization; see vim-6-0j).
- Normalise the syntax definition argument order by making
  _contained_ the first argument of each such definition.
- Normalise the argument tabulation for highlighting group
  definitions.

Reference:
https://web.archive.org/web/20010821025330/java.sun.com/docs/books/jls/first_edition/html/1.1Update.html

related: #15399

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Aliaksei Budavei 2024-07-31 22:14:37 +02:00 committed by Christian Brabandt
parent 3749dff093
commit 9aabcef1c8
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -8,12 +8,12 @@
" Please check :help java.vim for comments on some of the options available.
" quit when a syntax file was already loaded
if !exists("main_syntax")
if !exists("g:main_syntax")
if exists("b:current_syntax")
finish
endif
" we define it here so that included files can test for it
let main_syntax='java'
let g:main_syntax = 'java'
endif
let s:cpo_save = &cpo
@ -98,7 +98,7 @@ endtry
syn keyword javaType boolean char byte short int long float double
syn keyword javaType void
syn keyword javaStatement return
syn keyword javaStorageClass static synchronized transient volatile strictfp serializable
syn keyword javaStorageClass static synchronized transient volatile strictfp
syn keyword javaExceptions throw try catch finally
syn keyword javaAssert assert
syn keyword javaMethodDecl throws
@ -113,7 +113,7 @@ syn match javaAnnotation "@\%(\K\k*\.\)*\K\k*\>"
syn region javaAnnotation transparent matchgroup=javaAnnotationStart start=/@\%(\K\k*\.\)*\K\k*(/ end=/)/ skip=/\/\*.\{-}\*\/\|\/\/.*$/ contains=javaAnnotation,javaParenT,javaBlock,javaString,javaBoolean,javaNumber,javaTypedef,javaComment,javaLineComment
syn match javaClassDecl "@interface\>"
syn keyword javaBranch break continue nextgroup=javaUserLabelRef skipwhite
syn match javaUserLabelRef "\k\+" contained
syn match javaUserLabelRef contained "\k\+"
syn match javaVarArg "\.\.\."
syn keyword javaScopeDecl public protected private
syn keyword javaConceptKind abstract final
@ -139,7 +139,7 @@ else
let [s:ff.Engine, s:ff.UpperCase, s:ff.LowerCase] = repeat([s:ff.RightConstant], 3)
endif
if exists("java_highlight_signature")
if exists("g:java_highlight_signature")
let [s:ff.PeekTo, s:ff.PeekFrom, s:ff.GroupArgs] = repeat([s:ff.LeftConstant], 3)
else
let [s:ff.PeekTo, s:ff.PeekFrom, s:ff.GroupArgs] = repeat([s:ff.RightConstant], 3)
@ -156,7 +156,7 @@ endif
"
" Note that false positives may elsewhere occur whenever an identifier
" is butted against a less-than operator. Cf. (X<Y) and (X < Y).
if exists("java_highlight_generics")
if exists("g:java_highlight_generics")
syn keyword javaWildcardBound contained extends super
" Parameterised types are delegated to javaGenerics (s:ctx.gsg) and
@ -176,10 +176,10 @@ if exists("java_highlight_generics")
hi def link javaGenericsC2 javaType
endif
if exists("java_highlight_java_lang_ids")
let java_highlight_all=1
if exists("g:java_highlight_java_lang_ids")
let g:java_highlight_all = 1
endif
if exists("java_highlight_all") || exists("java_highlight_java") || exists("java_highlight_java_lang")
if exists("g:java_highlight_all") || exists("g:java_highlight_java") || exists("g:java_highlight_java_lang")
" java.lang.*
"
" The keywords of javaR_JavaLang, javaC_JavaLang, javaE_JavaLang,
@ -208,7 +208,7 @@ if exists("java_highlight_all") || exists("java_highlight_java") || exists("ja
syn keyword javaC_JavaLang Boolean Character ClassLoader Compiler Double Float Integer Long Math Number Object Process Runtime SecurityManager String StringBuffer Thread ThreadGroup Byte Short Void Package RuntimePermission StrictMath StackTraceElement ProcessBuilder StringBuilder Module ModuleLayer StackWalker Record
syn match javaC_JavaLang "\<System\>" " See javaDebug.
if !exists("java_highlight_generics")
if !exists("g:java_highlight_generics")
" The non-interface parameterised names of java.lang members.
exec 'syn match javaC_JavaLang "\%(\<Enum\.\)\@' . s:ff.Peek('5', '') . '<=\<EnumDesc\>"'
syn keyword javaC_JavaLang Class InheritableThreadLocal ThreadLocal Enum ClassValue
@ -251,11 +251,11 @@ if filereadable(expand("<sfile>:p:h") . "/javaid.vim")
source <sfile>:p:h/javaid.vim
endif
if exists("java_space_errors")
if !exists("java_no_trail_space_error")
if exists("g:java_space_errors")
if !exists("g:java_no_trail_space_error")
syn match javaSpaceError "\s\+$"
endif
if !exists("java_no_tab_space_error")
if !exists("g:java_no_tab_space_error")
syn match javaSpaceError " \+\t"me=e-1
endif
endif
@ -282,7 +282,7 @@ hi def link javaLabelCastType javaType
" Comments
syn keyword javaTodo contained TODO FIXME XXX
if exists("java_comment_strings")
if exists("g:java_comment_strings")
syn region javaCommentString contained start=+"+ end=+"+ end=+$+ end=+\*/+me=s-1,he=s-1 contains=javaSpecial,javaCommentStar,javaSpecialChar,@Spell
syn region javaCommentString contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaSpecial,javaCommentStar,javaSpecialChar,@Spell,javaSpecialError,javaTextBlockError
syn region javaComment2String contained start=+"+ end=+$\|"+ contains=javaSpecial,javaSpecialChar,@Spell
@ -308,7 +308,7 @@ syn match javaCommentError contained "/\*"me=e-1 display
hi def link javaCommentError javaError
hi def link javaCommentStart javaComment
if !exists("java_ignore_javadoc") && main_syntax != 'jsp'
if !exists("g:java_ignore_javadoc") && g:main_syntax != 'jsp'
" The overridable "html*" default links must be defined _before_ the
" inclusion of the same default links from "html.vim".
hi def link htmlComment Special
@ -381,10 +381,10 @@ syn match javaNumber "\<0[xX]\%(\x\%(_*\x\)*\.\=\|\%(\x\%(_*\x\)*\)\=\.\x\%(
syn match javaSpecial "\\u\x\x\x\x"
" Method declarations (JLS-17, §8.4.3, §8.4.4, §9.4).
if exists("java_highlight_functions")
if exists("g:java_highlight_functions")
syn cluster javaFuncParams contains=javaAnnotation,@javaClasses,javaGenerics,javaType,javaVarArg,javaComment,javaLineComment
if exists("java_highlight_signature")
if exists("g:java_highlight_signature")
syn keyword javaParamModifier contained final
syn cluster javaFuncParams add=javaParamModifier
hi def link javaParamModifier javaConceptKind
@ -393,8 +393,8 @@ if exists("java_highlight_functions")
syn cluster javaFuncParams add=javaScopeDecl,javaConceptKind,javaStorageClass,javaExternal
endif
if java_highlight_functions =~# '^indent[1-8]\=$'
let s:last = java_highlight_functions[-1 :]
if g:java_highlight_functions =~# '^indent[1-8]\=$'
let s:last = g:java_highlight_functions[-1 :]
let s:indent = s:last != 't' ? repeat("\x20", s:last) : "\t"
" Try to not match other type members, initialiser blocks, enum
" constants (JLS-17, §8.9.1), and constructors (JLS-17, §8.1.7):
@ -430,7 +430,7 @@ if exists("java_highlight_functions")
endif
endif
if exists("java_highlight_debug")
if exists("g:java_highlight_debug")
" Strings and constants
syn match javaDebugSpecial contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
syn region javaDebugString contained start=+"+ end=+"+ contains=javaDebugSpecial
@ -453,7 +453,7 @@ if exists("java_highlight_debug")
syn match javaDebugNumber contained "\<0[xX]\%(\x\%(_*\x\)*\.\=\|\%(\x\%(_*\x\)*\)\=\.\x\%(_*\x\)*\)[pP][-+]\=\d\%(_*\d\)*[fFdD]\=\>"
syn keyword javaDebugBoolean contained true false
syn keyword javaDebugType contained null this super
syn region javaDebugParen start=+(+ end=+)+ contained contains=javaDebug.*,javaDebugParen
syn region javaDebugParen contained start=+(+ end=+)+ contains=javaDebug.*,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
@ -485,31 +485,31 @@ endif
" but one such body.
exec 'syn region javaBlock transparent start="\%(^\|^\S[^:]\+\)\@' . s:ff.Peek('120', '') . '<!{" end="}" fold'
if exists("java_mark_braces_in_parens_as_errors")
if exists("g:java_mark_braces_in_parens_as_errors")
syn match javaInParen contained "[{}]"
hi def link javaInParen javaError
endif
" catch errors caused by wrong parenthesis
syn region javaParenT transparent matchgroup=javaParen start="(" end=")" contains=@javaTop,javaInParen,javaParenT1
syn region javaParenT1 transparent matchgroup=javaParen1 start="(" end=")" contains=@javaTop,javaInParen,javaParenT2 contained
syn region javaParenT2 transparent matchgroup=javaParen2 start="(" end=")" contains=@javaTop,javaInParen,javaParenT contained
syn region javaParenT1 contained transparent matchgroup=javaParen1 start="(" end=")" contains=@javaTop,javaInParen,javaParenT2
syn region javaParenT2 contained transparent matchgroup=javaParen2 start="(" end=")" contains=@javaTop,javaInParen,javaParenT
syn match javaParenError ")"
" catch errors caused by wrong square parenthesis
syn region javaParenT transparent matchgroup=javaParen start="\[" end="\]" contains=@javaTop,javaParenT1
syn region javaParenT1 transparent matchgroup=javaParen1 start="\[" end="\]" contains=@javaTop,javaParenT2 contained
syn region javaParenT2 transparent matchgroup=javaParen2 start="\[" end="\]" contains=@javaTop,javaParenT contained
syn region javaParenT1 contained transparent matchgroup=javaParen1 start="\[" end="\]" contains=@javaTop,javaParenT2
syn region javaParenT2 contained transparent matchgroup=javaParen2 start="\[" end="\]" contains=@javaTop,javaParenT
syn match javaParenError "\]"
hi def link javaParenError javaError
" Lambda expressions (JLS-17, §15.27) and method references (JLS-17,
" §15.13).
if exists("java_highlight_functions")
" Lambda expressions (JLS-17, §15.27) and method reference expressions
" (JLS-17, §15.13).
if exists("g:java_highlight_functions")
syn match javaMethodRef ":::\@!"
hi def link javaMethodRef javaFuncDef
if exists("java_highlight_signature")
if exists("g:java_highlight_signature")
let s:ff.LambdaDef = s:ff.LeftConstant
else
let s:ff.LambdaDef = s:ff.RightConstant
@ -543,8 +543,8 @@ endif
" Note that the syntax file "aidl.vim" relies on its availability.
syn cluster javaTop contains=TOP,javaTopEnumDeclaration
if !exists("java_minlines")
let java_minlines = 10
if !exists("g:java_minlines")
let g:java_minlines = 10
endif
" Note that variations of a /*/ balanced comment, e.g., /*/*/, /*//*/,
@ -553,7 +553,7 @@ endif
" to make synchronisation start further towards file's beginning by
" bumping up g:java_minlines or issuing ':syntax sync fromstart' or
" preferring &foldmethod set to 'syntax'.
exec "syn sync ccomment javaComment minlines=" . java_minlines
exec "syn sync ccomment javaComment minlines=" . g:java_minlines
" The default highlighting.
hi def link javaLambdaDef Function
@ -617,8 +617,8 @@ endif
let b:current_syntax = "java"
if main_syntax == 'java'
unlet main_syntax
if g:main_syntax == 'java'
unlet g:main_syntax
endif
let b:spell_options = "contained"