unsupported
     ˆ0_’I|¥‰ÓMjqØ‚¦ð¬÷À¿  "   ˆl–Ü4ý(&”ÔD¨ 	ÅŒ»q°)‹FÿÂƒh¹ÁÀ      0
  "   ˆl–Ü4ý(&ÔËm
�ÆŸ¸ÓêbÑ¿Ãƒ|{ÂÁ #:    # bash completion for java, javac and javadoc              -*- shell-script -*-

# available path elements completion
_java_path()
{
    cur=${cur##*:}
    _filedir '@(jar|zip)'
}

# exact classpath determination
_java_find_classpath()
{
    local i

    # search first in current options
    for ((i = 1; i < cword; i++)); do
        if [[ ${words[i]} == -@(cp|classpath) ]]; then
            classpath=${words[i + 1]}
            break
        fi
    done

    # default to environment
    [[ ! -v classpath ]] && classpath=${CLASSPATH-}

    # default to current directory
    [[ -z $classpath ]] && classpath=.
}

# exact sourcepath determination
_java_find_sourcepath()
{
    local i

    # search first in current options
    for ((i = 1; i < cword; i++)); do
        if [[ ${words[i]} == -sourcepath ]]; then
            sourcepath=${words[i + 1]}
            break
        fi
    done

    # default to classpath
    if [[ ! -v sourcepath ]]; then
        local classpath
        _java_find_classpath
        sourcepath=$classpath
    fi
}

# available classes completion
_java_classes()
{
    local classpath i

    # find which classpath to use
    _java_find_classpath

    # convert package syntax to path syntax
    cur=${cur//.//}
    # parse each classpath element for classes
    for i in ${classpath//:/ }; do
        if [[ $i == *.@(jar|zip) && -r $i ]]; then
            if type zipinfo &>/dev/null; then
                COMPREPLY+=($(zipinfo -1 "$i" "$cur*" 2>/dev/null |
                    command grep '^[^$]*\.class$'))
            elif type unzip &>/dev/null; then
                # Last column, between entries consisting entirely of dashes
                COMPREPLY+=($(unzip -lq "$i" "$cur*" 2>/dev/null |
                    awk '$NF ~ /^-+$/ { flag=!flag; next };
                         flag && $NF ~ /^[^$]*\.class/ { print $NF }'))
            elif type jar &>/dev/null; then
                COMPREPLY+=($(jar tf "$i" "$cur" |
                    command grep '^[^$]*\.class$'))
            fi

        elif [[ -d $i ]]; then
            COMPREPLY+=(
                $(compgen -d -- "$i/$cur" | command sed -e "s|^$i/\(.*\)|\1.|")
                $(compgen -f -X '!*.class' -- "$i/$cur" |
                    command sed -e '/\$/d' -e "s|^$i/||")
            )
            [[ ${COMPREPLY-} == *.class ]] || compopt -o nospace

            # FIXME: if we have foo.class and foo/, the completion
            # returns "foo/"... how to give precedence to files
            # over directories?
        fi
    done

    if ((${#COMPREPLY[@]} != 0)); then
        # remove class extension
        COMPREPLY=(${COMPREPLY[@]%.class})
        # convert path syntax to package syntax
        COMPREPLY=(${COMPREPLY[@]//\//.})
    fi
}

# available packages completion
_java_packages()
{
    local sourcepath i

    # find which sourcepath to use
    _java_find_sourcepath

    # convert package syntax to path syntax
    cur=${cur//.//}
    # parse each sourcepath element for packages
    for i in ${sourcepath//:/ }; do
        if [[ -d $i ]]; then
            COMPREPLY+=($(command ls -F -d $i/$cur* 2>/dev/null |
                command sed -e 's|^'$i'/||'))
        fi
    done
    if ((${#COMPREPLY[@]} != 0)); then
        # keep only packages
        COMPREPLY=($(tr " " "\n" <<<"${COMPREPLY[@]}" | command grep "/$"))
        # remove packages extension
        COMPREPLY=(${COMPREPLY[@]%/})
        # convert path syntax to package syntax
        cur="${COMPREPLY[*]//\//.}"
    fi
}

# java completion
#
_java()
{
    local cur prev words cword
    _init_completion -n : || return

    local i

    for ((i = 1; i < cword; i++)); do
        case ${words[i]} in
            -cp | -classpath)
                ((i++)) # skip the classpath string.
                ;;
            -*)
                # this is an option, not a class/jarfile name.
                ;;
            *)
                # once we've se