Skip to content

Commit aebd676

Browse files
scopakinomyoga
andcommitted
refactor(java): rework towards current API behavior
Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
1 parent 55d0e07 commit aebd676

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

completions/java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,65 @@ _comp_cmd_java__classpath()
88
}
99

1010
# exact classpath determination
11-
_java_find_classpath()
11+
# @var[out] ret Array to store classpaths
12+
# @return 0 if at least one element is generated, or otherwise 1
13+
_comp_cmd_java__find_classpath()
1214
{
1315
local i
1416

15-
classpath=
17+
ret=
1618

1719
# search first in current options
1820
for ((i = 1; i < cword; i++)); do
1921
if [[ ${words[i]} == -@(cp|classpath) ]]; then
20-
classpath=${words[i + 1]}
22+
ret=${words[i + 1]}
2123
break
2224
fi
2325
done
2426

25-
# default to environment
26-
[[ ! $classpath ]] && classpath=${CLASSPATH-}
27-
28-
# default to current directory
29-
[[ ! $classpath ]] && classpath=.
27+
# fall back to environment, followed by current directory
28+
_comp_split -F : ret "${ret:-${CLASSPATH:-.}}"
3029
}
3130

3231
# exact sourcepath determination
33-
_java_find_sourcepath()
32+
# @var[out] ret Array to store sourcepaths
33+
# @return 0 if at least one element is generated, or otherwise 1
34+
_comp_cmd_java__find_sourcepath()
3435
{
3536
local i
3637

37-
sourcepath=
38+
ret=
3839

3940
# search first in current options
4041
for ((i = 1; i < cword; i++)); do
4142
if [[ ${words[i]} == -sourcepath ]]; then
42-
sourcepath=${words[i + 1]}
43+
ret=${words[i + 1]}
4344
break
4445
fi
4546
done
4647

47-
# default to classpath
48-
if [[ ! -v sourcepath ]]; then
49-
local classpath
50-
_java_find_classpath
51-
sourcepath=$classpath
48+
# fall back to classpath
49+
if [[ ! $ret ]]; then
50+
_comp_cmd_java__find_classpath
51+
return
5252
fi
5353

54-
_comp_split -F : sourcepath "$sourcepath"
54+
_comp_split -F : ret "$ret"
5555
}
5656

5757
# available classes completion
5858
_comp_cmd_java__classes()
5959
{
60-
local classpath i
60+
local ret i
6161

6262
# find which classpath to use
63-
_java_find_classpath
63+
_comp_cmd_java__find_classpath
64+
local -a classpaths=("${ret[@]}")
6465

6566
# convert package syntax to path syntax
6667
cur=${cur//.//}
6768
# parse each classpath element for classes
68-
for i in ${classpath//:/ }; do
69+
for i in "${classpaths[@]}"; do
6970
if [[ $i == *.@(jar|zip) && -r $i ]]; then
7071
if type zipinfo &>/dev/null; then
7172
COMPREPLY+=($(zipinfo -1 "$i" "$cur*" 2>/dev/null |
@@ -105,16 +106,16 @@ _comp_cmd_java__classes()
105106
# available packages completion
106107
_comp_cmd_java__packages()
107108
{
108-
local sourcepath i files
109+
local ret i files
109110

110111
# find which sourcepath to use
111-
_java_find_sourcepath
112-
((${#sourcepath[@]})) || return 0
112+
_comp_cmd_java__find_sourcepath || return 0
113+
local -a sourcepaths=("${ret[@]}")
113114

114115
# convert package syntax to path syntax
115116
local cur=${cur//.//}
116117
# parse each sourcepath element for packages
117-
for i in "${sourcepath[@]}"; do
118+
for i in "${sourcepaths[@]}"; do
118119
if [[ -d $i ]]; then
119120
_comp_expand_glob files '"$i/$cur"*'
120121
((${#files[@]})) || continue

0 commit comments

Comments
 (0)