diff options
Diffstat (limited to 'value/src/main')
-rw-r--r-- | value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java | 5 | ||||
-rw-r--r-- | value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java | 22 |
2 files changed, 17 insertions, 10 deletions
diff --git a/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java b/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java index 696c9c5d..db6fc783 100644 --- a/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java +++ b/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java @@ -110,8 +110,8 @@ public class AutoBuilderProcessor extends AutoValueishProcessor { AnnotationMirror autoBuilderAnnotation = getAnnotationMirror(autoBuilderType, AUTO_BUILDER_NAME).get(); TypeElement ofClass = getOfClass(autoBuilderType, autoBuilderAnnotation); + checkModifiersIfNested(ofClass, autoBuilderType, "AutoBuilder ofClass"); String callMethod = findCallMethodValue(autoBuilderAnnotation); - checkModifiersIfNested(ofClass); // TODO: error message is wrong ImmutableSet<ExecutableElement> methods = abstractMethodsIn( getLocalAndInheritedMethods(autoBuilderType, typeUtils(), elementUtils())); @@ -160,7 +160,8 @@ public class AutoBuilderProcessor extends AutoValueishProcessor { ImmutableSet<ExecutableElement> methods) { List<ExecutableElement> executables = findRelevantExecutables(ofClass, callMethod, autoBuilderType); - String description = callMethod.isEmpty() ? "constructor" : "static method named " + callMethod; + String description = + callMethod.isEmpty() ? "constructor" : "static method named \"" + callMethod + "\""; switch (executables.size()) { case 0: throw errorReporter() diff --git a/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java b/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java index a12792fa..3aa95b46 100644 --- a/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java +++ b/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java @@ -643,27 +643,33 @@ abstract class AutoValueishProcessor extends AbstractProcessor { } /** - * Checks that, if the given {@code @AutoValue} or {@code @AutoOneOf} 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. + * 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. */ final void checkModifiersIfNested(TypeElement type) { + checkModifiersIfNested(type, type, simpleAnnotationName); + } + + 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( - type, "[AutoValuePrivate] @%s class must not be private", simpleAnnotationName); + 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( - type, - "[AutoValueInPrivate] @%s class must not be nested in a private class", - simpleAnnotationName); + reportedType, + "[%sInPrivate] @%s class must not be nested in a private class", + simpleAnnotationName, + what); } if (!type.getModifiers().contains(Modifier.STATIC)) { errorReporter.abortWithError( - type, "[AutoValueInner] Nested @%s class must be static", simpleAnnotationName); + reportedType, "[%sInner] Nested @%s class must be static", simpleAnnotationName, what); } } // In principle type.getEnclosingElement() could be an ExecutableElement (for a class |