Search in sources :

Example 6 with PsiAnnotationMemberValue

use of com.intellij.psi.PsiAnnotationMemberValue in project qi4j-sdk by Qi4j.

the class MixinImplementsMixinType method checkClass.

@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    // If psiClass is not an interface, ignore
    if (!psiClass.isInterface()) {
        return null;
    }
    // If @Mixins annotation is empty, ignore
    List<PsiAnnotationMemberValue> mixinAnnotationValues = getMixinsAnnotationValue(psiClass);
    if (mixinAnnotationValues.isEmpty()) {
        return null;
    }
    // Get all valid mixin type
    Set<PsiClass> validMixinsType = getAllValidMixinTypes(psiClass);
    if (validMixinsType.isEmpty()) {
        return null;
    }
    // For each mixin
    List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
    for (PsiAnnotationMemberValue mixinAnnotationValue : mixinAnnotationValues) {
        PsiJavaCodeReferenceElement mixinClassReference = getMixinClassReference(mixinAnnotationValue);
        // If it's not a class reference, ignore
        if (mixinClassReference == null) {
            continue;
        }
        // If class reference can't be resolved, ignore
        PsiClass mixinClass = (PsiClass) mixinClassReference.resolve();
        if (mixinClass == null) {
            continue;
        }
        String mixinQualifiedName = mixinClass.getQualifiedName();
        boolean isMixinsDeclarationValid = false;
        String message = "";
        if (mixinClass.isInterface()) {
            // Mixin can't be an interface
            message = message("mixin.implements.mixin.type.error.mixin.is.an.interface", mixinQualifiedName);
        } else if (isAConcern(mixinClass)) {
            // Mixin can't be a concern
            message = message("mixin.implements.mixin.type.error.mixin.is.a.concern", mixinQualifiedName);
        } else if (isASideEffect(mixinClass)) {
            // Mixin can't be a side effect
            message = message("mixin.implements.mixin.type.error.mixin.is.a.side.effect", mixinQualifiedName);
        } else {
            // If doesn't implement any mixin type, it's a problem
            if (!isImplementValidMixinType(mixinClass, validMixinsType)) {
                message = message("mixin.implements.mixin.type.error.does.not.implement.any.mixin.type", mixinQualifiedName, psiClass.getQualifiedName());
            } else {
                isMixinsDeclarationValid = true;
            }
        }
        if (!isMixinsDeclarationValid) {
            ProblemDescriptor problemDescriptor = createProblemDescriptor(manager, mixinAnnotationValue, mixinClassReference, message);
            problems.add(problemDescriptor);
        }
    }
    return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) LinkedList(java.util.LinkedList) PsiAnnotationMemberValue(com.intellij.psi.PsiAnnotationMemberValue)

Aggregations

PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)6 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)3 PsiAnnotation (com.intellij.psi.PsiAnnotation)3 PsiClass (com.intellij.psi.PsiClass)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 LinkedList (java.util.LinkedList)3 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ASTNode (com.intellij.lang.ASTNode)1 PsiArrayInitializerExpression (com.intellij.psi.PsiArrayInitializerExpression)1 PsiArrayInitializerMemberValue (com.intellij.psi.PsiArrayInitializerMemberValue)1 PsiExpression (com.intellij.psi.PsiExpression)1 PsiLiteral (com.intellij.psi.PsiLiteral)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 BaseInspectionVisitor (org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor)1 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1 GrParameterList (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList)1