Search in sources :

Example 36 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoImportReference method getQuickFixes.

@Override
public LocalQuickFix[] getQuickFixes() {
    if (GoPackageUtil.isBuiltinPackage(resolve())) {
        return new LocalQuickFix[] { new GoDeleteImportQuickFix() };
    }
    List<LocalQuickFix> result = ContainerUtil.newArrayList();
    FileReferenceSet fileReferenceSet = getFileReferenceSet();
    if (fileReferenceSet instanceof GoImportReferenceSet && !((GoImportReferenceSet) fileReferenceSet).isRelativeImport() && !fileReferenceSet.isAbsolutePathReference()) {
        result.add(new GoGetPackageFix(fileReferenceSet.getPathString()));
    }
    String fileNameToCreate = getFileNameToCreate();
    for (PsiFileSystemItem context : getContexts()) {
        if (context instanceof PsiDirectory) {
            try {
                ((PsiDirectory) context).checkCreateSubdirectory(fileNameToCreate);
                String targetPath = context.getVirtualFile().getPath();
                result.add(new CreateFileFix(true, fileNameToCreate, (PsiDirectory) context) {

                    @NotNull
                    @Override
                    public String getText() {
                        return "Create Directory " + fileNameToCreate + " at " + targetPath;
                    }
                });
            } catch (IncorrectOperationException ignore) {
            }
        }
    }
    return result.toArray(new LocalQuickFix[result.size()]);
}
Also used : GoDeleteImportQuickFix(com.goide.quickfix.GoDeleteImportQuickFix) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) NotNull(org.jetbrains.annotations.NotNull) CreateFileFix(com.intellij.codeInsight.daemon.quickFix.CreateFileFix) IncorrectOperationException(com.intellij.util.IncorrectOperationException) GoGetPackageFix(com.goide.codeInsight.imports.GoGetPackageFix)

Example 37 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 38 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 39 with LocalQuickFix

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

the class AntResolveInspection method checkReferences.

private static void checkReferences(final XmlElement xmlElement, @NonNls final DomElementAnnotationHolder holder, DomElement domElement) {
    if (xmlElement == null) {
        return;
    }
    Set<PsiReference> processed = null;
    // to be initialized lazily
    Collection<PropertiesFile> propertyFiles = null;
    for (final PsiReference ref : xmlElement.getReferences()) {
        if (!(ref instanceof AntDomReference)) {
            continue;
        }
        final AntDomReference antDomRef = (AntDomReference) ref;
        if (antDomRef.shouldBeSkippedByAnnotator()) {
            continue;
        }
        if (processed != null && processed.contains(ref)) {
            continue;
        }
        if (!isResolvable(ref)) {
            final List<LocalQuickFix> quickFixList = new SmartList<>();
            quickFixList.add(new AntChangeContextLocalFix());
            if (ref instanceof AntDomPropertyReference) {
                final String canonicalText = ref.getCanonicalText();
                quickFixList.add(new AntCreatePropertyFix(canonicalText, null));
                final PsiFile containingFile = xmlElement.getContainingFile();
                if (containingFile != null) {
                    if (propertyFiles == null) {
                        propertyFiles = getPropertyFiles(AntSupport.getAntDomProject(containingFile), xmlElement);
                    }
                    for (PropertiesFile propertyFile : propertyFiles) {
                        quickFixList.add(new AntCreatePropertyFix(canonicalText, propertyFile));
                    }
                }
            } else if (ref instanceof AntDomTargetReference) {
                quickFixList.add(new AntCreateTargetFix(ref.getCanonicalText()));
            }
            holder.createProblem(domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement(), quickFixList.toArray((new LocalQuickFix[quickFixList.size()])));
            if (ref instanceof AntDomFileReference) {
                if (processed == null) {
                    processed = new HashSet<>();
                }
                ContainerUtil.addAll(processed, ((AntDomFileReference) ref).getFileReferenceSet().getAllReferences());
            }
        }
    }
}
Also used : AntCreateTargetFix(com.intellij.lang.ant.quickfix.AntCreateTargetFix) AntChangeContextLocalFix(com.intellij.lang.ant.quickfix.AntChangeContextLocalFix) AntCreatePropertyFix(com.intellij.lang.ant.quickfix.AntCreatePropertyFix) PsiReference(com.intellij.psi.PsiReference) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFile(com.intellij.psi.PsiFile) SmartList(com.intellij.util.SmartList)

Example 40 with LocalQuickFix

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

the class ComponentNotRegisteredInspection method checkClass.

@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass checkedClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    PsiFile psiFile = checkedClass.getContainingFile();
    PsiIdentifier classIdentifier = checkedClass.getNameIdentifier();
    if (checkedClass.getQualifiedName() != null && classIdentifier != null && psiFile != null && psiFile.getVirtualFile() != null && !checkedClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
        if (PsiUtil.isInnerClass(checkedClass)) {
            // don't check inner classes (make this an option?)
            return null;
        }
        PsiManager psiManager = checkedClass.getManager();
        GlobalSearchScope scope = checkedClass.getResolveScope();
        if (CHECK_ACTIONS) {
            PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope);
            if (actionClass == null) {
                // stop if action class cannot be found (non-devkit module/project)
                return null;
            }
            if (checkedClass.isInheritor(actionClass, true)) {
                if (IGNORE_NON_PUBLIC && !checkedClass.hasModifierProperty(PsiModifier.PUBLIC)) {
                    return null;
                }
                if (!isActionRegistered(checkedClass) && canFix(checkedClass)) {
                    LocalQuickFix fix = new RegisterActionFix(org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
                    ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message("new.menu.action.text")), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
                    return new ProblemDescriptor[] { problem };
                } else {
                    // action IS registered, stop here
                    return null;
                }
            }
        }
        ComponentType[] types = ComponentType.values();
        for (ComponentType type : types) {
            PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope);
            if (compClass == null) {
                // stop if component classes cannot be found (non-devkit module/project)
                return null;
            }
            if (checkedClass.isInheritor(compClass, true)) {
                if (RegistrationCheckerUtil.getRegistrationTypes(checkedClass, false) == null && canFix(checkedClass)) {
                    LocalQuickFix fix = new RegisterComponentFix(type, org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
                    ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message(type.myPropertyKey)), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
                    return new ProblemDescriptor[] { problem };
                } else {
                    // component IS registered, stop here
                    return null;
                }
            }
        }
    }
    return null;
}
Also used : ComponentType(org.jetbrains.idea.devkit.util.ComponentType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) AnAction(com.intellij.openapi.actionSystem.AnAction) RegisterActionFix(org.jetbrains.idea.devkit.inspections.quickfix.RegisterActionFix) RegisterComponentFix(org.jetbrains.idea.devkit.inspections.quickfix.RegisterComponentFix) Nullable(org.jetbrains.annotations.Nullable)

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