Search in sources :

Example 1 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project qi4j-sdk by Qi4j.

the class InvocationAnnotationDeclaredCorrectlyInspection method verifyAnnotationDeclaredCorrectly.

@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly(@NotNull PsiVariable psiVariable, @NotNull PsiAnnotation invocationAnnotation, @NotNull InspectionManager manager) {
    LocalQuickFix fix = null;
    String message = null;
    String variableTypeQualifiedName = psiVariable.getType().getCanonicalText();
    InvocationAnnotationDeclarationValidationResult validationResult = isValidInvocationAnnotationDeclaration(psiVariable);
    switch(validationResult) {
        case invalidTypeIsInjectedViaStructureAnnotation:
            if (getStructureAnnotation(psiVariable) == null) {
                fix = new ReplaceWithStructureAnnotation(message("injections.invocation.annotation.declared.correctly.fix.replace.with.structure.annotation"), invocationAnnotation);
            }
            message = message("injections.invocation.annotation.declared.correctly.error.type.is.injected.by.structure", variableTypeQualifiedName);
            break;
        case invalidType:
            message = message("injections.invocation.annotation.declared.correctly.error.type.is.not.injectable", variableTypeQualifiedName);
            break;
    }
    // If it's not an error, return null
    if (message == null) {
        return null;
    }
    // If Fix not defined, by default we remove it.
    if (fix == null) {
        fix = createRemoveAnnotationFix(invocationAnnotation);
    }
    ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(invocationAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
    return new ProblemDescriptor[] { problemDescriptor };
}
Also used : InvocationAnnotationDeclarationValidationResult(org.qi4j.ide.plugin.idea.injections.invocation.common.Qi4jInvocationAnnotationUtil.InvocationAnnotationDeclarationValidationResult) ReplaceWithStructureAnnotation(org.qi4j.ide.plugin.idea.injections.structure.common.ReplaceWithStructureAnnotation) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project qi4j-sdk by Qi4j.

the class ServiceAnnotationDeclaredCorrectlyInspection method verifyAnnotationDeclaredCorrectly.

@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly(@NotNull PsiVariable psiVariable, @NotNull PsiAnnotation serviceAnnotation, @NotNull InspectionManager manager) {
    ServiceAnnotationDeclarationValidationResult annotationCheck = isValidServiceAnnotationDeclaration(psiVariable);
    String message = null;
    LocalQuickFix fix = null;
    switch(annotationCheck) {
        case invalidTypeIsInjectedViaStructureAnnotation:
            if (getStructureAnnotation(psiVariable) == null) {
                fix = new ReplaceWithStructureAnnotation(message("injections.service.annotation.declared.correctly.fix.replace.with.structure.annotation"), serviceAnnotation);
            }
            message = message("injections.service.annotation.declared.correctly.error.type.is.injected.by.structure", psiVariable.getType().getCanonicalText());
            break;
    }
    // If it's not an error, return null
    if (message == null) {
        return null;
    }
    // Default behavior to remove @Service annotation
    if (fix == null) {
        fix = createRemoveAnnotationFix(serviceAnnotation);
    }
    ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(serviceAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
    return new ProblemDescriptor[] { problemDescriptor };
}
Also used : ReplaceWithStructureAnnotation(org.qi4j.ide.plugin.idea.injections.structure.common.ReplaceWithStructureAnnotation) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) ServiceAnnotationDeclarationValidationResult(org.qi4j.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with LocalQuickFix

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

the class PyTestCase method findQuickFixByClassInIntentions.

/**
   * Searches for quickfix itetion by its class
   *
   * @param clazz quick fix class
   * @param <T>   quick fix class
   * @return quick fix or null if nothing found
   */
@Nullable
public <T extends LocalQuickFix> T findQuickFixByClassInIntentions(@NotNull final Class<T> clazz) {
    for (final IntentionAction action : myFixture.getAvailableIntentions()) {
        if ((action instanceof QuickFixWrapper)) {
            final QuickFixWrapper quickFixWrapper = (QuickFixWrapper) action;
            final LocalQuickFix fix = quickFixWrapper.getFix();
            if (clazz.isInstance(fix)) {
                @SuppressWarnings("unchecked") final T result = (T) fix;
                return result;
            }
        }
    }
    return null;
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LocalQuickFix

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

the class SpellingPopupActionGroup method extractActions.

private static void extractActions(List<HighlightInfo.IntentionActionDescriptor> descriptors, Map<Anchor, List<AnAction>> actions) {
    for (HighlightInfo.IntentionActionDescriptor actionDescriptor : descriptors) {
        IntentionAction action = actionDescriptor.getAction();
        if (action instanceof QuickFixWrapper) {
            QuickFixWrapper wrapper = (QuickFixWrapper) action;
            LocalQuickFix localQuickFix = wrapper.getFix();
            if (localQuickFix instanceof SpellCheckerQuickFix) {
                SpellCheckerQuickFix spellCheckerQuickFix = (SpellCheckerQuickFix) localQuickFix;
                Anchor anchor = spellCheckerQuickFix.getPopupActionAnchor();
                SpellCheckerIntentionAction popupAction = new SpellCheckerIntentionAction(action);
                List<AnAction> list = actions.get(anchor);
                if (list != null) {
                    list.add(popupAction);
                }
            }
        }
    }
}
Also used : SpellCheckerQuickFix(com.intellij.spellchecker.quickfixes.SpellCheckerQuickFix) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper)

Example 5 with LocalQuickFix

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

the class HtmlUnknownBooleanAttributeInspectionBase method checkAttribute.

@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    if (attribute.getValueElement() == null) {
        final XmlTag tag = attribute.getParent();
        if (tag instanceof HtmlTag) {
            XmlElementDescriptor elementDescriptor = tag.getDescriptor();
            if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
                return;
            }
            XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
            if (attributeDescriptor != null && !(attributeDescriptor instanceof AnyXmlAttributeDescriptor)) {
                String name = attribute.getName();
                if (!HtmlUtil.isBooleanAttribute(attributeDescriptor, null) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
                    final boolean html5 = HtmlUtil.isHtml5Context(tag);
                    LocalQuickFix[] quickFixes = !html5 ? new LocalQuickFix[] { new AddCustomHtmlElementIntentionAction(BOOLEAN_ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.boolean.attribute", name)), XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute), new RemoveAttributeIntentionAction(name) } : new LocalQuickFix[] { XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute) };
                    String error = null;
                    if (html5) {
                        if (attributeDescriptor instanceof XmlEnumerationDescriptor && ((XmlEnumerationDescriptor) attributeDescriptor).getValueDeclaration(attribute, "") == null) {
                            error = XmlErrorMessages.message("wrong.value", "attribute");
                        }
                    } else {
                        error = XmlErrorMessages.message("attribute.is.not.boolean", attribute.getName());
                    }
                    if (error != null) {
                        registerProblemOnAttributeName(attribute, error, holder, quickFixes);
                    }
                }
            }
        }
    }
}
Also used : AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) HtmlTag(com.intellij.psi.html.HtmlTag) XmlEnumerationDescriptor(com.intellij.xml.impl.XmlEnumerationDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

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