void (@NotNull ActionContext context, @NotNull PsiAnnotation annotation, @NotNull ModPsiUpdater updater) { PsiNameValuePair attribute = ArrayUtil.getFirstElement(annotation.getParameterList().getAttributes()); if (attribute == null) return; PsiAnnotationMemberValue origValue = attribute.getValue(); if (origValue == null) return; List<PsiAnnotation> annotations = findCollapsibleAnnotations(annotation, attribute); List<PsiAnnotationMemberValue> values = new ArrayList<>(); CommentTracker ct = new CommentTracker(); for (PsiAnnotation anno : annotations) { PsiAnnotationMemberValue value = anno.getParameterList().getAttributes()[0].getValue(); if (value instanceof PsiArrayInitializerMemberValue) { PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue)value).getInitializers(); for (PsiAnnotationMemberValue initializer : initializers) { values.add(ct.markUnchanged(initializer)); } } else if (value != null) { values.add(ct.markUnchanged(value)); } if (anno != annotation) { ct.delete(anno); } } String newValue = StreamEx.of(values).map(PsiElement::getText).joining(", ", "{", "}"); PsiAnnotation dummy = JavaPsiFacade.getElementFactory(context.project()) .createAnnotationFromText("@x(" + newValue + ")", origValue); ct.replaceAndRestoreComments(origValue, Objects.requireNonNull(dummy.getParameterList().getAttributes()[0].getValue())); }