Evaluate expression: check for syntactic errors
This commit is contained in:
@@ -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<JetNamedFunction> {
|
||||
override fun compute(): JetNamedFunction? {
|
||||
checkForSyntacticErrors(codeFragment)
|
||||
|
||||
val originalFile = breakpointFile as JetFile
|
||||
|
||||
val lineStart = CodeInsightUtils.getStartLineOffset(originalFile, breakpointLine)
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,9 @@
|
||||
package syntacticError
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
//Breakpoint!
|
||||
args.size
|
||||
}
|
||||
|
||||
// EXPRESSION: args.
|
||||
// RESULT: Expecting an element; looking at ERROR_ELEMENT '(1,6) in /fragment.kt
|
||||
+4
@@ -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)
|
||||
}
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user