From b1ba2e31b0410fe0f386b3c42e8666533377f7d8 Mon Sep 17 00:00:00 2001 From: dpb Date: Wed, 13 Jun 2018 10:14:39 -0700 Subject: [PATCH 1/4] Add a static overrides() method to MoreElements that uses ExplicitOverrides. RELNOTES=Add an `overrides()` method to `MoreElements` that is more consistent between javac and ECJ. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=200410431 --- .../com/google/auto/common/MoreElements.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/google/auto/common/MoreElements.java b/common/src/main/java/com/google/auto/common/MoreElements.java index 8ae9fca04a..288e411b9d 100644 --- a/common/src/main/java/com/google/auto/common/MoreElements.java +++ b/common/src/main/java/com/google/auto/common/MoreElements.java @@ -18,6 +18,7 @@ import static javax.lang.model.element.ElementKind.PACKAGE; +import com.google.auto.common.Overrides.ExplicitOverrides; import com.google.common.annotations.Beta; import com.google.common.base.Optional; import com.google.common.base.Predicate; @@ -299,11 +300,27 @@ public static ImmutableSet getLocalAndInheritedMethods( */ public static ImmutableSet getLocalAndInheritedMethods( TypeElement type, Types typeUtils, Elements elementUtils) { - // TODO(emcmanus): detect if the Types and Elements are the javac ones, and use - // NativeOverrides if so. We may need to adjust the logic further to avoid the bug - // tested for by MoreElementsTest.getLocalAndInheritedMethods_DaggerBug. - Overrides overrides = new Overrides.ExplicitOverrides(typeUtils); - return getLocalAndInheritedMethods(type, overrides); + return getLocalAndInheritedMethods(type, new ExplicitOverrides(typeUtils)); + } + + /** + * Tests whether one method, as a member of a given type, overrides another method. + * + *

This method does the same thing as {@link Elements#overrides(ExecutableElement, + * ExecutableElement, TypeElement)}, but in a way that is more consistent between compilers, in + * particular between javac and ecj (the Eclipse compiler). + * + * @param overrider the first method, possible overrider + * @param overridden the second method, possibly being overridden + * @param type the type of which the first method is a member + * @return {@code true} if and only if the first method overrides the second + */ + public static boolean overrides( + ExecutableElement overrider, + ExecutableElement overridden, + TypeElement type, + Types typeUtils) { + return new ExplicitOverrides(typeUtils).overrides(overrider, overridden, type); } private static ImmutableSet getLocalAndInheritedMethods( From 1a6c9fe31767e23f4daf9de2148735347a572890 Mon Sep 17 00:00:00 2001 From: emcmanus Date: Tue, 19 Jun 2018 10:47:24 -0700 Subject: [PATCH 2/4] Have CHANGES.md explain that it is obsolete. Fixes https://github.com/google/auto/issues/642. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201202544 --- value/CHANGES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/value/CHANGES.md b/value/CHANGES.md index 464632b488..32b6107ca5 100644 --- a/value/CHANGES.md +++ b/value/CHANGES.md @@ -1,5 +1,9 @@ # AutoValue Changes +**This document is obsolete.** For details of changes in releases since 1.5, +see the [releases page](https://github.com/google/auto/releases) for the Auto +project. + ## 1.4 → 1.5 ### Functional changes @@ -249,4 +253,3 @@ later. [AutoValueExtension]: src/main/java/com/google/auto/value/extension/AutoValueExtension.java - From fd6c6fa57f73fcbf3472b66a648648a710f1f050 Mon Sep 17 00:00:00 2001 From: emcmanus Date: Mon, 25 Jun 2018 08:20:19 -0700 Subject: [PATCH 3/4] Adjust AutoValueTest so that it covers setting an immutable collection of T from a Collection. The actual bug was fixed long ago but never closed and never covered by an explicit test. RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201956399 --- .../test/java/com/google/auto/value/AutoValueTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java b/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java index fbd378a6e2..b2ed4bed7b 100644 --- a/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java +++ b/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java @@ -2189,13 +2189,13 @@ public void testBuilderWithExoticPropertyBuilders() { public abstract static class BuilderWithCopyingSetters { public abstract ImmutableSet things(); - public abstract ImmutableList strings(); + public abstract ImmutableList numbers(); public abstract ImmutableMap map(); public static Builder builder(T value) { return new AutoValue_AutoValueTest_BuilderWithCopyingSetters.Builder() - .setStrings(ImmutableSet.of("foo", "bar")) + .setNumbers(ImmutableSet.of(17, 23.0)) .setMap(Collections.singletonMap("foo", value)); } @@ -2207,7 +2207,7 @@ public interface Builder { Builder setThings(T... things); - Builder setStrings(Collection strings); + Builder setNumbers(Collection strings); Builder setMap(Map map); @@ -2221,7 +2221,7 @@ public void testBuilderWithCopyingSetters() { BuilderWithCopyingSetters a = builder.setThings(ImmutableSet.of(1, 2)).build(); assertEquals(ImmutableSet.of(1, 2), a.things()); - assertEquals(ImmutableList.of("foo", "bar"), a.strings()); + assertEquals(ImmutableList.of(17, 23.0), a.numbers()); assertEquals(ImmutableMap.of("foo", 23), a.map()); BuilderWithCopyingSetters b = builder.setThings(Arrays.asList(1, 2)).build(); From 32a0ae3bf1a37be063cc3bdf9d599f38a1716db4 Mon Sep 17 00:00:00 2001 From: cushon Date: Mon, 25 Jun 2018 17:22:14 -0700 Subject: [PATCH 4/4] Template arguments should not be null If the generated annotation isn't available use the empty string instead of null. Fixes #645 RELNOTES=N/A ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=202048570 --- .../google/auto/value/processor/AutoAnnotationProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java b/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java index 02a519b131..ba7f806cdc 100644 --- a/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java +++ b/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java @@ -182,7 +182,7 @@ private void processMethod(ExecutableElement method) { private String getGeneratedTypeName() { return generatedAnnotation(elementUtils, processingEnv.getSourceVersion()) .map(generatedAnnotation -> TypeEncoder.encode(generatedAnnotation.asType())) - .orElse(null); + .orElse(""); } /**