Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 SAP AG All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at Contributors: Lazar Kirchev, SAP AG - initial API and implementation /
package org.eclipse.equinox.console.completion;
This class provides completion for command names.
public class CommandNamesCompleter implements Completer {
	private static final String COMMANDS = ".commands";
	public CommandNamesCompleter(BundleContext contextCommandSession session) {
		this. = session;
	public Map<StringIntegergetCandidates(String bufferint cursor) {
		Set<StringcommandNames = null;
		if (commandsTracker != null) {
			commandNames = commandsTracker.getCommands();
		// CommandSession.get(".commands") returns the names of all registered commands
		if (commandNames == null || commandNames.isEmpty()) {
			commandNames = (Set<String>) .get();
		// command names are stored in the session in lower case
		String currentToken = CommandLineParser.getCurrentToken(buffercursor).toLowerCase();
		if(currentToken == null || currentToken.equals("")) {
			return new HashMap<StringInteger>();
		if (!currentToken.contains(":")) {
			// the current token does not contain a scope qualifier, so remove scopes from possible candidates
			commandNames = clearScopes(commandNames);
		StringsCompleter completer = new StringsCompleter(commandNamestrue);
		return completer.getCandidates(buffercursor);
	private Set<StringclearScopes(Set<StringcommandNames) {
		Set<StringclearedCommandNames = new HashSet<String>();
		for(String commandName : commandNames) {
			clearedCommandNames.add(commandName.substring(commandName.indexOf(":") + 1));
		return clearedCommandNames;
New to GrepCode? Check out our FAQ X