void (PsiAnnotationMemberValue value, final @NlsSafe StringBuilder buffer) { value.accept(new JavaElementVisitor() { @Override public void visitAnnotation(@NotNull PsiAnnotation annotation) { buffer.append("@"); PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement(); if (ref == null) return; PsiElement resolved = ref.resolve(); if (resolved instanceof PsiClass && ((PsiClass)resolved).getQualifiedName() != null) { buffer.append(((PsiClass)resolved).getQualifiedName()); } else { buffer.append(ref.getText()); } PsiAnnotationParameterList parameterList = annotation.getParameterList(); parameterList.accept(this); } @Override public void visitAnnotationParameterList(@NotNull PsiAnnotationParameterList list) { PsiNameValuePair[] attributes = list.getAttributes(); if (attributes.length > 0) { buffer.append('('); for (PsiNameValuePair attribute : attributes) { attribute.accept(this); buffer.append(','); } buffer.replace(buffer.length() - 1, buffer.length(), ")"); } } @Override public void visitNameValuePair(@NotNull PsiNameValuePair pair) { String name = pair.getName(); PsiAnnotationMemberValue value = pair.getValue(); if (name != null) { buffer.append(name); buffer.append('='); } if (value != null) { value.accept(this); } } @Override public void visitExpression(@NotNull PsiExpression expression) { buffer.append(expression.getText()); } @Override public void visitAnnotationArrayInitializer(@NotNull PsiArrayInitializerMemberValue initializer) { PsiAnnotationMemberValue[] initializers = initializer.getInitializers(); processInitializers(initializers); } @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { PsiArrayInitializerExpression arrayInitializer = expression.getArrayInitializer(); if (arrayInitializer == null) { super.visitNewExpression(expression); } else { PsiType type = expression.getType(); if (type == null) { type = PsiType.getJavaLangObject(expression.getManager(), expression.getResolveScope()).createArrayType(); } buffer.append('('); arrayInitializer.accept(this); buffer.append(" as "); buffer.append(type.getCanonicalText()); buffer.append(")"); } } @Override public void visitArrayInitializerExpression(@NotNull PsiArrayInitializerExpression arrayInitializer) { processInitializers(arrayInitializer.getInitializers()); } private void processInitializers(PsiAnnotationMemberValue[] initializers) { buffer.append('['); for (PsiAnnotationMemberValue initializer : initializers) { initializer.accept(this); buffer.append(','); } if (initializers.length > 0) { buffer.delete(buffer.length() - 1, buffer.length()); } buffer.append(']'); } }); }