Search in sources :

Example 1 with Modifiers

use of lombok.ast.Modifiers in project kotlin by JetBrains.

the class LintDriver method isSuppressed.

/**
     * Returns true if the given AST modifier has a suppress annotation for the
     * given issue (which can be null to check for the "all" annotation)
     *
     * @param issue the issue to be checked
     * @param modifiers the modifier to check
     * @return true if the issue or all issues should be suppressed for this
     *         modifier
     */
private static boolean isSuppressed(@Nullable Issue issue, @Nullable Modifiers modifiers) {
    if (modifiers == null) {
        return false;
    }
    StrictListAccessor<Annotation, Modifiers> annotations = modifiers.astAnnotations();
    if (annotations == null) {
        return false;
    }
    for (Annotation annotation : annotations) {
        TypeReference t = annotation.astAnnotationTypeReference();
        String typeName = t.getTypeName();
        if (typeName.endsWith(SUPPRESS_LINT) || typeName.endsWith("SuppressWarnings")) {
            //$NON-NLS-1$
            StrictListAccessor<AnnotationElement, Annotation> values = annotation.astElements();
            if (values != null) {
                for (AnnotationElement element : values) {
                    AnnotationValue valueNode = element.astValue();
                    if (valueNode == null) {
                        continue;
                    }
                    if (valueNode instanceof StringLiteral) {
                        StringLiteral literal = (StringLiteral) valueNode;
                        String value = literal.astValue();
                        if (matches(issue, value)) {
                            return true;
                        }
                    } else if (valueNode instanceof ArrayInitializer) {
                        ArrayInitializer array = (ArrayInitializer) valueNode;
                        StrictListAccessor<Expression, ArrayInitializer> expressions = array.astExpressions();
                        if (expressions == null) {
                            continue;
                        }
                        for (Expression arrayElement : expressions) {
                            if (arrayElement instanceof StringLiteral) {
                                String value = ((StringLiteral) arrayElement).astValue();
                                if (matches(issue, value)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : StringLiteral(lombok.ast.StringLiteral) AnnotationElement(lombok.ast.AnnotationElement) PsiArrayInitializerExpression(com.intellij.psi.PsiArrayInitializerExpression) PsiExpression(com.intellij.psi.PsiExpression) Expression(lombok.ast.Expression) AnnotationValue(lombok.ast.AnnotationValue) TypeReference(lombok.ast.TypeReference) PsiAnnotation(com.intellij.psi.PsiAnnotation) Annotation(lombok.ast.Annotation) Modifiers(lombok.ast.Modifiers) ArrayInitializer(lombok.ast.ArrayInitializer) StrictListAccessor(lombok.ast.StrictListAccessor)

Aggregations

PsiAnnotation (com.intellij.psi.PsiAnnotation)1 PsiArrayInitializerExpression (com.intellij.psi.PsiArrayInitializerExpression)1 PsiExpression (com.intellij.psi.PsiExpression)1 Annotation (lombok.ast.Annotation)1 AnnotationElement (lombok.ast.AnnotationElement)1 AnnotationValue (lombok.ast.AnnotationValue)1 ArrayInitializer (lombok.ast.ArrayInitializer)1 Expression (lombok.ast.Expression)1 Modifiers (lombok.ast.Modifiers)1 StrictListAccessor (lombok.ast.StrictListAccessor)1 StringLiteral (lombok.ast.StringLiteral)1 TypeReference (lombok.ast.TypeReference)1