use of lombok.ast.AnnotationElement 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;
}
Aggregations