private static void addSuppressAnnotation(
     final Project project, final GrModifierList modifierList, final String id)
     throws IncorrectOperationException {
   PsiAnnotation annotation =
       modifierList.findAnnotation(BatchSuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
   final GrExpression toAdd =
       GroovyPsiElementFactory.getInstance(project).createExpressionFromText("\"" + id + "\"");
   if (annotation != null) {
     final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue(null);
     if (value instanceof GrAnnotationArrayInitializer) {
       value.add(toAdd);
     } else if (value != null) {
       GrAnnotation anno =
           GroovyPsiElementFactory.getInstance(project).createAnnotationFromText("@A([])");
       final GrAnnotationArrayInitializer list =
           (GrAnnotationArrayInitializer) anno.findDeclaredAttributeValue(null);
       list.add(value);
       list.add(toAdd);
       annotation.setDeclaredAttributeValue(null, list);
     }
   } else {
     modifierList
         .addAnnotation(BatchSuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME)
         .setDeclaredAttributeValue(null, toAdd);
   }
 }
  @Nullable
  public static PsiAnnotationMemberValue setDeclaredAttributeValue(
      @NotNull PsiAnnotation psiAnnotation,
      @Nullable String attributeName,
      @Nullable PsiAnnotationMemberValue value,
      @NotNull PairFunction<Project, String, PsiAnnotation> annotationCreator) {
    PsiAnnotationMemberValue existing = psiAnnotation.findDeclaredAttributeValue(attributeName);
    if (value == null) {
      if (existing == null) {
        return null;
      }
      existing.getParent().delete();
    } else {
      if (existing != null) {
        ((PsiNameValuePair) existing.getParent()).setValue(value);
      } else {
        PsiNameValuePair[] attributes = psiAnnotation.getParameterList().getAttributes();
        if (attributes.length == 1) {
          PsiNameValuePair attribute = attributes[0];
          if (attribute.getName() == null) {
            PsiAnnotationMemberValue defValue = attribute.getValue();
            assert defValue != null : attribute;
            attribute.replace(
                createNameValuePair(
                    defValue,
                    PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME + "=",
                    annotationCreator));
          }
        }

        boolean allowNoName =
            attributes.length == 0 && ("value".equals(attributeName) || null == attributeName);
        final String namePrefix;
        if (allowNoName) {
          namePrefix = "";
        } else {
          namePrefix = attributeName + "=";
        }
        psiAnnotation
            .getParameterList()
            .addBefore(createNameValuePair(value, namePrefix, annotationCreator), null);
      }
    }
    return psiAnnotation.findDeclaredAttributeValue(attributeName);
  }
 public static boolean isAnnotatedWithParameter(
     PsiAnnotation annotation, String parameter, Set<String> values) {
   final PsiAnnotationMemberValue attributeValue =
       annotation.findDeclaredAttributeValue(parameter);
   if (attributeValue != null) {
     Collection<String> matches = extractValuesFromParameter(attributeValue);
     for (String s : matches) {
       if (values.contains(s)) {
         return true;
       }
     }
   }
   return false;
 }
 public static PsiClass getProviderClass(final PsiElement element, final PsiClass topLevelClass) {
   final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(element, PsiAnnotation.class);
   if (annotation != null) {
     final PsiAnnotationMemberValue value =
         annotation.findDeclaredAttributeValue("dataProviderClass");
     if (value instanceof PsiClassObjectAccessExpression) {
       final PsiTypeElement operand = ((PsiClassObjectAccessExpression) value).getOperand();
       final PsiClass psiClass = PsiUtil.resolveClassInType(operand.getType());
       if (psiClass != null) {
         return psiClass;
       }
     }
   }
   return topLevelClass;
 }
 private static void appendAnnotationAttributeValues(
     final Map<String, Collection<String>> results,
     final PsiAnnotation annotation,
     final PsiDocCommentOwner commentOwner) {
   for (String parameter : results.keySet()) {
     final Collection<String> values = results.get(parameter);
     if (annotation != null) {
       final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue(parameter);
       if (value != null) {
         values.addAll(extractValuesFromParameter(value));
       }
     } else {
       values.addAll(extractAnnotationValuesFromJavaDoc(getTextJavaDoc(commentOwner), parameter));
     }
   }
 }
 public static boolean isDisabled(PsiAnnotation annotation) {
   final PsiAnnotationMemberValue attributeValue =
       annotation.findDeclaredAttributeValue("enabled");
   return attributeValue != null && attributeValue.textMatches("false");
 }