From 88fbc6522ecea6e731aa587e8cbbdeae7800504d Mon Sep 17 00:00:00 2001 From: Artemiy Sartakov Date: Tue, 19 Nov 2019 13:48:08 +0700 Subject: [PATCH] JavaQuoteHandler: moved language level check for text blocks to hasNonClosedLiteral method (IDEA-CR-55318) GitOrigin-RevId: d892b81916d12636c67118fdf240b661577c9bbb --- .../editorActions/JavaQuoteHandler.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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());