annotate runtime/indent/java.vim @ 10955:a555c11b59a9

Added tag v8.0.0366 for changeset 8ff62b4cffaedc9575a7ba3901c9228d6c8ee24e
author Christian Brabandt <cb@256bit.org>
date Sat, 25 Feb 2017 15:45:04 +0100
parents dd6c2497c997
children d0a20101ecb2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: Java
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
3 " Previous Maintainer: Toby Allsopp <toby.allsopp@peace.com>
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
4 " Current Maintainer: Hong Xu <xuhdev@gmail.com>
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
5 " Last Change: 2012 May 18
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
6 " Version: 1.0
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
7 " License: Same as Vim.
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
8 " Copyright (c) 2012 Hong Xu
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
9 " Before 2012, this file is maintained by Toby Allsopp.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " Indent Java anonymous classes correctly.
234
a686fd6c8beb updated for version 7.0065
vimboss
parents: 26
diff changeset
18 setlocal cindent cinoptions& cinoptions+=j1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 " The "extends" and "implements" lines start off with the wrong indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 setlocal indentkeys& indentkeys+=0=extends indentkeys+=0=implements
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " Set the function to do the work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 setlocal indentexpr=GetJavaIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
234
a686fd6c8beb updated for version 7.0065
vimboss
parents: 26
diff changeset
26 let b:undo_indent = "set cin< cino< indentkeys< indentexpr<"
a686fd6c8beb updated for version 7.0065
vimboss
parents: 26
diff changeset
27
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 if exists("*GetJavaIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 endif
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
32 let s:keepcpo= &cpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
33 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 function! SkipJavaBlanksAndComments(startline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 let lnum = a:startline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 while lnum > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let lnum = prevnonblank(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 if getline(lnum) =~ '\*/\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 while getline(lnum) !~ '/\*' && lnum > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 if getline(lnum) =~ '^\s*/\*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 elseif getline(lnum) =~ '^\s*//'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 return lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 function GetJavaIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " Java is just like C; use the built-in C indenting and then correct a few
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " specific cases.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 let theIndent = cindent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " If we're in the middle of a comment then just trust cindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 if getline(v:lnum) =~ '^\s*\*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 return theIndent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 " find start of previous line, in case it was a continuation line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 let lnum = SkipJavaBlanksAndComments(v:lnum - 1)
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
70
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
71 " If the previous line starts with '@', we should have the same indent as
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
72 " the previous one
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
73 if getline(lnum) =~ '^\s*@\S\+\s*$'
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
74 return indent(lnum)
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
75 endif
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 234
diff changeset
76
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 let prev = lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 while prev > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 let next_prev = SkipJavaBlanksAndComments(prev - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if getline(next_prev) !~ ',\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 let prev = next_prev
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 " Try to align "throws" lines for methods and "extends" and "implements" for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 " classes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 if getline(v:lnum) =~ '^\s*\(extends\|implements\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 \ && getline(lnum) !~ '^\s*\(extends\|implements\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 let theIndent = theIndent + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 " correct for continuation lines of "throws", "implements" and "extends"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 let cont_kw = matchstr(getline(prev),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 \ '^\s*\zs\(throws\|implements\|extends\)\>\ze.*,\s*$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 if strlen(cont_kw) > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 let amount = strlen(cont_kw) + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 if getline(lnum) !~ ',\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 let theIndent = theIndent - (amount + &sw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 if theIndent < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 let theIndent = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 elseif prev == lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 let theIndent = theIndent + amount
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 if cont_kw ==# 'throws'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 let theIndent = theIndent + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 elseif getline(prev) =~ '^\s*\(throws\|implements\|extends\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 \ && (getline(prev) =~ '{\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 \ || getline(v:lnum) =~ '^\s*{\s*$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 let theIndent = theIndent - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 " When the line starts with a }, try aligning it with the matching {,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 " skipping over "throws", "extends" and "implements" clauses.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 if getline(v:lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 call cursor(v:lnum, 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 silent normal %
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 let lnum = line('.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 if lnum < v:lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 while lnum > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 let next_lnum = SkipJavaBlanksAndComments(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 if getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 \ && getline(next_lnum) !~ ',\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 let lnum = prevnonblank(next_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 return indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 " Below a line starting with "}" never indent more. Needed for a method
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 " below a method with an indented "throws" clause.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 let lnum = SkipJavaBlanksAndComments(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 if getline(lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$' && indent(lnum) < theIndent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 let theIndent = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 return theIndent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
144 let &cpo = s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
145 unlet s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
146
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 " vi: sw=2 et