diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/EmbeddedConsoleHandler.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/EmbeddedConsoleHandler.java index 28cf90f683d6a7dcf6997e877d6a8cf426278716..c47155062d8634fd1b9d7b965304af8a6ccc7779 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/EmbeddedConsoleHandler.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/EmbeddedConsoleHandler.java @@ -27,7 +27,6 @@ import com.oracle.truffle.r.runtime.RInterfaceCallbacks; import com.oracle.truffle.r.runtime.RStartParams; import com.oracle.truffle.r.runtime.context.ConsoleHandler; import com.oracle.truffle.r.runtime.context.DefaultConsoleHandler; -import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.ffi.REmbedRFFI; import com.oracle.truffle.r.runtime.ffi.RFFIFactory; @@ -39,7 +38,7 @@ import com.oracle.truffle.r.runtime.ffi.RFFIFactory; * have be lazy about that. * */ -public class EmbeddedConsoleHandler implements ConsoleHandler { +public class EmbeddedConsoleHandler extends ConsoleHandler { private final RStartParams startParams; /** @@ -48,7 +47,6 @@ public class EmbeddedConsoleHandler implements ConsoleHandler { private ConsoleHandler delegate; private REmbedRFFI rEmbedRFFI; private String prompt; - private RContext ctx; EmbeddedConsoleHandler(RStartParams startParams) { this.startParams = startParams; @@ -149,14 +147,4 @@ public class EmbeddedConsoleHandler implements ConsoleHandler { public String getInputDescription() { return "<embedded input>"; } - - @Override - public void setContext(RContext ctx) { - this.ctx = ctx; - } - - @Override - public RContext getContext() { - return ctx; - } } diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleCompleter.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleCompleter.java index fb3e9cc90dc79846de9fb68cbbea11265008fcbc..eaeeb329ea451ca404e91fe0c99f69592298e2e8 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleCompleter.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleCompleter.java @@ -67,6 +67,7 @@ public class JLineConsoleCompleter implements Completer { return cursor; } + @SuppressWarnings("try") private int completeImpl(String buffer, int cursor, List<CharSequence> candidates) { if (buffer.isEmpty()) { return cursor; diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleHandler.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleHandler.java index da44616d459b470da8367eec5f9ffeeb97989bc2..6353be6e9a9fc9199ef8dea6a3744c386a8f8908 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleHandler.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/JLineConsoleHandler.java @@ -33,18 +33,16 @@ import com.oracle.truffle.r.runtime.RSource; import com.oracle.truffle.r.runtime.RStartParams; import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.context.ConsoleHandler; -import com.oracle.truffle.r.runtime.context.RContext; import jline.console.ConsoleReader; import jline.console.UserInterruptException; import jline.console.history.FileHistory; import jline.console.history.History; -class JLineConsoleHandler implements ConsoleHandler { +class JLineConsoleHandler extends ConsoleHandler { private final ConsoleReader console; private final boolean isInteractive; private final PrintWriter printWriter; - private RContext ctx; JLineConsoleHandler(RStartParams startParams, InputStream inStream, OutputStream outStream) { try { @@ -142,14 +140,4 @@ class JLineConsoleHandler implements ConsoleHandler { } } } - - @Override - public void setContext(RContext ctx) { - this.ctx = ctx; - } - - @Override - public RContext getContext() { - return ctx; - } } diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/StringConsoleHandler.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/StringConsoleHandler.java index d03bd0b583a40742f07da8c95553e134d8919104..271b69345df92e9297e4d81391d5fece14eff410 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/StringConsoleHandler.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/StringConsoleHandler.java @@ -30,7 +30,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.r.runtime.context.ConsoleHandler; import com.oracle.truffle.r.runtime.context.RContext; -class StringConsoleHandler implements ConsoleHandler { +class StringConsoleHandler extends ConsoleHandler { private final PrintStream output; private final List<String> lines; private final String inputDescription; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ConsoleHandler.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ConsoleHandler.java index 1cf687e107f55f51ea91ba130511b9141167661d..cd21de478bcbbc641621ce8c4e41ec50082b40e5 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ConsoleHandler.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ConsoleHandler.java @@ -31,24 +31,27 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; * implementations for different contexts. Since I/O is involved, all methods are tagged with * {@link TruffleBoundary} as a hint that so should the associated implementation methods. */ -public interface ConsoleHandler { +public abstract class ConsoleHandler { + + private RContext ctx; + /** * Normal output with a new line. */ @TruffleBoundary - void println(String s); + public abstract void println(String s); /** * Normal output without a newline. */ @TruffleBoundary - void print(String s); + public abstract void print(String s); /** * Formatted output. */ @TruffleBoundary - default void printf(String format, Object... args) { + public void printf(String format, Object... args) { print(String.format(format, args)); } @@ -58,20 +61,20 @@ public interface ConsoleHandler { * @param s */ @TruffleBoundary - void printErrorln(String s); + public abstract void printErrorln(String s); /** * Error output without a newline. */ @TruffleBoundary - void printError(String s); + public abstract void printError(String s); /** * Read a line of input, newline is <b>NOT</b> included in result. Returns null if * {@link #isInteractive() == false}. TODO worry about "\r\n"? */ @TruffleBoundary - String readLine(); + public abstract String readLine(); /** * Denote whether the FastR instance is running in 'interactive' mode. This can be set in a @@ -79,31 +82,35 @@ public interface ConsoleHandler { * final once set. */ @TruffleBoundary - boolean isInteractive(); + public abstract boolean isInteractive(); /** * Get the current prompt. */ @TruffleBoundary - String getPrompt(); + public abstract String getPrompt(); /** * Set the R prompt. */ @TruffleBoundary - void setPrompt(String prompt); + public abstract void setPrompt(String prompt); - String getInputDescription(); + public abstract String getInputDescription(); - void setContext(RContext ctx); + public void setContext(RContext ctx) { + this.ctx = ctx; + } - RContext getContext(); + public RContext getContext() { + return ctx; + } - default void setHistoryFrom(@SuppressWarnings("unused") File file) { + public void setHistoryFrom(@SuppressWarnings("unused") File file) { // by default, do nothing } - default void flushHistory() { + public void flushHistory() { // by default, do nothing } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/DefaultConsoleHandler.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/DefaultConsoleHandler.java index 14ed4cfb6a08b97db7d54d8af4f013f693e1f9a1..3bb4b182ccaf24cfbba29e1930d0fa3308614bf5 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/DefaultConsoleHandler.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/DefaultConsoleHandler.java @@ -29,12 +29,11 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; -public class DefaultConsoleHandler implements ConsoleHandler { +public class DefaultConsoleHandler extends ConsoleHandler { private final BufferedReader in; private final PrintStream out; private String prompt; - private RContext ctx; public DefaultConsoleHandler(InputStream in, OutputStream out) { this.in = new BufferedReader(new InputStreamReader(in)); @@ -92,14 +91,4 @@ public class DefaultConsoleHandler implements ConsoleHandler { public String getInputDescription() { return "<PolyglotEngine env input>"; } - - @Override - public void setContext(RContext ctx) { - this.ctx = ctx; - } - - @Override - public RContext getContext() { - return ctx; - } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java index 9dab26670e56af2dd448f1c2f202204df03475e9..015fa4ff405ce362e1a4378cbb4b82877f07e0e0 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java @@ -118,8 +118,7 @@ public class TestJLineConsoleCompleter { } } - private class DummyConsoleHandler implements ConsoleHandler { - private RContext ctx; + private class DummyConsoleHandler extends ConsoleHandler { @Override public void println(String s) { @@ -160,15 +159,5 @@ public class TestJLineConsoleCompleter { public String getInputDescription() { return ""; } - - @Override - public void setContext(RContext ctx) { - this.ctx = ctx; - } - - @Override - public RContext getContext() { - return ctx; - } } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java index 0471a49c421c926f007ae55214e6bb7a4c427d8d..ca61843663b6891e0e6bfea2f7358a2495c30ee8 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java @@ -66,10 +66,9 @@ public final class FastRSession implements RSession { * A (virtual) console handler that collects the output in a {@link StringBuilder} for * comparison. It does not separate error output as the test analysis doesn't need it. */ - public static class TestConsoleHandler implements ConsoleHandler { + public static class TestConsoleHandler extends ConsoleHandler { private final StringBuilder buffer = new StringBuilder(); private final Deque<String> input = new ArrayDeque<>(); - private RContext ctx; public void setInput(String[] lines) { input.clear(); @@ -130,16 +129,6 @@ public final class FastRSession implements RSession { public String getInputDescription() { return "<test input>"; } - - @Override - public void setContext(RContext ctx) { - this.ctx = ctx; - } - - @Override - public RContext getContext() { - return ctx; - } } private static FastRSession singleton;