Search in sources :

Example 76 with IntentionAction

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

the class RegisterExtensionFixProviderTest method testCreateExtensionPointMappingNoPluginId.

public void testCreateExtensionPointMappingNoPluginId() {
    myFixture.testHighlighting("MyExtensionPoint.java", "extensionPointNoPluginId.xml", "ExtensionPoint.java");
    IntentionAction intention = myFixture.findSingleIntention("Register extension");
    myFixture.launchAction(intention);
    myFixture.checkResultByFile("extensionPointNoPluginId.xml", "extensionPointNoPluginId_after.xml", true);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 77 with IntentionAction

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

the class RegisterExtensionFixProviderTest method testCreateExtensionPointQualifiedNameMapping.

public void testCreateExtensionPointQualifiedNameMapping() {
    myFixture.testHighlighting("MyExtensionPoint.java", "extensionPointQualifiedName.xml", "ExtensionPoint.java");
    IntentionAction intention = myFixture.findSingleIntention("Register extension");
    myFixture.launchAction(intention);
    myFixture.checkResultByFile("extensionPointQualifiedName.xml", "extensionPointQualifiedName_after.xml", true);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 78 with IntentionAction

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

the class UnsafeReturnStatementVisitorTest method testInsertVisitLambda.

public void testInsertVisitLambda() {
    myFixture.addClass("package com.intellij.psi;\n" + "public interface PsiLambdaExpression{}");
    myFixture.addClass("package com.intellij.psi;\n" + "public abstract class JavaRecursiveElementVisitor{}");
    myFixture.addClass("package com.intellij.psi;\n" + "public interface PsiReturnStatement{}");
    myFixture.addClass("package com.intellij.psi;\n" + "public interface PsiClass{}");
    myFixture.configureByText(JavaFileType.INSTANCE, "import com.intellij.psi.*;\n" + "class Te<caret>st extends JavaRecursiveElementVisitor {\n" + "   public void visitReturnStatement(PsiReturnStatement statement) {}\n" + "   public void visitClass(PsiClass aClass) {}\n" + "}");
    IntentionAction intention = myFixture.findSingleIntention("Insert visitLambdaExpression method");
    myFixture.launchAction(intention);
    myFixture.checkResult("import com.intellij.psi.*;\n" + "class Test extends JavaRecursiveElementVisitor {\n" + "   public void visitReturnStatement(PsiReturnStatement statement) {}\n" + "   public void visitClass(PsiClass aClass) {}\n" + "\n" + "    public void visitLambdaExpression(PsiLambdaExpression expression) {\n" + "    }\n" + "}");
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 79 with IntentionAction

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

the class LocalInspectionsPass method registerQuickFixes.

private static void registerQuickFixes(@NotNull LocalInspectionToolWrapper tool, @NotNull ProblemDescriptor descriptor, @NotNull HighlightInfo highlightInfo, @NotNull Set<Pair<TextRange, String>> emptyActionRegistered) {
    final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
    boolean needEmptyAction = true;
    final QuickFix[] fixes = descriptor.getFixes();
    if (fixes != null && fixes.length > 0) {
        for (int k = 0; k < fixes.length; k++) {
            if (fixes[k] != null) {
                // prevent null fixes from var args
                QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixWrapper.wrap(descriptor, k), key);
                needEmptyAction = false;
            }
        }
    }
    HintAction hintAction = descriptor instanceof ProblemDescriptorImpl ? ((ProblemDescriptorImpl) descriptor).getHintAction() : null;
    if (hintAction != null) {
        QuickFixAction.registerQuickFixAction(highlightInfo, hintAction, key);
        needEmptyAction = false;
    }
    if (((ProblemDescriptorBase) descriptor).getEnforcedTextAttributes() != null) {
        needEmptyAction = false;
    }
    if (needEmptyAction && emptyActionRegistered.add(Pair.create(highlightInfo.getFixTextRange(), tool.getShortName()))) {
        IntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName());
        QuickFixAction.registerQuickFixAction(highlightInfo, emptyIntentionAction, key);
    }
}
Also used : HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) EmptyIntentionAction(com.intellij.codeInsight.intention.EmptyIntentionAction) EmptyIntentionAction(com.intellij.codeInsight.intention.EmptyIntentionAction)

Example 80 with IntentionAction

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

the class GutterIntentionAction method addActions.

private static void addActions(@NotNull Project project, @NotNull RangeHighlighterEx info, @NotNull List<HighlightInfo.IntentionActionDescriptor> descriptors, @NotNull AnActionEvent event) {
    final GutterIconRenderer r = info.getGutterIconRenderer();
    if (r == null || DumbService.isDumb(project) && !DumbService.isDumbAware(r)) {
        return;
    }
    List<HighlightInfo.IntentionActionDescriptor> list = new ArrayList<>();
    for (AnAction action : ar(r.getClickAction(), r.getMiddleButtonClickAction(), r.getRightButtonClickAction(), r.getPopupMenuActions())) {
        if (action != null) {
            addActions(action, list, r, 0, event);
        }
    }
    if (list.isEmpty())
        return;
    if (list.size() == 1) {
        descriptors.addAll(list);
    } else {
        HighlightInfo.IntentionActionDescriptor first = list.get(0);
        List<IntentionAction> options = ContainerUtil.map(list.subList(1, list.size()), HighlightInfo.IntentionActionDescriptor::getAction);
        descriptors.add(new HighlightInfo.IntentionActionDescriptor(first.getAction(), options, null, first.getIcon()));
    }
}
Also used : AbstractIntentionAction(com.intellij.codeInsight.intention.AbstractIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) ArrayList(java.util.ArrayList) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

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