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 93e2a3e76b7c..591b291eb037 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java @@ -102,17 +102,18 @@ public class JavaQuoteHandler extends SimpleTokenSetQuoteHandler implements Java @Override public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) { if (iterator.getTokenType() == JavaTokenType.TEXT_BLOCK_LITERAL) { - Document document = iterator.getDocument(); - if (document != null) { - String text = document.getText(); - boolean hasOpenQuotes = StringUtil.equals(text.substring(iterator.getStart(), offset + 1), "\"\"\""); - if (hasOpenQuotes) { - boolean hasCloseQuotes = StringUtil.contains(text.substring(offset + 1, iterator.getEnd()), "\"\"\""); - if (!hasCloseQuotes) return true; - // check if parser interpreted next text block start quotes as end quotes for the current one - int nTextBlockQuotes = StringUtil.getOccurrenceCount(text.substring(iterator.getEnd()), "\"\"\""); - return nTextBlockQuotes % 2 != 0; - } + Document document = editor.getDocument(); + Project project = editor.getProject(); + PsiFile file = project == null ? null : PsiDocumentManager.getInstance(project).getPsiFile(document); + if (file == null || !HighlightUtil.Feature.TEXT_BLOCKS.isAvailable(file)) return false; + String text = document.getText(); + boolean hasOpenQuotes = StringUtil.equals(text.substring(iterator.getStart(), offset + 1), "\"\"\""); + if (hasOpenQuotes) { + boolean hasCloseQuotes = StringUtil.contains(text.substring(offset + 1, iterator.getEnd()), "\"\"\""); + if (!hasCloseQuotes) return true; + // check if parser interpreted next text block start quotes as end quotes for the current one + int nTextBlockQuotes = StringUtil.getOccurrenceCount(text.substring(iterator.getEnd()), "\"\"\""); + return nTextBlockQuotes % 2 != 0; } } return super.hasNonClosedLiteral(editor, iterator, offset); @@ -120,7 +121,6 @@ public class JavaQuoteHandler extends SimpleTokenSetQuoteHandler implements Java @Override public void insertClosingQuote(@NotNull Editor editor, int offset, @NotNull PsiFile file, @NotNull CharSequence closingQuote) { - if (!HighlightUtil.Feature.TEXT_BLOCKS.isAvailable(file)) return; editor.getDocument().insertString(offset, "\n\"\"\""); Project project = file.getProject(); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());