2014-07-10 21:05:51 -07:00
|
|
|
|
" Vim syntax file
|
2024-04-15 18:32:55 -07:00
|
|
|
|
" Language: Java
|
|
|
|
|
" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
|
|
|
|
|
" Former Maintainer: Claudio Fleiner <claudio@fleiner.com>
|
|
|
|
|
" Repository: https://github.com/zzzyxwvut/java-vim.git
|
2024-09-30 22:00:12 -07:00
|
|
|
|
" Last Change: 2024 Sep 28
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
|
" Please check :help java.vim for comments on some of the options available.
|
|
|
|
|
|
2017-04-28 12:06:44 -07:00
|
|
|
|
" quit when a syntax file was already loaded
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if !exists("g:main_syntax")
|
2017-04-28 12:06:44 -07:00
|
|
|
|
if exists("b:current_syntax")
|
2014-07-10 21:05:51 -07:00
|
|
|
|
finish
|
|
|
|
|
endif
|
|
|
|
|
" we define it here so that included files can test for it
|
2024-07-31 13:59:55 -07:00
|
|
|
|
let g:main_syntax = 'java'
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
let s:cpo_save = &cpo
|
|
|
|
|
set cpo&vim
|
|
|
|
|
|
2024-05-11 00:30:56 -07:00
|
|
|
|
"""" STRIVE TO REMAIN COMPATIBLE FOR AT LEAST VIM 7.0.
|
|
|
|
|
let s:ff = {}
|
|
|
|
|
|
|
|
|
|
function! s:ff.LeftConstant(x, y) abort
|
|
|
|
|
return a:x
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:ff.RightConstant(x, y) abort
|
|
|
|
|
return a:y
|
|
|
|
|
endfunction
|
|
|
|
|
|
2024-08-28 01:21:59 -07:00
|
|
|
|
function! s:ff.IsRequestedPreviewFeature(n) abort
|
|
|
|
|
return exists("g:java_syntax_previews") && index(g:java_syntax_previews, a:n) + 1
|
|
|
|
|
endfunction
|
|
|
|
|
|
2024-05-11 00:30:56 -07:00
|
|
|
|
if !exists("*s:ReportOnce")
|
|
|
|
|
function s:ReportOnce(message) abort
|
|
|
|
|
echomsg 'syntax/java.vim: ' . a:message
|
|
|
|
|
endfunction
|
|
|
|
|
else
|
|
|
|
|
function! s:ReportOnce(dummy)
|
|
|
|
|
endfunction
|
|
|
|
|
endif
|
|
|
|
|
|
2024-08-22 12:25:51 -07:00
|
|
|
|
if exists("g:java_foldtext_show_first_or_second_line")
|
|
|
|
|
function! s:LazyPrefix(prefix, dashes, count) abort
|
|
|
|
|
return empty(a:prefix)
|
|
|
|
|
\ ? printf('+-%s%3d lines: ', a:dashes, a:count)
|
|
|
|
|
\ : a:prefix
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! JavaSyntaxFoldTextExpr() abort
|
|
|
|
|
" Piggyback on NGETTEXT.
|
|
|
|
|
let summary = foldtext()
|
|
|
|
|
return getline(v:foldstart) !~ '/\*\+\s*$'
|
|
|
|
|
\ ? summary
|
|
|
|
|
\ : s:LazyPrefix(matchstr(summary, '^+-\+\s*\d\+\s.\{-1,}:\s'),
|
|
|
|
|
\ v:folddashes,
|
|
|
|
|
\ (v:foldend - v:foldstart + 1)) .
|
|
|
|
|
\ getline(v:foldstart + 1)
|
|
|
|
|
endfunction
|
2024-06-16 02:29:01 -07:00
|
|
|
|
|
2024-08-22 12:25:51 -07:00
|
|
|
|
" E120 for "fdt=s:JavaSyntaxFoldTextExpr()" before v8.2.3900.
|
|
|
|
|
setlocal foldtext=JavaSyntaxFoldTextExpr()
|
|
|
|
|
endif
|
2024-06-16 02:29:01 -07:00
|
|
|
|
|
2024-04-04 14:48:43 -07:00
|
|
|
|
" Admit the ASCII dollar sign to keyword characters (JLS-17, §3.8):
|
2024-05-11 00:30:56 -07:00
|
|
|
|
try
|
|
|
|
|
exec 'syntax iskeyword ' . &l:iskeyword . ',$'
|
|
|
|
|
catch /\<E410:/
|
|
|
|
|
call s:ReportOnce(v:exception)
|
|
|
|
|
setlocal iskeyword+=$
|
|
|
|
|
endtry
|
2024-04-04 14:48:43 -07:00
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
" some characters that cannot be in a java program (outside a string)
|
|
|
|
|
syn match javaError "[\\@`]"
|
2016-01-14 16:38:47 -07:00
|
|
|
|
syn match javaError "<<<\|\.\.\|=>\|||=\|&&=\|\*\/"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
|
" use separate name so that it can be deleted in javacc.vim
|
|
|
|
|
syn match javaError2 "#\|=<"
|
|
|
|
|
|
2024-04-04 14:48:43 -07:00
|
|
|
|
" Keywords (JLS-17, §3.9):
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn keyword javaExternal native package
|
2024-04-04 14:48:43 -07:00
|
|
|
|
syn match javaExternal "\<import\>\%(\s\+static\>\)\="
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn keyword javaError goto const
|
|
|
|
|
syn keyword javaConditional if else switch
|
|
|
|
|
syn keyword javaRepeat while for do
|
|
|
|
|
syn keyword javaBoolean true false
|
|
|
|
|
syn keyword javaConstant null
|
|
|
|
|
syn keyword javaTypedef this super
|
2024-04-04 14:48:43 -07:00
|
|
|
|
syn keyword javaOperator new instanceof
|
|
|
|
|
syn match javaOperator "\<var\>\%(\s*(\)\@!"
|
2024-05-11 00:30:56 -07:00
|
|
|
|
|
2024-09-21 01:26:54 -07:00
|
|
|
|
if s:ff.IsRequestedPreviewFeature(476)
|
|
|
|
|
" Module imports can be used in any source file.
|
|
|
|
|
syn match javaExternal "\<import\s\+module\>" contains=javaModuleImport
|
|
|
|
|
syn keyword javaModuleImport contained module
|
|
|
|
|
hi def link javaModuleImport Statement
|
|
|
|
|
endif
|
|
|
|
|
|
vim-patch:9ecf02cd5f5f
runtime(java): Recognise _when_ clauses in _switch_ blocks
Also:
- distinguish _yield_ when used as a contextual keyword from
when used qualified as a method or a method reference (as
can be seen in testdir/input/java_switch.java, variables
and method declarations named _yield_ will be recognised
as the namesake keyword--consider picking other names for
variables, and defining g:java_highlight_functions to have
method names painted; since _yield_ statements can have
trailing parens, they must be recognised as statements,
for only qualified _yield_ method calls are supported);
- recognise grouped _default_ _case_ labels;
- describe primitive types for _case_ labels (JLS, §14.11,
§3.10.1);
- recognise some non-ASCII identifiers (see javaLambdaDef,
javaUserLabel) (further improvement for better recognition
of identifiers will be arranged in a separate PR).
Because the arrow '->' is used in two kinds of expressions,
lambda (abstractions) and _switch_, necessary changes were
made for the recognition of either (and further improvement
touching lambda expressions will be separately arranged).
Because 'default' is used for instance method declarations
in interfaces and in _switch_ labels, necessary changes were
made for the recognition of either (and further improvement
touching method declarations will be separately arranged).
Finally, it deemed appropriate to put 'yield' in the syntax
group of javaOperator rather than javaStatement, for its
member 'var' is also another contextual keyword (e.g., this
is valid syntax: "var var = var(test.var);").
References:
https://openjdk.org/jeps/361 (Switch Expressions)
https://openjdk.org/jeps/440 (Record Patterns)
https://openjdk.org/jeps/441 (Pattern Matching for switch)
Also, add a Java specific filetype plugin for the syntax
test, so that no soft-wrapping of long indented lines occur.
Otherwise the syntax scripts would miss a few lines during
scrolling and verification of the screen dumps.
closes: vim/vim#14105
https://github.com/vim/vim/commit/9ecf02cd5f5feabe096f66cd5f503a822c78793f
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-02-29 01:36:07 -07:00
|
|
|
|
" Since the yield statement, which could take a parenthesised operand,
|
|
|
|
|
" and _qualified_ yield methods get along within the switch block
|
|
|
|
|
" (JLS-17, §3.8), it seems futile to make a region definition for this
|
|
|
|
|
" block; instead look for the _yield_ word alone, and if found,
|
|
|
|
|
" backtrack (arbitrarily) 80 bytes, at most, on the matched line and,
|
|
|
|
|
" if necessary, on the line before that (h: \@<=), trying to match
|
|
|
|
|
" neither a method reference nor a qualified method invocation.
|
2024-05-11 00:30:56 -07:00
|
|
|
|
try
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaOperator "\%(\%(::\|\.\)[[:space:]\n]*\)\@80<!\<yield\>"
|
2024-05-11 00:30:56 -07:00
|
|
|
|
let s:ff.Peek = s:ff.LeftConstant
|
|
|
|
|
catch /\<E59:/
|
|
|
|
|
call s:ReportOnce(v:exception)
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaOperator "\%(\%(::\|\.\)[[:space:]\n]*\)\@<!\<yield\>"
|
2024-05-11 00:30:56 -07:00
|
|
|
|
let s:ff.Peek = s:ff.RightConstant
|
|
|
|
|
endtry
|
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn keyword javaType boolean char byte short int long float double
|
|
|
|
|
syn keyword javaType void
|
vim-patch:9ecf02cd5f5f
runtime(java): Recognise _when_ clauses in _switch_ blocks
Also:
- distinguish _yield_ when used as a contextual keyword from
when used qualified as a method or a method reference (as
can be seen in testdir/input/java_switch.java, variables
and method declarations named _yield_ will be recognised
as the namesake keyword--consider picking other names for
variables, and defining g:java_highlight_functions to have
method names painted; since _yield_ statements can have
trailing parens, they must be recognised as statements,
for only qualified _yield_ method calls are supported);
- recognise grouped _default_ _case_ labels;
- describe primitive types for _case_ labels (JLS, §14.11,
§3.10.1);
- recognise some non-ASCII identifiers (see javaLambdaDef,
javaUserLabel) (further improvement for better recognition
of identifiers will be arranged in a separate PR).
Because the arrow '->' is used in two kinds of expressions,
lambda (abstractions) and _switch_, necessary changes were
made for the recognition of either (and further improvement
touching lambda expressions will be separately arranged).
Because 'default' is used for instance method declarations
in interfaces and in _switch_ labels, necessary changes were
made for the recognition of either (and further improvement
touching method declarations will be separately arranged).
Finally, it deemed appropriate to put 'yield' in the syntax
group of javaOperator rather than javaStatement, for its
member 'var' is also another contextual keyword (e.g., this
is valid syntax: "var var = var(test.var);").
References:
https://openjdk.org/jeps/361 (Switch Expressions)
https://openjdk.org/jeps/440 (Record Patterns)
https://openjdk.org/jeps/441 (Pattern Matching for switch)
Also, add a Java specific filetype plugin for the syntax
test, so that no soft-wrapping of long indented lines occur.
Otherwise the syntax scripts would miss a few lines during
scrolling and verification of the screen dumps.
closes: vim/vim#14105
https://github.com/vim/vim/commit/9ecf02cd5f5feabe096f66cd5f503a822c78793f
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-02-29 01:36:07 -07:00
|
|
|
|
syn keyword javaStatement return
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn keyword javaStorageClass static synchronized transient volatile strictfp
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn keyword javaExceptions throw try catch finally
|
|
|
|
|
syn keyword javaAssert assert
|
2024-04-04 14:48:43 -07:00
|
|
|
|
syn keyword javaMethodDecl throws
|
|
|
|
|
" Differentiate a "MyClass.class" literal from the keyword "class".
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn match javaTypedef "\.\s*\<class\>"ms=s+1
|
2024-04-04 14:48:43 -07:00
|
|
|
|
syn keyword javaClassDecl enum extends implements interface
|
|
|
|
|
syn match javaClassDecl "\<permits\>\%(\s*(\)\@!"
|
|
|
|
|
syn match javaClassDecl "\<record\>\%(\s*(\)\@!"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn match javaClassDecl "^class\>"
|
|
|
|
|
syn match javaClassDecl "[^.]\s*\<class\>"ms=s+1
|
2024-04-15 18:32:55 -07:00
|
|
|
|
syn match javaAnnotation "@\%(\K\k*\.\)*\K\k*\>"
|
2024-06-16 02:29:01 -07:00
|
|
|
|
syn region javaAnnotation transparent matchgroup=javaAnnotationStart start=/@\%(\K\k*\.\)*\K\k*(/ end=/)/ skip=/\/\*.\{-}\*\/\|\/\/.*$/ contains=javaAnnotation,javaParenT,javaBlock,javaString,javaBoolean,javaNumber,javaTypedef,javaComment,javaLineComment
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn match javaClassDecl "@interface\>"
|
|
|
|
|
syn keyword javaBranch break continue nextgroup=javaUserLabelRef skipwhite
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaUserLabelRef contained "\k\+"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn match javaVarArg "\.\.\."
|
2024-04-04 14:48:43 -07:00
|
|
|
|
syn keyword javaScopeDecl public protected private
|
|
|
|
|
syn keyword javaConceptKind abstract final
|
|
|
|
|
syn match javaConceptKind "\<non-sealed\>"
|
|
|
|
|
syn match javaConceptKind "\<sealed\>\%(\s*(\)\@!"
|
vim-patch:9ecf02cd5f5f
runtime(java): Recognise _when_ clauses in _switch_ blocks
Also:
- distinguish _yield_ when used as a contextual keyword from
when used qualified as a method or a method reference (as
can be seen in testdir/input/java_switch.java, variables
and method declarations named _yield_ will be recognised
as the namesake keyword--consider picking other names for
variables, and defining g:java_highlight_functions to have
method names painted; since _yield_ statements can have
trailing parens, they must be recognised as statements,
for only qualified _yield_ method calls are supported);
- recognise grouped _default_ _case_ labels;
- describe primitive types for _case_ labels (JLS, §14.11,
§3.10.1);
- recognise some non-ASCII identifiers (see javaLambdaDef,
javaUserLabel) (further improvement for better recognition
of identifiers will be arranged in a separate PR).
Because the arrow '->' is used in two kinds of expressions,
lambda (abstractions) and _switch_, necessary changes were
made for the recognition of either (and further improvement
touching lambda expressions will be separately arranged).
Because 'default' is used for instance method declarations
in interfaces and in _switch_ labels, necessary changes were
made for the recognition of either (and further improvement
touching method declarations will be separately arranged).
Finally, it deemed appropriate to put 'yield' in the syntax
group of javaOperator rather than javaStatement, for its
member 'var' is also another contextual keyword (e.g., this
is valid syntax: "var var = var(test.var);").
References:
https://openjdk.org/jeps/361 (Switch Expressions)
https://openjdk.org/jeps/440 (Record Patterns)
https://openjdk.org/jeps/441 (Pattern Matching for switch)
Also, add a Java specific filetype plugin for the syntax
test, so that no soft-wrapping of long indented lines occur.
Otherwise the syntax scripts would miss a few lines during
scrolling and verification of the screen dumps.
closes: vim/vim#14105
https://github.com/vim/vim/commit/9ecf02cd5f5feabe096f66cd5f503a822c78793f
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-02-29 01:36:07 -07:00
|
|
|
|
syn match javaConceptKind "\<default\>\%(\s*\%(:\|->\)\)\@!"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-05-11 00:30:56 -07:00
|
|
|
|
if !(v:version < 704)
|
|
|
|
|
" Request the new regexp engine for [:upper:] and [:lower:].
|
|
|
|
|
let [s:ff.Engine, s:ff.UpperCase, s:ff.LowerCase] = repeat([s:ff.LeftConstant], 3)
|
|
|
|
|
else
|
|
|
|
|
" XXX: \C\<[^a-z0-9]\k*\> rejects "type", but matches "τύπος".
|
|
|
|
|
" XXX: \C\<[^A-Z0-9]\k*\> rejects "Method", but matches "Μέθοδος".
|
|
|
|
|
let [s:ff.Engine, s:ff.UpperCase, s:ff.LowerCase] = repeat([s:ff.RightConstant], 3)
|
|
|
|
|
endif
|
2024-04-04 14:48:43 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_signature")
|
2024-06-23 03:00:49 -07:00
|
|
|
|
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)
|
|
|
|
|
endif
|
|
|
|
|
|
2024-09-30 22:00:12 -07:00
|
|
|
|
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
|
|
|
|
|
|
2024-07-31 14:00:22 -07:00
|
|
|
|
" Java module declarations (JLS-17, §7.7).
|
|
|
|
|
"
|
|
|
|
|
" Note that a "module-info" file will be recognised with an arbitrary
|
|
|
|
|
" file extension (or no extension at all) so that more than one such
|
|
|
|
|
" declaration for the same Java module can be maintained for modular
|
|
|
|
|
" testing in a project without attendant confusion for IDEs, with the
|
|
|
|
|
" ".java\=" extension used for a production version and an arbitrary
|
|
|
|
|
" extension used for a testing version.
|
2024-09-11 00:22:59 -07:00
|
|
|
|
if fnamemodify(bufname("%"), ":t") =~ '^module-info\>\%(\.class\>\)\@!'
|
2024-04-04 14:48:43 -07:00
|
|
|
|
syn keyword javaModuleStorageClass module transitive
|
|
|
|
|
syn keyword javaModuleStmt open requires exports opens uses provides
|
|
|
|
|
syn keyword javaModuleExternal to with
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaModuleStorageClass StorageClass
|
|
|
|
|
hi def link javaModuleStmt Statement
|
|
|
|
|
hi def link javaModuleExternal Include
|
2024-09-11 00:22:59 -07:00
|
|
|
|
|
2024-09-30 22:00:12 -07:00
|
|
|
|
if !exists("g:java_ignore_javadoc") && (s:with_html || s:with_markdown) && g:main_syntax != 'jsp'
|
2024-09-11 00:22:59 -07:00
|
|
|
|
syn match javaDocProvidesTag contained "@provides\_s\+\S\+" contains=javaDocParam
|
|
|
|
|
syn match javaDocUsesTag contained "@uses\_s\+\S\+" contains=javaDocParam
|
|
|
|
|
hi def link javaDocProvidesTag Special
|
|
|
|
|
hi def link javaDocUsesTag Special
|
|
|
|
|
endif
|
2018-10-29 01:50:39 -07:00
|
|
|
|
endif
|
|
|
|
|
|
vim-patch:beb02ed: runtime(java): Optionally highlight parameterised types
In the presence of parameterised types whose names begin
with a capital letter and end with a less-than sign "<" that
introduces a type argument or a list of comma-separated type
arguments, followed by a greater-than sign ">", a variable
"g:java_highlight_generics" can be defined to have some
components of such types uniformly coloured (by picking
highlight groups for javaGenericsC{1,2}, javaWildcardBound).
For example,
------------------------------------------------------------
java.io.InputStream stream = java.io.InputStream.nullInputStream();
java.util.function.Function<String,
java.util.function.BiFunction<String, String, String>> updater =
property -> (oldValue, newValue) -> oldValue;
java.util.logging.LogManager.getLogManager()
.updateConfiguration(stream, updater);
------------------------------------------------------------
Note that the diamond form and explicit type arguments do
not qualify for this kind of recognition.
For example,
------------------------------------------------------------
new java.util.HashSet<>().<String>toArray(new String[0]);
------------------------------------------------------------
References:
https://docs.oracle.com/javase/specs/jls/se21/html/jls-4.html#jls-4.5
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.9
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.12.2.1
closes: vim/vim#15050
https://github.com/vim/vim/commit/beb02ed674bc61f179c4ff71e93bdeeb44fe9c4e
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-06-21 01:34:59 -07:00
|
|
|
|
" Fancy parameterised types (JLS-17, §4.5).
|
|
|
|
|
"
|
|
|
|
|
" Note that false positives may elsewhere occur whenever an identifier
|
|
|
|
|
" is butted against a less-than operator. Cf. (X<Y) and (X < Y).
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_generics")
|
vim-patch:beb02ed: runtime(java): Optionally highlight parameterised types
In the presence of parameterised types whose names begin
with a capital letter and end with a less-than sign "<" that
introduces a type argument or a list of comma-separated type
arguments, followed by a greater-than sign ">", a variable
"g:java_highlight_generics" can be defined to have some
components of such types uniformly coloured (by picking
highlight groups for javaGenericsC{1,2}, javaWildcardBound).
For example,
------------------------------------------------------------
java.io.InputStream stream = java.io.InputStream.nullInputStream();
java.util.function.Function<String,
java.util.function.BiFunction<String, String, String>> updater =
property -> (oldValue, newValue) -> oldValue;
java.util.logging.LogManager.getLogManager()
.updateConfiguration(stream, updater);
------------------------------------------------------------
Note that the diamond form and explicit type arguments do
not qualify for this kind of recognition.
For example,
------------------------------------------------------------
new java.util.HashSet<>().<String>toArray(new String[0]);
------------------------------------------------------------
References:
https://docs.oracle.com/javase/specs/jls/se21/html/jls-4.html#jls-4.5
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.9
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.12.2.1
closes: vim/vim#15050
https://github.com/vim/vim/commit/beb02ed674bc61f179c4ff71e93bdeeb44fe9c4e
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-06-21 01:34:59 -07:00
|
|
|
|
syn keyword javaWildcardBound contained extends super
|
|
|
|
|
|
|
|
|
|
" Parameterised types are delegated to javaGenerics (s:ctx.gsg) and
|
|
|
|
|
" are not matched with javaTypeArgument.
|
|
|
|
|
exec 'syn match javaTypeArgument contained "' . s:ff.Engine('\%#=2', '') . '?\|\%(\<\%(b\%(oolean\|yte\)\|char\|short\|int\|long\|float\|double\)\[\]\|\%(\<\K\k*\>\.\)*\<' . s:ff.UpperCase('[$_[:upper:]]', '[^a-z0-9]') . '\k*\>\)\%(\[\]\)*"'
|
|
|
|
|
|
|
|
|
|
for s:ctx in [{'dsg': 'javaDimExpr', 'gsg': 'javaGenerics', 'ghg': 'javaGenericsC1', 'csg': 'javaGenericsX', 'c': ''},
|
|
|
|
|
\ {'dsg': 'javaDimExprX', 'gsg': 'javaGenericsX', 'ghg': 'javaGenericsC2', 'csg': 'javaGenerics', 'c': ' contained'}]
|
|
|
|
|
" Consider array creation expressions of reifiable types.
|
|
|
|
|
exec 'syn region ' . s:ctx.dsg . ' contained transparent matchgroup=' . s:ctx.ghg . ' start="\[" end="\]" nextgroup=' . s:ctx.dsg . ' skipwhite skipnl'
|
|
|
|
|
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 . ',javaAnnotation,javaTypeArgument,javaWildcardBound,javaType,@javaClasses nextgroup=' . s:ctx.dsg . ' skipwhite skipnl'
|
|
|
|
|
endfor
|
|
|
|
|
|
|
|
|
|
unlet s:ctx
|
2024-07-31 13:59:55 -07:00
|
|
|
|
hi def link javaWildcardBound Question
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaGenericsC1 Function
|
|
|
|
|
hi def link javaGenericsC2 Type
|
vim-patch:beb02ed: runtime(java): Optionally highlight parameterised types
In the presence of parameterised types whose names begin
with a capital letter and end with a less-than sign "<" that
introduces a type argument or a list of comma-separated type
arguments, followed by a greater-than sign ">", a variable
"g:java_highlight_generics" can be defined to have some
components of such types uniformly coloured (by picking
highlight groups for javaGenericsC{1,2}, javaWildcardBound).
For example,
------------------------------------------------------------
java.io.InputStream stream = java.io.InputStream.nullInputStream();
java.util.function.Function<String,
java.util.function.BiFunction<String, String, String>> updater =
property -> (oldValue, newValue) -> oldValue;
java.util.logging.LogManager.getLogManager()
.updateConfiguration(stream, updater);
------------------------------------------------------------
Note that the diamond form and explicit type arguments do
not qualify for this kind of recognition.
For example,
------------------------------------------------------------
new java.util.HashSet<>().<String>toArray(new String[0]);
------------------------------------------------------------
References:
https://docs.oracle.com/javase/specs/jls/se21/html/jls-4.html#jls-4.5
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.9
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.12.2.1
closes: vim/vim#15050
https://github.com/vim/vim/commit/beb02ed674bc61f179c4ff71e93bdeeb44fe9c4e
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-06-21 01:34:59 -07:00
|
|
|
|
endif
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_java_lang_ids")
|
|
|
|
|
let g:java_highlight_all = 1
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_all") || exists("g:java_highlight_java") || exists("g:java_highlight_java_lang")
|
2014-07-10 21:05:51 -07:00
|
|
|
|
" java.lang.*
|
2022-06-09 23:40:32 -07:00
|
|
|
|
"
|
|
|
|
|
" The keywords of javaR_JavaLang, javaC_JavaLang, javaE_JavaLang,
|
|
|
|
|
" and javaX_JavaLang are sub-grouped according to the Java version
|
|
|
|
|
" of their introduction, and sub-group keywords (that is, class
|
|
|
|
|
" names) are arranged in alphabetical order, so that future newer
|
|
|
|
|
" keywords can be pre-sorted and appended without disturbing
|
|
|
|
|
" the current keyword placement. The below _match_es follow suit.
|
|
|
|
|
|
2024-03-26 10:26:07 -07:00
|
|
|
|
syn keyword javaR_JavaLang ArithmeticException ArrayIndexOutOfBoundsException ArrayStoreException ClassCastException IllegalArgumentException IllegalMonitorStateException IllegalThreadStateException IndexOutOfBoundsException NegativeArraySizeException NullPointerException NumberFormatException RuntimeException SecurityException StringIndexOutOfBoundsException IllegalStateException UnsupportedOperationException EnumConstantNotPresentException TypeNotPresentException IllegalCallerException LayerInstantiationException WrongThreadException MatchException
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn cluster javaClasses add=javaR_JavaLang
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaR_JavaLang javaR_Java
|
2022-06-09 23:40:32 -07:00
|
|
|
|
" Member enumerations:
|
2024-05-11 00:30:56 -07:00
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<Thread\.\)\@' . s:ff.Peek('7', '') . '<=\<State\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<Character\.\)\@' . s:ff.Peek('10', '') . '<=\<UnicodeScript\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<ProcessBuilder\.Redirect\.\)\@' . s:ff.Peek('24', '') . '<=\<Type\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<StackWalker\.\)\@' . s:ff.Peek('12', '') . '<=\<Option\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<System\.Logger\.\)\@' . s:ff.Peek('14', '') . '<=\<Level\>"'
|
2022-06-09 23:40:32 -07:00
|
|
|
|
" Member classes:
|
2024-05-11 00:30:56 -07:00
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<Character\.\)\@' . s:ff.Peek('10', '') . '<=\<Subset\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<Character\.\)\@' . s:ff.Peek('10', '') . '<=\<UnicodeBlock\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<ProcessBuilder\.\)\@' . s:ff.Peek('15', '') . '<=\<Redirect\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<ModuleLayer\.\)\@' . s:ff.Peek('12', '') . '<=\<Controller\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<Runtime\.\)\@' . s:ff.Peek('8', '') . '<=\<Version\>"'
|
|
|
|
|
exec 'syn match javaC_JavaLang "\%(\<System\.\)\@' . s:ff.Peek('7', '') . '<=\<LoggerFinder\>"'
|
vim-patch:beb02ed: runtime(java): Optionally highlight parameterised types
In the presence of parameterised types whose names begin
with a capital letter and end with a less-than sign "<" that
introduces a type argument or a list of comma-separated type
arguments, followed by a greater-than sign ">", a variable
"g:java_highlight_generics" can be defined to have some
components of such types uniformly coloured (by picking
highlight groups for javaGenericsC{1,2}, javaWildcardBound).
For example,
------------------------------------------------------------
java.io.InputStream stream = java.io.InputStream.nullInputStream();
java.util.function.Function<String,
java.util.function.BiFunction<String, String, String>> updater =
property -> (oldValue, newValue) -> oldValue;
java.util.logging.LogManager.getLogManager()
.updateConfiguration(stream, updater);
------------------------------------------------------------
Note that the diamond form and explicit type arguments do
not qualify for this kind of recognition.
For example,
------------------------------------------------------------
new java.util.HashSet<>().<String>toArray(new String[0]);
------------------------------------------------------------
References:
https://docs.oracle.com/javase/specs/jls/se21/html/jls-4.html#jls-4.5
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.9
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.12.2.1
closes: vim/vim#15050
https://github.com/vim/vim/commit/beb02ed674bc61f179c4ff71e93bdeeb44fe9c4e
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-06-21 01:34:59 -07:00
|
|
|
|
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
|
2022-06-09 23:40:32 -07:00
|
|
|
|
syn match javaC_JavaLang "\<System\>" " See javaDebug.
|
vim-patch:beb02ed: runtime(java): Optionally highlight parameterised types
In the presence of parameterised types whose names begin
with a capital letter and end with a less-than sign "<" that
introduces a type argument or a list of comma-separated type
arguments, followed by a greater-than sign ">", a variable
"g:java_highlight_generics" can be defined to have some
components of such types uniformly coloured (by picking
highlight groups for javaGenericsC{1,2}, javaWildcardBound).
For example,
------------------------------------------------------------
java.io.InputStream stream = java.io.InputStream.nullInputStream();
java.util.function.Function<String,
java.util.function.BiFunction<String, String, String>> updater =
property -> (oldValue, newValue) -> oldValue;
java.util.logging.LogManager.getLogManager()
.updateConfiguration(stream, updater);
------------------------------------------------------------
Note that the diamond form and explicit type arguments do
not qualify for this kind of recognition.
For example,
------------------------------------------------------------
new java.util.HashSet<>().<String>toArray(new String[0]);
------------------------------------------------------------
References:
https://docs.oracle.com/javase/specs/jls/se21/html/jls-4.html#jls-4.5
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.9
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.12.2.1
closes: vim/vim#15050
https://github.com/vim/vim/commit/beb02ed674bc61f179c4ff71e93bdeeb44fe9c4e
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-06-21 01:34:59 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if !exists("g:java_highlight_generics")
|
vim-patch:beb02ed: runtime(java): Optionally highlight parameterised types
In the presence of parameterised types whose names begin
with a capital letter and end with a less-than sign "<" that
introduces a type argument or a list of comma-separated type
arguments, followed by a greater-than sign ">", a variable
"g:java_highlight_generics" can be defined to have some
components of such types uniformly coloured (by picking
highlight groups for javaGenericsC{1,2}, javaWildcardBound).
For example,
------------------------------------------------------------
java.io.InputStream stream = java.io.InputStream.nullInputStream();
java.util.function.Function<String,
java.util.function.BiFunction<String, String, String>> updater =
property -> (oldValue, newValue) -> oldValue;
java.util.logging.LogManager.getLogManager()
.updateConfiguration(stream, updater);
------------------------------------------------------------
Note that the diamond form and explicit type arguments do
not qualify for this kind of recognition.
For example,
------------------------------------------------------------
new java.util.HashSet<>().<String>toArray(new String[0]);
------------------------------------------------------------
References:
https://docs.oracle.com/javase/specs/jls/se21/html/jls-4.html#jls-4.5
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.9
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.12.2.1
closes: vim/vim#15050
https://github.com/vim/vim/commit/beb02ed674bc61f179c4ff71e93bdeeb44fe9c4e
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-06-21 01:34:59 -07:00
|
|
|
|
" 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
|
|
|
|
|
endif
|
|
|
|
|
|
2024-04-04 14:48:43 -07:00
|
|
|
|
" As of JDK 21, java.lang.Compiler is no more (deprecated in JDK 9).
|
2024-03-26 10:26:07 -07:00
|
|
|
|
syn keyword javaLangDeprecated Compiler
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn cluster javaClasses add=javaC_JavaLang
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaC_JavaLang javaC_Java
|
2022-06-09 23:40:32 -07:00
|
|
|
|
syn keyword javaE_JavaLang AbstractMethodError ClassCircularityError ClassFormatError Error IllegalAccessError IncompatibleClassChangeError InstantiationError InternalError LinkageError NoClassDefFoundError NoSuchFieldError NoSuchMethodError OutOfMemoryError StackOverflowError ThreadDeath UnknownError UnsatisfiedLinkError VerifyError VirtualMachineError ExceptionInInitializerError UnsupportedClassVersionError AssertionError BootstrapMethodError
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn cluster javaClasses add=javaE_JavaLang
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaE_JavaLang javaE_Java
|
2022-06-09 23:40:32 -07:00
|
|
|
|
syn keyword javaX_JavaLang ClassNotFoundException CloneNotSupportedException Exception IllegalAccessException InstantiationException InterruptedException NoSuchMethodException Throwable NoSuchFieldException ReflectiveOperationException
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn cluster javaClasses add=javaX_JavaLang
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaX_JavaLang javaX_Java
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaR_Java javaR_
|
|
|
|
|
hi def link javaC_Java javaC_
|
|
|
|
|
hi def link javaE_Java javaE_
|
|
|
|
|
hi def link javaX_Java javaX_
|
2024-07-31 13:59:55 -07:00
|
|
|
|
hi def link javaX_ javaExceptions
|
|
|
|
|
hi def link javaR_ javaExceptions
|
|
|
|
|
hi def link javaE_ javaExceptions
|
|
|
|
|
hi def link javaC_ javaConstant
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-06-23 03:00:49 -07:00
|
|
|
|
syn keyword javaLangObject getClass notify notifyAll wait
|
|
|
|
|
|
|
|
|
|
" Lower the syntax priority of overridable java.lang.Object method
|
|
|
|
|
" names for zero-width matching (define g:java_highlight_signature
|
|
|
|
|
" and see their base declarations for java.lang.Object):
|
|
|
|
|
syn match javaLangObject "\<clone\>"
|
|
|
|
|
syn match javaLangObject "\<equals\>"
|
|
|
|
|
syn match javaLangObject "\<finalize\>"
|
|
|
|
|
syn match javaLangObject "\<hashCode\>"
|
|
|
|
|
syn match javaLangObject "\<toString\>"
|
|
|
|
|
hi def link javaLangObject javaConstant
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
|
2024-05-11 00:30:56 -07:00
|
|
|
|
if filereadable(expand("<sfile>:p:h") . "/javaid.vim")
|
2014-07-10 21:05:51 -07:00
|
|
|
|
source <sfile>:p:h/javaid.vim
|
|
|
|
|
endif
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_space_errors")
|
|
|
|
|
if !exists("g:java_no_trail_space_error")
|
|
|
|
|
syn match javaSpaceError "\s\+$"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if !exists("g:java_no_tab_space_error")
|
|
|
|
|
syn match javaSpaceError " \+\t"me=e-1
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaSpaceError Error
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
|
2024-07-25 00:26:13 -07:00
|
|
|
|
exec 'syn match javaUserLabel "^\s*\<\K\k*\>\%(\<default\>\)\@' . s:ff.Peek('7', '') . '<!\s*::\@!"he=e-1'
|
2024-09-19 09:56:19 -07:00
|
|
|
|
|
|
|
|
|
if s:ff.IsRequestedPreviewFeature(455)
|
|
|
|
|
syn region javaLabelRegion transparent matchgroup=javaLabel start="\<case\>" matchgroup=NONE end=":\|->" contains=javaBoolean,javaNumber,javaCharacter,javaString,javaConstant,@javaClasses,javaGenerics,javaType,javaLabelDefault,javaLabelVarType,javaLabelWhenClause
|
|
|
|
|
else
|
|
|
|
|
syn region javaLabelRegion transparent matchgroup=javaLabel start="\<case\>" matchgroup=NONE end=":\|->" contains=javaLabelCastType,javaLabelNumber,javaCharacter,javaString,javaConstant,@javaClasses,javaGenerics,javaLabelDefault,javaLabelVarType,javaLabelWhenClause
|
|
|
|
|
syn keyword javaLabelCastType contained char byte short int
|
|
|
|
|
syn match javaLabelNumber contained "\<0\>[lL]\@!"
|
|
|
|
|
syn match javaLabelNumber contained "\<\%(0\%([xX]\x\%(_*\x\)*\|_*\o\%(_*\o\)*\|[bB][01]\%(_*[01]\)*\)\|[1-9]\%(_*\d\)*\)\>[lL]\@!"
|
|
|
|
|
hi def link javaLabelCastType javaType
|
|
|
|
|
hi def link javaLabelNumber javaNumber
|
|
|
|
|
endif
|
|
|
|
|
|
vim-patch:9ecf02cd5f5f
runtime(java): Recognise _when_ clauses in _switch_ blocks
Also:
- distinguish _yield_ when used as a contextual keyword from
when used qualified as a method or a method reference (as
can be seen in testdir/input/java_switch.java, variables
and method declarations named _yield_ will be recognised
as the namesake keyword--consider picking other names for
variables, and defining g:java_highlight_functions to have
method names painted; since _yield_ statements can have
trailing parens, they must be recognised as statements,
for only qualified _yield_ method calls are supported);
- recognise grouped _default_ _case_ labels;
- describe primitive types for _case_ labels (JLS, §14.11,
§3.10.1);
- recognise some non-ASCII identifiers (see javaLambdaDef,
javaUserLabel) (further improvement for better recognition
of identifiers will be arranged in a separate PR).
Because the arrow '->' is used in two kinds of expressions,
lambda (abstractions) and _switch_, necessary changes were
made for the recognition of either (and further improvement
touching lambda expressions will be separately arranged).
Because 'default' is used for instance method declarations
in interfaces and in _switch_ labels, necessary changes were
made for the recognition of either (and further improvement
touching method declarations will be separately arranged).
Finally, it deemed appropriate to put 'yield' in the syntax
group of javaOperator rather than javaStatement, for its
member 'var' is also another contextual keyword (e.g., this
is valid syntax: "var var = var(test.var);").
References:
https://openjdk.org/jeps/361 (Switch Expressions)
https://openjdk.org/jeps/440 (Record Patterns)
https://openjdk.org/jeps/441 (Pattern Matching for switch)
Also, add a Java specific filetype plugin for the syntax
test, so that no soft-wrapping of long indented lines occur.
Otherwise the syntax scripts would miss a few lines during
scrolling and verification of the screen dumps.
closes: vim/vim#14105
https://github.com/vim/vim/commit/9ecf02cd5f5feabe096f66cd5f503a822c78793f
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-02-29 01:36:07 -07:00
|
|
|
|
syn region javaLabelRegion transparent matchgroup=javaLabel start="\<default\>\%(\s*\%(:\|->\)\)\@=" matchgroup=NONE end=":\|->" oneline
|
|
|
|
|
" Consider grouped _default_ _case_ labels, i.e.
|
|
|
|
|
" case null, default ->
|
|
|
|
|
" case null: default:
|
|
|
|
|
syn keyword javaLabelDefault contained default
|
|
|
|
|
syn keyword javaLabelVarType contained var
|
|
|
|
|
" Allow for the contingency of the enclosing region not being able to
|
|
|
|
|
" _keep_ its _end_, e.g. case ':':.
|
2024-06-09 09:43:20 -07:00
|
|
|
|
syn region javaLabelWhenClause contained transparent matchgroup=javaLabel start="\<when\>" matchgroup=NONE end=":"me=e-1 end="->"me=e-2 contains=TOP,javaExternal,javaLambdaDef
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
|
" Comments
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn keyword javaTodo contained TODO FIXME XXX
|
2024-03-03 08:07:23 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
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
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn match javaCommentCharacter contained "'\\[^']\{1,6\}'" contains=javaSpecialChar
|
|
|
|
|
syn match javaCommentCharacter contained "'\\''" contains=javaSpecialChar
|
|
|
|
|
syn match javaCommentCharacter contained "'[^\\]'"
|
vim-patch:a2c65809dafe
runtime(java): Recognise string templates (vim/vim#14150)
As this is encouraged in the referenced JEPs, "to visually
distinguish a string template from a string literal, and
a text block template from a text block", the default
colours for java\%[Debug]StrTempl are made distinct from
java\%[Debug]String.
According to §3.2 Lexical Translations (JLS, c. 1996 or any
more recent version), line terminators, white space, and
comments are discarded before tokens are accepted. Since
a template expression comprises a template processor, a dot,
and a template, it may be visually appealing to break up
its head across a few lines whenever its tail already spans
multiple lines. Curiously, no allowance for it is made in
the distributed tests for OpenJDK 21; the proposed regexp
patterns take in consideration a line terminator and white
space after a dot.
References:
https://openjdk.org/jeps/430 (Preview)
https://openjdk.org/jeps/459 (Second Preview)
https://openjdk.org/jeps/465
https://github.com/vim/vim/commit/a2c65809dafe5c4f45f278fddf368c7c971d83e9
Co-authored-by: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>
2024-03-09 19:19:15 -07:00
|
|
|
|
syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber,javaStrTempl
|
|
|
|
|
syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber,javaStrTempl
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
2024-03-03 08:07:23 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn region javaComment matchgroup=javaCommentStart start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,javaCommentError,javaSpaceError,@Spell fold
|
|
|
|
|
syn match javaCommentStar contained "^\s*\*[^/]"me=e-1
|
|
|
|
|
syn match javaCommentStar contained "^\s*\*$"
|
2024-03-25 02:10:57 -07:00
|
|
|
|
syn match javaLineComment "//.*" contains=@javaCommentSpecial2,javaTodo,javaCommentMarkupTag,javaSpaceError,@Spell
|
vim-patch:8e59a7ba8877
runtime(java): Recognise the inline kind of the {@return} tag (vim/vim#14284)
Also:
- Refine comment matching (javaComment{Error\ and,Start}).
- Continue rewriting regexps (prefer atom grouping with
non-capturing parens; factor out common prefixes in
alternations).
- Allow for relative paths with the _file_ attribute of
{@snippet}.
- Anticipate HTML in the @see tags.
- Match the nullary method parens in javaDocSeeTagParam.
- Improve the boundary patterns for summary sentences of
documentation.
> This sentence ends at ... or at the first tag (as defined
> below).
There are Java documentation tags (@) and there are HTML
tags (<?>) (with Markdown looming large; see JEP 467). With
block tags, e.g. @param, @return, @see, we begin another
documentation "sentence" whether or not the author has
terminated the summary sentence with a period; with
.<!-- -->, we may follow abbreviations, enumerations,
initials, (but instead consider @literal or ) _within_
the summary sentence. On the other hand, inline tags, e.g.
@code, @link, @literal, should not terminate the summary
sentence.
References:
https://bugs.openjdk.org/browse/JDK-8075778
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#firstsentence
https://docs.oracle.com/en/java/javase/21/docs/specs/javadoc/doc-comment-spec.html
https://github.com/vim/vim/commit/8e59a7ba88776d5425bafc6eefd978de3312fcdf
Co-authored-by: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>
2024-03-25 11:03:26 -07:00
|
|
|
|
syn match javaCommentMarkupTag contained "@\%(end\|highlight\|link\|replace\|start\)\>" nextgroup=javaCommentMarkupTagAttr,javaSpaceError skipwhite
|
|
|
|
|
syn match javaCommentMarkupTagAttr contained "\<region\>" nextgroup=javaCommentMarkupTagAttr,javaSpaceError skipwhite
|
2024-07-31 14:00:22 -07:00
|
|
|
|
exec 'syn region javaCommentMarkupTagAttr contained transparent matchgroup=javaHtmlArg start=/\<\%(re\%(gex\|gion\|placement\)\|substring\|t\%(arget\|ype\)\)\%(\s*=\)\@=/ matchgroup=javaHtmlString end=/\%(=\s*\)\@' . s:ff.Peek('80', '') . '<=\%("[^"]\+"\|' . "\x27[^\x27]\\+\x27" . '\|\%([.-]\|\k\)\+\)/ nextgroup=javaCommentMarkupTagAttr,javaSpaceError skipwhite oneline'
|
vim-patch:8e59a7ba8877
runtime(java): Recognise the inline kind of the {@return} tag (vim/vim#14284)
Also:
- Refine comment matching (javaComment{Error\ and,Start}).
- Continue rewriting regexps (prefer atom grouping with
non-capturing parens; factor out common prefixes in
alternations).
- Allow for relative paths with the _file_ attribute of
{@snippet}.
- Anticipate HTML in the @see tags.
- Match the nullary method parens in javaDocSeeTagParam.
- Improve the boundary patterns for summary sentences of
documentation.
> This sentence ends at ... or at the first tag (as defined
> below).
There are Java documentation tags (@) and there are HTML
tags (<?>) (with Markdown looming large; see JEP 467). With
block tags, e.g. @param, @return, @see, we begin another
documentation "sentence" whether or not the author has
terminated the summary sentence with a period; with
.<!-- -->, we may follow abbreviations, enumerations,
initials, (but instead consider @literal or ) _within_
the summary sentence. On the other hand, inline tags, e.g.
@code, @link, @literal, should not terminate the summary
sentence.
References:
https://bugs.openjdk.org/browse/JDK-8075778
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#firstsentence
https://docs.oracle.com/en/java/javase/21/docs/specs/javadoc/doc-comment-spec.html
https://github.com/vim/vim/commit/8e59a7ba88776d5425bafc6eefd978de3312fcdf
Co-authored-by: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>
2024-03-25 11:03:26 -07:00
|
|
|
|
syn match javaCommentError contained "/\*"me=e-1 display
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-09-30 22:00:12 -07:00
|
|
|
|
if !exists("g:java_ignore_javadoc") && (s:with_html || s:with_markdown) && g:main_syntax != 'jsp'
|
|
|
|
|
" The overridable "html*" and "markdown*" default links must be
|
|
|
|
|
" defined _before_ the inclusion of the same default links from
|
|
|
|
|
" "html.vim" and "markdown.vim".
|
|
|
|
|
if s:with_html || s:with_markdown
|
|
|
|
|
hi def link htmlComment Special
|
|
|
|
|
hi def link htmlCommentPart Special
|
|
|
|
|
hi def link htmlArg Type
|
|
|
|
|
hi def link htmlString String
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
if s:with_markdown
|
|
|
|
|
hi def link markdownCode Special
|
|
|
|
|
hi def link markdownCodeBlock Special
|
|
|
|
|
hi def link markdownCodeDelimiter Special
|
|
|
|
|
hi def link markdownLinkDelimiter Comment
|
|
|
|
|
endif
|
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syntax case ignore
|
2024-05-11 00:30:56 -07:00
|
|
|
|
|
2024-09-30 22:00:12 -07:00
|
|
|
|
" Note that javaDocSeeTag is valid in HTML and Markdown.
|
|
|
|
|
let s:ff.WithMarkdown = s:ff.RightConstant
|
|
|
|
|
|
2024-05-11 00:30:56 -07:00
|
|
|
|
" Include HTML syntax coloring for Javadoc comments.
|
2024-09-30 22:00:12 -07:00
|
|
|
|
if s:with_html
|
|
|
|
|
syntax include @javaHtml syntax/html.vim
|
|
|
|
|
unlet b:current_syntax
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
" Include Markdown syntax coloring (v7.2.437) for Javadoc comments.
|
|
|
|
|
if s:with_markdown
|
|
|
|
|
try
|
|
|
|
|
syntax include @javaMarkdown syntax/markdown.vim
|
|
|
|
|
unlet b:current_syntax
|
|
|
|
|
let s:ff.WithMarkdown = s:ff.LeftConstant
|
|
|
|
|
catch /\<E48[45]:/
|
|
|
|
|
call s:ReportOnce(v:exception)
|
|
|
|
|
unlockvar s:with_markdown
|
|
|
|
|
let s:with_markdown = 0
|
|
|
|
|
lockvar s:with_markdown
|
|
|
|
|
hi clear markdownCode
|
|
|
|
|
hi clear markdownCodeBlock
|
|
|
|
|
hi clear markdownCodeDelimiter
|
|
|
|
|
hi clear markdownLinkDelimiter
|
|
|
|
|
endtry
|
|
|
|
|
endif
|
2024-05-11 00:30:56 -07:00
|
|
|
|
|
|
|
|
|
" HTML enables spell checking for all text that is not in a syntax
|
|
|
|
|
" item (:syntax spell toplevel); instead, limit spell checking to
|
|
|
|
|
" items matchable with syntax groups containing the @Spell cluster.
|
|
|
|
|
try
|
|
|
|
|
syntax spell default
|
|
|
|
|
catch /\<E390:/
|
|
|
|
|
call s:ReportOnce(v:exception)
|
|
|
|
|
endtry
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-09-30 22:00:12 -07:00
|
|
|
|
if s:with_markdown
|
|
|
|
|
syn region javaMarkdownComment start="///" skip="^\s*///.*$" end="^" keepend contains=javaMarkdownCommentTitle,javaMarkdownShortcutLink,@javaMarkdown,@javaDocTags,javaTodo,@Spell nextgroup=javaMarkdownCommentTitle fold
|
|
|
|
|
syn match javaMarkdownCommentMask contained "^\s*///"
|
|
|
|
|
exec 'syn region javaMarkdownCommentTitle contained matchgroup=javaMarkdownComment start="\%(///.*\r\=\n\s*\)\@' . s:ff.Peek('80', '') . '<!///" matchgroup=javaMarkdownCommentTitle end="\.$" end="\.[ \t\r]\@=" end="\n\%(\s*///\s*$\)\@=" end="\%(^\s*///\s*\)\@' . s:ff.Peek('80', '') . '<=@"me=s-2,he=s-1 contains=javaMarkdownShortcutLink,@javaMarkdown,javaMarkdownCommentMask,javaTodo,@Spell,@javaDocTags'
|
|
|
|
|
exec 'syn region javaMarkdownCommentTitle contained matchgroup=javaMarkdownComment start="\%(///.*\r\=\n\s*\)\@' . s:ff.Peek('80', '') . '<!///\s*\%({@return\>\)\@=" matchgroup=javaMarkdownCommentTitle end="}\%(\s*\.*\)*" contains=javaMarkdownShortcutLink,@javaMarkdown,javaMarkdownCommentMask,javaTodo,@Spell,@javaDocTags,javaTitleSkipBlock'
|
|
|
|
|
exec 'syn region javaMarkdownCommentTitle contained matchgroup=javaMarkdownComment start="\%(///.*\r\=\n\s*\)\@' . s:ff.Peek('80', '') . '<!///\s*\%({@summary\>\)\@=" matchgroup=javaMarkdownCommentTitle end="}" contains=javaMarkdownShortcutLink,@javaMarkdown,javaMarkdownCommentMask,javaTodo,@Spell,@javaDocTags,javaTitleSkipBlock'
|
|
|
|
|
|
|
|
|
|
syn clear markdownId markdownLineStart markdownH1 markdownH2 markdownHeadingRule markdownRule markdownCode markdownCodeBlock markdownIdDeclaration
|
|
|
|
|
" REDEFINE THE MARKDOWN ITEMS ANCHORED WITH "^", OBSERVING THE
|
|
|
|
|
" DEFINITION ORDER.
|
|
|
|
|
syn match markdownLineStart contained "^\s*///\s*[<@]\@!" contains=@markdownBlock,javaMarkdownCommentTitle,javaMarkdownCommentMask nextgroup=@markdownBlock,htmlSpecialChar
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#setext-headings.
|
|
|
|
|
syn match markdownH1 contained "^\s*/// \{,3}.\+\r\=\n\s*/// \{,3}=\+\s*$" contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink,javaMarkdownCommentMask
|
|
|
|
|
syn match markdownH2 contained "^\s*/// \{,3}.\+\r\=\n\s*/// \{,3}-\+\s*$" contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink,javaMarkdownCommentMask
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#atx-headings.
|
|
|
|
|
syn region markdownH1 contained matchgroup=markdownH1Delimiter start=" \{,3}#\s" end="#*\s*$" keepend contains=@markdownInline,markdownAutomaticLink oneline
|
|
|
|
|
syn region markdownH2 contained matchgroup=markdownH2Delimiter start=" \{,3}##\s" end="#*\s*$" keepend contains=@markdownInline,markdownAutomaticLink oneline
|
|
|
|
|
syn match markdownHeadingRule contained "^\s*/// \{,3}[=-]\+\s*$" contains=javaMarkdownCommentMask
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#thematic-breaks.
|
|
|
|
|
syn match markdownRule contained "^\s*/// \{,3}\*\s*\*\%(\s*\*\)\+\s*$" contains=javaMarkdownCommentMask
|
|
|
|
|
syn match markdownRule contained "^\s*/// \{,3}_\s*_\%(\s*_\)\+\s*$" contains=javaMarkdownCommentMask
|
|
|
|
|
syn match markdownRule contained "^\s*/// \{,3}-\s*-\%(\s*-\)\+\s*$" contains=javaMarkdownCommentMask
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#indented-code-blocks.
|
|
|
|
|
syn region markdownCodeBlock contained start="^\s*///\%( \{4,}\|\t\)" end="^\ze\s*///\%(\s*$\| \{,3}\S\)" keepend contains=javaMarkdownCommentMask
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#code-spans.
|
|
|
|
|
syn region markdownCode contained matchgroup=markdownCodeDelimiter start="\z(`\+\) \=" end=" \=\z1" keepend contains=markdownLineStart,javaMarkdownCommentMask
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#fenced-code-blocks.
|
|
|
|
|
syn region markdownCodeBlock contained start="^\s*/// \{,3}\z(```\+\)\%(.\{-}[^`]`\)\@!" end="^\s*/// \{,3}\z1`*" keepend contains=javaMarkdownCommentMask
|
|
|
|
|
syn region markdownCodeBlock contained start="^\s*/// \{,3}\z(\~\~\~\+\)" end="^\s*/// \{,3}\z1\~*" keepend contains=javaMarkdownCommentMask
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#link-reference-definitions.
|
|
|
|
|
syn region markdownIdDeclaration contained matchgroup=markdownLinkDelimiter start="^\s*/// \{,3\}!\=\[" end="\]:" keepend contains=javaMarkdownCommentMask nextgroup=markdownUrl oneline skipwhite
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#link-label.
|
|
|
|
|
syn region markdownId contained matchgroup=markdownIdDelimiter start="\[\%([\t ]\]\)\@!" end="\]" contains=javaMarkdownSkipBrackets,javaMarkdownCommentMask
|
|
|
|
|
" Note that escaped brackets can be unbalanced.
|
|
|
|
|
syn match javaMarkdownSkipBrackets contained transparent "\\\[\|\\\]"
|
|
|
|
|
" See https://spec.commonmark.org/0.31.2/#shortcut-reference-link.
|
|
|
|
|
syn region javaMarkdownShortcutLink contained matchgroup=markdownLinkTextDelimiter start="!\=\[^\@!\%(\_[^][]*\%(\[\_[^][]*\]\_[^][]*\)*]\%([[(]\)\@!\)\@=" end="\]\%([[(]\)\@!" contains=@markdownInline,markdownLineStart,javaMarkdownSkipBrackets,javaMarkdownCommentMask nextgroup=markdownLink,markdownId skipwhite
|
|
|
|
|
|
|
|
|
|
for s:name in ['markdownFootnoteDefinition', 'markdownFootnote']
|
|
|
|
|
if hlexists(s:name)
|
|
|
|
|
exec 'syn clear ' . s:name
|
|
|
|
|
endif
|
|
|
|
|
endfor
|
|
|
|
|
|
|
|
|
|
unlet s:name
|
|
|
|
|
|
|
|
|
|
" COMBAK: Footnotes are recognised by "markdown.vim", but are not
|
|
|
|
|
" in CommonMark. See https://pandoc.org/MANUAL.html#footnotes.
|
|
|
|
|
""""syn match markdownFootnoteDefinition contained "^\s*///\s*\[^[^\]]\+\]:" contains=javaMarkdownCommentMask
|
|
|
|
|
|
|
|
|
|
hi def link javaMarkdownComment Comment
|
|
|
|
|
hi def link javaMarkdownCommentMask javaMarkdownComment
|
|
|
|
|
hi def link javaMarkdownCommentTitle SpecialComment
|
|
|
|
|
hi def link javaMarkdownShortcutLink htmlLink
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
if s:with_html
|
|
|
|
|
syn region javaDocComment start="/\*\*" end="\*/" keepend contains=javaCommentTitle,@javaHtml,@javaDocTags,javaTodo,javaCommentError,javaSpaceError,@Spell fold
|
|
|
|
|
exec 'syn region javaCommentTitle contained matchgroup=javaDocComment start="/\*\*" matchgroup=javaCommentTitle end="\.$" end="\.[ \t\r]\@=" end="\%(^\s*\**\s*\)\@' . s:ff.Peek('80', '') . '<=@"me=s-2,he=s-1 end="\*/"me=s-1,he=s-1 contains=@javaHtml,javaCommentStar,javaTodo,javaCommentError,javaSpaceError,@Spell,@javaDocTags'
|
|
|
|
|
syn region javaCommentTitle contained matchgroup=javaDocComment start="/\*\*\s*\r\=\n\=\s*\**\s*\%({@return\>\)\@=" matchgroup=javaCommentTitle end="}\%(\s*\.*\)*" contains=@javaHtml,javaCommentStar,javaTodo,javaCommentError,javaSpaceError,@Spell,@javaDocTags,javaTitleSkipBlock
|
|
|
|
|
syn region javaCommentTitle contained matchgroup=javaDocComment start="/\*\*\s*\r\=\n\=\s*\**\s*\%({@summary\>\)\@=" matchgroup=javaCommentTitle end="}" contains=@javaHtml,javaCommentStar,javaTodo,javaCommentError,javaSpaceError,@Spell,@javaDocTags,javaTitleSkipBlock
|
|
|
|
|
hi def link javaDocComment Comment
|
|
|
|
|
hi def link javaCommentTitle SpecialComment
|
|
|
|
|
endif
|
|
|
|
|
|
2024-09-11 00:22:59 -07:00
|
|
|
|
" The members of javaDocTags are sub-grouped according to the Java
|
|
|
|
|
" version of their introduction, and sub-group members in turn are
|
|
|
|
|
" arranged in alphabetical order, so that future newer members can
|
|
|
|
|
" be pre-sorted and appended without disturbing the current member
|
|
|
|
|
" placement.
|
|
|
|
|
" Since they only have significance in javaCommentTitle, neither
|
|
|
|
|
" javaDocSummaryTag nor javaDocReturnTitleTag are defined.
|
|
|
|
|
syn cluster javaDocTags contains=javaDocAuthorTag,javaDocDeprecatedTag,javaDocExceptionTag,javaDocParamTag,javaDocReturnTag,javaDocSeeTag,javaDocVersionTag,javaDocSinceTag,javaDocLinkTag,javaDocSerialTag,javaDocSerialDataTag,javaDocSerialFieldTag,javaDocThrowsTag,javaDocDocRootTag,javaDocInheritDocTag,javaDocLinkplainTag,javaDocValueTag,javaDocCodeTag,javaDocLiteralTag,javaDocHiddenTag,javaDocIndexTag,javaDocProvidesTag,javaDocUsesTag,javaDocSystemPropertyTag,javaDocSnippetTag,javaDocSpecTag
|
|
|
|
|
|
|
|
|
|
" Anticipate non-standard inline tags in {@return} and {@summary}.
|
|
|
|
|
syn region javaTitleSkipBlock contained transparent start="{\%(@\%(return\|summary\)\>\)\@!" end="}"
|
|
|
|
|
syn match javaDocDocRootTag contained "{@docRoot}"
|
|
|
|
|
syn match javaDocInheritDocTag contained "{@inheritDoc}"
|
|
|
|
|
syn region javaIndexSkipBlock contained transparent start="{\%(@index\>\)\@!" end="}" contains=javaIndexSkipBlock,javaDocIndexTag
|
|
|
|
|
syn region javaDocIndexTag contained start="{@index\>" end="}" contains=javaDocIndexTag,javaIndexSkipBlock
|
|
|
|
|
syn region javaLinkSkipBlock contained transparent start="{\%(@link\>\)\@!" end="}" contains=javaLinkSkipBlock,javaDocLinkTag
|
|
|
|
|
syn region javaDocLinkTag contained start="{@link\>" end="}" contains=javaDocLinkTag,javaLinkSkipBlock
|
|
|
|
|
syn region javaLinkplainSkipBlock contained transparent start="{\%(@linkplain\>\)\@!" end="}" contains=javaLinkplainSkipBlock,javaDocLinkplainTag
|
|
|
|
|
syn region javaDocLinkplainTag contained start="{@linkplain\>" end="}" contains=javaDocLinkplainTag,javaLinkplainSkipBlock
|
|
|
|
|
syn region javaLiteralSkipBlock contained transparent start="{\%(@literal\>\)\@!" end="}" contains=javaLiteralSkipBlock,javaDocLiteralTag
|
|
|
|
|
syn region javaDocLiteralTag contained start="{@literal\>" end="}" contains=javaDocLiteralTag,javaLiteralSkipBlock
|
|
|
|
|
syn region javaSystemPropertySkipBlock contained transparent start="{\%(@systemProperty\>\)\@!" end="}" contains=javaSystemPropertySkipBlock,javaDocSystemPropertyTag
|
|
|
|
|
syn region javaDocSystemPropertyTag contained start="{@systemProperty\>" end="}" contains=javaDocSystemPropertyTag,javaSystemPropertySkipBlock
|
|
|
|
|
syn region javaValueSkipBlock contained transparent start="{\%(@value\>\)\@!" end="}" contains=javaValueSkipBlock,javaDocValueTag
|
|
|
|
|
syn region javaDocValueTag contained start="{@value\>" end="}" contains=javaDocValueTag,javaValueSkipBlock
|
|
|
|
|
|
|
|
|
|
syn match javaDocParam contained "\s\zs\S\+"
|
|
|
|
|
syn match javaDocExceptionTag contained "@exception\s\+\S\+" contains=javaDocParam
|
|
|
|
|
syn match javaDocParamTag contained "@param\s\+\S\+" contains=javaDocParam
|
|
|
|
|
syn match javaDocSinceTag contained "@since\s\+\S\+" contains=javaDocParam
|
|
|
|
|
syn match javaDocThrowsTag contained "@throws\s\+\S\+" contains=javaDocParam
|
|
|
|
|
syn match javaDocSpecTag contained "@spec\_s\+\S\+\ze\_s\+\S\+" contains=javaDocParam
|
|
|
|
|
|
|
|
|
|
syn match javaDocAuthorTag contained "@author\>"
|
|
|
|
|
syn match javaDocDeprecatedTag contained "@deprecated\>"
|
|
|
|
|
syn match javaDocHiddenTag contained "@hidden\>"
|
|
|
|
|
syn match javaDocReturnTag contained "@return\>"
|
|
|
|
|
syn match javaDocSerialTag contained "@serial\>"
|
|
|
|
|
syn match javaDocSerialDataTag contained "@serialData\>"
|
|
|
|
|
syn match javaDocSerialFieldTag contained "@serialField\>"
|
|
|
|
|
syn match javaDocVersionTag contained "@version\>"
|
|
|
|
|
|
2024-09-30 22:00:12 -07:00
|
|
|
|
syn match javaDocSeeTag contained "@see\>\s*" nextgroup=javaDocSeeTag1,javaDocSeeTag2,javaDocSeeTag3,javaDocSeeTag4,javaDocSeeTagStar,javaDocSeeTagSlash skipwhite skipempty
|
|
|
|
|
|
|
|
|
|
if s:with_html
|
|
|
|
|
syn match javaDocSeeTagStar contained "^\s*\*\+\%(\s*{\=@\|/\|$\)\@!" nextgroup=javaDocSeeTag1,javaDocSeeTag2,javaDocSeeTag3,javaDocSeeTag4 skipwhite skipempty
|
|
|
|
|
hi def link javaDocSeeTagStar javaDocComment
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
if s:with_markdown
|
|
|
|
|
syn match javaDocSeeTagSlash contained "^\s*///\%(\s*{\=@\|$\)\@!" nextgroup=javaDocSeeTag1,javaDocSeeTag2,javaDocSeeTag3,javaDocSeeTag4 skipwhite skipempty
|
|
|
|
|
hi def link javaDocSeeTagSlash javaMarkdownComment
|
|
|
|
|
endif
|
|
|
|
|
|
2024-09-11 00:22:59 -07:00
|
|
|
|
syn match javaDocSeeTag1 contained @"\_[^"]\+"@
|
|
|
|
|
syn match javaDocSeeTag2 contained @<a\s\+\_.\{-}</a>@ contains=@javaHtml extend
|
2024-09-30 22:00:12 -07:00
|
|
|
|
exec 'syn match javaDocSeeTag3 contained @[' . s:ff.WithMarkdown('[', '') . '"< \t]\@!\%(\k\|[/.]\)*\%(##\=\k\+\%((\_[^)]*)\)\=\)\=@ nextgroup=javaDocSeeTag3Label skipwhite skipempty'
|
2024-09-11 00:22:59 -07:00
|
|
|
|
syn match javaDocSeeTag3Label contained @\k\%(\k\+\s*\)*$@
|
|
|
|
|
|
2024-09-30 22:00:12 -07:00
|
|
|
|
" COMBAK: No support for type javaDocSeeTag2 in Markdown.
|
|
|
|
|
""if s:with_markdown
|
|
|
|
|
"" syn match javaDocSeeTag4 contained @\[.\+\]\s\=\%(\[.\+\]\|(.\+)\)@ contains=@javaMarkdown extend
|
|
|
|
|
"" hi def link javaDocSeeTag4 Special
|
|
|
|
|
""endif
|
|
|
|
|
|
2024-03-25 02:10:57 -07:00
|
|
|
|
syn region javaCodeSkipBlock contained transparent start="{\%(@code\>\)\@!" end="}" contains=javaCodeSkipBlock,javaDocCodeTag
|
|
|
|
|
syn region javaDocCodeTag contained start="{@code\>" end="}" contains=javaDocCodeTag,javaCodeSkipBlock
|
2024-09-11 00:22:59 -07:00
|
|
|
|
|
2024-07-31 14:00:22 -07:00
|
|
|
|
exec 'syn region javaDocSnippetTagAttr contained transparent matchgroup=javaHtmlArg start=/\<\%(class\|file\|id\|lang\|region\)\%(\s*=\)\@=/ matchgroup=javaHtmlString end=/:$/ end=/\%(=\s*\)\@' . s:ff.Peek('80', '') . '<=\%("[^"]\+"\|' . "\x27[^\x27]\\+\x27" . '\|\%([.\\/-]\|\k\)\+\)/ nextgroup=javaDocSnippetTagAttr skipwhite skipnl'
|
2024-03-25 02:10:57 -07:00
|
|
|
|
syn region javaSnippetSkipBlock contained transparent start="{\%(@snippet\>\)\@!" end="}" contains=javaSnippetSkipBlock,javaDocSnippetTag,javaCommentMarkupTag
|
|
|
|
|
syn region javaDocSnippetTag contained start="{@snippet\>" end="}" contains=javaDocSnippetTag,javaSnippetSkipBlock,javaDocSnippetTagAttr,javaCommentMarkupTag
|
2024-05-11 00:30:56 -07:00
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syntax case match
|
2024-09-11 00:22:59 -07:00
|
|
|
|
hi def link javaDocParam Function
|
|
|
|
|
|
|
|
|
|
hi def link javaDocAuthorTag Special
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaDocCodeTag Special
|
2024-09-11 00:22:59 -07:00
|
|
|
|
hi def link javaDocDeprecatedTag Special
|
|
|
|
|
hi def link javaDocDocRootTag Special
|
|
|
|
|
hi def link javaDocExceptionTag Special
|
|
|
|
|
hi def link javaDocHiddenTag Special
|
|
|
|
|
hi def link javaDocIndexTag Special
|
|
|
|
|
hi def link javaDocInheritDocTag Special
|
|
|
|
|
hi def link javaDocLinkTag Special
|
|
|
|
|
hi def link javaDocLinkplainTag Special
|
|
|
|
|
hi def link javaDocLiteralTag Special
|
|
|
|
|
hi def link javaDocParamTag Special
|
|
|
|
|
hi def link javaDocReturnTag Special
|
|
|
|
|
hi def link javaDocSeeTag Special
|
|
|
|
|
hi def link javaDocSeeTag1 String
|
|
|
|
|
hi def link javaDocSeeTag2 Special
|
|
|
|
|
hi def link javaDocSeeTag3 Function
|
|
|
|
|
hi def link javaDocSerialTag Special
|
|
|
|
|
hi def link javaDocSerialDataTag Special
|
|
|
|
|
hi def link javaDocSerialFieldTag Special
|
|
|
|
|
hi def link javaDocSinceTag Special
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaDocSnippetTag Special
|
2024-09-11 00:22:59 -07:00
|
|
|
|
hi def link javaDocSpecTag Special
|
|
|
|
|
hi def link javaDocSystemPropertyTag Special
|
|
|
|
|
hi def link javaDocThrowsTag Special
|
|
|
|
|
hi def link javaDocValueTag Special
|
|
|
|
|
hi def link javaDocVersionTag Special
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
" match the special comment /**/
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaComment "/\*\*/"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
|
" Strings and constants
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaSpecialError contained "\\."
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn match javaSpecialCharError contained "[^']"
|
2024-03-02 01:48:57 -07:00
|
|
|
|
" Escape Sequences (JLS-17, §3.10.7):
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaSpecialChar contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn region javaString start=+"+ end=+"+ end=+$+ contains=javaSpecialChar,javaSpecialError,@Spell
|
2024-03-03 08:07:23 -07:00
|
|
|
|
syn region javaString start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
|
|
|
|
|
syn match javaTextBlockError +"""\s*"""+
|
2024-08-28 01:21:59 -07:00
|
|
|
|
|
|
|
|
|
if s:ff.IsRequestedPreviewFeature(430)
|
|
|
|
|
syn region javaStrTemplEmbExp contained matchgroup=javaStrTempl start="\\{" end="}" contains=TOP
|
|
|
|
|
exec 'syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="+ end=+"+ contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,@Spell'
|
|
|
|
|
exec 'syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell'
|
|
|
|
|
hi def link javaStrTempl Macro
|
|
|
|
|
endif
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaCharacter "'[^']*'" contains=javaSpecialChar,javaSpecialCharError
|
|
|
|
|
syn match javaCharacter "'\\''" contains=javaSpecialChar
|
|
|
|
|
syn match javaCharacter "'[^\\]'"
|
2024-03-02 01:48:57 -07:00
|
|
|
|
" Integer literals (JLS-17, §3.10.1):
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn keyword javaNumber 0 0l 0L
|
|
|
|
|
syn match javaNumber "\<\%(0\%([xX]\x\%(_*\x\)*\|_*\o\%(_*\o\)*\|[bB][01]\%(_*[01]\)*\)\|[1-9]\%(_*\d\)*\)[lL]\=\>"
|
2024-03-02 01:48:57 -07:00
|
|
|
|
" Decimal floating-point literals (JLS-17, §3.10.2):
|
|
|
|
|
" Against "\<\d\+\>\.":
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaNumber "\<\d\%(_*\d\)*\."
|
|
|
|
|
syn match javaNumber "\%(\<\d\%(_*\d\)*\.\%(\d\%(_*\d\)*\)\=\|\.\d\%(_*\d\)*\)\%([eE][-+]\=\d\%(_*\d\)*\)\=[fFdD]\=\>"
|
|
|
|
|
syn match javaNumber "\<\d\%(_*\d\)*[eE][-+]\=\d\%(_*\d\)*[fFdD]\=\>"
|
|
|
|
|
syn match javaNumber "\<\d\%(_*\d\)*\%([eE][-+]\=\d\%(_*\d\)*\)\=[fFdD]\>"
|
2024-03-02 01:48:57 -07:00
|
|
|
|
" Hexadecimal floating-point literals (JLS-17, §3.10.2):
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn match javaNumber "\<0[xX]\%(\x\%(_*\x\)*\.\=\|\%(\x\%(_*\x\)*\)\=\.\x\%(_*\x\)*\)[pP][-+]\=\d\%(_*\d\)*[fFdD]\=\>"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-03-02 01:48:57 -07:00
|
|
|
|
" Unicode characters
|
|
|
|
|
syn match javaSpecial "\\u\x\x\x\x"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
vim-patch:a4c085a3e607
runtime(java): Improve the recognition of the "style" method declarations
- Request the new regexp engine (v7.3.970) for [:upper:] and
[:lower:].
- Recognise declarations of in-line annotated methods.
- Recognise declarations of _strictfp_ methods.
- Establish partial order for method modifiers as shown in
the MethodModifier production; namely, _public_ and
friends should be written the leftmost, possibly followed
by _abstract_ or _default_, or possibly followed by other
modifiers.
- Stop looking for parameterisable primitive types (void<?>,
int<Object>, etc., are malformed).
- Stop looking for arrays of _void_.
- Acknowledge the prevailing convention for method names to
begin with a small letter and for class/interface names to
begin with a capital letter; and, therefore, desist from
claiming declarations of enum constants and constructors
with javaFuncDef.
Rationale:
+ Constructor is distinct from method:
* its (overloaded) name is not arbitrary;
* its return type is implicit;
* its _throws_ clause depends on indirect vagaries of
instance (variable) initialisers;
* its invocation makes other constructors of its type
hierarchy invoked one by one, concluding with the
primordial constructor;
* its explicit invocation, via _this_ or _super_, can
only appear as the first statement in a constructor
(not anymore, see JEP 447); else, its _super_ call
cannot appear in constructors of _record_ or _enum_;
and neither invocation is allowed for the primordial
constructor;
* it is not a member of its class, like initialisers,
and is never inherited;
* it is never _abstract_ or _native_.
+ Constructor declarations tend to be few in number and
merit visual recognition from method declarations.
+ Enum constants define a fixed set of type instances
and more resemble class variable initialisers.
Note that the code duplicated for @javaFuncParams is written
keeping in mind for g:java_highlight_functions a pending 3rd
variant, which would require none of the :syn-cluster added
groups.
closes: vim/vim#14620
https://github.com/vim/vim/commit/a4c085a3e607bd01d34e1db600b6460fc35fb0a3
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-04-24 14:44:01 -07:00
|
|
|
|
" Method declarations (JLS-17, §8.4.3, §8.4.4, §9.4).
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_functions")
|
vim-patch:beb02ed: runtime(java): Optionally highlight parameterised types
In the presence of parameterised types whose names begin
with a capital letter and end with a less-than sign "<" that
introduces a type argument or a list of comma-separated type
arguments, followed by a greater-than sign ">", a variable
"g:java_highlight_generics" can be defined to have some
components of such types uniformly coloured (by picking
highlight groups for javaGenericsC{1,2}, javaWildcardBound).
For example,
------------------------------------------------------------
java.io.InputStream stream = java.io.InputStream.nullInputStream();
java.util.function.Function<String,
java.util.function.BiFunction<String, String, String>> updater =
property -> (oldValue, newValue) -> oldValue;
java.util.logging.LogManager.getLogManager()
.updateConfiguration(stream, updater);
------------------------------------------------------------
Note that the diamond form and explicit type arguments do
not qualify for this kind of recognition.
For example,
------------------------------------------------------------
new java.util.HashSet<>().<String>toArray(new String[0]);
------------------------------------------------------------
References:
https://docs.oracle.com/javase/specs/jls/se21/html/jls-4.html#jls-4.5
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.9
https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.12.2.1
closes: vim/vim#15050
https://github.com/vim/vim/commit/beb02ed674bc61f179c4ff71e93bdeeb44fe9c4e
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-06-21 01:34:59 -07:00
|
|
|
|
syn cluster javaFuncParams contains=javaAnnotation,@javaClasses,javaGenerics,javaType,javaVarArg,javaComment,javaLineComment
|
vim-patch:a4c085a3e607
runtime(java): Improve the recognition of the "style" method declarations
- Request the new regexp engine (v7.3.970) for [:upper:] and
[:lower:].
- Recognise declarations of in-line annotated methods.
- Recognise declarations of _strictfp_ methods.
- Establish partial order for method modifiers as shown in
the MethodModifier production; namely, _public_ and
friends should be written the leftmost, possibly followed
by _abstract_ or _default_, or possibly followed by other
modifiers.
- Stop looking for parameterisable primitive types (void<?>,
int<Object>, etc., are malformed).
- Stop looking for arrays of _void_.
- Acknowledge the prevailing convention for method names to
begin with a small letter and for class/interface names to
begin with a capital letter; and, therefore, desist from
claiming declarations of enum constants and constructors
with javaFuncDef.
Rationale:
+ Constructor is distinct from method:
* its (overloaded) name is not arbitrary;
* its return type is implicit;
* its _throws_ clause depends on indirect vagaries of
instance (variable) initialisers;
* its invocation makes other constructors of its type
hierarchy invoked one by one, concluding with the
primordial constructor;
* its explicit invocation, via _this_ or _super_, can
only appear as the first statement in a constructor
(not anymore, see JEP 447); else, its _super_ call
cannot appear in constructors of _record_ or _enum_;
and neither invocation is allowed for the primordial
constructor;
* it is not a member of its class, like initialisers,
and is never inherited;
* it is never _abstract_ or _native_.
+ Constructor declarations tend to be few in number and
merit visual recognition from method declarations.
+ Enum constants define a fixed set of type instances
and more resemble class variable initialisers.
Note that the code duplicated for @javaFuncParams is written
keeping in mind for g:java_highlight_functions a pending 3rd
variant, which would require none of the :syn-cluster added
groups.
closes: vim/vim#14620
https://github.com/vim/vim/commit/a4c085a3e607bd01d34e1db600b6460fc35fb0a3
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-04-24 14:44:01 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_signature")
|
2024-06-23 03:00:49 -07:00
|
|
|
|
syn cluster javaFuncParams add=javaParamModifier
|
|
|
|
|
hi def link javaFuncDefStart javaFuncDef
|
|
|
|
|
else
|
|
|
|
|
syn cluster javaFuncParams add=javaScopeDecl,javaConceptKind,javaStorageClass,javaExternal
|
|
|
|
|
endif
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if g:java_highlight_functions =~# '^indent[1-8]\=$'
|
|
|
|
|
let s:last = g:java_highlight_functions[-1 :]
|
2024-04-29 14:44:53 -07:00
|
|
|
|
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):
|
|
|
|
|
" at any _conventional_ indentation, skip over all fields with
|
|
|
|
|
" "[^=]*", all records with "\<record\s", and let the "*Skip*"
|
|
|
|
|
" definitions take care of constructor declarations and enum
|
2024-06-23 03:00:49 -07:00
|
|
|
|
" constants (with no support for @Foo(value = "bar")). Also,
|
|
|
|
|
" reject inlined declarations with "[^{]" for signature.
|
|
|
|
|
exec 'syn region javaFuncDef ' . s:ff.GroupArgs('transparent matchgroup=javaFuncDefStart', '') . ' start=/' . s:ff.PeekTo('\%(', '') . '^' . s:indent . '\%(<[^>]\+>\+\s\+\|\%(\%(@\%(\K\k*\.\)*\K\k*\>\)\s\+\)\+\)\=\%(\<\K\k*\>\.\)*\K\k*\>[^={]*\%(\<record\)\@' . s:ff.Peek('6', '') . '<!\s' . s:ff.PeekFrom('\)\@' . s:ff.Peek('80', '') . '<=', '') . '\K\k*\s*(/ end=/)/ contains=@javaFuncParams'
|
2024-04-29 14:44:53 -07:00
|
|
|
|
" As long as package-private constructors cannot be matched with
|
|
|
|
|
" javaFuncDef, do not look with javaConstructorSkipDeclarator for
|
|
|
|
|
" them.
|
2024-06-23 03:00:49 -07:00
|
|
|
|
exec 'syn match javaConstructorSkipDeclarator transparent /^' . s:indent . '\%(\%(@\%(\K\k*\.\)*\K\k*\>\)\s\+\)*p\%(ublic\|rotected\|rivate\)\s\+\%(<[^>]\+>\+\s\+\)\=\K\k*\s*\ze(/ contains=javaAnnotation,javaScopeDecl,javaClassDecl,javaTypedef,javaGenerics'
|
|
|
|
|
" With a zero-width span for signature applicable on demand to
|
|
|
|
|
" javaFuncDef, make related adjustments:
|
|
|
|
|
" (1) Claim all enum constants of a line as a unit.
|
|
|
|
|
exec 'syn match javaEnumSkipConstant contained transparent /^' . s:indent . '\%(\%(\%(@\%(\K\k*\.\)*\K\k*\>\)\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\+\)\=\<enum\_s\+\)\@' . s:ff.Peek('80', '') . '<=\K\k*\%(\_s\+implements\_s.\+\)\=\_s*{/ end=/}/ contains=@javaTop,javaEnumSkipConstant'
|
|
|
|
|
" (3) Define a base variant of javaParenT without using @javaTop
|
|
|
|
|
" in order to not include javaFuncDef.
|
|
|
|
|
syn region javaParenE transparent matchgroup=javaParen start="(" end=")" contains=@javaEnumConstants,javaInParen
|
|
|
|
|
syn region javaParenE transparent matchgroup=javaParen start="\[" end="\]" contains=@javaEnumConstants
|
|
|
|
|
syn cluster javaEnumConstants contains=TOP,javaTopEnumDeclaration,javaFuncDef,javaParenT
|
2024-04-29 14:44:53 -07:00
|
|
|
|
unlet s:indent s:last
|
2014-07-10 21:05:51 -07:00
|
|
|
|
else
|
2024-04-15 18:32:55 -07:00
|
|
|
|
" This is the "style" variant (:help ft-java-syntax).
|
vim-patch:a4c085a3e607
runtime(java): Improve the recognition of the "style" method declarations
- Request the new regexp engine (v7.3.970) for [:upper:] and
[:lower:].
- Recognise declarations of in-line annotated methods.
- Recognise declarations of _strictfp_ methods.
- Establish partial order for method modifiers as shown in
the MethodModifier production; namely, _public_ and
friends should be written the leftmost, possibly followed
by _abstract_ or _default_, or possibly followed by other
modifiers.
- Stop looking for parameterisable primitive types (void<?>,
int<Object>, etc., are malformed).
- Stop looking for arrays of _void_.
- Acknowledge the prevailing convention for method names to
begin with a small letter and for class/interface names to
begin with a capital letter; and, therefore, desist from
claiming declarations of enum constants and constructors
with javaFuncDef.
Rationale:
+ Constructor is distinct from method:
* its (overloaded) name is not arbitrary;
* its return type is implicit;
* its _throws_ clause depends on indirect vagaries of
instance (variable) initialisers;
* its invocation makes other constructors of its type
hierarchy invoked one by one, concluding with the
primordial constructor;
* its explicit invocation, via _this_ or _super_, can
only appear as the first statement in a constructor
(not anymore, see JEP 447); else, its _super_ call
cannot appear in constructors of _record_ or _enum_;
and neither invocation is allowed for the primordial
constructor;
* it is not a member of its class, like initialisers,
and is never inherited;
* it is never _abstract_ or _native_.
+ Constructor declarations tend to be few in number and
merit visual recognition from method declarations.
+ Enum constants define a fixed set of type instances
and more resemble class variable initialisers.
Note that the code duplicated for @javaFuncParams is written
keeping in mind for g:java_highlight_functions a pending 3rd
variant, which would require none of the :syn-cluster added
groups.
closes: vim/vim#14620
https://github.com/vim/vim/commit/a4c085a3e607bd01d34e1db600b6460fc35fb0a3
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
2024-04-24 14:44:01 -07:00
|
|
|
|
|
|
|
|
|
" Match arbitrarily indented camelCasedName method declarations.
|
|
|
|
|
" Match: [@ɐ] [abstract] [<α, β>] Τʬ[<γ>][[][]] μʭʭ(/* ... */);
|
2024-06-23 03:00:49 -07:00
|
|
|
|
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\+\)*\)\=\%(<.*[[: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*\>\%(<[^(){}]*[[:space:]-]\@' . s:ff.Peek('1', '') . '<!>\)\=\)\%(\[\]\)*\)\s\+' . s:ff.PeekFrom('\)\@' . s:ff.Peek('80', '') . '<=', '') . '\<' . s:ff.LowerCase('[$_[:lower:]]', '[^A-Z0-9]') . '\k*\>\s*(/ end=/)/ skip=/\/\*.\{-}\*\/\|\/\/.*$/ contains=@javaFuncParams'
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_debug")
|
2014-07-10 21:05:51 -07:00
|
|
|
|
" Strings and constants
|
2024-03-03 08:07:23 -07:00
|
|
|
|
syn match javaDebugSpecial contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn region javaDebugString contained start=+"+ end=+"+ contains=javaDebugSpecial
|
2024-03-03 08:07:23 -07:00
|
|
|
|
syn region javaDebugString contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugSpecial,javaDebugTextBlockError
|
2024-08-28 01:21:59 -07:00
|
|
|
|
|
|
|
|
|
if s:ff.IsRequestedPreviewFeature(430)
|
|
|
|
|
" The highlight groups of java{StrTempl,Debug{,Paren,StrTempl}}\,
|
|
|
|
|
" share one colour by default. Do not conflate unrelated parens.
|
|
|
|
|
syn region javaDebugStrTemplEmbExp contained matchgroup=javaDebugStrTempl start="\\{" end="}" contains=javaComment,javaLineComment,javaDebug\%(Paren\)\@!.*
|
|
|
|
|
exec 'syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="+ end=+"+ contains=javaDebugStrTemplEmbExp,javaDebugSpecial'
|
|
|
|
|
exec 'syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@' . s:ff.Peek('80', '') . '<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugStrTemplEmbExp,javaDebugSpecial,javaDebugTextBlockError'
|
|
|
|
|
hi def link javaDebugStrTempl Macro
|
|
|
|
|
endif
|
|
|
|
|
|
2024-03-03 08:07:23 -07:00
|
|
|
|
syn match javaDebugTextBlockError contained +"""\s*"""+
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn match javaDebugCharacter contained "'[^\\]'"
|
|
|
|
|
syn match javaDebugSpecialCharacter contained "'\\.'"
|
|
|
|
|
syn match javaDebugSpecialCharacter contained "'\\''"
|
2024-03-02 01:48:57 -07:00
|
|
|
|
syn keyword javaDebugNumber contained 0 0l 0L
|
2024-03-03 08:07:23 -07:00
|
|
|
|
syn match javaDebugNumber contained "\<\d\%(_*\d\)*\."
|
2024-03-02 01:48:57 -07:00
|
|
|
|
syn match javaDebugNumber contained "\<\%(0\%([xX]\x\%(_*\x\)*\|_*\o\%(_*\o\)*\|[bB][01]\%(_*[01]\)*\)\|[1-9]\%(_*\d\)*\)[lL]\=\>"
|
|
|
|
|
syn match javaDebugNumber contained "\%(\<\d\%(_*\d\)*\.\%(\d\%(_*\d\)*\)\=\|\.\d\%(_*\d\)*\)\%([eE][-+]\=\d\%(_*\d\)*\)\=[fFdD]\=\>"
|
|
|
|
|
syn match javaDebugNumber contained "\<\d\%(_*\d\)*[eE][-+]\=\d\%(_*\d\)*[fFdD]\=\>"
|
|
|
|
|
syn match javaDebugNumber contained "\<\d\%(_*\d\)*\%([eE][-+]\=\d\%(_*\d\)*\)\=[fFdD]\>"
|
|
|
|
|
syn match javaDebugNumber contained "\<0[xX]\%(\x\%(_*\x\)*\.\=\|\%(\x\%(_*\x\)*\)\=\.\x\%(_*\x\)*\)[pP][-+]\=\d\%(_*\d\)*[fFdD]\=\>"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
syn keyword javaDebugBoolean contained true false
|
|
|
|
|
syn keyword javaDebugType contained null this super
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn region javaDebugParen contained start=+(+ end=+)+ contains=javaDebug.*,javaDebugParen
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-04-15 18:32:55 -07:00
|
|
|
|
" 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
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
hi def link javaDebug Debug
|
|
|
|
|
hi def link javaDebugString DebugString
|
|
|
|
|
hi def link javaDebugTextBlockError Error
|
|
|
|
|
hi def link javaDebugType DebugType
|
|
|
|
|
hi def link javaDebugBoolean DebugBoolean
|
|
|
|
|
hi def link javaDebugNumber Debug
|
|
|
|
|
hi def link javaDebugSpecial DebugSpecial
|
|
|
|
|
hi def link javaDebugSpecialCharacter DebugSpecial
|
|
|
|
|
hi def link javaDebugCharacter DebugString
|
|
|
|
|
hi def link javaDebugParen Debug
|
|
|
|
|
|
|
|
|
|
hi def link DebugString String
|
|
|
|
|
hi def link DebugSpecial Special
|
|
|
|
|
hi def link DebugBoolean Boolean
|
|
|
|
|
hi def link DebugType Type
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
|
2024-06-20 00:08:10 -07:00
|
|
|
|
" Try not to fold top-level-type bodies under assumption that there is
|
|
|
|
|
" but one such body.
|
|
|
|
|
exec 'syn region javaBlock transparent start="\%(^\|^\S[^:]\+\)\@' . s:ff.Peek('120', '') . '<!{" end="}" fold'
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_mark_braces_in_parens_as_errors")
|
2024-06-16 02:29:01 -07:00
|
|
|
|
syn match javaInParen contained "[{}]"
|
|
|
|
|
hi def link javaInParen javaError
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
" catch errors caused by wrong parenthesis
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn region javaParenT transparent matchgroup=javaParen start="(" end=")" contains=@javaTop,javaInParen,javaParenT1
|
|
|
|
|
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 ")"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
" catch errors caused by wrong square parenthesis
|
2024-07-31 13:59:55 -07:00
|
|
|
|
syn region javaParenT transparent matchgroup=javaParen start="\[" end="\]" contains=@javaTop,javaParenT1
|
|
|
|
|
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 "\]"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
" Lambda expressions (JLS-17, §15.27) and method reference expressions
|
|
|
|
|
" (JLS-17, §15.13).
|
|
|
|
|
if exists("g:java_highlight_functions")
|
2024-07-25 00:26:13 -07:00
|
|
|
|
syn match javaMethodRef ":::\@!"
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if exists("g:java_highlight_signature")
|
2024-06-23 03:00:49 -07:00
|
|
|
|
let s:ff.LambdaDef = s:ff.LeftConstant
|
|
|
|
|
else
|
|
|
|
|
let s:ff.LambdaDef = s:ff.RightConstant
|
|
|
|
|
endif
|
|
|
|
|
|
2024-04-15 18:32:55 -07:00
|
|
|
|
" Make ()-matching definitions after the parenthesis error catcher.
|
2024-05-31 02:24:06 -07:00
|
|
|
|
"
|
2024-06-23 03:00:49 -07:00
|
|
|
|
" Note that here and elsewhere a single-line token is used for \z,
|
|
|
|
|
" with other tokens repeated as necessary, to overcome the lack of
|
|
|
|
|
" support for multi-line matching with \z.
|
|
|
|
|
"
|
2024-05-31 02:24:06 -07:00
|
|
|
|
" Match: ([@A [@B ...] final] var a[, var b, ...]) ->
|
|
|
|
|
" | ([@A [@B ...] final] T[<α>][[][]] a[, T b, ...]) ->
|
|
|
|
|
" There is no recognition of expressions interspersed with comments
|
|
|
|
|
" or of expressions whose parameterised parameter types are written
|
|
|
|
|
" across multiple lines.
|
2024-06-23 03:00:49 -07:00
|
|
|
|
exec 'syn ' . s:ff.LambdaDef('region javaLambdaDef transparent matchgroup=javaLambdaDefStart start=/', 'match javaLambdaDef "') . '\k\@' . s:ff.Peek('4', '') . '<!(' . s:ff.LambdaDef('\%(', '') . '[[:space:]\n]*\%(\%(@\%(\K\k*\.\)*\K\k*\>\%((\_.\{-1,})\)\{-,1}[[:space:]\n]\+\)*\%(final[[:space:]\n]\+\)\=\%(\<\K\k*\>\.\)*\<\K\k*\>\%(<[^(){}]*[[:space:]-]\@' . s:ff.Peek('1', '') . '<!>\)\=\%(\%(\%(\[\]\)\+\|\.\.\.\)\)\=[[:space:]\n]\+\<\K\k*\>\%(\[\]\)*\%(,[[:space:]\n]*\)\=\)\+)[[:space:]\n]*' . s:ff.LambdaDef('\z(->\)\)\@=/ end=/)[[:space:]\n]*\z1/', '->"') . ' contains=javaAnnotation,javaParamModifier,javaLambdaVarType,javaType,@javaClasses,javaGenerics,javaVarArg'
|
2024-05-31 02:24:06 -07:00
|
|
|
|
" Match: () ->
|
|
|
|
|
" | (a[, b, ...]) ->
|
2024-06-23 03:00:49 -07:00
|
|
|
|
exec 'syn ' . s:ff.LambdaDef('region javaLambdaDef transparent matchgroup=javaLambdaDefStart start=/', 'match javaLambdaDef "') . '\k\@' . s:ff.Peek('4', '') . '<!(' . s:ff.LambdaDef('\%(', '') . '[[:space:]\n]*\%(\<\K\k*\>\%(,[[:space:]\n]*\)\=\)*)[[:space:]\n]*' . s:ff.LambdaDef('\z(->\)\)\@=/ end=/)[[:space:]\n]*\z1/', '->"')
|
2024-05-31 02:24:06 -07:00
|
|
|
|
" Match: a ->
|
2024-06-23 03:00:49 -07:00
|
|
|
|
exec 'syn ' . s:ff.LambdaDef('region javaLambdaDef transparent start=/', 'match javaLambdaDef "') . '\<\K\k*\>\%(\<default\>\)\@' . s:ff.Peek('7', '') . '<!' . s:ff.LambdaDef('\%([[:space:]\n]*\z(->\)\)\@=/ matchgroup=javaLambdaDefStart end=/\z1/', '[[:space:]\n]*->"')
|
2024-05-31 02:24:06 -07:00
|
|
|
|
|
|
|
|
|
syn keyword javaParamModifier contained final
|
|
|
|
|
syn keyword javaLambdaVarType contained var
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaParamModifier javaConceptKind
|
|
|
|
|
hi def link javaLambdaVarType javaOperator
|
|
|
|
|
hi def link javaLambdaDef javaFuncDef
|
|
|
|
|
hi def link javaLambdaDefStart javaFuncDef
|
|
|
|
|
hi def link javaMethodRef javaFuncDef
|
|
|
|
|
hi def link javaFuncDef Function
|
2016-01-14 16:38:47 -07:00
|
|
|
|
endif
|
|
|
|
|
|
2024-05-10 08:05:25 -07:00
|
|
|
|
" The @javaTop cluster comprises non-contained Java syntax groups.
|
|
|
|
|
" Note that the syntax file "aidl.vim" relies on its availability.
|
2024-06-23 03:00:49 -07:00
|
|
|
|
syn cluster javaTop contains=TOP,javaTopEnumDeclaration
|
2024-05-10 08:05:25 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if !exists("g:java_minlines")
|
|
|
|
|
let g:java_minlines = 10
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
vim-patch:8e59a7ba8877
runtime(java): Recognise the inline kind of the {@return} tag (vim/vim#14284)
Also:
- Refine comment matching (javaComment{Error\ and,Start}).
- Continue rewriting regexps (prefer atom grouping with
non-capturing parens; factor out common prefixes in
alternations).
- Allow for relative paths with the _file_ attribute of
{@snippet}.
- Anticipate HTML in the @see tags.
- Match the nullary method parens in javaDocSeeTagParam.
- Improve the boundary patterns for summary sentences of
documentation.
> This sentence ends at ... or at the first tag (as defined
> below).
There are Java documentation tags (@) and there are HTML
tags (<?>) (with Markdown looming large; see JEP 467). With
block tags, e.g. @param, @return, @see, we begin another
documentation "sentence" whether or not the author has
terminated the summary sentence with a period; with
.<!-- -->, we may follow abbreviations, enumerations,
initials, (but instead consider @literal or ) _within_
the summary sentence. On the other hand, inline tags, e.g.
@code, @link, @literal, should not terminate the summary
sentence.
References:
https://bugs.openjdk.org/browse/JDK-8075778
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#firstsentence
https://docs.oracle.com/en/java/javase/21/docs/specs/javadoc/doc-comment-spec.html
https://github.com/vim/vim/commit/8e59a7ba88776d5425bafc6eefd978de3312fcdf
Co-authored-by: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>
2024-03-25 11:03:26 -07:00
|
|
|
|
|
|
|
|
|
" Note that variations of a /*/ balanced comment, e.g., /*/*/, /*//*/,
|
|
|
|
|
" /* /*/, /* /*/, etc., may have their rightmost /*/ part accepted
|
|
|
|
|
" as a comment start by ':syntax sync ccomment'; consider alternatives
|
|
|
|
|
" 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'.
|
2024-07-31 13:59:55 -07:00
|
|
|
|
exec "syn sync ccomment javaComment minlines=" . g:java_minlines
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
|
" The default highlighting.
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaVarArg Function
|
|
|
|
|
hi def link javaBranch Conditional
|
|
|
|
|
hi def link javaConditional Conditional
|
|
|
|
|
hi def link javaRepeat Repeat
|
|
|
|
|
hi def link javaExceptions Exception
|
|
|
|
|
hi def link javaAssert Statement
|
|
|
|
|
hi def link javaStorageClass StorageClass
|
|
|
|
|
hi def link javaMethodDecl javaStorageClass
|
|
|
|
|
hi def link javaClassDecl javaStorageClass
|
|
|
|
|
hi def link javaScopeDecl javaStorageClass
|
2024-09-15 10:57:03 -07:00
|
|
|
|
hi def link javaConceptKind javaStorageClass
|
2018-10-29 01:50:39 -07:00
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
hi def link javaBoolean Boolean
|
|
|
|
|
hi def link javaSpecial Special
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaSpecialError Error
|
|
|
|
|
hi def link javaSpecialCharError Error
|
|
|
|
|
hi def link javaString String
|
|
|
|
|
hi def link javaCharacter Character
|
|
|
|
|
hi def link javaSpecialChar SpecialChar
|
|
|
|
|
hi def link javaNumber Number
|
|
|
|
|
hi def link javaError Error
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaError2 javaError
|
2024-05-10 08:05:25 -07:00
|
|
|
|
hi def link javaTextBlockError Error
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaParenError javaError
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaStatement Statement
|
|
|
|
|
hi def link javaOperator Operator
|
|
|
|
|
hi def link javaConstant Constant
|
2024-07-31 13:59:55 -07:00
|
|
|
|
hi def link javaTypedef Typedef
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaTodo Todo
|
|
|
|
|
hi def link javaAnnotation PreProc
|
2024-06-13 09:00:52 -07:00
|
|
|
|
hi def link javaAnnotationStart javaAnnotation
|
2017-04-28 12:14:34 -07:00
|
|
|
|
hi def link javaType Type
|
|
|
|
|
hi def link javaExternal Include
|
|
|
|
|
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaUserLabel Label
|
|
|
|
|
hi def link javaUserLabelRef javaUserLabel
|
|
|
|
|
hi def link javaLabel Label
|
|
|
|
|
hi def link javaLabelDefault javaLabel
|
|
|
|
|
hi def link javaLabelVarType javaOperator
|
|
|
|
|
|
|
|
|
|
hi def link javaComment Comment
|
|
|
|
|
hi def link javaCommentStar javaComment
|
|
|
|
|
hi def link javaLineComment Comment
|
|
|
|
|
hi def link javaCommentMarkupTagAttr javaHtmlArg
|
|
|
|
|
hi def link javaCommentString javaString
|
|
|
|
|
hi def link javaComment2String javaString
|
|
|
|
|
hi def link javaCommentCharacter javaCharacter
|
|
|
|
|
hi def link javaCommentError javaError
|
|
|
|
|
hi def link javaCommentStart javaComment
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-07-31 14:00:22 -07:00
|
|
|
|
hi def link javaHtmlArg Type
|
|
|
|
|
hi def link javaHtmlString String
|
2018-10-29 01:50:39 -07:00
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
let b:current_syntax = "java"
|
|
|
|
|
|
2024-07-31 13:59:55 -07:00
|
|
|
|
if g:main_syntax == 'java'
|
|
|
|
|
unlet g:main_syntax
|
2014-07-10 21:05:51 -07:00
|
|
|
|
endif
|
|
|
|
|
|
2024-04-04 14:48:43 -07:00
|
|
|
|
let b:spell_options = "contained"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
let &cpo = s:cpo_save
|
2024-09-30 22:00:12 -07:00
|
|
|
|
unlet s:cpo_save s:ff s:with_html s:with_markdown
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
2024-06-16 02:29:01 -07:00
|
|
|
|
" See ":help vim9-mix".
|
|
|
|
|
if !has("vim9script")
|
|
|
|
|
finish
|
|
|
|
|
endif
|
|
|
|
|
|
2024-08-22 12:25:51 -07:00
|
|
|
|
if exists("g:java_foldtext_show_first_or_second_line")
|
|
|
|
|
def! s:LazyPrefix(prefix: string, dashes: string, count: number): string
|
|
|
|
|
return empty(prefix)
|
|
|
|
|
? printf('+-%s%3d lines: ', dashes, count)
|
|
|
|
|
: prefix
|
|
|
|
|
enddef
|
|
|
|
|
|
|
|
|
|
def! s:JavaSyntaxFoldTextExpr(): string
|
|
|
|
|
# Piggyback on NGETTEXT.
|
|
|
|
|
const summary: string = foldtext()
|
|
|
|
|
return getline(v:foldstart) !~ '/\*\+\s*$'
|
|
|
|
|
? summary
|
|
|
|
|
: LazyPrefix(matchstr(summary, '^+-\+\s*\d\+\s.\{-1,}:\s'),
|
|
|
|
|
v:folddashes,
|
|
|
|
|
(v:foldend - v:foldstart + 1)) ..
|
|
|
|
|
getline(v:foldstart + 1)
|
|
|
|
|
enddef
|
|
|
|
|
|
|
|
|
|
setlocal foldtext=s:JavaSyntaxFoldTextExpr()
|
|
|
|
|
delfunction! g:JavaSyntaxFoldTextExpr
|
|
|
|
|
endif
|
2024-09-30 22:00:12 -07:00
|
|
|
|
" vim: fdm=syntax sw=2 ts=8 noet sta
|