Search in sources :

Example 1 with ServiceAnnotationDeclarationValidationResult

use of org.qi4j.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult in project qi4j-sdk by Qi4j.

the class ServiceAnnotationDeclaredCorrectlyInspection method verifyAnnotationDeclaredCorrectly.

@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly(@NotNull PsiVariable psiVariable, @NotNull PsiAnnotation serviceAnnotation, @NotNull InspectionManager manager) {
    ServiceAnnotationDeclarationValidationResult annotationCheck = isValidServiceAnnotationDeclaration(psiVariable);
    String message = null;
    LocalQuickFix fix = null;
    switch(annotationCheck) {
        case invalidTypeIsInjectedViaStructureAnnotation:
            if (getStructureAnnotation(psiVariable) == null) {
                fix = new ReplaceWithStructureAnnotation(message("injections.service.annotation.declared.correctly.fix.replace.with.structure.annotation"), serviceAnnotation);
            }
            message = message("injections.service.annotation.declared.correctly.error.type.is.injected.by.structure", psiVariable.getType().getCanonicalText());
            break;
    }
    // If it's not an error, return null
    if (message == null) {
        return null;
    }
    // Default behavior to remove @Service annotation
    if (fix == null) {
        fix = createRemoveAnnotationFix(serviceAnnotation);
    }
    ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(serviceAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
    return new ProblemDescriptor[] { problemDescriptor };
}
Also used : ReplaceWithStructureAnnotation(org.qi4j.ide.plugin.idea.injections.structure.common.ReplaceWithStructureAnnotation) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) ServiceAnnotationDeclarationValidationResult(org.qi4j.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 Nullable (org.jetbrains.annotations.Nullable)1 ServiceAnnotationDeclarationValidationResult (org.qi4j.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult)1 ReplaceWithStructureAnnotation (org.qi4j.ide.plugin.idea.injections.structure.common.ReplaceWithStructureAnnotation)1