Search in sources :

Example 56 with LocalQuickFix

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

the class HtmlUnknownAttributeInspectionBase method checkAttribute.

@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    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 && !attribute.isNamespaceDeclaration()) {
            final String name = attribute.getName();
            if (!XmlUtil.attributeFromTemplateFramework(name, tag) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
                boolean maySwitchToHtml5 = HtmlUtil.isCustomHtml5Attribute(name) && !HtmlUtil.hasNonHtml5Doctype(tag);
                LocalQuickFix[] quickfixes = new LocalQuickFix[maySwitchToHtml5 ? 3 : 2];
                quickfixes[0] = new AddCustomHtmlElementIntentionAction(ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.attribute", name));
                quickfixes[1] = new RemoveAttributeIntentionAction(name);
                if (maySwitchToHtml5) {
                    quickfixes[2] = new SwitchToHtml5WithHighPriorityAction();
                }
                registerProblemOnAttributeName(attribute, XmlErrorMessages.message("attribute.is.not.allowed.here", attribute.getName()), holder, quickfixes);
            }
        }
    }
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) HtmlTag(com.intellij.psi.html.HtmlTag) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 57 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project android by JetBrains.

the class ResourceReferenceConverter method getQuickFixes.

@Override
public LocalQuickFix[] getQuickFixes(ConvertContext context) {
    AndroidFacet facet = AndroidFacet.getInstance(context);
    if (facet != null) {
        final DomElement domElement = context.getInvocationElement();
        if (domElement instanceof GenericDomValue) {
            final String value = ((GenericDomValue) domElement).getStringValue();
            if (value != null) {
                ResourceValue resourceValue = ResourceValue.parse(value, false, myWithPrefix, true);
                if (resourceValue != null) {
                    String aPackage = resourceValue.getNamespace();
                    ResourceType resType = resourceValue.getType();
                    if (resType == null && myResourceTypes.size() == 1) {
                        resType = myResourceTypes.iterator().next();
                    }
                    final String resourceName = resourceValue.getResourceName();
                    if (aPackage == null && resType != null && resourceName != null && AndroidResourceUtil.isCorrectAndroidResourceName(resourceName)) {
                        final List<LocalQuickFix> fixes = new ArrayList<>();
                        ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(resType);
                        if (folderType != null) {
                            fixes.add(new CreateFileResourceQuickFix(facet, folderType, resourceName, context.getFile(), false));
                        }
                        if (VALUE_RESOURCE_TYPES.contains(resType) && resType != ResourceType.LAYOUT) {
                            // layouts: aliases only
                            fixes.add(new CreateValueResourceQuickFix(facet, resType, resourceName, context.getFile(), false));
                        }
                        return fixes.toArray(new LocalQuickFix[fixes.size()]);
                    }
                }
            }
        }
    }
    return LocalQuickFix.EMPTY_ARRAY;
}
Also used : CreateValueResourceQuickFix(org.jetbrains.android.inspections.CreateValueResourceQuickFix) ResourceFolderType(com.android.resources.ResourceFolderType) ResourceValue(org.jetbrains.android.dom.resources.ResourceValue) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) ResourceType(com.android.resources.ResourceType) AndroidResourceType(org.jetbrains.android.dom.AndroidResourceType) CreateFileResourceQuickFix(org.jetbrains.android.inspections.CreateFileResourceQuickFix) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 58 with LocalQuickFix

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

the class FlexUnitMethodReturnTypeInspection method visitPotentialTestMethod.

protected void visitPotentialTestMethod(JSFunction method, ProblemsHolder holder, FlexUnitSupport support) {
    if (FlexUnitSupport.getCustomRunner((JSClass) method.getParent()) != null)
        return;
    if (method.getKind() != JSFunction.FunctionKind.SIMPLE)
        return;
    if (support.isFlexUnit1Subclass((JSClass) method.getParent()) || support.isFlunitSubclass((JSClass) method.getParent())) {
        return;
    }
    final JSType returnType = method.getReturnType();
    if (returnType != null && !(returnType instanceof JSVoidType)) {
        final ASTNode nameIdentifier = method.findNameIdentifier();
        if (nameIdentifier != null) {
            LocalQuickFix[] fix = canFix(method) ? new LocalQuickFix[] { new ChangeTypeFix(method, "void", "javascript.fix.set.method.return.type") } : LocalQuickFix.EMPTY_ARRAY;
            holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("flexunit.inspection.testmethodreturntype.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
        }
    }
}
Also used : ChangeTypeFix(com.intellij.lang.javascript.validation.fixes.ChangeTypeFix) JSType(com.intellij.lang.javascript.psi.JSType) ASTNode(com.intellij.lang.ASTNode) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSVoidType(com.intellij.lang.javascript.psi.types.primitives.JSVoidType)

Example 59 with LocalQuickFix

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

the class ActionMethodConverter method getQuickFixes.

public LocalQuickFix[] getQuickFixes(final ConvertContext context) {
    final Action action = getActionElement(context);
    final String methodName = action.getMethod().getStringValue();
    final PsiClass actionClass = action.searchActionClass();
    return new LocalQuickFix[] { new CreateActionMethodQuickFix(actionClass, methodName) };
}
Also used : PsiClass(com.intellij.psi.PsiClass) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix)

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