REPL, Refactoring: A number of trivial renames/moves
This commit is contained in:
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.ReplTerminalDiagnosticMessageHolder
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.ConsoleDiagnosticMessageHolder
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
@@ -43,8 +43,8 @@ const val KOTLIN_REPL_JVM_TARGET_PROPERTY = "kotlin.repl.jvm.target"
|
||||
|
||||
open class GenericReplChecker(
|
||||
disposable: Disposable,
|
||||
val scriptDefinition: KotlinScriptDefinition,
|
||||
val compilerConfiguration: CompilerConfiguration,
|
||||
private val scriptDefinition: KotlinScriptDefinition,
|
||||
private val compilerConfiguration: CompilerConfiguration,
|
||||
messageCollector: MessageCollector
|
||||
) : ReplCheckAction {
|
||||
|
||||
@@ -65,7 +65,7 @@ open class GenericReplChecker(
|
||||
|
||||
private val psiFileFactory: PsiFileFactoryImpl = PsiFileFactory.getInstance(environment.project) as PsiFileFactoryImpl
|
||||
|
||||
internal fun createDiagnosticHolder() = ReplTerminalDiagnosticMessageHolder()
|
||||
private fun createDiagnosticHolder() = ConsoleDiagnosticMessageHolder()
|
||||
|
||||
override fun check(state: IReplStageState<*>, codeLine: ReplCodeLine): ReplCheckResult {
|
||||
state.lock.write {
|
||||
@@ -88,7 +88,7 @@ open class GenericReplChecker(
|
||||
|
||||
return when {
|
||||
syntaxErrorReport.isHasErrors && syntaxErrorReport.isAllErrorsAtEof -> ReplCheckResult.Incomplete()
|
||||
syntaxErrorReport.isHasErrors -> ReplCheckResult.Error(errorHolder.renderedDiagnostics)
|
||||
syntaxErrorReport.isHasErrors -> ReplCheckResult.Error(errorHolder.renderMessage())
|
||||
else -> ReplCheckResult.Ok()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ import kotlin.concurrent.write
|
||||
// WARNING: not thread safe, assuming external synchronization
|
||||
|
||||
open class GenericReplCompiler(disposable: Disposable,
|
||||
protected val scriptDefinition: KotlinScriptDefinition,
|
||||
protected val compilerConfiguration: CompilerConfiguration,
|
||||
scriptDefinition: KotlinScriptDefinition,
|
||||
private val compilerConfiguration: CompilerConfiguration,
|
||||
messageCollector: MessageCollector
|
||||
) : ReplCompiler {
|
||||
|
||||
@@ -82,7 +82,7 @@ open class GenericReplCompiler(disposable: Disposable,
|
||||
val analysisResult = compilerState.analyzerEngine.analyzeReplLine(psiFile, codeLine)
|
||||
AnalyzerWithCompilerReport.reportDiagnostics(analysisResult.diagnostics, errorHolder)
|
||||
val scriptDescriptor = when (analysisResult) {
|
||||
is ReplCodeAnalyzer.ReplLineAnalysisResult.WithErrors -> return ReplCompileResult.Error(errorHolder.renderedDiagnostics)
|
||||
is ReplCodeAnalyzer.ReplLineAnalysisResult.WithErrors -> return ReplCompileResult.Error(errorHolder.renderMessage())
|
||||
is ReplCodeAnalyzer.ReplLineAnalysisResult.Successful -> analysisResult.scriptDescriptor
|
||||
else -> error("Unexpected result ${analysisResult::class.java}")
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.ReplWriter
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.writer.ReplWriter
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.GroupingMessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.configuration.ConsoleReplConfiguration
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.configuration.ReplConfiguration
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.configuration.IdeReplConfiguration
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.unescapeLineBreaks
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
@@ -167,7 +170,7 @@ class ReplFromTerminal(
|
||||
|
||||
fun run(disposable: Disposable, configuration: CompilerConfiguration) {
|
||||
val replIdeMode = System.getProperty("kotlin.repl.ideMode") == "true"
|
||||
val replConfiguration = if (replIdeMode) ReplForIdeConfiguration() else ConsoleReplConfiguration()
|
||||
val replConfiguration = if (replIdeMode) IdeReplConfiguration() else ConsoleReplConfiguration()
|
||||
return try {
|
||||
ReplFromTerminal(disposable, configuration, replConfiguration).doRun()
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JvmModulePathRoot
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.configuration.ReplConfiguration
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinition
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.configuration
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.ReplExceptionReporter
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.ConsoleDiagnosticMessageHolder
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.reader.ConsoleReplCommandReader
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.writer.ConsoleReplWriter
|
||||
|
||||
class ConsoleReplConfiguration : ReplConfiguration {
|
||||
override val writer = ConsoleReplWriter()
|
||||
|
||||
override val exceptionReporter
|
||||
get() = ReplExceptionReporter
|
||||
|
||||
override val commandReader = ConsoleReplCommandReader()
|
||||
|
||||
override val allowIncompleteLines: Boolean
|
||||
get() = true
|
||||
|
||||
override val executionInterceptor
|
||||
get() = SnippetExecutionInterceptor
|
||||
|
||||
override fun createDiagnosticHolder() = ConsoleDiagnosticMessageHolder()
|
||||
}
|
||||
+11
-34
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,24 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.configuration
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.*
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.reader.ConsoleReplCommandReader
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.IdeReplExceptionReporter
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.ReplExceptionReporter
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.IdeDiagnosticMessageHolder
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.reader.IdeReplCommandReader
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.reader.ReplCommandReader
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.reader.ReplSystemInWrapper
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.writer.IdeSystemOutWrapperReplWriter
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.writer.ReplWriter
|
||||
|
||||
interface ReplConfiguration {
|
||||
val writer: ReplWriter
|
||||
val exceptionReporter: ReplExceptionReporter
|
||||
val commandReader: ReplCommandReader
|
||||
val allowIncompleteLines: Boolean
|
||||
|
||||
val executionInterceptor: SnippetExecutionInterceptor
|
||||
fun createDiagnosticHolder(): DiagnosticMessageHolder
|
||||
}
|
||||
|
||||
class ReplForIdeConfiguration : ReplConfiguration {
|
||||
class IdeReplConfiguration : ReplConfiguration {
|
||||
override val allowIncompleteLines: Boolean
|
||||
get() = false
|
||||
|
||||
@@ -46,7 +40,7 @@ class ReplForIdeConfiguration : ReplConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
override fun createDiagnosticHolder() = ReplIdeDiagnosticMessageHolder()
|
||||
override fun createDiagnosticHolder() = IdeDiagnosticMessageHolder()
|
||||
|
||||
override val writer: ReplWriter
|
||||
override val exceptionReporter: ReplExceptionReporter
|
||||
@@ -58,7 +52,7 @@ class ReplForIdeConfiguration : ReplConfiguration {
|
||||
// wrapper for `out` is required to escape every input in [ideMode];
|
||||
// if [ideMode == false] then just redirects all input to [System.out]
|
||||
// if user calls [System.setOut(...)] then undefined behaviour
|
||||
val soutWrapper = ReplSystemOutWrapperForIde(System.out)
|
||||
val soutWrapper = IdeSystemOutWrapperReplWriter(System.out)
|
||||
System.setOut(soutWrapper)
|
||||
|
||||
// wrapper for `in` is required to give user possibility of calling
|
||||
@@ -70,21 +64,4 @@ class ReplForIdeConfiguration : ReplConfiguration {
|
||||
exceptionReporter = IdeReplExceptionReporter(writer)
|
||||
commandReader = IdeReplCommandReader()
|
||||
}
|
||||
}
|
||||
|
||||
class ConsoleReplConfiguration : ReplConfiguration {
|
||||
override val writer = ReplConsoleWriter()
|
||||
|
||||
override val exceptionReporter
|
||||
get() = ReplExceptionReporter.DoNothing
|
||||
|
||||
override val commandReader = ConsoleReplCommandReader()
|
||||
|
||||
override val allowIncompleteLines: Boolean
|
||||
get() = true
|
||||
|
||||
override val executionInterceptor
|
||||
get() = SnippetExecutionInterceptor.Plain
|
||||
|
||||
override fun createDiagnosticHolder() = ReplTerminalDiagnosticMessageHolder()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.configuration
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.ReplExceptionReporter
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.*
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.reader.ReplCommandReader
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.writer.ReplWriter
|
||||
|
||||
interface ReplConfiguration {
|
||||
val writer: ReplWriter
|
||||
val exceptionReporter: ReplExceptionReporter
|
||||
val commandReader: ReplCommandReader
|
||||
val allowIncompleteLines: Boolean
|
||||
|
||||
val executionInterceptor: SnippetExecutionInterceptor
|
||||
fun createDiagnosticHolder(): DiagnosticMessageHolder
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.configuration
|
||||
|
||||
interface SnippetExecutionInterceptor {
|
||||
fun <T> execute(block: () -> T): T
|
||||
+6
-10
@@ -22,20 +22,16 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.PrintStream
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class ReplTerminalDiagnosticMessageHolder : MessageCollectorBasedReporter, DiagnosticMessageHolder {
|
||||
class ConsoleDiagnosticMessageHolder : MessageCollectorBasedReporter, DiagnosticMessageHolder {
|
||||
private val outputStream = ByteArrayOutputStream()
|
||||
|
||||
override val messageCollector: GroupingMessageCollector = GroupingMessageCollector(
|
||||
PrintingMessageCollector(PrintStream(outputStream), MessageRenderer.WITHOUT_PATHS, false),
|
||||
false
|
||||
)
|
||||
false)
|
||||
|
||||
override val renderedDiagnostics: String
|
||||
get() {
|
||||
messageCollector.flush()
|
||||
val bytes = outputStream.toByteArray()
|
||||
return Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString()
|
||||
}
|
||||
override fun renderMessage(): String {
|
||||
messageCollector.flush()
|
||||
return outputStream.toString("UTF-8")
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -19,5 +19,5 @@ package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
import org.jetbrains.kotlin.cli.common.messages.DiagnosticMessageReporter
|
||||
|
||||
interface DiagnosticMessageHolder : DiagnosticMessageReporter {
|
||||
val renderedDiagnostics: String
|
||||
fun renderMessage(): String
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.w3c.dom.ls.DOMImplementationLS
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
class IdeDiagnosticMessageHolder : DiagnosticMessageHolder {
|
||||
private val diagnostics = arrayListOf<Pair<Diagnostic, String>>()
|
||||
|
||||
override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) {
|
||||
diagnostics.add(Pair(diagnostic, render))
|
||||
}
|
||||
|
||||
override fun renderMessage(): String {
|
||||
val docFactory = DocumentBuilderFactory.newInstance()
|
||||
val docBuilder = docFactory.newDocumentBuilder()
|
||||
val errorReport = docBuilder.newDocument()
|
||||
|
||||
val rootElement = errorReport.createElement("report")
|
||||
errorReport.appendChild(rootElement)
|
||||
|
||||
for ((diagnostic, message) in diagnostics) {
|
||||
val errorRange = DiagnosticUtils.firstRange(diagnostic.textRanges)
|
||||
|
||||
val reportEntry = errorReport.createElement("reportEntry")
|
||||
reportEntry.setAttribute("severity", diagnostic.severity.toString())
|
||||
reportEntry.setAttribute("rangeStart", errorRange.startOffset.toString())
|
||||
reportEntry.setAttribute("rangeEnd", errorRange.endOffset.toString())
|
||||
reportEntry.appendChild(errorReport.createTextNode(StringUtil.escapeXml(message)))
|
||||
|
||||
rootElement.appendChild(reportEntry)
|
||||
}
|
||||
|
||||
val domImplementation = errorReport.implementation as DOMImplementationLS
|
||||
val lsSerializer = domImplementation.createLSSerializer()
|
||||
return lsSerializer.writeToString(errorReport)
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.w3c.dom.ls.DOMImplementationLS
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
class ReplIdeDiagnosticMessageHolder : DiagnosticMessageHolder {
|
||||
private val diagnostics = arrayListOf<Pair<Diagnostic, String>>()
|
||||
|
||||
override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) {
|
||||
diagnostics.add(Pair(diagnostic, render))
|
||||
}
|
||||
|
||||
override val renderedDiagnostics: String
|
||||
get() {
|
||||
val docFactory = DocumentBuilderFactory.newInstance()
|
||||
val docBuilder = docFactory.newDocumentBuilder()
|
||||
val errorReport = docBuilder.newDocument()
|
||||
|
||||
val rootElement = errorReport.createElement("report")
|
||||
errorReport.appendChild(rootElement)
|
||||
|
||||
for ((diagnostic, message) in diagnostics) {
|
||||
val errorRange = DiagnosticUtils.firstRange(diagnostic.textRanges)
|
||||
|
||||
val reportEntry = errorReport.createElement("reportEntry")
|
||||
reportEntry.setAttribute("severity", diagnostic.severity.toString())
|
||||
reportEntry.setAttribute("rangeStart", errorRange.startOffset.toString())
|
||||
reportEntry.setAttribute("rangeEnd", errorRange.endOffset.toString())
|
||||
reportEntry.appendChild(errorReport.createTextNode(StringUtil.escapeXml(message)))
|
||||
|
||||
rootElement.appendChild(reportEntry)
|
||||
}
|
||||
|
||||
val domImplementation = errorReport.implementation as DOMImplementationLS
|
||||
val lsSerializer = domImplementation.createLSSerializer()
|
||||
return lsSerializer.writeToString(errorReport)
|
||||
}
|
||||
}
|
||||
@@ -17,24 +17,9 @@
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.w3c.dom.Element
|
||||
import org.xml.sax.InputSource
|
||||
import java.io.ByteArrayInputStream
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
// using '#' to avoid collisions with xml escaping
|
||||
internal val SOURCE_CHARS: Array<String> = arrayOf("\n", "#")
|
||||
internal val XML_REPLACEMENTS: Array<String> = arrayOf("#n", "#diez")
|
||||
|
||||
fun parseXml(inputMessage: String): String {
|
||||
fun strToSource(s: String) = InputSource(ByteArrayInputStream(s.toByteArray()))
|
||||
|
||||
val docFactory = DocumentBuilderFactory.newInstance()
|
||||
val docBuilder = docFactory.newDocumentBuilder()
|
||||
val input = docBuilder.parse(strToSource(inputMessage))
|
||||
|
||||
val root = input.firstChild as Element
|
||||
return root.textContent
|
||||
}
|
||||
|
||||
fun unescapeLineBreaks(s: String) = StringUtil.replace(s, XML_REPLACEMENTS, SOURCE_CHARS)
|
||||
+20
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,10 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.reader
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.unescapeLineBreaks
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.writer.END_LINE
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.writer.ReplWriter
|
||||
import org.w3c.dom.Element
|
||||
import org.xml.sax.InputSource
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
class ReplSystemInWrapper(
|
||||
private val stdin: InputStream,
|
||||
@@ -87,4 +94,15 @@ class ReplSystemInWrapper(
|
||||
isLastByteProcessed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseXml(inputMessage: String): String {
|
||||
fun strToSource(s: String) = InputSource(ByteArrayInputStream(s.toByteArray()))
|
||||
|
||||
val docFactory = DocumentBuilderFactory.newInstance()
|
||||
val docBuilder = docFactory.newDocumentBuilder()
|
||||
val input = docBuilder.parse(strToSource(inputMessage))
|
||||
|
||||
val root = input.firstChild as Element
|
||||
return root.textContent
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.writer
|
||||
|
||||
class ReplConsoleWriter : ReplWriter {
|
||||
class ConsoleReplWriter : ReplWriter {
|
||||
override fun printlnWelcomeMessage(x: String) = println(x)
|
||||
override fun printlnHelpMessage(x: String) = println(x)
|
||||
override fun outputCompileError(x: String) = println(x)
|
||||
+7
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.writer
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.LineSeparator
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.SOURCE_CHARS
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.XML_REPLACEMENTS
|
||||
import org.jetbrains.kotlin.utils.repl.ReplEscapeType
|
||||
import java.io.PrintStream
|
||||
import org.jetbrains.kotlin.utils.repl.ReplEscapeType.*
|
||||
@@ -25,7 +27,7 @@ import org.jetbrains.kotlin.utils.repl.ReplEscapeType.*
|
||||
internal val END_LINE: String = LineSeparator.getSystemLineSeparator().separatorString
|
||||
internal val XML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
|
||||
class ReplSystemOutWrapperForIde(standardOut: PrintStream) : PrintStream(standardOut, true), ReplWriter {
|
||||
class IdeSystemOutWrapperReplWriter(standardOut: PrintStream) : PrintStream(standardOut, true), ReplWriter {
|
||||
override fun print(x: Boolean) = printWithEscaping(x.toString())
|
||||
override fun print(x: Char) = printWithEscaping(x.toString())
|
||||
override fun print(x: Int) = printWithEscaping(x.toString())
|
||||
@@ -40,12 +42,12 @@ class ReplSystemOutWrapperForIde(standardOut: PrintStream) : PrintStream(standar
|
||||
}
|
||||
|
||||
private fun printWithEscaping(text: String, escapeType: ReplEscapeType = USER_OUTPUT) {
|
||||
super.print("${xmlEscape(text, escapeType)}$END_LINE")
|
||||
super.print("${xmlEscape(text, escapeType)}${END_LINE}")
|
||||
}
|
||||
|
||||
private fun xmlEscape(s: String, escapeType: ReplEscapeType): String {
|
||||
val singleLine = StringUtil.replace(s, SOURCE_CHARS, XML_REPLACEMENTS)
|
||||
return "$XML_PREAMBLE<output type=\"$escapeType\">${StringUtil.escapeXml(singleLine)}</output>"
|
||||
return "${XML_PREAMBLE}<output type=\"$escapeType\">${StringUtil.escapeXml(singleLine)}</output>"
|
||||
}
|
||||
|
||||
override fun printlnWelcomeMessage(x: String) = printlnWithEscaping(x, INITIAL_PROMPT)
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.writer
|
||||
|
||||
interface ReplWriter {
|
||||
fun printlnWelcomeMessage(x: String)
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.repl
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.ConsoleReplConfiguration
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.configuration.ConsoleReplConfiguration
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.ReplInterpreter
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
|
||||
Reference in New Issue
Block a user