Added suggestions to a lot of factory-related commands

This commit is contained in:
Matthew Miller
2019-05-18 16:47:08 +10:00
parent 7b47d9a945
commit a3ffb91917
14 changed files with 75 additions and 17 deletions

View File

@ -27,8 +27,11 @@ import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* An abstract implementation of a factory for internal usage.
@ -76,6 +79,10 @@ public abstract class AbstractFactory<E> {
throw new NoMatchException("No match for '" + input + "'");
}
public Stream<String> getSuggestions() {
return parsers.stream().flatMap(InputParser::getSuggestions);
}
/**
* Registers an InputParser to this factory
*

View File

@ -25,6 +25,7 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
/**
* Input parser interface for {@link AbstractFactory}.
@ -43,11 +44,11 @@ public abstract class InputParser<E> {
public abstract E parseFromInput(String input, ParserContext context) throws InputParseException;
/**
* Gets a list of suggestions of input to this parser.
* Gets a stream of suggestions of input to this parser.
*
* @return a list of suggestions
* @return a stream of suggestions
*/
public List<String> getSuggestions() {
return Collections.emptyList();
public Stream<String> getSuggestions() {
return Stream.empty();
}
}

View File

@ -25,6 +25,7 @@ import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.List;
import java.util.stream.Stream;
/**
* An input parser that only performs a single function from aliases.
@ -65,7 +66,7 @@ public abstract class SimpleInputParser<E> extends InputParser<E> {
}
@Override
public List<String> getSuggestions() {
return Lists.newArrayList(getPrimaryMatcher());
public Stream<String> getSuggestions() {
return Stream.of(getPrimaryMatcher());
}
}