当前位置: 首页>>代码示例>>Java>>正文


Java Completer.complete方法代码示例

本文整理汇总了Java中jline.console.completer.Completer.complete方法的典型用法代码示例。如果您正苦于以下问题:Java Completer.complete方法的具体用法?Java Completer.complete怎么用?Java Completer.complete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jline.console.completer.Completer的用法示例。


在下文中一共展示了Completer.complete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: complete

import jline.console.completer.Completer; //导入方法依赖的package包/类
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
	int completionIndex = super.complete(buffer, cursor, candidates);
	int spaceIndex = buffer.indexOf(' ');
	String commandName = (spaceIndex == -1) ? "" : buffer.substring(0, spaceIndex);
	if (!"".equals(commandName.trim())) {
		for (Command command : this.commands) {
			if (command.getName().equals(commandName)) {
				if (cursor == buffer.length() && buffer.endsWith(" ")) {
					printUsage(command);
					break;
				}
				Completer completer = this.commandCompleters.get(command.getName());
				if (completer != null) {
					completionIndex = completer.complete(buffer, cursor, candidates);
					break;
				}
			}
		}
	}
	return completionIndex;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:CommandCompleter.java

示例2: complete

import jline.console.completer.Completer; //导入方法依赖的package包/类
/**
 * Use the completers to modify the buffer with the appropriate completions.
 *
 * @return true if successful
 */
protected boolean complete() throws IOException {
    // debug ("tab for (" + buf + ")");
    if (completers.size() == 0) {
        return false;
    }

    List<CharSequence> candidates = new LinkedList<CharSequence>();
    String bufstr = buf.buffer.toString();
    int cursor = buf.cursor;

    int position = -1;

    for (Completer comp : completers) {
        if ((position = comp.complete(bufstr, cursor, candidates)) != -1) {
            break;
        }
    }

    return candidates.size() != 0 && getCompletionHandler().complete(this, candidates, position);
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:26,代码来源:ConsoleReader.java

示例3: printCompletionCandidates

import jline.console.completer.Completer; //导入方法依赖的package包/类
protected void printCompletionCandidates() throws IOException {
    // debug ("tab for (" + buf + ")");
    if (completers.size() == 0) {
        return;
    }

    List<CharSequence> candidates = new LinkedList<CharSequence>();
    String bufstr = buf.buffer.toString();
    int cursor = buf.cursor;

    for (Completer comp : completers) {
        if (comp.complete(bufstr, cursor, candidates) != -1) {
            break;
        }
    }
    CandidateListCompletionHandler.printCandidates(this, candidates);
    drawLine();
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:19,代码来源:ConsoleReader.java

示例4: complete

import jline.console.completer.Completer; //导入方法依赖的package包/类
@Override
public int complete(String buffer, final int cursor, final List<CharSequence> candidates) {
    // candidates can be null
    checkNotNull(candidates);

    if (buffer == null) {
        buffer = "";
    }
    ArgumentDelimiter delim = getDelimiter();
    ArgumentList list = delim.delimit(buffer, cursor);
    int argpos = list.getArgumentPosition();
    int argIndex = list.getCursorArgumentIndex();

    if (argIndex < 0) {
        return -1;
    }

    List<Completer> completers = getCompleters();
    Completer completer;

    // if we are beyond the end of the completers, just use the last one
    if (argIndex >= completers.size()) {
        completer = completers.get(completers.size() - 1);
    }
    else {
        completer = completers.get(argIndex);
    }

    // ensure that all the previous completers are successful before allowing this completer to pass (only if strict).
    for (int i = 0; isStrict() && (i < argIndex); i++) {
        Completer sub = completers.get(i >= completers.size() ? (completers.size() - 1) : i);
        String[] args = list.getArguments();
        String arg = (args == null || i >= args.length) ? "" : args[i];

        List<CharSequence> subCandidates = new LinkedList<CharSequence>();
        if (sub instanceof ArgumentListAware) {
            ((ArgumentListAware) sub).setArgumentList(list);
        }

        if (sub.complete(arg, arg.length(), subCandidates) == -1) {
            return -1;
        }

        if (subCandidates.size() == 0) {
            return -1;
        }
    }

    if (completer instanceof ArgumentListAware) {
        ((ArgumentListAware) completer).setArgumentList(list);
    }

    int ret = completer.complete(list.getCursorArgument(), argpos, candidates);
    if (ret == -1) {
        return -1;
    }

    int pos = ret + list.getBufferPosition() - argpos;

    // Special case: when completing in the middle of a line, and the area under the cursor is a delimiter,
    // then trim any delimiters from the candidates, since we do not need to have an extra delimiter.
    //
    // E.g., if we have a completion for "foo", and we enter "f bar" into the buffer, and move to after the "f"
    // and hit TAB, we want "foo bar" instead of "foo  bar".

    if ((cursor != buffer.length()) && delim.isDelimiter(buffer, cursor)) {
        for (int i = 0; i < candidates.size(); i++) {
            CharSequence val = candidates.get(i);

            while (val.length() > 0 && delim.isDelimiter(val, val.length() - 1)) {
                val = val.subSequence(0, val.length() - 1);
            }

            candidates.set(i, val);
        }
    }

    Log.trace("Completing ", buffer, " (pos=", cursor, ") with: ", candidates, ": offset=", pos);

    return pos;
}
 
开发者ID:vmware,项目名称:workflowTools,代码行数:82,代码来源:ImprovedArgumentCompleter.java

示例5: complete

import jline.console.completer.Completer; //导入方法依赖的package包/类
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {

    if (buffer.contains(CliConstants.RESOURCE_PATH_LONG_OPTION)) {
        return fileNameCompleter.complete(buffer, cursor, candidates);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Buffer: {}, cursor: {}", buffer, cursor);
        logger.trace("Candidates {}", candidates);
    }
    if (StringUtils.isNotBlank(buffer)) {
        // User is typing a command
        StrTokenizer strTokenizer = new StrTokenizer(buffer);
        String action = strTokenizer.next();
        Collection<String> arguments = argumentMap.get(action);
        if (arguments != null) {
            if (logger.isTraceEnabled()) {
                logger.trace("Arguments found for {}, Tokens: {}", action, strTokenizer.getTokenList());
                logger.trace("Arguments for {}: {}", action, arguments);
            }
            List<String> args = new ArrayList<String>(arguments);
            List<Completer> completers = new ArrayList<Completer>();
            for (String token : strTokenizer.getTokenList()) {
                boolean argContains = arguments.contains(token);
                if (token.startsWith("-") && !argContains) {
                    continue;
                }
                if (argContains) {
                    if (logger.isTraceEnabled()) {
                        logger.trace("Removing argument {}", token);
                    }
                    args.remove(token);
                }
                completers.add(new StringsCompleter(token));
            }
            completers.add(new StringsCompleter(args));
            Completer completer = new ArgumentCompleter(completers);
            return completer.complete(buffer, cursor, candidates);
        } else if (CliConstants.HELP_ACTION.equals(action)) {
            // For help action, we need to display available commands as arguments
            return helpCommandCompleter.complete(buffer, cursor, candidates);
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Using Default Completer...");
    }
    return defaultCommandCompleter.complete(buffer, cursor, candidates);
}
 
开发者ID:apache,项目名称:stratos,代码行数:49,代码来源:CommandCompleter.java


注:本文中的jline.console.completer.Completer.complete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。