2014-07-10 21:05:51 -07:00
|
|
|
" Vim syntax file
|
|
|
|
" Language: Java
|
|
|
|
" Maintainer: Claudio Fleiner <claudio@fleiner.com>
|
2018-10-29 01:50:39 -07:00
|
|
|
" URL: https://github.com/fleiner/vim/blob/master/runtime/syntax/java.vim
|
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
|
|
|
" Last Change: 2024 Mar 06
|
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
|
2014-07-10 21:05:51 -07:00
|
|
|
if !exists("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
|
|
|
|
let main_syntax='java'
|
|
|
|
syn region javaFold start="{" end="}" transparent fold
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
" 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 "#\|=<"
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaError2 javaError
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" keyword definitions
|
|
|
|
syn keyword javaExternal native package
|
|
|
|
syn match javaExternal "\<import\>\(\s\+static\>\)\?"
|
|
|
|
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
|
2018-10-29 01:50:39 -07:00
|
|
|
syn keyword javaOperator var new instanceof
|
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.
|
|
|
|
syn match javaOperator "\%(\%(::\|\.\)[[:space:]\n]*\)\@80<!\<yield\>"
|
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
|
2014-07-10 21:05:51 -07:00
|
|
|
syn keyword javaStorageClass static synchronized transient volatile final strictfp serializable
|
|
|
|
syn keyword javaExceptions throw try catch finally
|
|
|
|
syn keyword javaAssert assert
|
|
|
|
syn keyword javaMethodDecl synchronized throws
|
|
|
|
syn keyword javaClassDecl extends implements interface
|
|
|
|
" to differentiate the keyword class from MyClass.class we use a match here
|
|
|
|
syn match javaTypedef "\.\s*\<class\>"ms=s+1
|
|
|
|
syn keyword javaClassDecl enum
|
|
|
|
syn match javaClassDecl "^class\>"
|
|
|
|
syn match javaClassDecl "[^.]\s*\<class\>"ms=s+1
|
2018-10-29 01:50:39 -07:00
|
|
|
syn match javaAnnotation "@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>" contains=javaString
|
2014-07-10 21:05:51 -07:00
|
|
|
syn match javaClassDecl "@interface\>"
|
|
|
|
syn keyword javaBranch break continue nextgroup=javaUserLabelRef skipwhite
|
|
|
|
syn match javaUserLabelRef "\k\+" contained
|
|
|
|
syn match javaVarArg "\.\.\."
|
|
|
|
syn keyword javaScopeDecl public protected private abstract
|
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
|
|
|
|
2022-06-09 23:40:32 -07:00
|
|
|
function s:isModuleInfoDeclarationCurrentBuffer() abort
|
|
|
|
return fnamemodify(bufname("%"), ":t") =~ '^module-info\%(\.class\>\)\@!'
|
|
|
|
endfunction
|
|
|
|
|
2018-10-29 01:50:39 -07:00
|
|
|
" Java Modules(Since Java 9, for "module-info.java" file)
|
2022-06-09 23:40:32 -07:00
|
|
|
if s:isModuleInfoDeclarationCurrentBuffer()
|
2018-10-29 01:50:39 -07:00
|
|
|
syn keyword javaModuleStorageClass module transitive
|
|
|
|
syn keyword javaModuleStmt open requires exports opens uses provides
|
|
|
|
syn keyword javaModuleExternal to with
|
|
|
|
syn cluster javaTop add=javaModuleStorageClass,javaModuleStmt,javaModuleExternal
|
|
|
|
endif
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
if exists("java_highlight_java_lang_ids")
|
|
|
|
let java_highlight_all=1
|
|
|
|
endif
|
2018-10-29 01:50:39 -07:00
|
|
|
if exists("java_highlight_all") || exists("java_highlight_java") || exists("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.
|
|
|
|
|
|
|
|
syn keyword javaR_JavaLang ArithmeticException ArrayIndexOutOfBoundsException ArrayStoreException ClassCastException IllegalArgumentException IllegalMonitorStateException IllegalThreadStateException IndexOutOfBoundsException NegativeArraySizeException NullPointerException NumberFormatException RuntimeException SecurityException StringIndexOutOfBoundsException IllegalStateException UnsupportedOperationException EnumConstantNotPresentException TypeNotPresentException IllegalCallerException LayerInstantiationException
|
2014-07-10 21:05:51 -07:00
|
|
|
syn cluster javaTop add=javaR_JavaLang
|
|
|
|
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:
|
|
|
|
syn match javaC_JavaLang "\%(\<Thread\.\)\@<=\<State\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<Character\.\)\@<=\<UnicodeScript\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<ProcessBuilder\.Redirect\.\)\@<=\<Type\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<StackWalker\.\)\@<=\<Option\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<System\.Logger\.\)\@<=\<Level\>"
|
|
|
|
" Member classes:
|
|
|
|
syn match javaC_JavaLang "\%(\<Character\.\)\@<=\<Subset\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<Character\.\)\@<=\<UnicodeBlock\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<ProcessBuilder\.\)\@<=\<Redirect\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<ModuleLayer\.\)\@<=\<Controller\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<Runtime\.\)\@<=\<Version\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<System\.\)\@<=\<LoggerFinder\>"
|
|
|
|
syn match javaC_JavaLang "\%(\<Enum\.\)\@<=\<EnumDesc\>"
|
|
|
|
syn keyword javaC_JavaLang Boolean Character Class ClassLoader Compiler Double Float Integer Long Math Number Object Process Runtime SecurityManager String StringBuffer Thread ThreadGroup Byte Short Void InheritableThreadLocal Package RuntimePermission ThreadLocal StrictMath StackTraceElement Enum ProcessBuilder StringBuilder ClassValue Module ModuleLayer StackWalker Record
|
|
|
|
syn match javaC_JavaLang "\<System\>" " See javaDebug.
|
2014-07-10 21:05:51 -07:00
|
|
|
syn cluster javaTop add=javaC_JavaLang
|
|
|
|
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 javaTop add=javaE_JavaLang
|
|
|
|
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 javaTop add=javaX_JavaLang
|
|
|
|
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_
|
|
|
|
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
|
|
|
|
|
|
|
syn keyword javaLangObject clone equals finalize getClass hashCode
|
|
|
|
syn keyword javaLangObject notify notifyAll toString wait
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaLangObject javaConstant
|
2014-07-10 21:05:51 -07:00
|
|
|
syn cluster javaTop add=javaLangObject
|
|
|
|
endif
|
|
|
|
|
|
|
|
if filereadable(expand("<sfile>:p:h")."/javaid.vim")
|
|
|
|
source <sfile>:p:h/javaid.vim
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists("java_space_errors")
|
|
|
|
if !exists("java_no_trail_space_error")
|
|
|
|
syn match javaSpaceError "\s\+$"
|
|
|
|
endif
|
|
|
|
if !exists("java_no_tab_space_error")
|
|
|
|
syn match javaSpaceError " \+\t"me=e-1
|
|
|
|
endif
|
|
|
|
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 match javaUserLabel "^\s*\<\K\k*\>\%(\<default\>\)\@<!\s*:"he=e-1
|
|
|
|
syn region javaLabelRegion transparent matchgroup=javaLabel start="\<case\>" matchgroup=NONE end=":\|->" contains=javaLabelCastType,javaLabelNumber,javaCharacter,javaString,javaConstant,@javaClasses,javaLabelDefault,javaLabelVarType,javaLabelWhenClause
|
|
|
|
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
|
|
|
|
syn keyword javaLabelCastType contained char byte short int
|
|
|
|
" Allow for the contingency of the enclosing region not being able to
|
|
|
|
" _keep_ its _end_, e.g. case ':':.
|
|
|
|
syn region javaLabelWhenClause contained transparent matchgroup=javaLabel start="\<when\>" matchgroup=NONE end=":"me=e-1 end="->"me=e-2 contains=TOP,javaExternal
|
|
|
|
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 javaLabelDefault javaLabel
|
|
|
|
hi def link javaLabelVarType javaOperator
|
|
|
|
hi def link javaLabelNumber javaNumber
|
|
|
|
hi def link javaLabelCastType javaType
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" highlighting C++ keywords as errors removed, too many people find it
|
|
|
|
" annoying. Was: if !exists("java_allow_cpp_keywords")
|
|
|
|
|
|
|
|
" The following cluster contains all java groups except the contained ones
|
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 cluster javaTop add=javaExternal,javaError,javaBranch,javaLabelRegion,javaConditional,javaRepeat,javaBoolean,javaConstant,javaTypedef,javaOperator,javaType,javaStatement,javaStorageClass,javaAssert,javaExceptions,javaMethodDecl,javaClassDecl,javaScopeDecl,javaConceptKind,javaError2,javaUserLabel,javaLangObject,javaAnnotation,javaVarArg
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
" Comments
|
|
|
|
syn keyword javaTodo contained TODO FIXME XXX
|
2024-03-03 08:07:23 -07:00
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
if exists("java_comment_strings")
|
|
|
|
syn region javaCommentString contained start=+"+ end=+"+ end=+$+ end=+\*/+me=s-1,he=s-1 contains=javaSpecial,javaCommentStar,javaSpecialChar,@Spell
|
2024-03-03 08:07:23 -07:00
|
|
|
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
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
syn region javaComment start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
|
|
|
|
syn match javaCommentStar contained "^\s*\*[^/]"me=e-1
|
|
|
|
syn match javaCommentStar contained "^\s*\*$"
|
|
|
|
syn match javaLineComment "//.*" contains=@javaCommentSpecial2,javaTodo,@Spell
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaCommentString javaString
|
|
|
|
hi def link javaComment2String javaString
|
|
|
|
hi def link javaCommentCharacter javaCharacter
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
syn cluster javaTop add=javaComment,javaLineComment
|
|
|
|
|
|
|
|
if !exists("java_ignore_javadoc") && main_syntax != 'jsp'
|
|
|
|
syntax case ignore
|
|
|
|
" syntax coloring for javadoc comments (HTML)
|
2022-06-09 23:40:32 -07:00
|
|
|
syntax include @javaHtml syntax/html.vim
|
2014-07-10 21:05:51 -07:00
|
|
|
unlet b:current_syntax
|
|
|
|
" HTML enables spell checking for all text that is not in a syntax item. This
|
|
|
|
" is wrong for Java (all identifiers would be spell-checked), so it's undone
|
|
|
|
" here.
|
|
|
|
syntax spell default
|
|
|
|
|
|
|
|
syn region javaDocComment start="/\*\*" end="\*/" keepend contains=javaCommentTitle,@javaHtml,javaDocTags,javaDocSeeTag,javaTodo,@Spell
|
|
|
|
syn region javaCommentTitle contained matchgroup=javaDocComment start="/\*\*" matchgroup=javaCommentTitle keepend end="\.$" end="\.[ \t\r<&]"me=e-1 end="[^{]@"me=s-2,he=s-1 end="\*/"me=s-1,he=s-1 contains=@javaHtml,javaCommentStar,javaTodo,@Spell,javaDocTags,javaDocSeeTag
|
|
|
|
|
|
|
|
syn region javaDocTags contained start="{@\(code\|link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}"
|
|
|
|
syn match javaDocTags contained "@\(param\|exception\|throws\|since\)\s\+\S\+" contains=javaDocParam
|
|
|
|
syn match javaDocParam contained "\s\S\+"
|
|
|
|
syn match javaDocTags contained "@\(version\|author\|return\|deprecated\|serial\|serialField\|serialData\)\>"
|
|
|
|
syn region javaDocSeeTag contained matchgroup=javaDocTags start="@see\s\+" matchgroup=NONE end="\_."re=e-1 contains=javaDocSeeTagParam
|
|
|
|
syn match javaDocSeeTagParam contained @"\_[^"]\+"\|<a\s\+\_.\{-}</a>\|\(\k\|\.\)*\(#\k\+\((\_[^)]\+)\)\=\)\=@ extend
|
|
|
|
syntax case match
|
|
|
|
endif
|
|
|
|
|
|
|
|
" match the special comment /**/
|
|
|
|
syn match javaComment "/\*\*/"
|
|
|
|
|
|
|
|
" Strings and constants
|
|
|
|
syn match javaSpecialError contained "\\."
|
|
|
|
syn match javaSpecialCharError contained "[^']"
|
2024-03-02 01:48:57 -07:00
|
|
|
" Escape Sequences (JLS-17, §3.10.7):
|
2024-03-03 08:07:23 -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*"""+
|
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 region javaStrTemplEmbExp contained matchgroup=javaStrTempl start="\\{" end="}" contains=TOP
|
|
|
|
syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@<="+ end=+"+ contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,@Spell
|
|
|
|
syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
|
2024-03-02 01:48:57 -07:00
|
|
|
" The next line is commented out, it can cause a crash for a long line
|
2024-03-03 08:07:23 -07:00
|
|
|
"syn match javaStringError +"\%([^"\\]\|\\.\)*$+
|
2014-07-10 21:05:51 -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):
|
|
|
|
syn keyword javaNumber 0 0l 0L
|
|
|
|
syn match javaNumber "\<\%(0\%([xX]\x\%(_*\x\)*\|_*\o\%(_*\o\)*\|[bB][01]\%(_*[01]\)*\)\|[1-9]\%(_*\d\)*\)[lL]\=\>"
|
|
|
|
" Decimal floating-point literals (JLS-17, §3.10.2):
|
|
|
|
" Against "\<\d\+\>\.":
|
|
|
|
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]\>"
|
|
|
|
" Hexadecimal floating-point literals (JLS-17, §3.10.2):
|
|
|
|
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: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 javaTop add=javaString,javaStrTempl,javaCharacter,javaNumber,javaSpecial,javaStringError,javaTextBlockError
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
if exists("java_highlight_functions")
|
|
|
|
if java_highlight_functions == "indent"
|
2016-01-14 16:38:47 -07:00
|
|
|
syn match javaFuncDef "^\(\t\| \{8\}\)[_$a-zA-Z][_$a-zA-Z0-9_. \[\]<>]*([^-+*/]*)" contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses,javaAnnotation
|
|
|
|
syn region javaFuncDef start=+^\(\t\| \{8\}\)[$_a-zA-Z][$_a-zA-Z0-9_. \[\]<>]*([^-+*/]*,\s*+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses,javaAnnotation
|
|
|
|
syn match javaFuncDef "^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]<>]*([^-+*/]*)" contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses,javaAnnotation
|
|
|
|
syn region javaFuncDef start=+^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]<>]*([^-+*/]*,\s*+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses,javaAnnotation
|
2014-07-10 21:05:51 -07:00
|
|
|
else
|
|
|
|
" This line catches method declarations at any indentation>0, but it assumes
|
|
|
|
" two things:
|
|
|
|
" 1. class names are always capitalized (ie: Button)
|
|
|
|
" 2. method names are never capitalized (except constructors, of course)
|
2016-01-14 16:38:47 -07:00
|
|
|
"syn region javaFuncDef start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(<[^>]*>\)\=\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*([^0-9]+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses
|
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 javaFuncDef start=+^\s\+\%(\%(public\|protected\|private\|static\|\%(abstract\|default\)\|final\|native\|synchronized\)\s\+\)*\%(<.*>\s\+\)\?\%(\%(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\%([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\%(<[^(){}]*>\)\=\%(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*(+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses,javaAnnotation
|
2014-07-10 21:05:51 -07:00
|
|
|
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 match javaLambdaDef "\<\K\k*\>\%(\<default\>\)\@<!\s*->"
|
2014-07-10 21:05:51 -07:00
|
|
|
syn match javaBraces "[{}]"
|
2016-01-14 16:38:47 -07:00
|
|
|
syn cluster javaTop add=javaFuncDef,javaBraces,javaLambdaDef
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
|
|
|
|
if exists("java_highlight_debug")
|
|
|
|
" 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"'\\]\)"
|
2014-07-10 21:05:51 -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
|
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
|
|
|
" 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\)\@!.*
|
|
|
|
syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@<="+ end=+"+ contains=javaDebugStrTemplEmbExp,javaDebugSpecial
|
|
|
|
syn region javaDebugStrTempl contained start=+\%(\.[[:space:]\n]*\)\@<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugStrTemplEmbExp,javaDebugSpecial,javaDebugTextBlockError
|
|
|
|
" The next line is commented out, it can cause a crash for a long line
|
2024-03-03 08:07:23 -07:00
|
|
|
" syn match javaDebugStringError contained +"\%([^"\\]\|\\.\)*$+
|
|
|
|
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
|
|
|
|
syn region javaDebugParen start=+(+ end=+)+ contained contains=javaDebug.*,javaDebugParen
|
|
|
|
|
|
|
|
" to make this work you must define the highlighting for these groups
|
|
|
|
syn match javaDebug "\<System\.\(out\|err\)\.print\(ln\)*\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
|
|
|
|
syn match javaDebug "\<p\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
|
|
|
|
syn match javaDebug "[A-Za-z][a-zA-Z0-9_]*\.printStackTrace\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
|
|
|
|
syn match javaDebug "\<trace[SL]\=\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
|
|
|
|
|
|
|
|
syn cluster javaTop add=javaDebug
|
|
|
|
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaDebug Debug
|
|
|
|
hi def link javaDebugString DebugString
|
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
|
|
|
hi def link javaDebugStrTempl Macro
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaDebugStringError javaError
|
2024-03-03 08:07:23 -07:00
|
|
|
hi def link javaDebugTextBlockError javaDebugStringError
|
2017-04-28 12:14:34 -07:00
|
|
|
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
|
|
|
|
|
|
|
|
if exists("java_mark_braces_in_parens_as_errors")
|
|
|
|
syn match javaInParen contained "[{}]"
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaInParen javaError
|
2014-07-10 21:05:51 -07:00
|
|
|
syn cluster javaTop add=javaInParen
|
|
|
|
endif
|
|
|
|
|
|
|
|
" catch errors caused by wrong parenthesis
|
2016-01-14 16:38:47 -07:00
|
|
|
syn region javaParenT transparent matchgroup=javaParen start="(" end=")" contains=@javaTop,javaParenT1
|
2014-07-10 21:05:51 -07:00
|
|
|
syn region javaParenT1 transparent matchgroup=javaParen1 start="(" end=")" contains=@javaTop,javaParenT2 contained
|
|
|
|
syn region javaParenT2 transparent matchgroup=javaParen2 start="(" end=")" contains=@javaTop,javaParenT contained
|
|
|
|
syn match javaParenError ")"
|
|
|
|
" catch errors caused by wrong square parenthesis
|
2016-01-14 16:38:47 -07:00
|
|
|
syn region javaParenT transparent matchgroup=javaParen start="\[" end="\]" contains=@javaTop,javaParenT1
|
2014-07-10 21:05:51 -07:00
|
|
|
syn region javaParenT1 transparent matchgroup=javaParen1 start="\[" end="\]" contains=@javaTop,javaParenT2 contained
|
|
|
|
syn region javaParenT2 transparent matchgroup=javaParen2 start="\[" end="\]" contains=@javaTop,javaParenT contained
|
|
|
|
syn match javaParenError "\]"
|
|
|
|
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaParenError javaError
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2016-01-14 16:38:47 -07:00
|
|
|
if exists("java_highlight_functions")
|
|
|
|
syn match javaLambdaDef "([a-zA-Z0-9_<>\[\], \t]*)\s*->"
|
|
|
|
" needs to be defined after the parenthesis error catcher to work
|
|
|
|
endif
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
if !exists("java_minlines")
|
|
|
|
let java_minlines = 10
|
|
|
|
endif
|
|
|
|
exec "syn sync ccomment javaComment minlines=" . java_minlines
|
|
|
|
|
|
|
|
" The default highlighting.
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaLambdaDef Function
|
|
|
|
hi def link javaFuncDef Function
|
|
|
|
hi def link javaVarArg Function
|
|
|
|
hi def link javaBraces Function
|
|
|
|
hi def link javaBranch Conditional
|
|
|
|
hi def link javaUserLabelRef javaUserLabel
|
|
|
|
hi def link javaLabel Label
|
|
|
|
hi def link javaUserLabel Label
|
|
|
|
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
|
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
|
|
|
hi def link javaConceptKind NonText
|
2018-10-29 01:50:39 -07:00
|
|
|
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaBoolean Boolean
|
|
|
|
hi def link javaSpecial Special
|
|
|
|
hi def link javaSpecialError Error
|
|
|
|
hi def link javaSpecialCharError Error
|
|
|
|
hi def link javaString String
|
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
|
|
|
hi def link javaStrTempl Macro
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaCharacter Character
|
|
|
|
hi def link javaSpecialChar SpecialChar
|
|
|
|
hi def link javaNumber Number
|
|
|
|
hi def link javaError Error
|
|
|
|
hi def link javaStringError Error
|
2024-03-03 08:07:23 -07:00
|
|
|
hi def link javaTextBlockError javaStringError
|
2017-04-28 12:14:34 -07:00
|
|
|
hi def link javaStatement Statement
|
|
|
|
hi def link javaOperator Operator
|
|
|
|
hi def link javaComment Comment
|
|
|
|
hi def link javaDocComment Comment
|
|
|
|
hi def link javaLineComment Comment
|
|
|
|
hi def link javaConstant Constant
|
|
|
|
hi def link javaTypedef Typedef
|
|
|
|
hi def link javaTodo Todo
|
|
|
|
hi def link javaAnnotation PreProc
|
|
|
|
|
|
|
|
hi def link javaCommentTitle SpecialComment
|
|
|
|
hi def link javaDocTags Special
|
|
|
|
hi def link javaDocParam Function
|
|
|
|
hi def link javaDocSeeTagParam Function
|
|
|
|
hi def link javaCommentStar javaComment
|
|
|
|
|
|
|
|
hi def link javaType Type
|
|
|
|
hi def link javaExternal Include
|
|
|
|
|
|
|
|
hi def link htmlComment Special
|
|
|
|
hi def link htmlCommentPart Special
|
|
|
|
hi def link javaSpaceError Error
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2022-06-09 23:40:32 -07:00
|
|
|
if s:isModuleInfoDeclarationCurrentBuffer()
|
2018-10-29 01:50:39 -07:00
|
|
|
hi def link javaModuleStorageClass StorageClass
|
|
|
|
hi def link javaModuleStmt Statement
|
|
|
|
hi def link javaModuleExternal Include
|
|
|
|
endif
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
let b:current_syntax = "java"
|
|
|
|
|
|
|
|
if main_syntax == 'java'
|
|
|
|
unlet main_syntax
|
|
|
|
endif
|
|
|
|
|
2022-06-09 23:40:32 -07:00
|
|
|
delfunction! s:isModuleInfoDeclarationCurrentBuffer
|
2014-07-10 21:05:51 -07:00
|
|
|
let b:spell_options="contained"
|
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
|
|
|
|
|
|
|
" vim: ts=8
|