3 " Maintainer: Claudio Fleiner <claudio@fleiner.com>
4 " URL: http://www.fleiner.com/vim/syntax/java.vim
5 " Last Change: 2001 May 10
7 " Please check :help java.vim for comments on some of the options available.
9 " Quit when a syntax file was already loaded
10 if !exists("main_syntax")
13 elseif exists("b:current_syntax")
16 " we define it here so that included files can test for it
17 let main_syntax='java'
20 " don't use standard HiLink, it will not work with included syntax files
22 command! -nargs=+ JavaHiLink hi link <args>
24 command! -nargs=+ JavaHiLink hi def link <args>
27 " some characters that cannot be in a java program (outside a string)
28 syn match javaError "[\\@`]"
29 syn match javaError "<<<\|\.\.\|=>\|<>\|||=\|&&=\|[^-]->\|\*\/"
31 " use separate name so that it can be deleted in javacc.vim
32 syn match javaError2 "#\|=<"
33 JavaHiLink javaError2 javaError
38 syn keyword javaExternal import native package
39 syn keyword javaError goto const
40 syn keyword javaConditional if else switch
41 syn keyword javaRepeat while for do
42 syn keyword javaBoolean true false
43 syn keyword javaConstant null
44 syn keyword javaTypedef this super
45 syn keyword javaOperator new instanceof
46 syn keyword javaType boolean char byte short int long float double
47 syn keyword javaType void
48 syn keyword javaStatement return
49 syn keyword javaStorageClass static synchronized transient volatile final strictfp serializable
50 syn keyword javaExceptions throw try catch finally
51 syn keyword javaMethodDecl synchronized throws
52 syn keyword javaClassDecl extends implements interface
53 " to differentiate the keyword class from MyClass.class we use a match here
54 syn match javaTypedef "\.\s*\<class\>"ms=s+1
55 syn match javaClassDecl "^class\>"
56 syn match javaClassDecl "[^.]\s*\<class\>"ms=s+1
57 syn keyword javaBranch break continue nextgroup=javaUserLabelRef skipwhite
58 syn match javaUserLabelRef "\k\+" contained
59 syn keyword javaScopeDecl public protected private abstract
61 if exists("java_highlight_java_lang_ids") || exists("java_highlight_java_lang") || exists("java_highlight_all")
63 syn match javaLangClass "\<System\>"
64 syn keyword javaLangClass Cloneable Comparable Runnable Boolean Byte Class
65 syn keyword javaLangClass Character ClassLoader Compiler Double Float
66 syn keyword javaLangClass Integer Long Math Number Object Package Process
67 syn keyword javaLangClass Runtime RuntimePermission InheritableThreadLocal
68 syn keyword javaLangClass SecurityManager Short String
69 syn keyword javaLangClass StringBuffer Thread ThreadGroup
70 syn keyword javaLangClass ThreadLocal Throwable Void ArithmeticException
71 syn keyword javaLangClass ArrayIndexOutOfBoundsException
72 syn keyword javaLangClass ArrayStoreException ClassCastException
73 syn keyword javaLangClass ClassNotFoundException
74 syn keyword javaLangClass CloneNotSupportedException Exception
75 syn keyword javaLangClass IllegalAccessException
76 syn keyword javaLangClass IllegalArgumentException
77 syn keyword javaLangClass IllegalMonitorStateException
78 syn keyword javaLangClass IllegalStateException
79 syn keyword javaLangClass IllegalThreadStateException
80 syn keyword javaLangClass IndexOutOfBoundsException
81 syn keyword javaLangClass InstantiationException InterruptedException
82 syn keyword javaLangClass NegativeArraySizeException NoSuchFieldException
83 syn keyword javaLangClass NoSuchMethodException NullPointerException
84 syn keyword javaLangClass NumberFormatException RuntimeException
85 syn keyword javaLangClass SecurityException StringIndexOutOfBoundsException
86 syn keyword javaLangClass UnsupportedOperationException
87 syn keyword javaLangClass AbstractMethodError ClassCircularityError
88 syn keyword javaLangClass ClassFormatError Error ExceptionInInitializerError
89 syn keyword javaLangClass IllegalAccessError InstantiationError
90 syn keyword javaLangClass IncompatibleClassChangeError InternalError
91 syn keyword javaLangClass LinkageError NoClassDefFoundError
92 syn keyword javaLangClass NoSuchFieldError NoSuchMethodError
93 syn keyword javaLangClass OutOfMemoryError StackOverflowError
94 syn keyword javaLangClass ThreadDeath UnknownError UnsatisfiedLinkError
95 syn keyword javaLangClass UnsupportedClassVersionError VerifyError
96 syn keyword javaLangClass VirtualMachineError
97 syn keyword javaLangObject clone equals finalize getClass hashCode
98 syn keyword javaLangObject notify notifyAll toString wait
99 JavaHiLink javaLangClass javaConstant
100 JavaHiLink javaLangObject javaConstant
101 syn cluster javaTop add=javaLangObject,javaLangClass
102 syn cluster javaClasses add=javaLangClass
105 if filereadable(expand("<sfile>:p:h")."/javaid.vim")
106 source <sfile>:p:h/javaid.vim
109 if exists("java_space_errors")
110 if !exists("java_no_trail_space_error")
111 syn match javaSpaceError "\s\+$"
113 if !exists("java_no_tab_space_error")
114 syn match javaSpaceError " \+\t"me=e-1
118 syn region javaLabelRegion transparent matchgroup=javaLabel start="\<case\>" matchgroup=NONE end=":" contains=javaNumber,javaCharacter
119 syn match javaUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=javaLabel
120 syn keyword javaLabel default
122 if !exists("java_allow_cpp_keywords")
123 syn keyword javaError auto delete enum extern friend inline redeclared
124 syn keyword javaError register signed sizeof struct template typedef union
125 syn keyword javaError unsigned operator
128 " The following cluster contains all java groups except the contained ones
129 syn cluster javaTop add=javaExternal,javaError,javaError,javaBranch,javaLabelRegion,javaLabel,javaConditional,javaRepeat,javaBoolean,javaConstant,javaTypedef,javaOperator,javaType,javaType,javaStatement,javaStorageClass,javaExceptions,javaMethodDecl,javaClassDecl,javaClassDecl,javaClassDecl,javaScopeDecl,javaError,javaError2,javaUserLabel,javaLangObject
133 syn keyword javaTodo contained TODO FIXME XXX
134 if exists("java_comment_strings")
135 syn region javaCommentString contained start=+"+ end=+"+ end=+$+ end=+\*/+me=s-1,he=s-1 contains=javaSpecial,javaCommentStar,javaSpecialChar,@Spell
136 syn region javaComment2String contained start=+"+ end=+$\|"+ contains=javaSpecial,javaSpecialChar,@Spell
137 syn match javaCommentCharacter contained "'\\[^']\{1,6\}'" contains=javaSpecialChar
138 syn match javaCommentCharacter contained "'\\''" contains=javaSpecialChar
139 syn match javaCommentCharacter contained "'[^\\]'"
140 syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber
141 syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber
143 syn region javaComment start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
144 syn match javaCommentStar contained "^\s*\*[^/]"me=e-1
145 syn match javaCommentStar contained "^\s*\*$"
146 syn match javaLineComment "//.*" contains=@javaCommentSpecial2,javaTodo,@Spell
147 JavaHiLink javaCommentString javaString
148 JavaHiLink javaComment2String javaString
149 JavaHiLink javaCommentCharacter javaCharacter
151 syn cluster javaTop add=javaComment,javaLineComment
153 if !exists("java_ignore_javadoc") && main_syntax != 'jsp'
155 " syntax coloring for javadoc comments (HTML)
156 syntax include @javaHtml <sfile>:p:h/html.vim
157 unlet b:current_syntax
158 syn region javaDocComment start="/\*\*" end="\*/" keepend contains=javaCommentTitle,@javaHtml,javaDocTags,javaTodo,@Spell
159 syn region javaCommentTitle contained matchgroup=javaDocComment start="/\*\*" matchgroup=javaCommentTitle keepend end="\.$" end="\.[ \t\r<&]"me=e-1 end="@"me=s-1,he=s-1 end="\*/"me=s-1,he=s-1 contains=@javaHtml,javaCommentStar,javaTodo,@Spell
161 syn region javaDocTags contained start="{@link" end="}"
162 syn match javaDocTags contained "@\(see\|param\|exception\|throws\)\s\+\S\+" contains=javaDocParam
163 syn match javaDocParam contained "\s\S\+"
164 syn match javaDocTags contained "@\(version\|author\|return\|deprecated\|since\)\>"
168 " match the special comment /**/
169 syn match javaComment "/\*\*/"
171 " Strings and constants
172 syn match javaSpecialError contained "\\."
173 syn match javaSpecialCharError contained "[^']"
174 syn match javaSpecialChar contained "\\\([4-9]\d\|[0-3]\d\d\|[\"\\'ntbrf]\|u\x\{4\}\)"
175 syn region javaString start=+"+ end=+"+ end=+$+ contains=javaSpecialChar,javaSpecialError,@Spell
176 " next line disabled, it can cause a crash for a long line
177 "syn match javaStringError +"\([^"\\]\|\\.\)*$+
178 syn match javaCharacter "'[^']*'" contains=javaSpecialChar,javaSpecialCharError
179 syn match javaCharacter "'\\''" contains=javaSpecialChar
180 syn match javaCharacter "'[^\\]'"
181 syn match javaNumber "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>"
182 syn match javaNumber "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\="
183 syn match javaNumber "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>"
184 syn match javaNumber "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>"
187 syn match javaSpecial "\\u\d\{4\}"
189 syn cluster javaTop add=javaString,javaCharacter,javaNumber,javaSpecial,javaStringError
191 if exists("java_highlight_functions")
192 if java_highlight_functions == "indent"
193 syn match javaFuncDef "^\(\t\| \{8\}\)[_$a-zA-Z][_$a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses
194 syn region javaFuncDef start=+^\(\t\| \{8\}\)[$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses
195 syn match javaFuncDef "^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses
196 syn region javaFuncDef start=+^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,@javaClasses
198 " This line catches method declarations at any indentation>0, but it assumes
200 " 1. class names are always capitalized (ie: Button)
201 " 2. method names are never capitalized (except constructors, of course)
202 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*(+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses
204 syn match javaBraces "[{}]"
205 syn cluster javaTop add=javaFuncDef,javaBraces
208 if exists("java_highlight_debug")
210 " Strings and constants
211 syn match javaDebugSpecial contained "\\\d\d\d\|\\."
212 syn region javaDebugString contained start=+"+ end=+"+ contains=javaDebugSpecial
213 syn match javaDebugStringError +"\([^"\\]\|\\.\)*$+
214 syn match javaDebugCharacter contained "'[^\\]'"
215 syn match javaDebugSpecialCharacter contained "'\\.'"
216 syn match javaDebugSpecialCharacter contained "'\\''"
217 syn match javaDebugNumber contained "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>"
218 syn match javaDebugNumber contained "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\="
219 syn match javaDebugNumber contained "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>"
220 syn match javaDebugNumber contained "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>"
221 syn keyword javaDebugBoolean contained true false
222 syn keyword javaDebugType contained null this super
223 syn region javaDebugParen start=+(+ end=+)+ contained contains=javaDebug.*,javaDebugParen
225 " to make this work you must define the highlighting for these groups
226 syn match javaDebug "System\.\(out\|err\)\.print\(ln\)*\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
227 syn match javaDebug "[A-Za-z][a-zA-Z0-9_]*\.printStackTrace\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
228 syn match javaDebug "trace[SL]\=\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
230 syn cluster javaTop add=javaDebug
232 if version >= 508 || !exists("did_c_syn_inits")
233 JavaHiLink javaDebug Debug
234 JavaHiLink javaDebugString DebugString
235 JavaHiLink javaDebugStringError javaError
236 JavaHiLink javaDebugType DebugType
237 JavaHiLink javaDebugBoolean DebugBoolean
238 JavaHiLink javaDebugNumber Debug
239 JavaHiLink javaDebugSpecial DebugSpecial
240 JavaHiLink javaDebugSpecialCharacter DebugSpecial
241 JavaHiLink javaDebugCharacter DebugString
242 JavaHiLink javaDebugParen Debug
244 JavaHiLink DebugString String
245 JavaHiLink DebugSpecial Special
246 JavaHiLink DebugBoolean Boolean
247 JavaHiLink DebugType Type
251 if exists("java_mark_braces_in_parens_as_errors")
252 syn match javaInParen contained "[{}]"
253 JavaHiLink javaInParen javaError
254 syn cluster javaTop add=javaInParen
257 " catch errors caused by wrong parenthesis
258 syn region javaParen transparent start="(" end=")" contains=@javaTop,javaParen
259 syn match javaParenError ")"
260 JavaHiLink javaParenError javaError
262 if !exists("java_minlines")
263 let java_minlines = 10
265 exec "syn sync ccomment javaComment minlines=" . java_minlines
267 " The default highlighting.
268 if version >= 508 || !exists("did_java_syn_inits")
270 let did_java_syn_inits = 1
272 JavaHiLink javaFuncDef Function
273 JavaHiLink javaBraces Function
274 JavaHiLink javaBranch Conditional
275 JavaHiLink javaUserLabelRef javaUserLabel
276 JavaHiLink javaLabel Label
277 JavaHiLink javaUserLabel Label
278 JavaHiLink javaConditional Conditional
279 JavaHiLink javaRepeat Repeat
280 JavaHiLink javaExceptions Exception
281 JavaHiLink javaStorageClass StorageClass
282 JavaHiLink javaMethodDecl javaStorageClass
283 JavaHiLink javaClassDecl javaStorageClass
284 JavaHiLink javaScopeDecl javaStorageClass
285 JavaHiLink javaBoolean Boolean
286 JavaHiLink javaSpecial Special
287 JavaHiLink javaSpecialError Error
288 JavaHiLink javaSpecialCharError Error
289 JavaHiLink javaString String
290 JavaHiLink javaCharacter Character
291 JavaHiLink javaSpecialChar SpecialChar
292 JavaHiLink javaNumber Number
293 JavaHiLink javaError Error
294 JavaHiLink javaStringError Error
295 JavaHiLink javaStatement Statement
296 JavaHiLink javaOperator Operator
297 JavaHiLink javaComment Comment
298 JavaHiLink javaDocComment Comment
299 JavaHiLink javaLineComment Comment
300 JavaHiLink javaConstant javaBoolean
301 JavaHiLink javaTypedef Typedef
302 JavaHiLink javaTodo Todo
304 JavaHiLink javaCommentTitle SpecialComment
305 JavaHiLink javaDocTags Special
306 JavaHiLink javaDocParam Function
307 JavaHiLink javaCommentStar javaComment
309 JavaHiLink javaType Type
310 JavaHiLink javaExternal Include
312 JavaHiLink htmlComment Special
313 JavaHiLink htmlCommentPart Special
314 JavaHiLink javaSpaceError Error
317 delcommand JavaHiLink
319 let b:current_syntax = "java"
321 if main_syntax == 'java'
325 let b:spell_options="contained"