final void checkModifiersIfNested(TypeElement type, TypeElement reportedType, String what) {
    ElementKind enclosingKind = type.getEnclosingElement().getKind();
    if (enclosingKind.isClass() || enclosingKind.isInterface()) {
      if (type.getModifiers().contains(Modifier.PRIVATE)) {
        errorReporter.abortWithError(
            reportedType, "[%sPrivate] @%s class must not be private", simpleAnnotationName, what);
      } else if (Visibility.effectiveVisibilityOfElement(type).equals(Visibility.PRIVATE)) {
        // The previous case, where the class itself is private, is much commoner so it deserves
        // its own error message, even though it would be caught by the test here too.
        errorReporter.abortWithError(
            reportedType,
            "[%sInPrivate] @%s class must not be nested in a private class",
            simpleAnnotationName,
            what);
      }
      if (!type.getModifiers().contains(Modifier.STATIC)) {
        errorReporter.abortWithError(
            reportedType, "[%sInner] Nested @%s class must be static", simpleAnnotationName, what);
      }
    }
    // In principle type.getEnclosingElement() could be an ExecutableElement (for a class
    // declared inside a method), but since RoundEnvironment.getElementsAnnotatedWith doesn't
    // return such classes we won't see them here.
  }
Checks that, if the given {@code @AutoValue}, {@code @AutoOneOf}, or {@code @AutoBuilder} class
is nested, it is static and not private. This check is not necessary for correctness, since the
generated code would not compile if the check fails, but it produces better error messages for
the user.
value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java