void (@NotNull ActionContext context, @NotNull PsiNameValuePair pair, @NotNull ModPsiUpdater updater) { PsiAnnotationParameterList parameterList = (PsiAnnotationParameterList)pair.getParent(); PsiNameValuePair[] attributes = parameterList.getAttributes(); List<String> strings = new ArrayList<>(); String name = pair.getName(); if (name == null) return; for (PsiNameValuePair attribute : attributes) { String attributeName = attribute.getName(); if (!name.equals(attributeName) && (attributeName != null || !PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(name))) continue; PsiAnnotationMemberValue value = attribute.getValue(); if (value == null) continue; CommentTracker ct = new CommentTracker(); if (value instanceof PsiArrayInitializerMemberValue) { if (((PsiArrayInitializerMemberValue)value).getInitializers().length != 0) { PsiElement lBrace = value.getFirstChild(); PsiElement rBrace = value.getLastChild(); PsiElement maybeTrailingComma = PsiTreeUtil.skipWhitespacesAndCommentsBackward(rBrace); // if there is a trailing comma in the array initializer, this allows you to copy comments between the last initializer and // the trailing comma to the merged value PsiElement to = (PsiUtil.isJavaToken(maybeTrailingComma, JavaTokenType.COMMA) ? maybeTrailingComma : rBrace).getPrevSibling(); strings.add(ct.rangeText(lBrace.getNextSibling(), to)); } } else { strings.add(value.getText()); } if (strings.size() != 1) { // the check above allows you to get from // @SuppressWarnings(value = "foo", value = "bar") // to // @SuppressWarnings(value = {"foo", "bar"}), // but not to // @SuppressWarnings({"foo", "bar"}) ct.deleteAndRestoreComments(value.getParent()); } } PsiAnnotation dummyAnnotation = JavaPsiFacade.getElementFactory(context.project()).createAnnotationFromText("@A({" + Strings.join(strings, ", ") + "})", null); PsiAnnotationMemberValue mergedValue = dummyAnnotation.getParameterList().getAttributes()[0].getValue(); PsiAnnotation annotation = (PsiAnnotation)parameterList.getParent(); annotation.setDeclaredAttributeValue(pair.getName(), mergedValue); }