Repl, minor: more meaningful method names
This commit is contained in:
@@ -121,9 +121,9 @@ public class ReplFromTerminal {
|
|||||||
|
|
||||||
private void doRun() {
|
private void doRun() {
|
||||||
try {
|
try {
|
||||||
replWriter.printlnInit("Welcome to Kotlin version " + KotlinVersion.VERSION +
|
replWriter.printlnWelcomeMessage("Welcome to Kotlin version " + KotlinVersion.VERSION +
|
||||||
" (JRE " + System.getProperty("java.runtime.version") + ")");
|
" (JRE " + System.getProperty("java.runtime.version") + ")");
|
||||||
replWriter.printlnInit("Type :help for help, :quit for quit");
|
replWriter.printlnWelcomeMessage("Type :help for help, :quit for quit");
|
||||||
WhatNextAfterOneLine next = WhatNextAfterOneLine.READ_LINE;
|
WhatNextAfterOneLine next = WhatNextAfterOneLine.READ_LINE;
|
||||||
while (true) {
|
while (true) {
|
||||||
next = one(next);
|
next = one(next);
|
||||||
@@ -185,17 +185,17 @@ public class ReplFromTerminal {
|
|||||||
ReplInterpreter.LineResult lineResult = getReplInterpreter().eval(line);
|
ReplInterpreter.LineResult lineResult = getReplInterpreter().eval(line);
|
||||||
if (lineResult.getType() == ReplInterpreter.LineResultType.SUCCESS) {
|
if (lineResult.getType() == ReplInterpreter.LineResultType.SUCCESS) {
|
||||||
if (!lineResult.isUnit()) {
|
if (!lineResult.isUnit()) {
|
||||||
replWriter.printlnResult(lineResult.getValue());
|
replWriter.outputCommandResult(lineResult.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (lineResult.getType() == ReplInterpreter.LineResultType.INCOMPLETE) {
|
else if (lineResult.getType() == ReplInterpreter.LineResultType.INCOMPLETE) {
|
||||||
replWriter.printlnIncomplete();
|
replWriter.notifyIncomplete();
|
||||||
}
|
}
|
||||||
else if (lineResult.getType() == ReplInterpreter.LineResultType.COMPILE_ERROR) {
|
else if (lineResult.getType() == ReplInterpreter.LineResultType.COMPILE_ERROR) {
|
||||||
replWriter.printlnCompileError(lineResult.getErrorText());
|
replWriter.outputCompileError(lineResult.getErrorText());
|
||||||
}
|
}
|
||||||
else if (lineResult.getType() == ReplInterpreter.LineResultType.RUNTIME_ERROR) {
|
else if (lineResult.getType() == ReplInterpreter.LineResultType.RUNTIME_ERROR) {
|
||||||
replWriter.printlnRuntimeError(lineResult.getErrorText());
|
replWriter.outputRuntimeError(lineResult.getErrorText());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("unknown line result type: " + lineResult);
|
throw new IllegalStateException("unknown line result type: " + lineResult);
|
||||||
@@ -206,11 +206,11 @@ public class ReplFromTerminal {
|
|||||||
private boolean oneCommand(@NotNull String command) throws Exception {
|
private boolean oneCommand(@NotNull String command) throws Exception {
|
||||||
List<String> split = splitCommand(command);
|
List<String> split = splitCommand(command);
|
||||||
if (split.size() >= 1 && command.equals("help")) {
|
if (split.size() >= 1 && command.equals("help")) {
|
||||||
replWriter.printlnHelp("Available commands:\n" +
|
replWriter.printlnHelpMessage("Available commands:\n" +
|
||||||
":help show this help\n" +
|
":help show this help\n" +
|
||||||
":quit exit the interpreter\n" +
|
":quit exit the interpreter\n" +
|
||||||
":dump bytecode dump classes to terminal\n" +
|
":dump bytecode dump classes to terminal\n" +
|
||||||
":load <file> load script from specified file"
|
":load <file> load script from specified file"
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -228,8 +228,8 @@ public class ReplFromTerminal {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
replWriter.printlnHelp("Unknown command\n" +
|
replWriter.printlnHelpMessage("Unknown command\n" +
|
||||||
"Type :help for help"
|
"Type :help for help"
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class ReplSystemInWrapper(
|
|||||||
if (isLastByteProcessed) {
|
if (isLastByteProcessed) {
|
||||||
if (isReplScriptExecuting) {
|
if (isReplScriptExecuting) {
|
||||||
isReadLineStartSent = false
|
isReadLineStartSent = false
|
||||||
replWriter.printlnReadLineEnd()
|
replWriter.notifyReadLineEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
isLastByteProcessed = false
|
isLastByteProcessed = false
|
||||||
@@ -48,7 +48,7 @@ public class ReplSystemInWrapper(
|
|||||||
|
|
||||||
while (isXmlIncomplete) {
|
while (isXmlIncomplete) {
|
||||||
if (!isReadLineStartSent && isReplScriptExecuting) {
|
if (!isReadLineStartSent && isReplScriptExecuting) {
|
||||||
replWriter.printlnReadLineStart()
|
replWriter.notifyReadLineStart()
|
||||||
isReadLineStartSent = true
|
isReadLineStartSent = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ public class ReplSystemOutWrapper(private val ideMode: Boolean, standardOut: Pri
|
|||||||
return "$XML_PREAMBLE<output type=\"$escapeType\">${StringUtil.escapeXml(singleLine)}</output>"
|
return "$XML_PREAMBLE<output type=\"$escapeType\">${StringUtil.escapeXml(singleLine)}</output>"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun printlnInit(x: String) = printlnWithEscaping(x, EscapeType.INITIAL_PROMPT)
|
fun printlnWelcomeMessage(x: String) = printlnWithEscaping(x, EscapeType.INITIAL_PROMPT)
|
||||||
fun printlnHelp(x: String) = printlnWithEscaping(x, EscapeType.HELP_PROMPT)
|
fun printlnHelpMessage(x: String) = printlnWithEscaping(x, EscapeType.HELP_PROMPT)
|
||||||
fun printlnResult(x: Any?) = printlnWithEscaping(x.toString(), EscapeType.REPL_RESULT)
|
fun outputCommandResult(x: Any?) = printlnWithEscaping(x.toString(), EscapeType.REPL_RESULT)
|
||||||
fun printlnReadLineStart() = printlnWithEscaping("", EscapeType.READLINE_START)
|
fun notifyReadLineStart() = printlnWithEscaping("", EscapeType.READLINE_START)
|
||||||
fun printlnReadLineEnd() = printlnWithEscaping("", EscapeType.READLINE_END)
|
fun notifyReadLineEnd() = printlnWithEscaping("", EscapeType.READLINE_END)
|
||||||
fun printlnIncomplete() = printlnWithEscaping("", EscapeType.REPL_INCOMPLETE)
|
fun notifyIncomplete() = printlnWithEscaping("", EscapeType.REPL_INCOMPLETE)
|
||||||
fun printlnCompileError(x: String) = printlnWithEscaping(x, EscapeType.COMPILE_ERROR)
|
fun outputCompileError(x: String) = printlnWithEscaping(x, EscapeType.COMPILE_ERROR)
|
||||||
fun printlnRuntimeError(x: String) = printlnWithEscaping(x, EscapeType.RUNTIME_ERROR)
|
fun outputRuntimeError(x: String) = printlnWithEscaping(x, EscapeType.RUNTIME_ERROR)
|
||||||
fun sendInternalErrorReport(x: String) = printlnWithEscaping(x, EscapeType.INTERNAL_ERROR)
|
fun sendInternalErrorReport(x: String) = printlnWithEscaping(x, EscapeType.INTERNAL_ERROR)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user