71
71
import javax .lang .model .element .TypeElement ;
72
72
import javax .lang .model .element .TypeParameterElement ;
73
73
import javax .lang .model .element .VariableElement ;
74
- import javax .lang .model .type .ArrayType ;
75
74
import javax .lang .model .type .DeclaredType ;
76
75
import javax .lang .model .type .TypeKind ;
77
76
import javax .lang .model .type .TypeMirror ;
@@ -301,7 +300,8 @@ public final boolean process(Set<? extends TypeElement> annotations, RoundEnviro
301
300
for (TypeElement type : deferredTypes ) {
302
301
errorReporter .reportError (
303
302
type ,
304
- "Did not generate @%s class for %s because it references undefined types" ,
303
+ "[AutoValueUndefined] Did not generate @%s class for %s because it references"
304
+ + " undefined types" ,
305
305
simpleAnnotationName ,
306
306
type .getQualifiedName ());
307
307
}
@@ -331,7 +331,10 @@ public final boolean process(Set<? extends TypeElement> annotations, RoundEnviro
331
331
} catch (RuntimeException e ) {
332
332
String trace = Throwables .getStackTraceAsString (e );
333
333
errorReporter .reportError (
334
- type , "@%s processor threw an exception: %s" , simpleAnnotationName , trace );
334
+ type ,
335
+ "[AutoValueException] @%s processor threw an exception: %s" ,
336
+ simpleAnnotationName ,
337
+ trace );
335
338
throw e ;
336
339
}
337
340
}
@@ -378,8 +381,9 @@ final ImmutableSet<Property> propertySet(
378
381
ImmutableSet .Builder <Property > props = ImmutableSet .builder ();
379
382
propertyMethodsAndTypes .forEach (
380
383
(propertyMethod , returnType ) -> {
381
- String propertyType = TypeEncoder .encodeWithAnnotations (
382
- returnType , getExcludedAnnotationTypes (propertyMethod ));
384
+ String propertyType =
385
+ TypeEncoder .encodeWithAnnotations (
386
+ returnType , getExcludedAnnotationTypes (propertyMethod ));
383
387
String propertyName = methodToPropertyName .get (propertyMethod );
384
388
String identifier = methodToIdentifier .get (propertyMethod );
385
389
ImmutableList <String > fieldAnnotations =
@@ -399,7 +403,9 @@ final ImmutableSet<Property> propertySet(
399
403
nullableAnnotation );
400
404
props .add (p );
401
405
if (p .isNullable () && returnType .getKind ().isPrimitive ()) {
402
- errorReporter ().reportError (propertyMethod , "Primitive types cannot be @Nullable" );
406
+ errorReporter ()
407
+ .reportError (
408
+ propertyMethod , "[AutoValueNullPrimitive] Primitive types cannot be @Nullable" );
403
409
}
404
410
});
405
411
return props .build ();
@@ -517,7 +523,10 @@ final ImmutableBiMap<String, ExecutableElement> propertyNameToMethodMap(
517
523
// reportedDups prevents us from reporting more than one error for the same method.
518
524
for (ExecutableElement context : contexts ) {
519
525
errorReporter .reportError (
520
- context , "More than one @%s property called %s" , simpleAnnotationName , name );
526
+ context ,
527
+ "[AutoValueDupProperty] More than one @%s property called %s" ,
528
+ simpleAnnotationName ,
529
+ name );
521
530
}
522
531
}
523
532
}
@@ -622,16 +631,18 @@ final void checkModifiersIfNested(TypeElement type) {
622
631
if (enclosingKind .isClass () || enclosingKind .isInterface ()) {
623
632
if (type .getModifiers ().contains (Modifier .PRIVATE )) {
624
633
errorReporter .abortWithError (
625
- type , "@%s class must not be private" , simpleAnnotationName );
634
+ type , "[AutoValuePrivate] @%s class must not be private" , simpleAnnotationName );
626
635
} else if (Visibility .effectiveVisibilityOfElement (type ).equals (Visibility .PRIVATE )) {
627
636
// The previous case, where the class itself is private, is much commoner so it deserves
628
637
// its own error message, even though it would be caught by the test here too.
629
638
errorReporter .abortWithError (
630
- type , "@%s class must not be nested in a private class" , simpleAnnotationName );
639
+ type ,
640
+ "[AutoValueInPrivate] @%s class must not be nested in a private class" ,
641
+ simpleAnnotationName );
631
642
}
632
643
if (!type .getModifiers ().contains (Modifier .STATIC )) {
633
644
errorReporter .abortWithError (
634
- type , "Nested @%s class must be static" , simpleAnnotationName );
645
+ type , "[AutoValueInner] Nested @%s class must be static" , simpleAnnotationName );
635
646
}
636
647
}
637
648
// In principle type.getEnclosingElement() could be an ExecutableElement (for a class
@@ -766,13 +777,14 @@ boolean propertiesCanBeVoid() {
766
777
final void checkReturnType (TypeElement autoValueClass , ExecutableElement getter ) {
767
778
TypeMirror type = getter .getReturnType ();
768
779
if (type .getKind () == TypeKind .ARRAY ) {
769
- TypeMirror componentType = (( ArrayType ) type ).getComponentType ();
770
- if (componentType .getKind ().isPrimitive ()) {
780
+ TypeMirror componentType = MoreTypes . asArray ( type ).getComponentType ();
781
+ if (componentType .getKind ().isPrimitive ()) {
771
782
warnAboutPrimitiveArrays (autoValueClass , getter );
772
783
} else {
773
784
errorReporter .reportError (
774
785
getter ,
775
- "An @%s class cannot define an array-valued property unless it is a primitive array" ,
786
+ "[AutoValueArray] An @%s class cannot define an array-valued property unless it is a"
787
+ + " primitive array" ,
776
788
simpleAnnotationName );
777
789
}
778
790
}
@@ -799,10 +811,11 @@ private void warnAboutPrimitiveArrays(TypeElement autoValueClass, ExecutableElem
799
811
String context = sameClass ? "" : (" Method: " + getter .getEnclosingElement () + "." + getter );
800
812
errorReporter .reportWarning (
801
813
element ,
802
- "An @%s property that is a primitive array returns the original array, which can"
803
- + " therefore be modified by the caller. If this is OK, you can suppress this warning"
804
- + " with @SuppressWarnings(\" mutable\" ). Otherwise, you should replace the property"
805
- + " with an immutable type, perhaps a simple wrapper around the original array.%s" ,
814
+ "[AutoValueMutable] An @%s property that is a primitive array returns the original"
815
+ + " array, which can therefore be modified by the caller. If this is OK, you can"
816
+ + " suppress this warning with @SuppressWarnings(\" mutable\" ). Otherwise, you should"
817
+ + " replace the property with an immutable type, perhaps a simple wrapper around the"
818
+ + " original array.%s" ,
806
819
simpleAnnotationName ,
807
820
context );
808
821
}
@@ -815,8 +828,8 @@ private void warnAboutPrimitiveArrays(TypeElement autoValueClass, ExecutableElem
815
828
private static class ContainsMutableVisitor extends SimpleAnnotationValueVisitor8 <Boolean , Void > {
816
829
@ Override
817
830
public Boolean visitArray (List <? extends AnnotationValue > list , Void p ) {
818
- return list .stream ().map (av -> av . getValue () ).anyMatch ("mutable" ::equals );
819
- }
831
+ return list .stream ().map (AnnotationValue :: getValue ).anyMatch ("mutable" ::equals );
832
+ }
820
833
}
821
834
822
835
/**
@@ -1102,7 +1115,10 @@ final void writeSourceFile(String className, String text, TypeElement originatin
1102
1115
// error later because user code will have a reference to the code we were supposed to
1103
1116
// generate (new AutoValue_Foo() or whatever) and that reference will be undefined.
1104
1117
errorReporter .reportWarning (
1105
- originatingType , "Could not write generated class %s: %s" , className , e );
1118
+ originatingType ,
1119
+ "[AutoValueCouldNotWrite] Could not write generated class %s: %s" ,
1120
+ className ,
1121
+ e );
1106
1122
}
1107
1123
}
1108
1124
}
0 commit comments