diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java index 2091044a709..3ee4c56fe57 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java @@ -167,32 +167,32 @@ public final class AnalyzerWithCompilerReport { public static class SyntaxErrorReport { private final boolean hasErrors; - private final boolean onlyErrorAtEof; + private final boolean allErrorsAtEof; - public SyntaxErrorReport(boolean hasErrors, boolean onlyErrorAtEof) { + public SyntaxErrorReport(boolean hasErrors, boolean allErrorsAtEof) { this.hasErrors = hasErrors; - this.onlyErrorAtEof = onlyErrorAtEof; + this.allErrorsAtEof = allErrorsAtEof; } public boolean isHasErrors() { return hasErrors; } - public boolean isOnlyErrorAtEof() { - return onlyErrorAtEof; + public boolean isAllErrorsAtEof() { + return allErrorsAtEof; } } public static SyntaxErrorReport reportSyntaxErrors(@NotNull final PsiElement file, @NotNull final MessageCollector messageCollector) { class ErrorReportingVisitor extends AnalyzingUtils.PsiErrorElementVisitor { boolean hasErrors = false; - boolean onlyErrorAtEof = false; + boolean allErrorsAtEof = true; private void reportDiagnostic(E element, DiagnosticFactory0 factory, String message) { MyDiagnostic diagnostic = new MyDiagnostic(element, factory, message); AnalyzerWithCompilerReport.reportDiagnostic(diagnostic, messageCollector); - if (element.getTextRange().getStartOffset() == file.getTextRange().getEndOffset()) { - onlyErrorAtEof = !hasErrors; + if (element.getTextRange().getStartOffset() != file.getTextRange().getEndOffset()) { + allErrorsAtEof = false; } hasErrors = true; } @@ -207,7 +207,7 @@ public final class AnalyzerWithCompilerReport { file.accept(visitor); - return new SyntaxErrorReport(visitor.hasErrors, visitor.onlyErrorAtEof); + return new SyntaxErrorReport(visitor.hasErrors, visitor.allErrorsAtEof); } @Nullable diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java index c2d1699cb5a..6b929dc1f2c 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java @@ -222,7 +222,7 @@ public class ReplInterpreter { AnalyzerWithCompilerReport.SyntaxErrorReport syntaxErrorReport = AnalyzerWithCompilerReport.reportSyntaxErrors(psiFile, errorCollector); - if (syntaxErrorReport.isOnlyErrorAtEof()) { + if (syntaxErrorReport.isHasErrors() && syntaxErrorReport.isAllErrorsAtEof()) { previousIncompleteLines.add(line); return LineResult.incomplete(); } diff --git a/compiler/testData/repl/multiline3.repl b/compiler/testData/repl/multiline/functionOnSeveralLines.repl similarity index 100% rename from compiler/testData/repl/multiline3.repl rename to compiler/testData/repl/multiline/functionOnSeveralLines.repl diff --git a/compiler/testData/repl/multiline/multilineFunctionInvocation.repl b/compiler/testData/repl/multiline/multilineFunctionInvocation.repl new file mode 100644 index 00000000000..4140207d6ee --- /dev/null +++ b/compiler/testData/repl/multiline/multilineFunctionInvocation.repl @@ -0,0 +1,10 @@ +>>> fun concat(a: String, b: String, c: String, d: String) = "$a$b$c$d" +>>> concat( +... "hel", +... "lo" +... , +... "wo" + +... "r", "l" + +... "d" +... ) +helloworld diff --git a/compiler/testData/repl/multiline/openParenthesisIncomplete.repl b/compiler/testData/repl/multiline/openParenthesisIncomplete.repl new file mode 100644 index 00000000000..c5b053f6bbb --- /dev/null +++ b/compiler/testData/repl/multiline/openParenthesisIncomplete.repl @@ -0,0 +1,4 @@ +>>> fun sum(x: Int, y: Int) = x + y +>>> sum( +... 23,19) +42 diff --git a/compiler/testData/repl/multiline.repl b/compiler/testData/repl/multiline/simpleFunctionBodyOnNextLine.repl similarity index 100% rename from compiler/testData/repl/multiline.repl rename to compiler/testData/repl/multiline/simpleFunctionBodyOnNextLine.repl diff --git a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java index 6d25c9552d9..dbe8f761604 100644 --- a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.repl.AbstractReplInterpreterTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/repl") -@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.Reflection.class}) +@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Multiline.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.Reflection.class}) public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest { public void testAllFilesPresentInRepl() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/repl"), Pattern.compile("^(.+)\\.repl$"), true); @@ -82,16 +82,6 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest { doTest("compiler/testData/repl/imports.repl"); } - @TestMetadata("multiline.repl") - public void testMultiline() throws Exception { - doTest("compiler/testData/repl/multiline.repl"); - } - - @TestMetadata("multiline3.repl") - public void testMultiline3() throws Exception { - doTest("compiler/testData/repl/multiline3.repl"); - } - @TestMetadata("simple.repl") public void testSimple() throws Exception { doTest("compiler/testData/repl/simple.repl"); @@ -160,6 +150,34 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest { } + @TestMetadata("compiler/testData/repl/multiline") + public static class Multiline extends AbstractReplInterpreterTest { + public void testAllFilesPresentInMultiline() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/repl/multiline"), Pattern.compile("^(.+)\\.repl$"), true); + } + + @TestMetadata("functionOnSeveralLines.repl") + public void testFunctionOnSeveralLines() throws Exception { + doTest("compiler/testData/repl/multiline/functionOnSeveralLines.repl"); + } + + @TestMetadata("multilineFunctionInvocation.repl") + public void testMultilineFunctionInvocation() throws Exception { + doTest("compiler/testData/repl/multiline/multilineFunctionInvocation.repl"); + } + + @TestMetadata("openParenthesisIncomplete.repl") + public void testOpenParenthesisIncomplete() throws Exception { + doTest("compiler/testData/repl/multiline/openParenthesisIncomplete.repl"); + } + + @TestMetadata("simpleFunctionBodyOnNextLine.repl") + public void testSimpleFunctionBodyOnNextLine() throws Exception { + doTest("compiler/testData/repl/multiline/simpleFunctionBodyOnNextLine.repl"); + } + + } + @TestMetadata("compiler/testData/repl/objects") public static class Objects extends AbstractReplInterpreterTest { public void testAllFilesPresentInObjects() throws Exception { @@ -195,6 +213,7 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest { TestSuite suite = new TestSuite("ReplInterpreterTestGenerated"); suite.addTestSuite(ReplInterpreterTestGenerated.class); suite.addTestSuite(Classes.class); + suite.addTestSuite(Multiline.class); suite.addTestSuite(Objects.class); suite.addTestSuite(Reflection.class); return suite;