From 8c0f99001b9aa5ffdfc56ab477e1618bface83e1 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Wed, 14 May 2014 11:46:12 +0400 Subject: [PATCH] Evaluate expression: check for syntactic errors --- .../debugger/evaluate/KotlinEvaluationBuilder.kt | 13 +++++++++++++ .../debugger/tinyApp/outs/syntacticError.out | 7 +++++++ .../debugger/tinyApp/src/evaluate/syntacticError.kt | 9 +++++++++ .../AbstractKotlinEvaluateExpressionTest.kt | 4 ++++ .../KotlinEvaluateExpressionTestGenerated.java | 5 +++++ 5 files changed, 38 insertions(+) create mode 100644 idea/testData/debugger/tinyApp/outs/syntacticError.out create mode 100644 idea/testData/debugger/tinyApp/src/evaluate/syntacticError.kt diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt index 5f00f3372d9..0933b064f7c 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -172,6 +172,8 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment, override fun compute(): ClassFileFactory? { val file = createFileForDebugger(codeFragment, extractedFunction) + checkForSyntacticErrors(file) + val analyzeExhaust = file.getAnalysisResults() val bindingContext = analyzeExhaust.getBindingContext() try { @@ -267,6 +269,15 @@ fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment, contex return newDebugExpression as JetExpression } +fun checkForSyntacticErrors(file: JetFile) { + try { + AnalyzingUtils.checkForSyntacticErrors(file) + } + catch (e: IllegalArgumentException) { + throw EvaluateExceptionUtil.createEvaluateException(e.getMessage()) + } +} + private fun getFunctionForExtractedFragment( codeFragment: JetCodeFragment, breakpointFile: PsiFile, @@ -274,6 +285,8 @@ private fun getFunctionForExtractedFragment( ): JetNamedFunction? { return ApplicationManager.getApplication()?.runReadAction(object: Computable { override fun compute(): JetNamedFunction? { + checkForSyntacticErrors(codeFragment) + val originalFile = breakpointFile as JetFile val lineStart = CodeInsightUtils.getStartLineOffset(originalFile, breakpointLine) diff --git a/idea/testData/debugger/tinyApp/outs/syntacticError.out b/idea/testData/debugger/tinyApp/outs/syntacticError.out new file mode 100644 index 00000000000..dba0f7b5319 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/syntacticError.out @@ -0,0 +1,7 @@ +LineBreakpoint created at syntacticError.kt:5 +!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!RT_JAR! syntacticError.SyntacticErrorPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +syntacticError.kt:4 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/evaluate/syntacticError.kt b/idea/testData/debugger/tinyApp/src/evaluate/syntacticError.kt new file mode 100644 index 00000000000..bd5fc6267e0 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/syntacticError.kt @@ -0,0 +1,9 @@ +package syntacticError + +fun main(args: Array) { + //Breakpoint! + args.size +} + +// EXPRESSION: args. +// RESULT: Expecting an element; looking at ERROR_ELEMENT '(1,6) in /fragment.kt \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt index 6ab59e7fd74..43b459d6087 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt @@ -34,6 +34,7 @@ import org.jetbrains.eval4j.ObjectValue import com.sun.jdi.ObjectReference import org.jetbrains.jet.lang.psi.JetCodeFragment import java.util.Collections +import com.intellij.debugger.engine.evaluation.EvaluateException public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestCase() { fun doTest(path: String) { @@ -118,6 +119,9 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC val actualResult = value.asValue().asString() Assert.assertTrue("Evaluate expression returns wrong result for $text:\nexpected = $expectedResult\nactual = $actualResult\n", expectedResult == actualResult) } + catch (e: EvaluateException) { + Assert.assertTrue("Evaluate expression throws wrong exception for $text:\nexpected = $expectedResult\nactual = ${e.getMessage()}\n", expectedResult == e.getMessage()) + } finally { resume(this) } diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java index 85c2bf3e835..524c3034da2 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java @@ -116,6 +116,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat doTest("idea/testData/debugger/tinyApp/src/evaluate/stdlib.kt"); } + @TestMetadata("syntacticError.kt") + public void testSyntacticError() throws Exception { + doTest("idea/testData/debugger/tinyApp/src/evaluate/syntacticError.kt"); + } + @TestMetadata("vars.kt") public void testVars() throws Exception { doTest("idea/testData/debugger/tinyApp/src/evaluate/vars.kt");