Search in sources :

Example 41 with ProblemDescriptor

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

the class AbstractInjectionAnnotationDeclarationOnFieldAndConstructorInspection method checkMethod.

@Override
public final ProblemDescriptor[] checkMethod(@NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
    PsiParameterList parameterList = method.getParameterList();
    PsiParameter[] parameters = parameterList.getParameters();
    if (method.isConstructor()) {
        List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
        for (PsiParameter parameter : parameters) {
            PsiAnnotation annotation = getAnnotationToCheck(parameter);
            if (annotation != null) {
                ProblemDescriptor[] descriptors = verifyAnnotationDeclaredCorrectly(parameter, annotation, manager);
                if (descriptors != null) {
                    problems.addAll(asList(descriptors));
                }
            }
        }
        return problems.toArray(new ProblemDescriptor[problems.size()]);
    } else {
        List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
        for (PsiParameter parameter : parameters) {
            PsiAnnotation annotationToCheck = getAnnotationToCheck(parameter);
            if (annotationToCheck != null) {
                String message = getInjectionAnnotationValidDeclarationMessage();
                AbstractFix removeAnnotationFix = createRemoveAnnotationFix(annotationToCheck);
                ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(annotationToCheck, message, removeAnnotationFix, GENERIC_ERROR_OR_WARNING);
                problems.add(problemDescriptor);
            }
        }
        return problems.toArray(new ProblemDescriptor[problems.size()]);
    }
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) AbstractFix(org.qi4j.ide.plugin.idea.common.inspections.AbstractFix) PsiParameterList(com.intellij.psi.PsiParameterList) PsiAnnotation(com.intellij.psi.PsiAnnotation) LinkedList(java.util.LinkedList)

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