diff --git a/common/src/main/java/com/google/auto/common/Visibility.java b/common/src/main/java/com/google/auto/common/Visibility.java index db15f8bd43..266d4fdbc7 100644 --- a/common/src/main/java/com/google/auto/common/Visibility.java +++ b/common/src/main/java/com/google/auto/common/Visibility.java @@ -77,7 +77,7 @@ public static Visibility effectiveVisibilityOfElement(Element element) { Visibility effectiveVisibility = PUBLIC; Element currentElement = element; while (currentElement != null) { - // NOTE: We don't use Guava's Comparators.min() because that requires Guava 30, which would + // NOTE - because that requires Guava 30, which would // make this library unusable in annotation processors using Bazel < 5.0. effectiveVisibility = Ordering.natural().min(effectiveVisibility, ofElement(currentElement)); currentElement = currentElement.getEnclosingElement(); diff --git a/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java b/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java index a04d41f3f2..de6885cf38 100644 --- a/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java +++ b/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java @@ -178,6 +178,8 @@ public void testEmpty() { StringValues anAnnotation(); + Class aClass(); + byte[] bytes(); short[] shorts(); @@ -199,6 +201,8 @@ public void testEmpty() { RetentionPolicy[] enums(); StringValues[] annotations(); + + Class[] classes(); } @AutoAnnotation @@ -214,6 +218,7 @@ static Everything newEverything( String aString, RetentionPolicy anEnum, StringValues anAnnotation, + Class aClass, byte[] bytes, short[] shorts, int[] ints, @@ -224,7 +229,8 @@ static Everything newEverything( boolean[] booleans, String[] strings, RetentionPolicy[] enums, - StringValues[] annotations) { + StringValues[] annotations, + Class... classes) { return new AutoAnnotation_AutoAnnotationTest_newEverything( aByte, aShort, @@ -237,6 +243,7 @@ static Everything newEverything( aString, anEnum, anAnnotation, + aClass, bytes, shorts, ints, @@ -247,7 +254,8 @@ static Everything newEverything( booleans, strings, enums, - annotations); + annotations, + classes); } @AutoAnnotation @@ -263,6 +271,7 @@ static Everything newEverythingCollections( String aString, RetentionPolicy anEnum, StringValues anAnnotation, + Class aClass, Collection bytes, List shorts, ArrayList ints, @@ -273,7 +282,8 @@ static Everything newEverythingCollections( ImmutableCollection booleans, ImmutableList strings, ImmutableSet enums, - Set annotations) { + Set annotations, + List> classes) { return new AutoAnnotation_AutoAnnotationTest_newEverythingCollections( aByte, aShort, @@ -286,6 +296,7 @@ static Everything newEverythingCollections( aString, anEnum, anAnnotation, + aClass, bytes, shorts, ints, @@ -296,7 +307,8 @@ static Everything newEverythingCollections( booleans, strings, enums, - annotations); + annotations, + classes); } @Everything( @@ -311,6 +323,7 @@ static Everything newEverythingCollections( aString = "maybe\nmaybe not\n", anEnum = RetentionPolicy.RUNTIME, anAnnotation = @StringValues("whatever"), + aClass = String.class, bytes = {5, 6}, shorts = {}, ints = {7}, @@ -321,7 +334,8 @@ static Everything newEverythingCollections( booleans = {false, true, false}, strings = {"ver", "vers", "vert", "verre", "vair"}, enums = {RetentionPolicy.CLASS, RetentionPolicy.RUNTIME}, - annotations = {@StringValues({}), @StringValues({"foo", "bar"})}) + annotations = {@StringValues({}), @StringValues({"foo", "bar"})}, + classes = {String.class, StringBuilder.class}) private static class AnnotatedWithEverything {} // Get an instance of @Everything via reflection on the class AnnotatedWithEverything, @@ -342,6 +356,7 @@ private static class AnnotatedWithEverything {} "maybe\nmaybe not\n", RetentionPolicy.RUNTIME, newStringValues(new String[] {"whatever"}), + String.class, new byte[] {5, 6}, new short[] {}, new int[] {7}, @@ -354,7 +369,9 @@ private static class AnnotatedWithEverything {} new RetentionPolicy[] {RetentionPolicy.CLASS, RetentionPolicy.RUNTIME}, new StringValues[] { newStringValues(new String[] {}), newStringValues(new String[] {"foo", "bar"}), - }); + }, + String.class, + StringBuilder.class); private static final Everything EVERYTHING_FROM_AUTO_COLLECTIONS = newEverythingCollections( (byte) 1, @@ -368,6 +385,7 @@ private static class AnnotatedWithEverything {} "maybe\nmaybe not\n", RetentionPolicy.RUNTIME, newStringValues(new String[] {"whatever"}), + String.class, Arrays.asList((byte) 5, (byte) 6), Collections.emptyList(), new ArrayList(Collections.singleton(7)), @@ -380,7 +398,10 @@ private static class AnnotatedWithEverything {} ImmutableList.of("ver", "vers", "vert", "verre", "vair"), ImmutableSet.of(RetentionPolicy.CLASS, RetentionPolicy.RUNTIME), ImmutableSet.of( - newStringValues(new String[] {}), newStringValues(new String[] {"foo", "bar"}))); + newStringValues(new String[] {}), newStringValues(new String[] {"foo", "bar"})), + ImmutableList.of(String.class.asSubclass(CharSequence.class), StringBuilder.class)); + // .asSubclass because of pre-Java8, where otherwise we get a compilation error because + // the inferred type is >. private static final Everything EVERYTHING_ELSE_FROM_AUTO = newEverything( (byte) 0, @@ -394,6 +415,7 @@ private static class AnnotatedWithEverything {} "", RetentionPolicy.SOURCE, newStringValues(new String[] {""}), + String.class, new byte[0], new short[0], new int[0], @@ -418,6 +440,7 @@ private static class AnnotatedWithEverything {} "", RetentionPolicy.SOURCE, newStringValues(new String[] {""}), + String.class, ImmutableList.of(), Collections.emptyList(), new ArrayList(), @@ -428,7 +451,8 @@ private static class AnnotatedWithEverything {} ImmutableSet.of(), ImmutableList.of(), ImmutableSet.of(), - Collections.emptySet()); + Collections.emptySet(), + Collections.>emptyList()); @Test public void testEqualsAndHashCode() { @@ -515,6 +539,7 @@ public void testToString() { + "aByte=1, aShort=2, anInt=3, aLong=-4, aFloat=NaN, aDouble=NaN, aChar='#', " + "aBoolean=true, aString=\"maybe\\nmaybe not\\n\", anEnum=RUNTIME, " + "anAnnotation=@com.google.auto.value.annotations.StringValues([\"whatever\"]), " + + "aClass=class java.lang.String, " + "bytes=[5, 6], shorts=[], ints=[7], longs=[8, 9], floats=[10.0, 11.0], " + "doubles=[-Infinity, -12.0, Infinity], " + "chars=['?', '!', '\\n'], " @@ -524,7 +549,8 @@ public void testToString() { + "annotations=[" + "@com.google.auto.value.annotations.StringValues([]), " + "@com.google.auto.value.annotations.StringValues([\"foo\", \"bar\"])" - + "]" + + "], " + + "classes=[class java.lang.String, class java.lang.StringBuilder]" + ")"; assertThat(EVERYTHING_FROM_AUTO.toString()).isEqualTo(expected); assertThat(EVERYTHING_FROM_AUTO_COLLECTIONS.toString()).isEqualTo(expected); diff --git a/value/src/main/java/com/google/auto/value/processor/TypeVariables.java b/value/src/main/java/com/google/auto/value/processor/TypeVariables.java index ae27f91b46..5000389ee3 100644 --- a/value/src/main/java/com/google/auto/value/processor/TypeVariables.java +++ b/value/src/main/java/com/google/auto/value/processor/TypeVariables.java @@ -236,7 +236,7 @@ public TypeMirror visitArray(ArrayType t, Void p) { // ImmutableSet target = ImmutableSet.copyOf(actualParameter); // We will infer E= and rewrite the formal parameter type to // [], which we must simplify to T[]. - // TODO: what if getExtendsBound() returns null? + // TODO - returns null? comp = MoreTypes.asWildcard(comp).getExtendsBound(); } return typeUtils.getArrayType(comp);