Search in sources :

Example 11 with ProblemDescriptor

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

the class HardwiredNamespacePrefix method createVisitor.

protected Visitor createVisitor(final InspectionManager manager, final boolean isOnTheFly) {
    return new Visitor(manager, isOnTheFly) {

        protected void checkExpression(XPathExpression expression) {
            if (!(expression instanceof XPathBinaryExpression)) {
                return;
            }
            final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
            if (expr.getOperator() == XPathTokenTypes.EQ) {
                final XPathExpression lop = expr.getLOperand();
                final XPathExpression rop = expr.getROperand();
                if (isNameComparison(lop, rop)) {
                    assert rop != null;
                    final ProblemDescriptor p = manager.createProblemDescriptor(rop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                    addProblem(p);
                } else if (isNameComparison(rop, lop)) {
                    assert lop != null;
                    final ProblemDescriptor p = manager.createProblemDescriptor(lop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                    addProblem(p);
                } else if (isNameFunctionCall(lop)) {
                // TODO
                } else if (isNameFunctionCall(rop)) {
                // TODO
                }
            }
        }
    };
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathBinaryExpression(org.intellij.lang.xpath.psi.XPathBinaryExpression) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor)

Example 12 with ProblemDescriptor

use of com.intellij.codeInspection.ProblemDescriptor 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 ProblemDescriptor

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

the class BuildoutUnresolvedPartInspection method checkFile.

@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    List<ProblemDescriptor> problems = Lists.newArrayList();
    if (file.getFileType().equals(BuildoutCfgFileType.INSTANCE)) {
        Visitor visitor = new Visitor();
        file.accept(visitor);
        for (BuildoutPartReference ref : visitor.getUnresolvedParts()) {
            ProblemDescriptor d = manager.createProblemDescriptor(ref.getElement(), ref.getRangeInElement(), PyBundle.message("buildout.unresolved.part.inspection.msg"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
            problems.add(d);
        }
    }
    return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) BuildoutPartReference(com.jetbrains.python.buildout.config.ref.BuildoutPartReference)

Example 14 with ProblemDescriptor

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

the class PyRemoveParameterQuickFix method applyFix.

public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement parameter = descriptor.getPsiElement();
    assert parameter instanceof PyParameter;
    final PyFunction function = PsiTreeUtil.getParentOfType(parameter, PyFunction.class);
    if (function != null) {
        final PyResolveContext resolveContext = PyResolveContext.noImplicits();
        StreamEx.of(PyRefactoringUtil.findUsages(function, false)).map(UsageInfo::getElement).nonNull().map(PsiElement::getParent).select(PyCallExpression.class).flatMap(callExpression -> callExpression.multiMapArguments(resolveContext).stream()).flatMap(mapping -> mapping.getMappedParameters().entrySet().stream()).filter(entry -> entry.getValue() == parameter).forEach(entry -> entry.getKey().delete());
        final PyStringLiteralExpression docStringExpression = function.getDocStringExpression();
        final String parameterName = ((PyParameter) parameter).getName();
        if (docStringExpression != null && parameterName != null) {
            PyDocstringGenerator.forDocStringOwner(function).withoutParam(parameterName).buildAndInsert();
        }
    }
    parameter.delete();
}
Also used : PyBundle(com.jetbrains.python.PyBundle) PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression) UsageInfo(com.intellij.usageView.UsageInfo) PyParameter(com.jetbrains.python.psi.PyParameter) PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) PyRefactoringUtil(com.jetbrains.python.refactoring.PyRefactoringUtil) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PyCallExpression(com.jetbrains.python.psi.PyCallExpression) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) StreamEx(one.util.streamex.StreamEx) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PyDocstringGenerator(com.jetbrains.python.documentation.docstrings.PyDocstringGenerator) NotNull(org.jetbrains.annotations.NotNull) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PyFunction(com.jetbrains.python.psi.PyFunction) PyFunction(com.jetbrains.python.psi.PyFunction) PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression) PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) PsiElement(com.intellij.psi.PsiElement) PyParameter(com.jetbrains.python.psi.PyParameter)

Example 15 with ProblemDescriptor

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

the class InspectionDescriptionNotFoundInspection method checkClass.

@Override
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    final Project project = psiClass.getProject();
    final PsiIdentifier nameIdentifier = psiClass.getNameIdentifier();
    final Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);
    if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(psiClass))
        return null;
    final PsiClass base = JavaPsiFacade.getInstance(project).findClass(INSPECTION_PROFILE_ENTRY, psiClass.getResolveScope());
    if (base == null || !psiClass.isInheritor(base, true) || isPathMethodsAreOverridden(psiClass))
        return null;
    final InspectionDescriptionInfo info = InspectionDescriptionInfo.create(module, psiClass);
    if (!info.isValid() || info.hasDescriptionFile())
        return null;
    final PsiElement problemElement = getProblemElement(psiClass, info.getShortNameMethod());
    final ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(problemElement == null ? nameIdentifier : problemElement, "Inspection does not have a description", isOnTheFly, new LocalQuickFix[] { new CreateHtmlDescriptionFix(info.getFilename(), module, DescriptionType.INSPECTION) }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    return new ProblemDescriptor[] { problemDescriptor };
}
Also used : Project(com.intellij.openapi.project.Project) CreateHtmlDescriptionFix(org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) Module(com.intellij.openapi.module.Module)

Aggregations

ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)41 Project (com.intellij.openapi.project.Project)15 NotNull (org.jetbrains.annotations.NotNull)13 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)11 PsiElement (com.intellij.psi.PsiElement)11 Nullable (org.jetbrains.annotations.Nullable)8 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)5 PsiAnnotation (com.intellij.psi.PsiAnnotation)5 LinkedList (java.util.LinkedList)5 InspectionManager (com.intellij.codeInspection.InspectionManager)4 PsiFile (com.intellij.psi.PsiFile)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 QuickFix (com.intellij.codeInspection.QuickFix)3 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)3 PsiClass (com.intellij.psi.PsiClass)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 GroovyFix (org.jetbrains.plugins.groovy.codeInspection.GroovyFix)3 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)2 ASTNode (com.intellij.lang.ASTNode)2 Editor (com.intellij.openapi.editor.Editor)2