Skip to content

Commit ed70503

Browse files
clasonzzzyxwvutKonfekt
committed
vim-patch:7344024: runtime(java): Search type and method declarations with "&inc" and "&def"
=============== LIMITATIONS AND OBSERVATIONS =============== * Remember that external-type names can only be found when they match filenames resolvable in "&path" with "import" declarations; load the source file of an external type to look up its nested types and sibling top types, if any. * Strive to narrow the search by assigning only relevant pathnames for directories *or* an archive to "&path", e.g. ":set path-=/usr/include". * Use "{Visual}gf" on fully-qualified names. * Accept the fact that "&define" cannot contain end-of-line characters (":help definition-search"). A declaration whose matchable header is not contained within a line can be found iff all of its non-optional components belong to the same line; for types, such components are a keyword, e.g. "class", followed by a run of blank characters and an identifier, e.g. "Test"; for methods: a return type, e.g. "String", or a keyword "void", followed by a run of blank characters and an identifier, e.g. "toString", that is followed by "(". * The members of the "java.lang" package are usually not associated with "import" declarations; to look up their declarations, load a source file for a member of that package, and then use, on a simple name of interest for a member, either "[-Ctrl-d" etc. for local declarations or "gf" for external declarations, assuming that "." *or* the appropriate pathname for a JDK archive is assigned to "&path". * Follow the above instruction made for the "java.lang" members for any type whose simple name is not associated with an "import" declaration, i.e. a member type of the same package that is declared in another compilation unit. * Append the "$" character to "&iskeyword" when looking up declarations of generated code. See zzzyxwvut/java-vim#4. closes: vim/vim#17281 vim/vim@7344024 Co-authored-by: Aliaksei Budavei <[email protected]> Co-authored-by: Konfekt <[email protected]>
1 parent e4e9833 commit ed70503

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

runtime/ftplugin/java.vim

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
44
" Former Maintainer: Dan Sharp
55
" Repository: https://github.com/zzzyxwvut/java-vim.git
6-
" Last Change: 2024 Dec 25
7-
" 2024 Jan 14 by Vim Project (browsefilter)
8-
" 2024 May 23 by Riley Bruins <[email protected]> ('commentstring')
6+
" Last Change: 2025 May 08
97

108
" Make sure the continuation lines below do not cause problems in
119
" compatibility mode.
@@ -30,6 +28,32 @@ let b:did_ftplugin = 1
3028
" extension.
3129
set suffixes+=.class
3230

31+
" Set up "&define" and "&include".
32+
let s:peek = ''
33+
34+
try
35+
" Since v7.3.1037.
36+
if 'ab' !~ 'a\@1<!b'
37+
let s:peek = string(strlen('instanceof') + 8)
38+
endif
39+
catch /\<E59:/
40+
endtry
41+
42+
" Treat "s:common" as a non-backtracking unit to avoid matching constructor
43+
" declarations whose package-private headers are indistinguishable from method
44+
" invocation. Note that "[@-]" must not and "$" may not be in "&l:iskeyword".
45+
let s:common = '\%(\%(\%(@\%(interface\)\@!\%(\K\k*\.\)*\K\k*\)\s\+\)*' .
46+
\ '\%(p\%(rivate\|rotected\|ublic\)\s\+\)\=\)\@>'
47+
let s:types = '\%(\%(abstract\|final\|non-sealed\|s\%(ealed\|tatic\|trictfp\)\)\s\+\)*' .
48+
\ '\%(class\|enum\|@\=interface\|record\)\s\+\ze\K\k*\>'
49+
let s:methods = '\%(\%(abstract\|default\|final\|native\|s\%(tatic\|trictfp\|ynchronized\)\)\s\+\)*' .
50+
\ '\%(<.\{-1,}>\s\+\)\=\%(\K\k*\.\)*\K\k*\s*\%(<.\{-1,}>\%(\s\|\[\)\@=\)\=\s*\%(\[\]\s*\)*' .
51+
\ '\s\+\ze\%(\<\%(assert\|case\|instanceof\|new\|return\|throw\|when\)\s\+\)\@' .
52+
\ s:peek . '<!\K\k*\s*('
53+
let &l:define = printf('\C\m^\s*%s\%%(%s\|%s\)', s:common, s:types, s:methods)
54+
let &l:include = '\C\m^\s*import\s\+\ze\%(\K\k*\.\)\+\K\k*;'
55+
unlet s:methods s:types s:common s:peek
56+
3357
" Enable gf on import statements. Convert . in the package
3458
" name to / and append .java to the name, then search the path.
3559
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
@@ -341,7 +365,7 @@ if (!empty(get(g:, 'spotbugs_properties', {})) ||
341365
endif
342366

343367
function! JavaFileTypeCleanUp() abort
344-
setlocal suffixes< suffixesadd< formatoptions< comments< commentstring< path< includeexpr<
368+
setlocal suffixes< suffixesadd< formatoptions< comments< commentstring< path< includeexpr< include< define<
345369
unlet! b:browsefilter
346370

347371
" The concatenated ":autocmd" removals may be misparsed as an ":autocmd".

0 commit comments

Comments
 (0)