Search in sources :

Example 66 with IntentionAction

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

the class AndroidDomTestCase method doTestOnClickQuickfix.

protected final void doTestOnClickQuickfix(VirtualFile file) {
    myFixture.configureFromExistingVirtualFile(file);
    List<IntentionAction> actions = highlightAndFindQuickFixes(AndroidMissingOnClickHandlerInspection.MyQuickFix.class);
    assertEquals(1, actions.size());
    IntentionAction action = actions.get(0);
    assertInstanceOf(action, AndroidMissingOnClickHandlerInspection.MyQuickFix.class);
    WriteCommandAction.runWriteCommandAction(null, () -> ((AndroidMissingOnClickHandlerInspection.MyQuickFix) action).doApplyFix(getProject()));
    myFixture.checkResultByFile(myTestFolder + "/onClickIntention.xml");
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AndroidMissingOnClickHandlerInspection(org.jetbrains.android.inspections.AndroidMissingOnClickHandlerInspection)

Example 67 with IntentionAction

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

the class AndroidLayoutDomTest method testOnClickQuickFixIncorrectName.

public void testOnClickQuickFixIncorrectName() throws Throwable {
    myFixture.enableInspections(AndroidMissingOnClickHandlerInspection.class);
    myFixture.copyFileToProject(myTestFolder + "/OnClickActivityIncorrectName.java", "src/p1/p2/Activity1.java");
    VirtualFile file = copyFileToProject("onClickIntentionIncorrectName.xml");
    myFixture.configureFromExistingVirtualFile(file);
    List<IntentionAction> fixes = highlightAndFindQuickFixes(AndroidMissingOnClickHandlerInspection.MyQuickFix.class);
    assertEmpty(fixes);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AndroidMissingOnClickHandlerInspection(org.jetbrains.android.inspections.AndroidMissingOnClickHandlerInspection)

Example 68 with IntentionAction

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

the class AndroidLayoutDomTest method testOnClickQuickFix1.

public void testOnClickQuickFix1() throws Throwable {
    myFixture.enableInspections(AndroidMissingOnClickHandlerInspection.class);
    myFixture.copyFileToProject(myTestFolder + "/OnClickActivity.java", "src/p1/p2/Activity1.java");
    VirtualFile file = copyFileToProject("onClickIntention.xml");
    myFixture.configureFromExistingVirtualFile(file);
    List<IntentionAction> fixes = highlightAndFindQuickFixes(AndroidMissingOnClickHandlerInspection.MyQuickFix.class);
    assertEmpty(fixes);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AndroidMissingOnClickHandlerInspection(org.jetbrains.android.inspections.AndroidMissingOnClickHandlerInspection)

Example 69 with IntentionAction

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

the class RegisterExtensionFixProvider method getQuickFixes.

@NotNull
@Override
public IntentionAction[] getQuickFixes(@NotNull PsiElement element) {
    if (!(element instanceof PsiIdentifier))
        return IntentionAction.EMPTY_ARRAY;
    PsiElement parent = element.getParent();
    if (!(parent instanceof PsiClass))
        return IntentionAction.EMPTY_ARRAY;
    PsiClass psiClass = (PsiClass) parent;
    if (InheritanceUtil.isInheritor(psiClass, LocalInspectionTool.class.getName())) {
        return new IntentionAction[] { new RegisterInspectionFix(psiClass, LocalInspectionEP.LOCAL_INSPECTION) };
    }
    if (InheritanceUtil.isInheritor(psiClass, GlobalInspectionTool.class.getName())) {
        return new IntentionAction[] { new RegisterInspectionFix(psiClass, InspectionEP.GLOBAL_INSPECTION) };
    }
    ExtensionPointLocator extensionPointLocator = new ExtensionPointLocator(psiClass);
    List<ExtensionPointCandidate> candidateList = extensionPointLocator.findSuperCandidates();
    if (!candidateList.isEmpty()) {
        return new IntentionAction[] { new RegisterExtensionFix(psiClass, candidateList) };
    }
    return IntentionAction.EMPTY_ARRAY;
}
Also used : GlobalInspectionTool(com.intellij.codeInspection.GlobalInspectionTool) ExtensionPointLocator(org.jetbrains.idea.devkit.util.ExtensionPointLocator) ExtensionPointCandidate(org.jetbrains.idea.devkit.util.ExtensionPointCandidate) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) PsiIdentifier(com.intellij.psi.PsiIdentifier) PsiClass(com.intellij.psi.PsiClass) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with IntentionAction

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

the class CreateClassFixTest method runSingle.

@Test
public void runSingle() throws Throwable {
    invokeTestRunnable(() -> {
        IntentionAction resultAction = null;
        final String createAction = QuickFixBundle.message(myCreateClass ? "create.class.text" : "create.interface.text", myTestName);
        final List<IntentionAction> actions = myFixture.getAvailableIntentions(getSourceRoot() + "/plugin" + myTestName + ".xml");
        for (IntentionAction action : actions) {
            if (Comparing.strEqual(action.getText(), createAction)) {
                resultAction = action;
                break;
            }
        }
        Assert.assertNotNull(resultAction);
        myFixture.launchAction(resultAction);
        final Project project = myFixture.getProject();
        Assert.assertNotNull(JavaPsiFacade.getInstance(project).findClass(myTestName, GlobalSearchScope.allScope(project)));
    });
}
Also used : Project(com.intellij.openapi.project.Project) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) Test(org.junit.Test)

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