Search in sources :

Example 56 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method doGetAvailableIntentions.

@NotNull
private static List<IntentionAction> doGetAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) {
    ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
    List<IntentionAction> result = new ArrayList<>();
    IntentionListStep intentionListStep = new IntentionListStep(null, intentions, editor, file, file.getProject());
    for (Map.Entry<IntentionAction, List<IntentionAction>> entry : intentionListStep.getActionsWithSubActions().entrySet()) {
        result.add(entry.getKey());
        result.addAll(entry.getValue());
    }
    List<HighlightInfo> infos = DaemonCodeAnalyzerEx.getInstanceEx(file.getProject()).getFileLevelHighlights(file.getProject(), file);
    for (HighlightInfo info : infos) {
        for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
            HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
            if (actionInGroup.getAction().isAvailable(file.getProject(), editor, file)) {
                result.add(actionInGroup.getAction());
                List<IntentionAction> options = actionInGroup.getOptions(file, editor);
                if (options != null) {
                    for (IntentionAction subAction : options) {
                        if (subAction.isAvailable(file.getProject(), editor, file)) {
                            result.add(subAction);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : IntentionListStep(com.intellij.codeInsight.intention.impl.IntentionListStep) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project android by JetBrains.

the class AndroidLintTest method doTestWithFix.

private void doTestWithFix(@NotNull AndroidLintInspectionBase inspection, @NotNull String message, @NotNull String copyTo, @NotNull String extension) throws IOException {
    final IntentionAction action = doTestHighlightingAndGetQuickfix(inspection, message, copyTo, extension);
    assertNotNull(action);
    doTestWithAction(extension, action);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 58 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project android by JetBrains.

the class AndroidLintTest method testSingleLine.

/**
   * Quick fix is available on singleLine="true" and does the right thing
   */
public void testSingleLine() throws Exception {
    deleteManifest();
    myFixture.copyFileToProject(BASE_PATH_GLOBAL + "deprecation/AndroidManifest.xml", "AndroidManifest.xml");
    myFixture.enableInspections(new AndroidLintDeprecatedInspection());
    myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(BASE_PATH + "singleLine.xml", "res/layout/singleLine.xml"));
    final IntentionAction action = AndroidTestUtils.getIntentionAction(myFixture, "Replace singleLine=\"true\" with maxLines=\"1\"");
    assertNotNull(action);
    doTestWithAction("xml", action);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 59 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-plugins by JetBrains.

the class DartServerQuickFixTest method doCrLfAwareTest.

private void doCrLfAwareTest(@NotNull final String content, @NotNull final String intentionStartText, @NotNull final String after) {
    final VirtualFile file = myFixture.configureByText("foo.dart", content).getVirtualFile();
    // configureByText() has normalized line breaks, save once again
    ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            final int i = content.indexOf("<caret>");
            VfsUtil.saveText(file, content.substring(0, i) + content.substring(i + "<caret>".length()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    final IntentionAction quickFix = myFixture.findSingleIntention(intentionStartText);
    ApplicationManager.getApplication().runWriteAction(() -> quickFix.invoke(getProject(), getEditor(), getFile()));
    myFixture.checkResult(after);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) IOException(java.io.IOException)

Example 60 with IntentionAction

use of com.intellij.codeInsight.intention.IntentionAction in project intellij-plugins by JetBrains.

the class DartServerQuickFixTest method testCreatePartFile.

public void testCreatePartFile() throws Throwable {
    myFixture.configureByFile(getTestName(false) + ".dart");
    final IntentionAction quickFix = myFixture.findSingleIntention("Create file 'CreatePartFile_part.dart'");
    assertEquals(true, quickFix.isAvailable(getProject(), getEditor(), getFile()));
    ApplicationManager.getApplication().runWriteAction(() -> quickFix.invoke(getProject(), getEditor(), getFile()));
    final VirtualFile newFile = myFixture.findFileInTempDir("CreatePartFile_part.dart");
    assertNotNull(newFile);
// TODO content of created file is not added because DartQuickFix.navigate() behaves differently in test environment
//myFixture.openFileInEditor(newFile);
//myFixture.checkResultByFile("CreatePartFile_part.after.dart");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Aggregations

IntentionAction (com.intellij.codeInsight.intention.IntentionAction)242 VirtualFile (com.intellij.openapi.vfs.VirtualFile)39 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)31 NotNull (org.jetbrains.annotations.NotNull)23 Project (com.intellij.openapi.project.Project)20 TextRange (com.intellij.openapi.util.TextRange)20 Editor (com.intellij.openapi.editor.Editor)17 PsiFile (com.intellij.psi.PsiFile)17 Annotation (com.intellij.lang.annotation.Annotation)16 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)15 ArrayList (java.util.ArrayList)14 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)10 QuickFixWrapper (com.intellij.codeInspection.ex.QuickFixWrapper)9 Pair (com.intellij.openapi.util.Pair)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)7 EmptyIntentionAction (com.intellij.codeInsight.intention.EmptyIntentionAction)6 AndroidMissingOnClickHandlerInspection (org.jetbrains.android.inspections.AndroidMissingOnClickHandlerInspection)6 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)5 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)5