Search in sources :

Example 61 with IntentionAction

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

the class DartServerQuickFixTest method doQuickFixTest.

/**
   * @param fileUpdatedByFix <code>null</code> if quick fix updates the file from which it was invoked
   */
private void doQuickFixTest(@NotNull final String intentionStartText, @Nullable final VirtualFile fileUpdatedByFix, boolean fixAvailable) {
    myFixture.configureByFile(getTestName(false) + ".dart");
    final IntentionAction quickFix = myFixture.findSingleIntention(intentionStartText);
    assertEquals(fixAvailable, quickFix.isAvailable(getProject(), getEditor(), getFile()));
    if (!fixAvailable)
        return;
    if (fileUpdatedByFix != null) {
        // todo This is a workaround because DartQuickFix.navigate() behaves differently in test environment.
        // Would be great to remove this code and instead check that correct editor becomes open after fix.invoke()
        myFixture.openFileInEditor(fileUpdatedByFix);
    }
    ApplicationManager.getApplication().runWriteAction(() -> quickFix.invoke(getProject(), getEditor(), getFile()));
    final String updatedFileName = fileUpdatedByFix == null ? getTestName(false) : fileUpdatedByFix.getNameWithoutExtension();
    myFixture.checkResultByFile(updatedFileName + ".after.dart");
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 62 with IntentionAction

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

the class LintIdeApiDetectorTest method doTest.

private void doTest(@NotNull final AndroidLintInspectionBase inspection, @Nullable String quickFixName, boolean createManifest) throws Exception {
    if (createManifest) {
        createManifest();
    }
    myFixture.enableInspections(inspection);
    VirtualFile file = myFixture.copyFileToProject(BASE_PATH + getTestName(false) + ".java", "src/p1/p2/Class.java");
    myFixture.configureFromExistingVirtualFile(file);
    myFixture.checkHighlighting(true, false, false);
    if (quickFixName != null) {
        IntentionAction quickFix = AndroidTestUtils.getIntentionAction(myFixture, quickFixName);
        assertNotNull(quickFix);
        myFixture.launchAction(quickFix);
        myFixture.checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 63 with IntentionAction

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

the class LintIdeGradleDetectorTest method doTest.

private void doTest(@NotNull final AndroidLintInspectionBase inspection, @Nullable String quickFixName) throws Exception {
    createManifest();
    myFixture.enableInspections(inspection);
    VirtualFile file = myFixture.copyFileToProject(BASE_PATH + getTestName(false) + ".gradle", "build.gradle");
    myFixture.configureFromExistingVirtualFile(file);
    myFixture.checkHighlighting(true, false, false);
    if (quickFixName != null) {
        final IntentionAction quickFix = myFixture.getAvailableIntention(quickFixName);
        assertNotNull(quickFix);
        myFixture.launchAction(quickFix);
        myFixture.checkResultByFile(BASE_PATH + getTestName(false) + "_after.gradle");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 64 with IntentionAction

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

the class RegisterComponentsTest method testAddActivityNoShow.

/**
   * Test that "add activity" doesn't show up when activity is already registered
   */
public void testAddActivityNoShow() throws Exception {
    deleteManifest();
    myFixture.copyFileToProject("intentions/DummyActivity_manifest_after.xml", "AndroidManifest.xml");
    final VirtualFile file = myFixture.copyFileToProject("intentions/DummyActivity.java", "src/com/example/DummyActivity.java");
    myFixture.configureFromExistingVirtualFile(file);
    final IntentionAction action = AndroidTestUtils.getIntentionAction(myFixture, ADD_ACTIVITY_TO_MANIFEST);
    assertNull(action);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 65 with IntentionAction

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

the class AndroidDomTestCase method doTestSpellcheckerQuickFixes.

protected final void doTestSpellcheckerQuickFixes() throws IOException {
    myFixture.enableInspections(SpellCheckingInspection.class);
    // TODO: Kill getTestName, make test classes specify the golden file explicitly.
    VirtualFile virtualFile = copyFileToProject(getTestName(true) + ".xml");
    myFixture.configureFromExistingVirtualFile(virtualFile);
    List<IntentionAction> fixes = highlightAndFindQuickFixes(null);
    assertEquals(2, fixes.size());
    assertInstanceOf(((QuickFixWrapper) fixes.get(0)).getFix(), RenameTo.class);
    assertInstanceOf(((QuickFixWrapper) fixes.get(1)).getFix(), AcceptWordAsCorrect.class);
}
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