//# 0 errors, 239 messages
//#
/*
    //#TabCompleter.java:1:1: class: com.dmdirc.ui.input.TabCompleter
    //#TabCompleter.java:1:1: method: com.dmdirc.ui.input.TabCompleter.com.dmdirc.ui.input.TabCompleter__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.ui.input;

import com.dmdirc.commandparser.CommandInfo;
import com.dmdirc.commandparser.CommandManager;
import com.dmdirc.commandparser.commands.Command;
import com.dmdirc.commandparser.commands.IntelligentCommand;
import com.dmdirc.config.IdentityManager;
import com.dmdirc.util.MapList;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * The tab completer handles a user's request to tab complete some word.
 * 
 * @author chris
 */
public final class TabCompleter implements Serializable {
    
    /**
     * A version number for this class. It should be changed whenever the class
     * structure is changed (or anything else that would prevent serialized
     * objects being unserialized with the new class).
     */
    private static final long serialVersionUID = 1;
    
    /**
     * The parent TabCompleter. Results from parents are merged with results
     * from this completer.
     */
    private TabCompleter parent;

    /**
     * The entries in this completer.
     */
    private final MapList<TabCompletionType, String> entries
    //#TabCompleter.java:61: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void com.dmdirc.ui.input.TabCompleter()
    //#    unanalyzed callee: void com.dmdirc.util.MapList()
    //#TabCompleter.java:61: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void com.dmdirc.ui.input.TabCompleter(TabCompleter)
    //#    unanalyzed callee: void com.dmdirc.util.MapList()
            = new MapList<TabCompletionType, String>();
    
    /** Creates a new instance of TabCompleter. */
    public TabCompleter() {
    //#TabCompleter.java:65: method: void com.dmdirc.ui.input.TabCompleter.com.dmdirc.ui.input.TabCompleter()
    //#input(void com.dmdirc.ui.input.TabCompleter()): this
    //#output(void com.dmdirc.ui.input.TabCompleter()): new MapList(TabCompleter#1) num objects
    //#output(void com.dmdirc.ui.input.TabCompleter()): this.entries
    //#new obj(void com.dmdirc.ui.input.TabCompleter()): new MapList(TabCompleter#1)
    //#post(void com.dmdirc.ui.input.TabCompleter()): this.entries == &new MapList(TabCompleter#1)
    //#post(void com.dmdirc.ui.input.TabCompleter()): new MapList(TabCompleter#1) num objects == 1
        //Do nothing.
    }
    //#TabCompleter.java:67: end of method: void com.dmdirc.ui.input.TabCompleter.com.dmdirc.ui.input.TabCompleter()
    
    /**
     * Creates a new instance of TabCompleter, with a designated parent.
     * @param newParent The parent TabCompleter, which is checked for matches if
     * local ones fail
     */
    public TabCompleter(final TabCompleter newParent) {
    //#TabCompleter.java:74: method: void com.dmdirc.ui.input.TabCompleter.com.dmdirc.ui.input.TabCompleter(TabCompleter)
    //#input(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): newParent
    //#input(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): this
    //#output(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): new MapList(TabCompleter#1) num objects
    //#output(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): this.entries
    //#output(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): this.parent
    //#new obj(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): new MapList(TabCompleter#1)
    //#post(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): this.entries == &new MapList(TabCompleter#1)
    //#post(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): this.parent == newParent
    //#post(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): init'ed(this.parent)
    //#post(void com.dmdirc.ui.input.TabCompleter(TabCompleter)): new MapList(TabCompleter#1) num objects == 1
        this.parent = newParent;
    }
    //#TabCompleter.java:76: end of method: void com.dmdirc.ui.input.TabCompleter.com.dmdirc.ui.input.TabCompleter(TabCompleter)
    
    /**
     * Attempts to complete the partial string.
     *
     * @param partial The string to tab complete
     * @param additionals A list of additional strings to use
     * @return A TabCompleterResult containing any matches found
     */
    public TabCompleterResult complete(final String partial,
            final AdditionalTabTargets additionals) {
        final TabCompleterResult result = new TabCompleterResult();
    //#TabCompleter.java:87: method: TabCompleterResult com.dmdirc.ui.input.TabCompleter.complete(String, AdditionalTabTargets)
    //#TabCompleter.java:87: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.ui.input.TabCompleterResult()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: void com.dmdirc.ui.input.TabCompleterResult()
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): additionals
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): additionals.includes
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.ui.input.TabCompletionType.ADDITIONAL
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): partial
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): this
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): this...entries
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): this...parent
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): this.entries
    //#input(TabCompleterResult complete(String, AdditionalTabTargets)): this.parent
    //#output(TabCompleterResult complete(String, AdditionalTabTargets)): new TabCompleterResult(complete#1) num objects
    //#output(TabCompleterResult complete(String, AdditionalTabTargets)): return_value
    //#new obj(TabCompleterResult complete(String, AdditionalTabTargets)): new TabCompleterResult(complete#1)
    //#pre[3] (TabCompleterResult complete(String, AdditionalTabTargets)): partial != null
    //#pre[2] (TabCompleterResult complete(String, AdditionalTabTargets)): (soft) additionals.includes != null
    //#pre[6] (TabCompleterResult complete(String, AdditionalTabTargets)): (soft) init'ed(this...parent)
    //#pre[8] (TabCompleterResult complete(String, AdditionalTabTargets)): (soft) init'ed(this.parent)
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.config.IdentityManager:getGlobalConfig(...)@92 != null
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.config.IdentityManager:getGlobalConfig(...)@94 != null
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): init'ed(com.dmdirc.ui.input.TabCompletionType.ADDITIONAL)
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.util.MapList:entrySet(...)@105 != null
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.util.MapList:safeGet(...)@102 != null
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): java.util.Iterator:next(...)@105 != null
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): java.util.Iterator:next(...)@111 != null
    //#presumption(TabCompleterResult complete(String, AdditionalTabTargets)): java.util.Map_Entry:getValue(...)@111 != null
    //#post(TabCompleterResult complete(String, AdditionalTabTargets)): return_value == &new TabCompleterResult(complete#1)
    //#post(TabCompleterResult complete(String, AdditionalTabTargets)): new TabCompleterResult(complete#1) num objects == 1
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.ui.input.TabCompleterResult
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.util.MapList
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.config.IdentityManager:getGlobalConfig
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.config.ConfigManager:getOptionBool
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.lang.String:isEmpty
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.util.MapList:safeGet
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.List:addAll
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.util.MapList:entrySet
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.Set:iterator
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.Map$Entry:getKey
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.List:contains
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.Map$Entry:getValue
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.ui.input.TabCompleterResult:hasResult
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.lang.String:startsWith
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.ui.input.TabCompleterResult:addResult
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.util.Locale:getDefault
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:java.lang.String:toLowerCase
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.ui.input.AdditionalTabTargets:clear
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:complete
    //#unanalyzed(TabCompleterResult complete(String, AdditionalTabTargets)): Effects-of-calling:com.dmdirc.ui.input.TabCompleterResult:merge
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): additionals: Addr_Set{null}, Inverse{null}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): this.parent: Addr_Set{null}, Inverse{null}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.config.ConfigManager:getOptionBool(...)@92: {0}, {1}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.config.ConfigManager:getOptionBool(...)@94: {1}, {0}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): com.dmdirc.ui.input.TabCompleterResult:hasResult(...)@113: {0}, {1}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): java.lang.String:isEmpty(...)@97: {0}, {1}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): java.lang.String:startsWith(...)@117: {0}, {1}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): java.lang.String:startsWith(...)@119: {0}, {1}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): java.util.Iterator:hasNext(...)@105: {0}, {1}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): java.util.Iterator:hasNext(...)@111: {0}, {1}
    //#test_vector(TabCompleterResult complete(String, AdditionalTabTargets)): java.util.List:contains(...)@61: {1}, {0}
        
        final MapList<TabCompletionType, String> targets
    //#TabCompleter.java:89: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList(MapList)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: void com.dmdirc.util.MapList(MapList)
                = new MapList<TabCompletionType, String>(entries);
        
        final boolean caseSensitive = IdentityManager.getGlobalConfig()
    //#TabCompleter.java:92: Warning: method not available - call not analyzed
    //#    call on ConfigManager com.dmdirc.config.IdentityManager:getGlobalConfig()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: ConfigManager com.dmdirc.config.IdentityManager:getGlobalConfig()
    //#TabCompleter.java:92: Warning: method not available - call not analyzed
    //#    call on bool com.dmdirc.config.ConfigManager:getOptionBool(String, String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: bool com.dmdirc.config.ConfigManager:getOptionBool(String, String)
                .getOptionBool("tabcompletion", "casesensitive");
        final boolean allowEmpty = IdentityManager.getGlobalConfig()
    //#TabCompleter.java:94: Warning: method not available - call not analyzed
    //#    call on ConfigManager com.dmdirc.config.IdentityManager:getGlobalConfig()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: ConfigManager com.dmdirc.config.IdentityManager:getGlobalConfig()
    //#TabCompleter.java:94: Warning: method not available - call not analyzed
    //#    call on bool com.dmdirc.config.ConfigManager:getOptionBool(String, String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: bool com.dmdirc.config.ConfigManager:getOptionBool(String, String)
                .getOptionBool("tabcompletion", "allowempty");

        if (partial.isEmpty() && !allowEmpty) {
            return result;
        }
                
        if (additionals != null) {
            targets.safeGet(TabCompletionType.ADDITIONAL).addAll(additionals);
    //#TabCompleter.java:102: Warning: method not available - call not analyzed
    //#    call on List com.dmdirc.util.MapList:safeGet(Object)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: List com.dmdirc.util.MapList:safeGet(Object)
        }
        
        for (Map.Entry<TabCompletionType, List<String>> typeEntry : targets.entrySet()) {
    //#TabCompleter.java:105: Warning: method not available - call not analyzed
    //#    call on Set com.dmdirc.util.MapList:entrySet()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: Set com.dmdirc.util.MapList:entrySet()
            if (additionals != null && !additionals.shouldInclude(typeEntry.getKey())) {
                // If we're not including this type, skip to the next.
                continue;
            }
            
            for (String entry : typeEntry.getValue()) {
                // Skip over duplicates
                if (result.hasResult(entry)) {
    //#TabCompleter.java:113: Warning: method not available - call not analyzed
    //#    call on bool com.dmdirc.ui.input.TabCompleterResult:hasResult(String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: bool com.dmdirc.ui.input.TabCompleterResult:hasResult(String)
                    continue;
                }

                if (caseSensitive && entry.startsWith(partial)) {
                    result.addResult(entry);
    //#TabCompleter.java:118: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.ui.input.TabCompleterResult:addResult(String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: void com.dmdirc.ui.input.TabCompleterResult:addResult(String)
                } else if (!caseSensitive && entry.toLowerCase(Locale.getDefault())
                        .startsWith(partial.toLowerCase(Locale.getDefault()))) {
                    result.addResult(entry);
    //#TabCompleter.java:121: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.ui.input.TabCompleterResult:addResult(String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: void com.dmdirc.ui.input.TabCompleterResult:addResult(String)
                }
            }
        }
        
        if (parent != null) {
            if (additionals != null) {
                additionals.clear();
    //#TabCompleter.java:128: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.ui.input.AdditionalTabTargets:clear()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: void com.dmdirc.ui.input.AdditionalTabTargets:clear()
            }
            
            result.merge(parent.complete(partial, additionals));
    //#TabCompleter.java:131: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.ui.input.TabCompleterResult:merge(TabCompleterResult)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: TabCompleterResult complete(String, AdditionalTabTargets)
    //#    unanalyzed callee: void com.dmdirc.ui.input.TabCompleterResult:merge(TabCompleterResult)
        }
        
        return result;
    //#TabCompleter.java:134: end of method: TabCompleterResult com.dmdirc.ui.input.TabCompleter.complete(String, AdditionalTabTargets)
    }
    
    /**
     * Adds a new entry to this tab completer's list.
     * 
     * @param type The type of the entry that's being added
     * @param entry The new entry to be added
     */
    public void addEntry(final TabCompletionType type, final String entry) {
        entries.add(type, entry);
    //#TabCompleter.java:144: method: void com.dmdirc.ui.input.TabCompleter.addEntry(TabCompletionType, String)
    //#TabCompleter.java:144: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList:add(Object, Object)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void addEntry(TabCompletionType, String)
    //#    unanalyzed callee: void com.dmdirc.util.MapList:add(Object, Object)
    //#input(void addEntry(TabCompletionType, String)): entry
    //#input(void addEntry(TabCompletionType, String)): this
    //#input(void addEntry(TabCompletionType, String)): this.entries
    //#input(void addEntry(TabCompletionType, String)): type
    //#pre[3] (void addEntry(TabCompletionType, String)): this.entries != null
    }
    //#TabCompleter.java:145: end of method: void com.dmdirc.ui.input.TabCompleter.addEntry(TabCompletionType, String)
    
    /**
     * Adds multiple new entries to this tab completer's list.
     * 
     * @param type The type of the entries that're being added
     * @param newEntries Entries to be added
     */
    public void addEntries(final TabCompletionType type, final List<String> newEntries) {
        if (newEntries == null) {
    //#TabCompleter.java:154: method: void com.dmdirc.ui.input.TabCompleter.addEntries(TabCompletionType, List)
    //#input(void addEntries(TabCompletionType, List)): newEntries
    //#input(void addEntries(TabCompletionType, List)): this
    //#input(void addEntries(TabCompletionType, List)): this.entries
    //#input(void addEntries(TabCompletionType, List)): type
    //#pre[3] (void addEntries(TabCompletionType, List)): (soft) this.entries != null
    //#unanalyzed(void addEntries(TabCompletionType, List)): Effects-of-calling:com.dmdirc.util.MapList:add
    //#test_vector(void addEntries(TabCompletionType, List)): newEntries: Inverse{null}, Addr_Set{null}
    //#test_vector(void addEntries(TabCompletionType, List)): java.util.Iterator:hasNext(...)@158: {0}, {1}
            return;
        }
        
        for (String entry : newEntries) {
            addEntry(type, entry);
        }
    }
    //#TabCompleter.java:161: end of method: void com.dmdirc.ui.input.TabCompleter.addEntries(TabCompletionType, List)
    
    /**
     * Removes a specified entry from this tab completer's list.
     * 
     * @param type The type of the entry that should be removed
     * @param entry The entry to be removed
     */
    public void removeEntry(final TabCompletionType type, final String entry) {
        entries.remove(type, entry);
    //#TabCompleter.java:170: method: void com.dmdirc.ui.input.TabCompleter.removeEntry(TabCompletionType, String)
    //#TabCompleter.java:170: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList:remove(Object, Object)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void removeEntry(TabCompletionType, String)
    //#    unanalyzed callee: void com.dmdirc.util.MapList:remove(Object, Object)
    //#input(void removeEntry(TabCompletionType, String)): entry
    //#input(void removeEntry(TabCompletionType, String)): this
    //#input(void removeEntry(TabCompletionType, String)): this.entries
    //#input(void removeEntry(TabCompletionType, String)): type
    //#pre[3] (void removeEntry(TabCompletionType, String)): this.entries != null
    }
    //#TabCompleter.java:171: end of method: void com.dmdirc.ui.input.TabCompleter.removeEntry(TabCompletionType, String)
    
    /**
     * Replaces the current entries with the new list.
     * 
     * @param type The type of entry which should be replaced
     * @param newEntries the new entries to use
     */
    public void replaceEntries(final TabCompletionType type, final List<String> newEntries) {
        entries.clear(type);
    //#TabCompleter.java:180: method: void com.dmdirc.ui.input.TabCompleter.replaceEntries(TabCompletionType, List)
    //#TabCompleter.java:180: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList:clear(Object)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void replaceEntries(TabCompletionType, List)
    //#    unanalyzed callee: void com.dmdirc.util.MapList:clear(Object)
    //#input(void replaceEntries(TabCompletionType, List)): newEntries
    //#input(void replaceEntries(TabCompletionType, List)): this
    //#input(void replaceEntries(TabCompletionType, List)): this.entries
    //#input(void replaceEntries(TabCompletionType, List)): type
    //#pre[3] (void replaceEntries(TabCompletionType, List)): this.entries != null
        entries.add(type, newEntries);
    //#TabCompleter.java:181: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList:add(Object, Collection)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void replaceEntries(TabCompletionType, List)
    //#    unanalyzed callee: void com.dmdirc.util.MapList:add(Object, Collection)
    }
    //#TabCompleter.java:182: end of method: void com.dmdirc.ui.input.TabCompleter.replaceEntries(TabCompletionType, List)
    
    /**
     * Clears all entries in this tab completer.
     */
    public void clear() {
        entries.clear();
    //#TabCompleter.java:188: method: void com.dmdirc.ui.input.TabCompleter.clear()
    //#TabCompleter.java:188: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList:clear()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void clear()
    //#    unanalyzed callee: void com.dmdirc.util.MapList:clear()
    //#input(void clear()): this
    //#input(void clear()): this.entries
    //#pre[2] (void clear()): this.entries != null
    }
    //#TabCompleter.java:189: end of method: void com.dmdirc.ui.input.TabCompleter.clear()
    
    /**
     * Clears all entries of the specified type in this tab completer.
     * 
     * @param type The type of entry to clear
     */
    public void clear(final TabCompletionType type) {
        entries.clear(type);
    //#TabCompleter.java:197: method: void com.dmdirc.ui.input.TabCompleter.clear(TabCompletionType)
    //#TabCompleter.java:197: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.util.MapList:clear(Object)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: void clear(TabCompletionType)
    //#    unanalyzed callee: void com.dmdirc.util.MapList:clear(Object)
    //#input(void clear(TabCompletionType)): this
    //#input(void clear(TabCompletionType)): this.entries
    //#input(void clear(TabCompletionType)): type
    //#pre[2] (void clear(TabCompletionType)): this.entries != null
    }
    //#TabCompleter.java:198: end of method: void com.dmdirc.ui.input.TabCompleter.clear(TabCompletionType)
    
    /**
     * Retrieves intelligent results for a deferred command.
     * 
     * @param arg The argument number that is being requested
     * @param previousArgs The full list of previous arguments
     * @param offset The number of arguments our command used before deferring
     * to this method
     * @return Additional tab targets for the text, or null if none are available
     */
    public static AdditionalTabTargets getIntelligentResults(final int arg,
            final List<String> previousArgs, final int offset) {
        if (arg == offset) {
    //#TabCompleter.java:211: method: AdditionalTabTargets com.dmdirc.ui.input.TabCompleter.getIntelligentResults(int, List, int)
    //#input(AdditionalTabTargets getIntelligentResults(int, List, int)): arg
    //#input(AdditionalTabTargets getIntelligentResults(int, List, int)): com.dmdirc.ui.input.TabCompletionType.COMMAND
    //#input(AdditionalTabTargets getIntelligentResults(int, List, int)): com/dmdirc/ui/input/AdditionalTabTargets.com.dmdirc.ui.input.TabCompletionType.ADDITIONAL
    //#input(AdditionalTabTargets getIntelligentResults(int, List, int)): offset
    //#input(AdditionalTabTargets getIntelligentResults(int, List, int)): previousArgs
    //#output(AdditionalTabTargets getIntelligentResults(int, List, int)): new AdditionalTabTargets(getIntelligentResults#1) num objects
    //#output(AdditionalTabTargets getIntelligentResults(int, List, int)): new AdditionalTabTargets(getIntelligentResults#1).__Tag
    //#output(AdditionalTabTargets getIntelligentResults(int, List, int)): new AdditionalTabTargets(getIntelligentResults#1).includes
    //#output(AdditionalTabTargets getIntelligentResults(int, List, int)): new ArrayList(AdditionalTabTargets#1) num objects
    //#output(AdditionalTabTargets getIntelligentResults(int, List, int)): return_value
    //#new obj(AdditionalTabTargets getIntelligentResults(int, List, int)): new AdditionalTabTargets(getIntelligentResults#1)
    //#new obj(AdditionalTabTargets getIntelligentResults(int, List, int)): new ArrayList(AdditionalTabTargets#1)
    //#pre[4] (AdditionalTabTargets getIntelligentResults(int, List, int)): (soft) previousArgs != null
    //#presumption(AdditionalTabTargets getIntelligentResults(int, List, int)): init'ed(com.dmdirc.ui.input.TabCompletionType.COMMAND)
    //#presumption(AdditionalTabTargets getIntelligentResults(int, List, int)): java.util.List:subList(...)@216 != null
    //#post(AdditionalTabTargets getIntelligentResults(int, List, int)): init'ed(return_value)
    //#post(AdditionalTabTargets getIntelligentResults(int, List, int)): new AdditionalTabTargets(getIntelligentResults#1) num objects <= 1
    //#post(AdditionalTabTargets getIntelligentResults(int, List, int)): new AdditionalTabTargets(getIntelligentResults#1).__Tag == com/dmdirc/ui/input/AdditionalTabTargets
    //#post(AdditionalTabTargets getIntelligentResults(int, List, int)): new AdditionalTabTargets(getIntelligentResults#1).includes == &new ArrayList(AdditionalTabTargets#1)
    //#post(AdditionalTabTargets getIntelligentResults(int, List, int)): new ArrayList(AdditionalTabTargets#1) num objects <= 1
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.List:contains
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.Map$Entry:getValue
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.List:isEmpty
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.List:get
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.lang.String:charAt
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:com.dmdirc.commandparser.CommandManager:getCommandChar
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.lang.String:substring
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:com.dmdirc.commandparser.CommandManager:getCommand
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:com.dmdirc.commandparser.commands.IntelligentCommand:instanceof
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.List:size
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.List:subList
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:com.dmdirc.commandparser.commands.IntelligentCommand:getSuggestions
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:com.dmdirc.ui.input.TabCompletionType:values
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.Arrays:asList
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.List:add
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(int, List, int)): Effects-of-calling:java.util.List:clear
    //#test_vector(AdditionalTabTargets getIntelligentResults(int, List, int)): offset - arg: {-6_442_450_943..-1, 1..6_442_450_943}, {0}
            final AdditionalTabTargets targets = new AdditionalTabTargets().excludeAll();
            targets.include(TabCompletionType.COMMAND);
            return targets;
        } else {
            return TabCompleter.getIntelligentResults(previousArgs.subList(offset,
    //#TabCompleter.java:216: end of method: AdditionalTabTargets com.dmdirc.ui.input.TabCompleter.getIntelligentResults(int, List, int)
                    previousArgs.size()));
        }        
    }
    
    /**
     * Retrieves the intelligent results for the command and its arguments
     * formed from args.
     * 
     * @param args A list of "words" in the input
     * @return Additional tab targets for the text, or null if none are available
     */
    private static AdditionalTabTargets getIntelligentResults(final List<String> args) {
        if (args.isEmpty() || args.get(0).charAt(0) != CommandManager.getCommandChar()) {
    //#TabCompleter.java:229: method: AdditionalTabTargets com.dmdirc.ui.input.TabCompleter.getIntelligentResults(List)
    //#TabCompleter.java:229: Warning: method not available - call not analyzed
    //#    call on char com.dmdirc.commandparser.CommandManager:getCommandChar()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: AdditionalTabTargets getIntelligentResults(List)
    //#    unanalyzed callee: char com.dmdirc.commandparser.CommandManager:getCommandChar()
    //#input(AdditionalTabTargets getIntelligentResults(List)): args
    //#output(AdditionalTabTargets getIntelligentResults(List)): return_value
    //#pre[1] (AdditionalTabTargets getIntelligentResults(List)): args != null
    //#presumption(AdditionalTabTargets getIntelligentResults(List)): java.util.List:get(...)@229 != null
    //#presumption(AdditionalTabTargets getIntelligentResults(List)): java.util.List:get(...)@233 != null
    //#presumption(AdditionalTabTargets getIntelligentResults(List)): java.util.List:size(...)@237 >= -2_147_483_647
    //#presumption(AdditionalTabTargets getIntelligentResults(List)): java.util.Map_Entry:getValue(...)@237 != null
    //#post(AdditionalTabTargets getIntelligentResults(List)): init'ed(return_value)
    //#test_vector(AdditionalTabTargets getIntelligentResults(List)): com.dmdirc.commandparser.CommandManager:getCommand(...)@234: Addr_Set{null}, Inverse{null}
    //#test_vector(AdditionalTabTargets getIntelligentResults(List)): java.util.List:isEmpty(...)@229: {1}, {0}
            return null;
        }
        
        final String signature = args.get(0).substring(1);
        final Map.Entry<CommandInfo, Command> command = CommandManager.getCommand(signature);
    //#TabCompleter.java:234: Warning: method not available - call not analyzed
    //#    call on Map$Entry com.dmdirc.commandparser.CommandManager:getCommand(String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: AdditionalTabTargets getIntelligentResults(List)
    //#    unanalyzed callee: Map$Entry com.dmdirc.commandparser.CommandManager:getCommand(String)
        
        if (command != null && command.getValue() instanceof IntelligentCommand) {
            return ((IntelligentCommand) command.getValue()).getSuggestions(args.size() - 1,
    //#TabCompleter.java:237: Warning: method not available - call not analyzed
    //#    call on AdditionalTabTargets com.dmdirc.commandparser.commands.IntelligentCommand:getSuggestions(int, List)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ui.input.TabCompleter
    //#    method: AdditionalTabTargets getIntelligentResults(List)
    //#    unanalyzed callee: AdditionalTabTargets com.dmdirc.commandparser.commands.IntelligentCommand:getSuggestions(int, List)
                    args.subList(1, args.size()));
        } else {
            return null;
    //#TabCompleter.java:240: end of method: AdditionalTabTargets com.dmdirc.ui.input.TabCompleter.getIntelligentResults(List)
        }        
    }
    
    /**
     * Handles potentially intelligent tab completion.
     *
     * @param text The text that is being completed
     * @return Additional tab targets for the text, or null if none are available
     */
    public static AdditionalTabTargets getIntelligentResults(final String text) {
        return getIntelligentResults(Arrays.asList(text.split(" ")));
    //#TabCompleter.java:251: method: AdditionalTabTargets com.dmdirc.ui.input.TabCompleter.getIntelligentResults(String)
    //#input(AdditionalTabTargets getIntelligentResults(String)): text
    //#input(AdditionalTabTargets getIntelligentResults(String)): text._tainted
    //#output(AdditionalTabTargets getIntelligentResults(String)): return_value
    //#pre[1] (AdditionalTabTargets getIntelligentResults(String)): text != null
    //#presumption(AdditionalTabTargets getIntelligentResults(String)): java.util.Arrays:asList(...)@251 != null
    //#post(AdditionalTabTargets getIntelligentResults(String)): init'ed(return_value)
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:java.util.Map$Entry:getValue
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:java.util.List:isEmpty
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:java.util.List:get
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:java.lang.String:charAt
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:com.dmdirc.commandparser.CommandManager:getCommandChar
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:java.lang.String:substring
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:com.dmdirc.commandparser.CommandManager:getCommand
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:com.dmdirc.commandparser.commands.IntelligentCommand:instanceof
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:java.util.List:size
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:java.util.List:subList
    //#unanalyzed(AdditionalTabTargets getIntelligentResults(String)): Effects-of-calling:com.dmdirc.commandparser.commands.IntelligentCommand:getSuggestions
    //#TabCompleter.java:251: end of method: AdditionalTabTargets com.dmdirc.ui.input.TabCompleter.getIntelligentResults(String)
    }
}
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Descendant_Table[com/dmdirc/ui/input/TabCompleter]
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.addEntries(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/util/List;)V
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.addEntry(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/lang/String;)V
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.clear()V
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.clear(Lcom/dmdirc/ui/input/TabCompletionType;)V
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.complete(Ljava/lang/String;Lcom/dmdirc/ui/input/AdditionalTabTargets;)Lcom/dmdirc/ui/input/TabCompleterResult;
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.removeEntry(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/lang/String;)V
    //#output(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.replaceEntries(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/util/List;)V
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Descendant_Table[com/dmdirc/ui/input/TabCompleter] == &__Dispatch_Table
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.addEntries(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/util/List;)V == &addEntries
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.addEntry(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/lang/String;)V == &addEntry
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.clear()V == &clear
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.clear(Lcom/dmdirc/ui/input/TabCompletionType;)V == &clear
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.complete(Ljava/lang/String;Lcom/dmdirc/ui/input/AdditionalTabTargets;)Lcom/dmdirc/ui/input/TabCompleterResult; == &complete
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.removeEntry(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/lang/String;)V == &removeEntry
    //#post(com.dmdirc.ui.input.TabCompleter__static_init): __Dispatch_Table.replaceEntries(Lcom/dmdirc/ui/input/TabCompletionType;Ljava/util/List;)V == &replaceEntries
    //#TabCompleter.java:: end of method: com.dmdirc.ui.input.TabCompleter.com.dmdirc.ui.input.TabCompleter__static_init
    //#TabCompleter.java:: end of class: com.dmdirc.ui.input.TabCompleter
