From b15a0fb68278c55e2c489e5b3fbe2a7a9169f0b5 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 30 Jul 2019 13:39:01 -0700 Subject: [PATCH] [java] drops raw string literal support GitOrigin-RevId: 153517ad5e0ac8f8165128ed8797d4157b5512b2 --- .../src/META-INF/JavaAnalysisPlugin.xml | 5 - .../daemon/impl/analysis/HighlightUtil.java | 3 +- .../impl/analysis/HighlightVisitorImpl.java | 9 +- ...ticksAroundRawStringLiteralInspection.java | 56 ------- .../ide/highlighter/JavaFileHighlighter.java | 1 - java/java-impl/src/META-INF/JavaPlugin.xml | 13 -- .../ConvertRawToStringLiteralAction.java | 60 ------- .../ConvertStringLiteralToRawAction.java | 86 ---------- .../editorActions/JavaQuoteHandler.java | 16 +- .../RawStringLiteralPasteProcessor.java | 125 --------------- .../impl/SplitRawStringIntentionAction.java | 102 ------------ .../LiteralExpressionTokenizer.java | 3 - ...undantBackticksAroundRawStringLiteral.html | 5 - .../after.java.template | 3 - .../before.java.template | 3 - .../description.html | 5 - .../after.java.template | 4 - .../before.java.template | 3 - .../description.html | 5 - .../after.java.template | 1 - .../before.java.template | 1 - .../description.html | 5 - .../intellij/psi/PsiRawStringLiteralUtil.java | 84 ---------- .../intellij/lang/java/lexer/JavaLexer.java | 22 --- .../lang/java/parser/ExpressionParser.java | 2 +- .../StringLiteralManipulator.java | 10 -- .../psi/impl/source/tree/ElementType.java | 4 +- .../tree/java/PsiLiteralExpressionImpl.java | 27 +--- .../src/messages/JavaErrorMessages.properties | 1 - .../RawToStringTransformation.after.java | 8 - .../RawToStringTransformation.java | 8 - .../SplitRawStringLiteral.after.java | 5 - .../SplitRawStringLiteral.java | 5 - .../SplitRawStringLiteralDisabledOnTic.java | 5 - .../StringAssignability.java | 10 -- .../StringToRawTransformation.after.java | 7 - .../StringToRawTransformation.java | 7 - ...gToRawTransformationLeadingTics.after.java | 5 - .../StringToRawTransformationLeadingTics.java | 5 - .../StringToRawTransformationOnlyTics.java | 5 - ...RawTransformationWithTicsInside.after.java | 7 - ...ringToRawTransformationWithTicsInside.java | 7 - ...ansformationWithWrongSeparators.after.java | 6 - ...oRawTransformationWithWrongSeparators.java | 5 - .../TypingOpeningTic.1.after.java | 5 - .../TypingOpeningTic.after.java | 5 - .../advRawStringLiteral/TypingOpeningTic.java | 5 - .../daemon/LightAdvRawStringLiteralsTest.java | 151 ------------------ 48 files changed, 11 insertions(+), 914 deletions(-) delete mode 100644 java/java-analysis-impl/src/com/intellij/codeInspection/RedundantBackticksAroundRawStringLiteralInspection.java delete mode 100644 java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertRawToStringLiteralAction.java delete mode 100644 java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertStringLiteralToRawAction.java delete mode 100644 java/java-impl/src/com/intellij/codeInsight/editorActions/RawStringLiteralPasteProcessor.java delete mode 100644 java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitRawStringIntentionAction.java delete mode 100644 java/java-impl/src/inspectionDescriptions/RedundantBackticksAroundRawStringLiteral.html delete mode 100644 java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/after.java.template delete mode 100644 java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/before.java.template delete mode 100644 java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/description.html delete mode 100644 java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/after.java.template delete mode 100644 java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/before.java.template delete mode 100644 java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/description.html delete mode 100644 java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/after.java.template delete mode 100644 java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/before.java.template delete mode 100644 java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/description.html delete mode 100644 java/java-psi-api/src/com/intellij/psi/PsiRawStringLiteralUtil.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteralDisabledOnTic.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringAssignability.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationOnlyTics.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.1.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.after.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.java delete mode 100644 java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvRawStringLiteralsTest.java diff --git a/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml b/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml index e6a5a3393cd3..678dadff1e6a 100644 --- a/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml +++ b/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml @@ -235,11 +235,6 @@ - 0) { - String newBackticksSequence = StringUtil.repeat("`", reducedNumberOfBackTicks); - int redundantTicksLength = (text.length() - rawString.length()) / 2 - reducedNumberOfBackTicks; - holder.registerProblem(expression, "Number of backticks may be reduced by " + redundantTicksLength, - ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, - new TextRange(0, redundantTicksLength), - new LocalQuickFix() { - @Nls - @NotNull - @Override - public String getFamilyName() { - return "Reduce number of backticks"; - } - - @Override - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { - PsiElement element = descriptor.getPsiElement(); - PsiExpression newRawStringLiteral = JavaPsiFacade.getElementFactory(project) - .createExpressionFromText( - newBackticksSequence + rawString + newBackticksSequence, element); - element.replace(newRawStringLiteral); - } - }); - } - } - } - }; - } -} diff --git a/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java b/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java index 73d35e6e3fa2..0f4164a2b8d8 100644 --- a/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java +++ b/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java @@ -46,7 +46,6 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase { ourMap1.put(JavaTokenType.DOUBLE_LITERAL, JavaHighlightingColors.NUMBER); ourMap1.put(JavaTokenType.STRING_LITERAL, JavaHighlightingColors.STRING); ourMap1.put(JavaTokenType.TEXT_BLOCK_LITERAL, JavaHighlightingColors.STRING); - ourMap1.put(JavaTokenType.RAW_STRING_LITERAL, JavaHighlightingColors.STRING); ourMap1.put(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, JavaHighlightingColors.VALID_STRING_ESCAPE); ourMap1.put(StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN, JavaHighlightingColors.INVALID_STRING_ESCAPE); ourMap1.put(StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN, JavaHighlightingColors.INVALID_STRING_ESCAPE); diff --git a/java/java-impl/src/META-INF/JavaPlugin.xml b/java/java-impl/src/META-INF/JavaPlugin.xml index 4bb734a895e8..57abb09dd535 100644 --- a/java/java-impl/src/META-INF/JavaPlugin.xml +++ b/java/java-impl/src/META-INF/JavaPlugin.xml @@ -1035,7 +1035,6 @@ - @@ -1662,14 +1661,6 @@ com.intellij.codeInsight.daemon.impl.quickfix.ConvertToStringLiteralAction Java/Strings - - com.intellij.codeInsight.daemon.impl.quickfix.ConvertRawToStringLiteralAction - Java/Strings - - - com.intellij.codeInsight.daemon.impl.quickfix.ConvertStringLiteralToRawAction - Java/Strings - com.intellij.codeInsight.intention.impl.InsertLiteralUnderscoresAction Java/Numbers @@ -1682,10 +1673,6 @@ com.intellij.codeInsight.intention.impl.BreakStringOnLineBreaksIntentionAction Java/Strings - - com.intellij.codeInsight.intention.impl.SplitRawStringIntentionAction - Java/Strings - com.intellij.codeInsight.intention.impl.ReplaceCastWithVariableAction Java/Imports diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertRawToStringLiteralAction.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertRawToStringLiteralAction.java deleted file mode 100644 index dce527212be0..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertRawToStringLiteralAction.java +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2000-2018 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.daemon.impl.quickfix; - -import com.intellij.codeInsight.daemon.QuickFixBundle; -import com.intellij.codeInsight.editorActions.StringLiteralCopyPasteProcessor; -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl; -import com.intellij.psi.util.PsiUtil; -import com.intellij.util.IncorrectOperationException; -import com.siyeh.ig.psiutils.ExpressionUtils; -import org.jetbrains.annotations.NotNull; - -public class ConvertRawToStringLiteralAction implements IntentionAction { - @NotNull - @Override - public String getText() { - return QuickFixBundle.message("convert.to.string.text"); - } - - @NotNull - @Override - public String getFamilyName() { - return "Convert raw to String literal"; - } - - @Override - public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) { - final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); - return PsiUtil.isJavaToken(element, JavaTokenType.RAW_STRING_LITERAL); - } - - @Override - public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { - final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); - if (element != null && PsiUtil.isJavaToken(element, JavaTokenType.RAW_STRING_LITERAL)) { - PsiElement parent = element.getParent(); - if (parent instanceof PsiLiteralExpressionImpl) { - String text = ((PsiLiteralExpressionImpl)parent).getRawString(); - PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); - PsiElement literalToken = elementFactory.createExpressionFromText("\"\"", file).getFirstChild(); - String preprocessedValue = new StringLiteralCopyPasteProcessor().escapeAndSplit(text, literalToken); - PsiExpression replacement = elementFactory.createExpressionFromText('\"' + preprocessedValue + '\"', null); - PsiElement replacedExpression = ExpressionUtils.replacePolyadicWithParent((PsiExpression)parent, replacement); - if (replacedExpression == null) { - replacedExpression = parent.replace(replacement); - } - CodeStyleManager.getInstance(project).reformat(replacedExpression); - } - } - } - - @Override - public boolean startInWriteAction() { - return true; - } -} diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertStringLiteralToRawAction.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertStringLiteralToRawAction.java deleted file mode 100644 index 8b9247a8f255..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertStringLiteralToRawAction.java +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2000-2018 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.daemon.impl.quickfix; - -import com.intellij.codeInsight.daemon.QuickFixBundle; -import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil; -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInsight.intention.LowPriorityAction; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.*; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl; -import com.intellij.psi.util.PsiUtil; -import com.intellij.util.IncorrectOperationException; -import com.siyeh.ipp.concatenation.CopyConcatenatedStringToClipboardIntention; -import org.jetbrains.annotations.NotNull; - -public class ConvertStringLiteralToRawAction implements IntentionAction, LowPriorityAction { - @NotNull - @Override - public String getText() { - return QuickFixBundle.message("convert.to.raw.string.text"); - } - - @NotNull - @Override - public String getFamilyName() { - return "Convert to raw string literal"; - } - - @Override - public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) { - final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); - if (PsiUtil.isJavaToken(element, JavaTokenType.STRING_LITERAL) && HighlightUtil.Feature.RAW_LITERALS.isAvailable(file)) { - PsiElement parent = element.getParent(); - if (parent instanceof PsiLiteralExpressionImpl) { - String text = ((PsiLiteralExpressionImpl)parent).getInnerText(); - return text != null && PsiRawStringLiteralUtil.getLeadingTicksSequence(text) < text.length(); - } - } - return false; - } - - @Override - public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { - final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); - if (element != null && PsiUtil.isJavaToken(element, JavaTokenType.STRING_LITERAL)) { - PsiElement parent = element.getParent(); - if (parent instanceof PsiLiteralExpressionImpl) { - PsiElement elementToReplace = parent; - String text; - PsiElement gParent = PsiUtil.skipParenthesizedExprUp(parent.getParent()); - if (gParent instanceof PsiPolyadicExpression) { - text = CopyConcatenatedStringToClipboardIntention.buildConcatenationText((PsiPolyadicExpression)gParent); - elementToReplace = gParent; - } - else { - String innerText = ((PsiLiteralExpressionImpl)parent).getInnerText(); - if (innerText == null) return; - text = StringUtil.unescapeStringCharacters(innerText); - } - String prefix = ""; - int startingSeq = PsiRawStringLiteralUtil.getLeadingTicksSequence(text); - if (startingSeq > 0) { - prefix = "\"" + StringUtil.repeat("`", startingSeq) + "\" + "; - } - String suffix = ""; - int trailingSequence = PsiRawStringLiteralUtil.getTrailingTicksSequence(text); - if (trailingSequence > 0) { - suffix = "+ \"" + StringUtil.repeat("`", trailingSequence) + "\""; - } - String textTicsTrimmed = text.substring(Math.max(startingSeq, 0), text.length() - Math.max(trailingSequence, 0)); - String additionalQuotes = PsiRawStringLiteralUtil.getAdditionalTicks(textTicsTrimmed, "`"); - PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); - CodeStyleManager.getInstance(project).reformat( - elementToReplace.replace(elementFactory.createExpressionFromText(prefix + '`' + additionalQuotes + StringUtil.convertLineSeparators(textTicsTrimmed) + additionalQuotes + '`' + suffix, null))); - } - } - } - - @Override - public boolean startInWriteAction() { - return true; - } -} 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 8ba23570045c..eaf2cc2d9d28 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaQuoteHandler.java @@ -92,21 +92,7 @@ public class JavaQuoteHandler extends SimpleTokenSetQuoteHandler implements Java @Nullable @Override public CharSequence getClosingQuote(@NotNull HighlighterIterator iterator, int offset) { - IElementType tokenType = iterator.getTokenType(); - if (tokenType == JavaTokenType.TEXT_BLOCK_LITERAL && offset == iterator.getStart() + 3) { - return "\"\"\""; - } - if (tokenType == JavaTokenType.RAW_STRING_LITERAL) { - CharSequence text = iterator.getDocument().getImmutableCharSequence(); - int leadingTicsSequence = PsiRawStringLiteralUtil.getLeadingTicksSequence(text.subSequence(iterator.getStart(), offset)); - if (isOpeningQuote(iterator, offset - leadingTicsSequence)) { - int closingSequence = PsiRawStringLiteralUtil.getLeadingTicksSequence(text.subSequence(offset, iterator.getEnd())); - if (closingSequence + 1 == leadingTicsSequence) { - return "`"; - } - } - } - return null; + return iterator.getTokenType() == JavaTokenType.TEXT_BLOCK_LITERAL && offset == iterator.getStart() + 3 ? "\"\"\"" : null; } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/RawStringLiteralPasteProcessor.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/RawStringLiteralPasteProcessor.java deleted file mode 100644 index 7fa5243e3f6f..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/RawStringLiteralPasteProcessor.java +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2000-2018 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.codeInsight.FileModificationService; -import com.intellij.ide.PasteProvider; -import com.intellij.lang.ASTNode; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.EditorModificationUtil; -import com.intellij.openapi.editor.RangeMarker; -import com.intellij.openapi.ide.CopyPasteManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.*; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.awt.datatransfer.DataFlavor; - -/** - * Disable all preprocessing to get the string AS IS - */ -public class RawStringLiteralPasteProcessor implements PasteProvider { - - @Override - public void performPaste(@NotNull DataContext dataContext) { - final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); - final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); - if (editor == null || file == null) return; - - String text = getTextInClipboard(); - if (text == null) return; - - final Document document = editor.getDocument(); - PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); - - final int offset = editor.getCaretModel().getOffset(); - PsiElement stringLiteral = findRawStringLiteralAtCaret(file, offset); - if (stringLiteral == null) return; - - int leadingTicsSequence = PsiRawStringLiteralUtil.getLeadingTicksSequence(text); - int trailingTicsSequence = PsiRawStringLiteralUtil.getTrailingTicksSequence(text); - - String prefix = ""; - TextRange textRange = stringLiteral.getTextRange(); - if (offset == textRange.getStartOffset() + 1 && leadingTicsSequence > 0) { - prefix = "\"" + StringUtil.repeat("`", leadingTicsSequence) + "\" + "; - text = text.substring(leadingTicsSequence); - } - - String suffix = ""; - if (offset == textRange.getEndOffset() - 1 && trailingTicsSequence > 0) { - suffix = "+ \"" + StringUtil.repeat("`", trailingTicsSequence) + "\""; - text = text.substring(0, text.length() - trailingTicsSequence); - } - - String literalText = stringLiteral.getText(); - int ticsLength = PsiRawStringLiteralUtil.getLeadingTicksSequence(literalText); - String quotes = literalText.substring(0, ticsLength); - String additionalQuotes = PsiRawStringLiteralUtil.getAdditionalTicks(text, quotes); - insertAtCaret(StringUtil.convertLineSeparators(text), additionalQuotes, stringLiteral, editor, prefix, suffix); - } - - @Override - public boolean isPastePossible(@NotNull DataContext dataContext) { - final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); - final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); - - return editor != null && - file != null && - findRawStringLiteralAtCaret(file, editor.getCaretModel().getOffset()) != null && - getTextInClipboard() != null; - } - - @Override - public boolean isPasteEnabled(@NotNull DataContext dataContext) { - return isPastePossible(dataContext); - } - - @Nullable - private static String getTextInClipboard() { - return CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); - } - - @Nullable - private static PsiElement findRawStringLiteralAtCaret(PsiFile file, int offset) { - final PsiElement elementAtSelectionStart = file.findElementAt(offset); - if (elementAtSelectionStart == null) { - return null; - } - ASTNode node = elementAtSelectionStart.getNode(); - return node != null && node.getElementType() == JavaTokenType.RAW_STRING_LITERAL ? elementAtSelectionStart : null; - } - - - private static void insertAtCaret(final String text, - final String additionalQuotes, - final PsiElement element, - final Editor editor, String prefix, String suffix) { - final Project project = editor.getProject(); - if (project == null) return; - - RangeMarker range = editor.getDocument().createRangeMarker(element.getTextRange()); - final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); - - final PsiFile file = documentManager.getPsiFile(editor.getDocument()); - if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; - - WriteCommandAction.runWriteCommandAction(project, "Raw paste", null, () -> { - Document document = editor.getDocument(); - documentManager.commitDocument(document); - - EditorModificationUtil.insertStringAtCaret(editor, text); - - if (!additionalQuotes.isEmpty() || !prefix.isEmpty() || !suffix.isEmpty()) { - document.insertString(range.getStartOffset(), prefix + additionalQuotes); - document.insertString(range.getEndOffset(), additionalQuotes + suffix); - } - }); - } -} diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitRawStringIntentionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitRawStringIntentionAction.java deleted file mode 100644 index 5d6142f2fdc7..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitRawStringIntentionAction.java +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2000-2018 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.intention.impl; - -import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.*; -import com.intellij.util.ArrayUtil; -import com.intellij.util.IncorrectOperationException; -import com.siyeh.ig.psiutils.ExpressionUtils; -import org.jetbrains.annotations.NotNull; - -public class SplitRawStringIntentionAction extends PsiElementBaseIntentionAction { - @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { - if (!(element instanceof PsiJavaToken)) { - return false; - } - - final PsiJavaToken token = (PsiJavaToken)element; - - if (token.getTokenType() != JavaTokenType.RAW_STRING_LITERAL) { - return false; - } - - final String text = token.getText(); - if (text == null) { - return false; - } - - int leadingTicsSequence = PsiRawStringLiteralUtil.getLeadingTicksSequence(text); - int trailingTicsSequence = PsiRawStringLiteralUtil.getTrailingTicksSequence(text); - if (leadingTicsSequence == trailingTicsSequence) { - int offset = editor.getCaretModel().getOffset(); - int caretInTokenIdx = offset - token.getTextOffset(); - if (caretInTokenIdx > leadingTicsSequence && - offset < token.getTextRange().getEndOffset() - trailingTicsSequence && - text.charAt(caretInTokenIdx) != '`' && - text.charAt(caretInTokenIdx - 1) != '`') { - return true; - } - } - return false; - } - - @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { - if (!(element instanceof PsiJavaToken)) { - return; - } - - final PsiJavaToken token = (PsiJavaToken)element; - - if (token.getTokenType() != JavaTokenType.RAW_STRING_LITERAL) { - return; - } - - - final String text = token.getText(); - if (text == null) { - return; - } - - int ticsSequenceLength = PsiRawStringLiteralUtil.getLeadingTicksSequence(text); - String breakSequence = StringUtil.repeat("`", ticsSequenceLength); - - int offset = editor.getCaretModel().getOffset(); - int splitIdx = offset - token.getTextOffset(); - final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); - PsiBinaryExpression replacement = (PsiBinaryExpression)factory - .createExpressionFromText(text.substring(0, splitIdx) + breakSequence + " + " + breakSequence + text.substring(splitIdx), element); - PsiPolyadicExpression replacedExpression = (PsiPolyadicExpression)ExpressionUtils.replacePolyadicWithParent((PsiExpression)token.getParent(), replacement); - if (replacedExpression != null) { - PsiElement leftOperand = replacedExpression.findElementAt(splitIdx); - PsiExpression[] operands = replacedExpression.getOperands(); - int idx = ArrayUtil.find(operands, leftOperand); - if (idx < operands.length - 1) { - PsiJavaToken tokenBeforeOperand = replacedExpression.getTokenBeforeOperand(operands[idx + 1]); - if (tokenBeforeOperand != null) { - editor.getCaretModel().moveToOffset(tokenBeforeOperand.getTextOffset()); - } - } - } - else { - PsiBinaryExpression replaced = (PsiBinaryExpression)token.getParent().replace(replacement); - editor.getCaretModel().moveToOffset(replaced.getOperationSign().getTextOffset()); - } - } - - @NotNull - @Override - public String getText() { - return getFamilyName(); - } - - @NotNull - @Override - public String getFamilyName() { - return "Split raw string literal"; - } -} diff --git a/java/java-impl/src/com/intellij/spellchecker/LiteralExpressionTokenizer.java b/java/java-impl/src/com/intellij/spellchecker/LiteralExpressionTokenizer.java index f51619078a19..5144305e0714 100644 --- a/java/java-impl/src/com/intellij/spellchecker/LiteralExpressionTokenizer.java +++ b/java/java-impl/src/com/intellij/spellchecker/LiteralExpressionTokenizer.java @@ -29,9 +29,6 @@ public class LiteralExpressionTokenizer extends EscapeSequenceTokenizer - -Reports raw string literals when the number of backticks around the value may be reduced. - - \ No newline at end of file diff --git a/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/after.java.template b/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/after.java.template deleted file mode 100644 index 9a935b685c9b..000000000000 --- a/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/after.java.template +++ /dev/null @@ -1,3 +0,0 @@ -String s = "raw\n" + -"string\n" + -"literal"; diff --git a/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/before.java.template b/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/before.java.template deleted file mode 100644 index e1bdab08693e..000000000000 --- a/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/before.java.template +++ /dev/null @@ -1,3 +0,0 @@ -String s = `raw -string -literal`; diff --git a/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/description.html b/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/description.html deleted file mode 100644 index 73c6b6e72e03..000000000000 --- a/java/java-impl/src/intentionDescriptions/ConvertRawToStringLiteralAction/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention converts raw string literals into (multi-line) string literals. - - diff --git a/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/after.java.template b/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/after.java.template deleted file mode 100644 index 7f54a05b89d4..000000000000 --- a/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/after.java.template +++ /dev/null @@ -1,4 +0,0 @@ -String s = `raw -string -literal`; - diff --git a/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/before.java.template b/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/before.java.template deleted file mode 100644 index 9a935b685c9b..000000000000 --- a/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/before.java.template +++ /dev/null @@ -1,3 +0,0 @@ -String s = "raw\n" + -"string\n" + -"literal"; diff --git a/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/description.html b/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/description.html deleted file mode 100644 index d616f50f5ff7..000000000000 --- a/java/java-impl/src/intentionDescriptions/ConvertStringLiteralToRawAction/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention converts (multi-line) string literals into raw string literals. - - diff --git a/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/after.java.template b/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/after.java.template deleted file mode 100644 index f0f6d121b227..000000000000 --- a/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/after.java.template +++ /dev/null @@ -1 +0,0 @@ -String s = ```Hello, ``` + ```world!```; \ No newline at end of file diff --git a/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/before.java.template b/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/before.java.template deleted file mode 100644 index f74b3af6c8a4..000000000000 --- a/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/before.java.template +++ /dev/null @@ -1 +0,0 @@ -String s = ```Hello, world!```; \ No newline at end of file diff --git a/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/description.html b/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/description.html deleted file mode 100644 index f6182e73603f..000000000000 --- a/java/java-impl/src/intentionDescriptions/SplitRawStringIntentionAction/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention allows to break raw string literal into 2 parts at caret position. - - diff --git a/java/java-psi-api/src/com/intellij/psi/PsiRawStringLiteralUtil.java b/java/java-psi-api/src/com/intellij/psi/PsiRawStringLiteralUtil.java deleted file mode 100644 index f10924e9d109..000000000000 --- a/java/java-psi-api/src/com/intellij/psi/PsiRawStringLiteralUtil.java +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2000-2018 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.psi; - -import com.intellij.openapi.util.text.StringUtil; - -import java.util.BitSet; - -public class PsiRawStringLiteralUtil { - /** - * Check if text contains ticks, and - * if yes, returns the number of additional ticks required around text to have a valid raw string literal - * empty string otherwise - */ - public static String getAdditionalTicks(String text, String tics) { - int quotesLength = tics.length(); - int textLength = text.length(); - int idx = 0; - int maxQuotesNumber = -1; - boolean hasToReplace = false; - while ((idx = text.indexOf(tics, idx)) >= 0 && idx < textLength) { - int additionalQuotesLength = getTicksSequence(text, textLength, idx + quotesLength); - if (additionalQuotesLength == 0) { - hasToReplace = true; - } - maxQuotesNumber = Math.max(maxQuotesNumber, additionalQuotesLength); - idx += additionalQuotesLength + quotesLength; - } - - return hasToReplace ? StringUtil.repeat("`", maxQuotesNumber + 1) : ""; - } - - /** - * Return number of leading ticks in the text - */ - public static int getLeadingTicksSequence(CharSequence text) { - return getTicksSequence(text, text.length(), 0); - } - - /** - * Return number of trailing ticks in the text - */ - public static int getTrailingTicksSequence(CharSequence text) { - int length = text.length(); - while (length > 0 && text.charAt(length - 1) == '`') length--; - return text.length() - length; - } - - private static int getTicksSequence(CharSequence literalText, int length, int startIndex) { - int quotesLength = startIndex; - while (quotesLength < length && literalText.charAt(quotesLength) == '`') quotesLength++; - return quotesLength - startIndex; - } - - /** - * For given raw string literal text (with backticks) returns minimal number of backticks required for string content - * @return number less than current number of backticks, - * -1 otherwise - */ - public static int getReducedNumberOfBackticks(String text) { - int leadingTicsSequence = getLeadingTicksSequence(text); - int trailingTicsSequence = getTrailingTicksSequence(text); - if (leadingTicsSequence == trailingTicsSequence && leadingTicsSequence > 1) { - int length = text.length() - trailingTicsSequence; - int idx = leadingTicsSequence; - BitSet usedTicSequences = new BitSet(); - usedTicSequences.set(leadingTicsSequence); - while (idx < length) { - idx = text.indexOf("`", idx); - if (idx < 0) break; - int ticsSequence = getTicksSequence(text, length, idx); - usedTicSequences.set(ticsSequence); - idx += ticsSequence; - } - - for (int i = 1; i < leadingTicsSequence; i++) { - if (!usedTicSequences.get(i)) { - return i; - } - } - } - return -1; - } - -} diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java index be8325a1b6f9..2a6fe237035d 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java @@ -160,11 +160,6 @@ public class JavaLexer extends LexerBase { } break; - case '`': - myTokenType = JavaTokenType.RAW_STRING_LITERAL; - myTokenEndOffset = getRawLiteralEnd(myBufferIndex); - break; - default: flexLocateToken(); } @@ -275,23 +270,6 @@ public class JavaLexer extends LexerBase { return pos; } - private int getRawLiteralEnd(int offset) { - int pos = offset; - - while (pos < myBufferEndOffset && charAt(pos) == '`') pos++; - int quoteLen = pos - offset; - - int start; - do { - while (pos < myBufferEndOffset && charAt(pos) != '`') pos++; - start = pos; - while (pos < myBufferEndOffset && charAt(pos) == '`') pos++; - } - while (pos - start != quoteLen && pos < myBufferEndOffset); - - return pos; - } - private char charAt(int position) { return myBufferArray != null ? myBufferArray[position] : myBuffer.charAt(position); } diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java index a5d9ce394a80..d2fbf50591c5 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java @@ -36,7 +36,7 @@ public class ExpressionParser { private static final TokenSet LITERALS = TokenSet.create( JavaTokenType.TRUE_KEYWORD, JavaTokenType.FALSE_KEYWORD, JavaTokenType.NULL_KEYWORD, JavaTokenType.INTEGER_LITERAL, JavaTokenType.LONG_LITERAL, JavaTokenType.FLOAT_LITERAL, JavaTokenType.DOUBLE_LITERAL, JavaTokenType.CHARACTER_LITERAL, - JavaTokenType.STRING_LITERAL, JavaTokenType.TEXT_BLOCK_LITERAL, JavaTokenType.RAW_STRING_LITERAL); + JavaTokenType.STRING_LITERAL, JavaTokenType.TEXT_BLOCK_LITERAL); private static final TokenSet CONDITIONAL_OR_OPS = TokenSet.create(JavaTokenType.OROR); private static final TokenSet CONDITIONAL_AND_OPS = TokenSet.create(JavaTokenType.ANDAND); private static final TokenSet OR_OPS = TokenSet.create(JavaTokenType.OR); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/StringLiteralManipulator.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/StringLiteralManipulator.java index f7ce31a4159c..11f37cade050 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/StringLiteralManipulator.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/StringLiteralManipulator.java @@ -44,20 +44,10 @@ public class StringLiteralManipulator extends AbstractElementManipulator= leadingSeq + trailingSeq ? TextRange.from(leadingSeq, length - trailingSeq - leadingSeq) : TextRange.from(0, length); - } - if (type == JavaTokenType.TEXT_BLOCK_LITERAL) { int startOffset = element.getValue() == null ? -1 : element.getText().indexOf('\n'); return startOffset < 0 ? TextRange.from(0, length) : new TextRange(startOffset + 1, Math.max(startOffset + 1, length - 3)); } - isQuoted = type == JavaTokenType.STRING_LITERAL || type == JavaTokenType.CHARACTER_LITERAL; } else { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/ElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/ElementType.java index 0faaf45851d1..ddb04f77861f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/ElementType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/ElementType.java @@ -65,6 +65,6 @@ public interface ElementType extends JavaTokenType, JavaDocTokenType, JavaElemen TokenSet INTEGER_LITERALS = TokenSet.create(INTEGER_LITERAL, LONG_LITERAL); TokenSet REAL_LITERALS = TokenSet.create(FLOAT_LITERAL, DOUBLE_LITERAL); - TokenSet STRING_LITERALS = TokenSet.create(STRING_LITERAL, TEXT_BLOCK_LITERAL, RAW_STRING_LITERAL); - TokenSet TEXT_LITERALS = TokenSet.create(STRING_LITERAL, TEXT_BLOCK_LITERAL, RAW_STRING_LITERAL, CHARACTER_LITERAL); + TokenSet STRING_LITERALS = TokenSet.create(STRING_LITERAL, TEXT_BLOCK_LITERAL); + TokenSet TEXT_LITERALS = TokenSet.create(STRING_LITERAL, TEXT_BLOCK_LITERAL, CHARACTER_LITERAL); } \ No newline at end of file diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLiteralExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLiteralExpressionImpl.java index 6e70dfdfd93b..3764447d0e56 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLiteralExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLiteralExpressionImpl.java @@ -3,7 +3,6 @@ package com.intellij.psi.impl.source.tree.java; import com.intellij.codeInsight.CodeInsightUtilCore; import com.intellij.lang.ASTNode; -import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.ResolveScopeManager; @@ -110,9 +109,6 @@ public class PsiLiteralExpressionImpl if (type == JavaTokenType.TEXT_BLOCK_LITERAL) { return internedParseStringCharacters(getTextBlockText()); } - if (type == JavaTokenType.RAW_STRING_LITERAL) { - return getRawString(); - } String text = NUMERIC_LITERALS.contains(type) ? StringUtil.toLowerCase(getCanonicalText()) : getCanonicalText(); final int textLength = text.length(); @@ -211,7 +207,7 @@ public class PsiLiteralExpressionImpl @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "2019.3") public String getRawString() { - return StringUtil.nullize(StringUtil.trimLeading(StringUtil.trimTrailing(getCanonicalText(), '`'), '`')); + return null; } @Nullable @@ -263,28 +259,9 @@ public class PsiLiteralExpressionImpl return this; } - @Override @NotNull + @Override public LiteralTextEscaper createLiteralTextEscaper() { - if (getLiteralElementType() == JavaTokenType.RAW_STRING_LITERAL) { - return new LiteralTextEscaper(this) { - @Override - public boolean decode(@NotNull final TextRange rangeInsideHost, @NotNull StringBuilder outChars) { - outChars.append(rangeInsideHost.substring(myHost.getText())); - return true; - } - - @Override - public int getOffsetInHost(int offsetInDecoded, @NotNull final TextRange rangeInsideHost) { - return offsetInDecoded + rangeInsideHost.getStartOffset(); - } - - @Override - public boolean isOneLine() { - return false; - } - }; - } return new StringLiteralEscaper<>(this); } } \ No newline at end of file diff --git a/java/java-psi-impl/src/messages/JavaErrorMessages.properties b/java/java-psi-impl/src/messages/JavaErrorMessages.properties index 00232d36b163..6eceacb447ea 100644 --- a/java/java-psi-impl/src/messages/JavaErrorMessages.properties +++ b/java/java-psi-impl/src/messages/JavaErrorMessages.properties @@ -494,7 +494,6 @@ feature.static.interface.calls=Static interface method calls feature.try.with.resources.refs=Resource references feature.modules=Modules feature.text.blocks=Text block literals -feature.raw.literals=Raw string literals feature.enhanced.switch=Enhanced 'switch' blocks feature.switch.expressions='switch' expressions insufficient.language.level={0} are not supported at language level ''{1}'' diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.after.java deleted file mode 100644 index 811baa10f373..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.after.java +++ /dev/null @@ -1,8 +0,0 @@ -class A { - { - String s = "a\n" + - " symbol to escape: \"\\\" (slash)\n" + - " and something else as well\n" + - " "; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.java deleted file mode 100644 index 643a81338289..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/RawToStringTransformation.java +++ /dev/null @@ -1,8 +0,0 @@ -class A { - { - String s = `a - symbol to escape: "\" (slash) - and something else as well - `; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.after.java deleted file mode 100644 index e7eb78860c68..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.after.java +++ /dev/null @@ -1,5 +0,0 @@ -class Test { - { - String s = ```ab``` + ```c```; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.java deleted file mode 100644 index f9f6d8170dfb..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteral.java +++ /dev/null @@ -1,5 +0,0 @@ -class Test { - { - String s = ```abc```; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteralDisabledOnTic.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteralDisabledOnTic.java deleted file mode 100644 index b2701608c305..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/SplitRawStringLiteralDisabledOnTic.java +++ /dev/null @@ -1,5 +0,0 @@ -class Test { - { - String s = ```ab`c```; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringAssignability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringAssignability.java deleted file mode 100644 index 6539291edf36..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringAssignability.java +++ /dev/null @@ -1,10 +0,0 @@ -class Test { - void m(String s) {} - void n(T s) {} - { - String s = ``abc``; - m(`abc`); - n(`abc`); - String[] array = {``abc``}; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.after.java deleted file mode 100644 index f82346cbf630..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.after.java +++ /dev/null @@ -1,7 +0,0 @@ -class A { - { - String s = `a" -"b -c \`; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.java deleted file mode 100644 index 385c867212d2..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformation.java +++ /dev/null @@ -1,7 +0,0 @@ -class A { - { - String s = "a\"\n" + - "\"b\n" + - "c \\"; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.after.java deleted file mode 100644 index de0ec8596559..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.after.java +++ /dev/null @@ -1,5 +0,0 @@ -class A { - { - String s = "````" + `a` + "`"; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.java deleted file mode 100644 index 9ebf0bf0a509..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationLeadingTics.java +++ /dev/null @@ -1,5 +0,0 @@ -class A { - { - String s = "````a`"; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationOnlyTics.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationOnlyTics.java deleted file mode 100644 index 26830e023992..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationOnlyTics.java +++ /dev/null @@ -1,5 +0,0 @@ -class A { - { - String s = "`````"; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.after.java deleted file mode 100644 index 982b3fd52bf5..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.after.java +++ /dev/null @@ -1,7 +0,0 @@ -class A { - { - String s = ``a" -"b` -c \``; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.java deleted file mode 100644 index 354c4a1dacce..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithTicsInside.java +++ /dev/null @@ -1,7 +0,0 @@ -class A { - { - String s = "a\"\n" + - "\"b`\n" + - "c \\"; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.after.java deleted file mode 100644 index 750e06fdf83f..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.after.java +++ /dev/null @@ -1,6 +0,0 @@ -class A { - { - String s = `a -`; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.java deleted file mode 100644 index 0c8a5738afb4..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/StringToRawTransformationWithWrongSeparators.java +++ /dev/null @@ -1,5 +0,0 @@ -class A { - { - String s = "a\r"; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.1.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.1.after.java deleted file mode 100644 index c821637a744c..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.1.after.java +++ /dev/null @@ -1,5 +0,0 @@ -class A { - { - String s = `` `` - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.after.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.after.java deleted file mode 100644 index f08573f9b607..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.after.java +++ /dev/null @@ -1,5 +0,0 @@ -class A { - { - String s = ` ` - } -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.java deleted file mode 100644 index bd10887251c0..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advRawStringLiteral/TypingOpeningTic.java +++ /dev/null @@ -1,5 +0,0 @@ -class A { - { - String s = - } -} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvRawStringLiteralsTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvRawStringLiteralsTest.java deleted file mode 100644 index 42cce9151583..000000000000 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvRawStringLiteralsTest.java +++ /dev/null @@ -1,151 +0,0 @@ -// 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.java.codeInsight.daemon; - -import com.intellij.JavaTestUtil; -import com.intellij.codeInsight.daemon.QuickFixBundle; -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInspection.RedundantBackticksAroundRawStringLiteralInspection; -import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.psi.JavaPsiFacade; -import com.intellij.psi.PsiElementFactory; -import com.intellij.psi.PsiExpression; -import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl; -import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class LightAdvRawStringLiteralsTest extends LightJavaCodeInsightFixtureTestCase { - @Override - protected String getBasePath() { - return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/advRawStringLiteral"; - } - - @NotNull - @Override - protected LightProjectDescriptor getProjectDescriptor() { - return JAVA_X; - } - - public void testStringAssignability() { - doTestHighlighting(); - } - - public void testRawToStringTransformation() { doTestIntention(QuickFixBundle.message("convert.to.string.text")); } - public void testStringToRawTransformation() { doTestIntention(QuickFixBundle.message("convert.to.raw.string.text")); } - public void testStringToRawTransformationWithWrongSeparators() { doTestIntention(QuickFixBundle.message("convert.to.raw.string.text")); } - public void testStringToRawTransformationLeadingTics() { doTestIntention(QuickFixBundle.message("convert.to.raw.string.text")); } - - public void testStringToRawTransformationOnlyTics() { - myFixture.configureByFile(getTestName(false) + ".java"); - assertEmpty(myFixture.filterAvailableIntentions(QuickFixBundle.message("convert.to.raw.string.text"))); - } - - public void testStringToRawTransformationWithTicsInside() { doTestIntention(QuickFixBundle.message("convert.to.raw.string.text")); } - - public void testSplitRawStringLiteral() { doTestIntention("Split raw string literal"); } - public void testSplitRawStringLiteralDisabledOnTic() { - myFixture.configureByFile(getTestName(false) + ".java"); - assertEmpty(myFixture.filterAvailableIntentions("Split raw string literal")); - } - - public void testPasteInRawStringLiteral() { - doTestPaste("class A {{String s = `q`;}}", "a\nb`\nc", "class A {{String s = ``qa\nb`\nc``;}}"); - } - - public void testPasteInRawStringLiteralWrongLineSeparator() { - doTestPaste("class A {{String s = `x`;}}", "\r", "class A {{String s = `\nx`;}}"); - } - - public void testPasteInRawStringStaringWithTics() { - doTestPaste("class A {{String s = `q`;}}", "``a\n``b", "class A {{String s = \"``\" + `a\n" + "``bq`;}}"); - } - - public void testPasteInRawStringEndingWithTics() { - doTestPaste("class A {{String s = `q`;}}", "``a\n``b``", "class A {{String s = `q``a\n" + "``b`+ \"``\";}}"); - } - - public void testPasteInRawStringStaringWithStartingTics() { - doTestPaste("class A {{String s = `q`;}}", "`a", "class A {{String s = ``q`a``;}}"); - } - - public void testPasteInRawStringLiteralOneAndTwo() { - doTestPaste("class A {{String s = `q`;}}", "a\n``b`\nc", "class A {{String s = ```qa\n``b`\nc```;}}"); - } - - public void testPasteInRawStringLiteralOnlyTwo() { - doTestPaste("class A {{String s = `q`;}}", "a\n``b\nc", "class A {{String s = `qa\n``b\nc`;}}"); - } - - public void testPasteInRawStringLiteralNoTicInside() { - doTestPaste("class A {{String s = `a`;}}", "a\nb\nc", "class A {{String s = `aa\nb\nc`;}}"); - } - - public void testRawStringValue() { - PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject()); - - PsiExpression rawStringLiteral = factory.createExpressionFromText("``abc``", null); - assertEquals("abc", ((PsiLiteralExpressionImpl)rawStringLiteral).getRawString()); - - rawStringLiteral = factory.createExpressionFromText("``abc`", null); - assertEquals("abc", ((PsiLiteralExpressionImpl)rawStringLiteral).getRawString()); - - rawStringLiteral = factory.createExpressionFromText("`abc````", null); - assertEquals("abc", ((PsiLiteralExpressionImpl)rawStringLiteral).getRawString()); - } - - public void testReduceNumberOfBackticks() { - doTestRedundantBackticks("class A {{String s = ```a`b```;}}", "class A {{String s = ``a`b``;}}"); - } - - public void testReduceNumberOfBackticksSimple() { - doTestRedundantBackticks("class A {{String s = ```a``b```;}}", "class A {{String s = `a``b`;}}"); - } - - private void doTestRedundantBackticks(String beforeText, String afterText) { - myFixture.configureByText("a.java", beforeText); - myFixture.enableInspections(new RedundantBackticksAroundRawStringLiteralInspection()); - IntentionAction reduceNumberOfBackticks = myFixture.getAvailableIntention("Reduce number of backticks"); - assertNotNull(reduceNumberOfBackticks); - myFixture.launchAction(reduceNumberOfBackticks); - myFixture.checkResult(afterText); - } - - public void testTypingOpeningTic() { - myFixture.configureByFile(getTestName(false ) + ".java"); - myFixture.type('`'); - myFixture.checkResultByFile(getTestName(false) + ".after.java"); - myFixture.type('`'); - myFixture.checkResultByFile(getTestName(false) + ".1.after.java"); - } - - private void doTestHighlighting() { - myFixture.configureByFile(getTestName(false) + ".java"); - myFixture.checkHighlighting(); - } - - private void doTestPaste(String documentTextBefore, String textToPaste, String expectedDocumentText) { - myFixture.configureByText("plain.txt", "" + textToPaste + ""); - performCopy(); - myFixture.configureByText("a.java", documentTextBefore); - performPaste(); - myFixture.checkResult(expectedDocumentText); - } - - private void doTestIntention(final String hint) { - myFixture.configureByFile(getTestName(false) + ".java"); - List actions = myFixture.filterAvailableIntentions(hint); - assertNotEmpty(actions); - myFixture.launchAction(actions.get(0)); - myFixture.checkResultByFile(getTestName(false) + ".after.java"); - } - - private void performPaste() { - myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE); - } - - private void performCopy() { - myFixture.performEditorAction(IdeActions.ACTION_EDITOR_COPY); - } -} \ No newline at end of file