Search in sources :

Example 11 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.

the class DefinitionReference method getQuickFixes.

@Override
public LocalQuickFix[] getQuickFixes() {
    final XmlTag tag = PsiTreeUtil.getParentOfType(getElement(), XmlTag.class);
    assert tag != null;
    final RngGrammar scope = myValue.getParentOfType(RngGrammar.class, true);
    if (scope != null) {
        return new LocalQuickFix[] { new CreatePatternFix(this) };
    }
    return LocalQuickFix.EMPTY_ARRAY;
}
Also used : LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) XmlTag(com.intellij.psi.xml.XmlTag) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar)

Example 12 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.

the class AbstractFix method createQuickFix.

@Nullable
public LocalQuickFix createQuickFix(boolean isOnTheFly) {
    final boolean requiresEditor = requiresEditor();
    if (requiresEditor && !isOnTheFly)
        return null;
    return new LocalQuickFix() {

        @NotNull
        public String getName() {
            return AbstractFix.this.getText();
        }

        @NotNull
        public String getFamilyName() {
            return AbstractFix.this.getFamilyName();
        }

        public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
            Editor editor;
            if (requiresEditor) {
                final DataContext dataContext = DataManager.getInstance().getDataContext();
                editor = CommonDataKeys.EDITOR.getData(dataContext);
                if (editor == null) {
                    if ((editor = FileEditorManager.getInstance(project).getSelectedTextEditor()) == null) {
                        return;
                    }
                }
            } else {
                editor = null;
            }
            final PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
            if (!isAvailable(project, editor, psiFile)) {
                return;
            }
            invoke(project, editor, psiFile);
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.

the class IntentionListStep method getWeight.

private int getWeight(IntentionActionWithTextCaching action) {
    IntentionAction a = action.getAction();
    int group = getGroup(action);
    if (a instanceof IntentionActionWrapper) {
        a = ((IntentionActionWrapper) a).getDelegate();
    }
    if (a instanceof IntentionWrapper) {
        a = ((IntentionWrapper) a).getAction();
    }
    if (a instanceof HighPriorityAction) {
        return group + 3;
    }
    if (a instanceof LowPriorityAction) {
        return group - 3;
    }
    if (a instanceof SuppressIntentionActionFromFix) {
        if (((SuppressIntentionActionFromFix) a).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
            return group - 1;
        }
    }
    if (a instanceof QuickFixWrapper) {
        final LocalQuickFix quickFix = ((QuickFixWrapper) a).getFix();
        if (quickFix instanceof HighPriorityAction) {
            return group + 3;
        }
        if (quickFix instanceof LowPriorityAction) {
            return group - 3;
        }
    }
    return group;
}
Also used : SuppressIntentionActionFromFix(com.intellij.codeInspection.SuppressIntentionActionFromFix) IntentionWrapper(com.intellij.codeInspection.IntentionWrapper) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) IntentionActionWrapper(com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper)

Example 14 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.

the class QuickFixWrapper method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    //if (!CodeInsightUtil.prepareFileForWrite(file)) return;
    // consider all local quick fixes do it themselves
    final PsiElement element = myDescriptor.getPsiElement();
    final PsiFile fileForUndo = element == null ? null : element.getContainingFile();
    LocalQuickFix fix = getFix();
    fix.applyFix(project, myDescriptor);
    DaemonCodeAnalyzer.getInstance(project).restart();
    if (fileForUndo != null && !fileForUndo.equals(file)) {
        UndoUtil.markPsiFileForUndo(fileForUndo);
    }
}
Also used : LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 15 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.

the class QuickFixWrapper method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    PsiElement psiElement = myDescriptor.getPsiElement();
    if (psiElement == null || !psiElement.isValid())
        return false;
    final LocalQuickFix fix = getFix();
    return !(fix instanceof IntentionAction) || ((IntentionAction) fix).isAvailable(project, editor, file);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)59 NotNull (org.jetbrains.annotations.NotNull)20 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)11 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)10 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)10 ASTNode (com.intellij.lang.ASTNode)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 XmlTag (com.intellij.psi.xml.XmlTag)6 PsiFile (com.intellij.psi.PsiFile)5 PsiReference (com.intellij.psi.PsiReference)5 ArrayList (java.util.ArrayList)5 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)4 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)3 QuickFixWrapper (com.intellij.codeInspection.ex.QuickFixWrapper)3 Pair (com.intellij.openapi.util.Pair)3 TextRange (com.intellij.openapi.util.TextRange)3 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3