Skip to content
Snippets Groups Projects
Commit 8d82ee1e authored by dgelessus's avatar dgelessus
Browse files

Move Inspector and Completer out of CommandUtils

Most of the inspection/completion code is no longer part of
CommandUtils.
parent 29be62a2
No related branches found
No related tags found
No related merge requests found
......@@ -42,16 +42,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class CommandUtils {
@FunctionalInterface
public interface Inspector {
public abstract @Nullable DisplayData inspect(final @NotNull String argString, final int at);
}
@FunctionalInterface
public interface Completer {
public abstract @Nullable ReplacementOptions complete(final @NotNull String argString, final int at);
}
private static final @NotNull Logger LOGGER = LoggerFactory.getLogger(CommandUtils.class);
private static final @NotNull Pattern BODY_SPLIT_PATTERN = Pattern.compile("\\n");
......
package de.prob2.jupyter;
import io.github.spencerpark.jupyter.kernel.ReplacementOptions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@FunctionalInterface
public interface Completer {
public abstract @Nullable ReplacementOptions complete(final @NotNull String argString, final int at);
}
package de.prob2.jupyter;
import io.github.spencerpark.jupyter.kernel.display.DisplayData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@FunctionalInterface
public interface Inspector {
public abstract @Nullable DisplayData inspect(final @NotNull String argString, final int at);
}
......@@ -19,9 +19,9 @@ public final class ParameterCompleters {
*/
public static final @NotNull ParameterCompleters NONE = new ParameterCompleters(Collections.emptyMap());
private final @NotNull Map<@NotNull Parameter<?>, CommandUtils.@NotNull Completer> completers;
private final @NotNull Map<@NotNull Parameter<?>, @NotNull Completer> completers;
public ParameterCompleters(final @NotNull Map<@NotNull Parameter<?>, CommandUtils.@NotNull Completer> completers) {
public ParameterCompleters(final @NotNull Map<@NotNull Parameter<?>, @NotNull Completer> completers) {
super();
this.completers = Collections.unmodifiableMap(new HashMap<>(completers));
......@@ -32,7 +32,7 @@ public final class ParameterCompleters {
*
* @return the stored mapping of parameters to code completion handlers
*/
public @NotNull Map<@NotNull Parameter<?>, CommandUtils.@NotNull Completer> getCompleters() {
public @NotNull Map<@NotNull Parameter<?>, @NotNull Completer> getCompleters() {
return this.completers;
}
......@@ -50,7 +50,7 @@ public final class ParameterCompleters {
* @return the code completion handler for a parameter,
* or {@link Optional#empty()} if there is none
*/
public @NotNull Optional<CommandUtils.Completer> getCompleterForParameter(final @NotNull Parameter<?> parameter) {
public @NotNull Optional<Completer> getCompleterForParameter(final @NotNull Parameter<?> parameter) {
if (this.getCompleters().containsKey(parameter)) {
return Optional.of(this.getCompleters().get(parameter));
} else {
......
......@@ -19,9 +19,9 @@ public final class ParameterInspectors {
*/
public static final @NotNull ParameterInspectors NONE = new ParameterInspectors(Collections.emptyMap());
private final @NotNull Map<@NotNull Parameter<?>, CommandUtils.@NotNull Inspector> inspectors;
private final @NotNull Map<@NotNull Parameter<?>, @NotNull Inspector> inspectors;
public ParameterInspectors(final @NotNull Map<@NotNull Parameter<?>, CommandUtils.@NotNull Inspector> inspectors) {
public ParameterInspectors(final @NotNull Map<@NotNull Parameter<?>, @NotNull Inspector> inspectors) {
super();
this.inspectors = Collections.unmodifiableMap(new HashMap<>(inspectors));
......@@ -32,7 +32,7 @@ public final class ParameterInspectors {
*
* @return the stored mapping of parameters to inspection handlers
*/
public @NotNull Map<@NotNull Parameter<?>, CommandUtils.@NotNull Inspector> getInspectors() {
public @NotNull Map<@NotNull Parameter<?>, @NotNull Inspector> getInspectors() {
return this.inspectors;
}
......@@ -50,7 +50,7 @@ public final class ParameterInspectors {
* @return the inspection handler for a parameter,
* or {@link Optional#empty()} if there is none
*/
public @NotNull Optional<CommandUtils.Inspector> getInspectorForParameter(final @NotNull Parameter<?> parameter) {
public @NotNull Optional<Inspector> getInspectorForParameter(final @NotNull Parameter<?> parameter) {
if (this.getInspectors().containsKey(parameter)) {
return Optional.of(this.getInspectors().get(parameter));
} else {
......
......@@ -357,7 +357,7 @@ public final class ProBKernel extends BaseKernel {
private static @Nullable DisplayData inspectCommandArguments(final @NotNull Command command, final @NotNull String argString, final int at) {
final SplitResult split = CommandUtils.splitArgs(command.getParameters(), argString, at);
if (split.getParameterAtPosition().isPresent()) {
final Optional<CommandUtils.Inspector> inspector = command.getParameterInspectors().getInspectorForParameter(split.getParameterAtPosition().get());
final Optional<Inspector> inspector = command.getParameterInspectors().getInspectorForParameter(split.getParameterAtPosition().get());
if (inspector.isPresent()) {
final List<PositionedString> argsAtPosition = split.getArguments().get(split.getParameterAtPosition().get());
assert !argsAtPosition.isEmpty();
......@@ -414,7 +414,7 @@ public final class ProBKernel extends BaseKernel {
private static @Nullable ReplacementOptions completeCommandArguments(final @NotNull Command command, final @NotNull String argString, final int at) {
final SplitResult split = CommandUtils.splitArgs(command.getParameters(), argString, at);
if (split.getParameterAtPosition().isPresent()) {
final Optional<CommandUtils.Completer> completer = command.getParameterCompleters().getCompleterForParameter(split.getParameterAtPosition().get());
final Optional<Completer> completer = command.getParameterCompleters().getCompleterForParameter(split.getParameterAtPosition().get());
if (completer.isPresent()) {
final List<PositionedString> argsAtPosition = split.getArguments().get(split.getParameterAtPosition().get());
assert !argsAtPosition.isEmpty();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment