Search in sources :

Example 1 with AbstractFix

use of org.qi4j.ide.plugin.idea.common.inspections.AbstractFix in project qi4j-sdk by Qi4j.

the class AbstractInjectionAnnotationDeclarationOnFieldInspection method checkField.

@Override
public final ProblemDescriptor[] checkField(@NotNull PsiField field, @NotNull InspectionManager manager, boolean isOnTheFly) {
    PsiAnnotation annotationToCheck = getAnnotationToCheck(field);
    if (annotationToCheck == null) {
        return null;
    }
    PsiModifierList modifierList = field.getModifierList();
    if (modifierList != null) {
        if (modifierList.hasModifierProperty(com.intellij.psi.PsiModifier.STATIC)) {
            String message = getInjectionAnnotationValidDeclarationMessage();
            AbstractFix removeAnnotationFix = createRemoveAnnotationFix(annotationToCheck);
            ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(annotationToCheck, message, removeAnnotationFix, com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            return new ProblemDescriptor[] { problemDescriptor };
        }
    }
    return verifyAnnotationDeclaredCorrectly(field, annotationToCheck, manager);
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) AbstractFix(org.qi4j.ide.plugin.idea.common.inspections.AbstractFix) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 2 with AbstractFix

use of org.qi4j.ide.plugin.idea.common.inspections.AbstractFix in project qi4j-sdk by Qi4j.

the class StructureAnnotationDeclaredCorrectlyInspection method verifyAnnotationDeclaredCorrectly.

@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly(@NotNull PsiVariable psiVariable, @NotNull PsiAnnotation structureAnnotation, @NotNull InspectionManager manager) {
    StructureAnnotationDeclarationValidationResult annotationCheck = validateStructureAnnotationDeclaration(psiVariable);
    switch(annotationCheck) {
        case invalidInjectionType:
            String message = message("injections.structure.annotation.declared.correctly.error.invalid.injection.type", psiVariable.getType().getCanonicalText());
            AbstractFix removeStructureAnnotationFix = createRemoveAnnotationFix(structureAnnotation);
            ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(structureAnnotation, message, removeStructureAnnotationFix, GENERIC_ERROR_OR_WARNING);
            return new ProblemDescriptor[] { problemDescriptor };
    }
    return null;
}
Also used : StructureAnnotationDeclarationValidationResult(org.qi4j.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.StructureAnnotationDeclarationValidationResult) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) AbstractFix(org.qi4j.ide.plugin.idea.common.inspections.AbstractFix) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AbstractFix

use of org.qi4j.ide.plugin.idea.common.inspections.AbstractFix 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)3 AbstractFix (org.qi4j.ide.plugin.idea.common.inspections.AbstractFix)3 PsiAnnotation (com.intellij.psi.PsiAnnotation)2 PsiModifierList (com.intellij.psi.PsiModifierList)1 PsiParameter (com.intellij.psi.PsiParameter)1 PsiParameterList (com.intellij.psi.PsiParameterList)1 LinkedList (java.util.LinkedList)1 Nullable (org.jetbrains.annotations.Nullable)1 StructureAnnotationDeclarationValidationResult (org.qi4j.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.StructureAnnotationDeclarationValidationResult)1