Evaluate expression: check for errors before running extract function for code fragment
This commit is contained in:
@@ -71,6 +71,7 @@ import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaClassImpl
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||||
import org.jetbrains.jet.codegen.StackValue
|
import org.jetbrains.jet.codegen.StackValue
|
||||||
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust
|
||||||
|
|
||||||
private val RECEIVER_NAME = "\$receiver"
|
private val RECEIVER_NAME = "\$receiver"
|
||||||
private val THIS_NAME = "this"
|
private val THIS_NAME = "this"
|
||||||
@@ -139,6 +140,8 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment,
|
|||||||
|
|
||||||
class object {
|
class object {
|
||||||
private fun extractAndCompile(codeFragment: JetCodeFragment, sourcePosition: SourcePosition): CompiledDataDescriptor {
|
private fun extractAndCompile(codeFragment: JetCodeFragment, sourcePosition: SourcePosition): CompiledDataDescriptor {
|
||||||
|
codeFragment.checkForErrors(codeFragment.getAnalysisResults())
|
||||||
|
|
||||||
val extractedFunction = getFunctionForExtractedFragment(codeFragment, sourcePosition.getFile(), sourcePosition.getLine())
|
val extractedFunction = getFunctionForExtractedFragment(codeFragment, sourcePosition.getFile(), sourcePosition.getLine())
|
||||||
if (extractedFunction == null) {
|
if (extractedFunction == null) {
|
||||||
throw IllegalStateException("Code fragment cannot be extracted to function")
|
throw IllegalStateException("Code fragment cannot be extracted to function")
|
||||||
@@ -229,26 +232,14 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment,
|
|||||||
return runReadAction {
|
return runReadAction {
|
||||||
val file = createFileForDebugger(codeFragment, extractedFunction)
|
val file = createFileForDebugger(codeFragment, extractedFunction)
|
||||||
|
|
||||||
checkForSyntacticErrors(file)
|
|
||||||
|
|
||||||
val analyzeExhaust = file.getAnalysisResults()
|
val analyzeExhaust = file.getAnalysisResults()
|
||||||
if (analyzeExhaust.isError()) {
|
file.checkForErrors(analyzeExhaust)
|
||||||
exception(analyzeExhaust.getError())
|
|
||||||
}
|
|
||||||
|
|
||||||
val bindingContext = analyzeExhaust.getBindingContext()
|
|
||||||
bindingContext.getDiagnostics().forEach {
|
|
||||||
diagnostic ->
|
|
||||||
if (diagnostic.getSeverity() == Severity.ERROR) {
|
|
||||||
exception(DefaultErrorMessages.RENDERER.render(diagnostic))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val state = GenerationState(
|
val state = GenerationState(
|
||||||
file.getProject(),
|
file.getProject(),
|
||||||
ClassBuilderFactories.BINARIES,
|
ClassBuilderFactories.BINARIES,
|
||||||
analyzeExhaust.getModuleDescriptor(),
|
analyzeExhaust.getModuleDescriptor(),
|
||||||
bindingContext,
|
analyzeExhaust.getBindingContext(),
|
||||||
listOf(file)
|
listOf(file)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -267,6 +258,29 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment,
|
|||||||
}
|
}
|
||||||
throw EvaluateExceptionUtil.createEvaluateException(e)
|
throw EvaluateExceptionUtil.createEvaluateException(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun JetFile.checkForErrors(analyzeExhaust: AnalyzeExhaust) {
|
||||||
|
runReadAction {
|
||||||
|
try {
|
||||||
|
AnalyzingUtils.checkForSyntacticErrors(this)
|
||||||
|
}
|
||||||
|
catch (e: IllegalArgumentException) {
|
||||||
|
throw EvaluateExceptionUtil.createEvaluateException(e.getMessage())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (analyzeExhaust.isError()) {
|
||||||
|
throw EvaluateExceptionUtil.createEvaluateException(analyzeExhaust.getError())
|
||||||
|
}
|
||||||
|
|
||||||
|
val bindingContext = analyzeExhaust.getBindingContext()
|
||||||
|
bindingContext.getDiagnostics().forEach {
|
||||||
|
diagnostic ->
|
||||||
|
if (diagnostic.getSeverity() == Severity.ERROR) {
|
||||||
|
throw EvaluateExceptionUtil.createEvaluateException(DefaultErrorMessages.RENDERER.render(diagnostic))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,15 +315,6 @@ private fun createFileForDebugger(codeFragment: JetCodeFragment,
|
|||||||
return jetFile
|
return jetFile
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkForSyntacticErrors(file: JetFile) {
|
|
||||||
try {
|
|
||||||
AnalyzingUtils.checkForSyntacticErrors(file)
|
|
||||||
}
|
|
||||||
catch (e: IllegalArgumentException) {
|
|
||||||
throw EvaluateExceptionUtil.createEvaluateException(e.getMessage())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun SuspendContext.getInvokePolicy(): Int {
|
private fun SuspendContext.getInvokePolicy(): Int {
|
||||||
return if (getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD) ObjectReference.INVOKE_SINGLE_THREADED else 0
|
return if (getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD) ObjectReference.INVOKE_SINGLE_THREADED else 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ fun getFunctionForExtractedFragment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun generateFunction(): JetNamedFunction? {
|
fun generateFunction(): JetNamedFunction? {
|
||||||
checkForSyntacticErrors(codeFragment)
|
|
||||||
|
|
||||||
val originalFile = breakpointFile as JetFile
|
val originalFile = breakpointFile as JetFile
|
||||||
|
|
||||||
val tmpFile = originalFile.createTempCopy { it }
|
val tmpFile = originalFile.createTempCopy { it }
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ open class Base {
|
|||||||
// EXPRESSION: a
|
// EXPRESSION: a
|
||||||
// RESULT: Unresolved reference: a
|
// RESULT: Unresolved reference: a
|
||||||
|
|
||||||
|
// EXPRESSION: a + 1
|
||||||
|
// RESULT: Unresolved reference: a
|
||||||
|
|
||||||
// EXPRESSION: prop.
|
// EXPRESSION: prop.
|
||||||
// RESULT: Expecting an element; looking at ERROR_ELEMENT '(1,6) in /fragment.kt
|
// RESULT: Expecting an element; looking at ERROR_ELEMENT '(1,6) in /fragment.kt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user