diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java index d3d7cc2b1e39..e62d24cd21e4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java @@ -1,8 +1,10 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.editorActions; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.highlighter.HighlighterIterator; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.source.tree.ElementType; import com.intellij.psi.tree.IElementType; @@ -106,6 +108,17 @@ public class JavaQuoteHandler extends SimpleTokenSetQuoteHandler implements Java return null; } + @Override + public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) { + if (iterator.getTokenType() == JavaTokenType.TEXT_BLOCK_LITERAL) { + Document document = iterator.getDocument(); + if (document != null && StringUtil.equals(document.getCharsSequence().subSequence(iterator.getStart(), offset + 1), "\"\"\"")) { + return true; + } + } + return super.hasNonClosedLiteral(editor, iterator, offset); + } + @Override public void insertClosingQuote(@NotNull Editor editor, int offset, @NotNull CharSequence closingQuote) { if (closingQuote.charAt(0) == '`') { diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/editorActions/JavaQuoteTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/editorActions/JavaQuoteTest.groovy index f8a653e63b43..ffd461cce5f1 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/editorActions/JavaQuoteTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/editorActions/JavaQuoteTest.groovy @@ -30,6 +30,7 @@ class JavaQuoteTest extends LightJavaCodeInsightFixtureTestCase { doTest ' """.""" ', ' """.""" ' doTest ' """.""" ', ' """.""" ' } + void testPrecedingTextBlock() { doTest 'f("" + """\n .""")', 'f("""\n""" + """\n .""")' } private void doTest(String before, String after, char c = '"') { myFixture.configureByText("a.java", "class C {{\n ${before}\n}}")