@Override
        protected boolean doEquivalent(AnnotationValue left, AnnotationValue right) {
          return left.accept(
              new SimpleAnnotationValueVisitor8<Boolean, AnnotationValue>() {
                // LHS is not an annotation or array of annotation values, so just test equality.
                @Override
                protected Boolean defaultAction(Object left, AnnotationValue right) {
                  return left.equals(
                      right.accept(
                          new SimpleAnnotationValueVisitor8<Object, Void>() {
                            @Override
                            protected Object defaultAction(Object object, Void unused) {
                              return object;
                            }
                          },
                          null));
                }

                // LHS is an annotation mirror so test equivalence for RHS annotation mirrors
                // and false for other types.
                @Override
                public Boolean visitAnnotation(AnnotationMirror left, AnnotationValue right) {
                  return right.accept(
                      new SimpleAnnotationValueVisitor8<Boolean, AnnotationMirror>() {
                        @Override
                        protected Boolean defaultAction(Object right, AnnotationMirror left) {
                          return false; // Not an annotation mirror, so can't be equal to such.
                        }

                        @Override
                        public Boolean visitAnnotation(
                            AnnotationMirror right, AnnotationMirror left) {
                          return AnnotationMirrors.equivalence().equivalent(left, right);
                        }
                      },
                      left);
                }

                // LHS is a list of annotation values have to collect-test equivalences, or false
                // for any other types.
                @Override
                public Boolean visitArray(
                    List<? extends AnnotationValue> left, AnnotationValue right) {
                  return right.accept(
                      new SimpleAnnotationValueVisitor8<
                          Boolean, List<? extends AnnotationValue>>() {
                        @Override
                        protected Boolean defaultAction(
                            Object ignored, List<? extends AnnotationValue> alsoIgnored) {
                          return false; // Not an array, so can't be equal to such.
                        }

                        @SuppressWarnings("unchecked") // safe covariant cast
                        @Override
                        public Boolean visitArray(
                            List<? extends AnnotationValue> right,
                            List<? extends AnnotationValue> left) {
                          return AnnotationValues.equivalence()
                              .pairwise()
                              .equivalent(
                                  (List<AnnotationValue>) left, (List<AnnotationValue>) right);
                        }
                      },
                      left);
                }

                @Override
                public Boolean visitType(TypeMirror left, AnnotationValue right) {
                  return right.accept(
                      new SimpleAnnotationValueVisitor8<Boolean, TypeMirror>() {
                        @Override
                        protected Boolean defaultAction(Object ignored, TypeMirror alsoIgnored) {
                          return false; // Not an annotation mirror, so can't be equal to such.
                        }

                        @Override
                        public Boolean visitType(TypeMirror right, TypeMirror left) {
                          return MoreTypes.equivalence().equivalent(left, right);
                        }
                      },
                      left);
                }
              },
              right);
        }
A utility class for working with {@link AnnotationValue} instances.

@author Christian Gruber
common/src/main/java/com/google/auto/common/AnnotationValues.java