mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
convert to string literal: filter intentions when they were already added as compilation fixes
GitOrigin-RevId: 32db7ed8885afc26ad1c5ebb928bec81066055ff
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d8d57e3a2f
commit
c879fd36f9
+1
-9
@@ -7,7 +7,6 @@ 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.impl.source.tree.java.PsiLiteralExpressionImpl;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -28,14 +27,7 @@ public class ConvertToStringLiteralAction implements IntentionActionWithFixAllOp
|
||||
@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.CHARACTER_LITERAL)) {
|
||||
StringBuilder chars = new StringBuilder();
|
||||
String text = element.getText();
|
||||
return text.length() > 1 &&
|
||||
PsiLiteralExpressionImpl.parseStringCharacters(text.substring(1, text.length() - 1), chars, null) &&
|
||||
chars.length() == 1;
|
||||
}
|
||||
return false;
|
||||
return PsiUtil.isJavaToken(element, JavaTokenType.CHARACTER_LITERAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-10
@@ -4,12 +4,9 @@ package com.intellij.java.codeInsight.intention;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
|
||||
public class ConvertToStringLiteralTest extends JavaCodeInsightFixtureTestCase {
|
||||
@@ -25,13 +22,9 @@ public class ConvertToStringLiteralTest extends JavaCodeInsightFixtureTestCase {
|
||||
CodeInsightTestUtil.doIntentionTest(myFixture, myIntention, "Simple.java", "Simple_after.java");
|
||||
}
|
||||
|
||||
public void testNotAvailable() {
|
||||
public void testAvailableOnce() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
List<IntentionAction> availableIntentions = myFixture.getAvailableIntentions();
|
||||
final IntentionAction intentionAction = CodeInsightTestUtil.findIntentionByText(availableIntentions, myIntention);
|
||||
if (intentionAction != null) {
|
||||
Assert.fail("Action found: " + myIntention);
|
||||
}
|
||||
assertSize(1, ContainerUtil.filter(myFixture.getAvailableIntentions(), a -> myIntention.equals(a.getText())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 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.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. 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.daemon.impl.GutterIntentionAction;
|
||||
@@ -327,7 +327,11 @@ public final class CachedIntentions {
|
||||
public List<IntentionActionWithTextCaching> getAllActions() {
|
||||
List<IntentionActionWithTextCaching> result = new ArrayList<>(myErrorFixes);
|
||||
result.addAll(myInspectionFixes);
|
||||
result.addAll(myIntentions);
|
||||
for (IntentionActionWithTextCaching intention : myIntentions) {
|
||||
if (!myErrorFixes.contains(intention)) {
|
||||
result.add(intention);
|
||||
}
|
||||
}
|
||||
result.addAll(myGutters);
|
||||
result.addAll(myNotifications);
|
||||
result = DumbService.getInstance(myProject).filterByDumbAwareness(result);
|
||||
|
||||
Reference in New Issue
Block a user