Skip to content

Commit

Permalink
Merge pull request #646 from cushon/master
Browse files Browse the repository at this point in the history
Moe sync
  • Loading branch information
eamonnmcmanus committed Jun 26, 2018
2 parents a36cc06 + 32a0ae3 commit 1339e40
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
27 changes: 22 additions & 5 deletions common/src/main/java/com/google/auto/common/MoreElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -299,11 +300,27 @@ public static ImmutableSet<ExecutableElement> getLocalAndInheritedMethods(
*/
public static ImmutableSet<ExecutableElement> 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.
*
* <p>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<ExecutableElement> getLocalAndInheritedMethods(
Expand Down
5 changes: 4 additions & 1 deletion value/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -249,4 +253,3 @@ later.


[AutoValueExtension]: src/main/java/com/google/auto/value/extension/AutoValueExtension.java

Original file line number Diff line number Diff line change
Expand Up @@ -2189,13 +2189,13 @@ public void testBuilderWithExoticPropertyBuilders() {
public abstract static class BuilderWithCopyingSetters<T extends Number> {
public abstract ImmutableSet<? extends T> things();

public abstract ImmutableList<String> strings();
public abstract ImmutableList<Number> numbers();

public abstract ImmutableMap<String, T> map();

public static <T extends Number> Builder<T> builder(T value) {
return new AutoValue_AutoValueTest_BuilderWithCopyingSetters.Builder<T>()
.setStrings(ImmutableSet.of("foo", "bar"))
.setNumbers(ImmutableSet.of(17, 23.0))
.setMap(Collections.singletonMap("foo", value));
}

Expand All @@ -2207,7 +2207,7 @@ public interface Builder<T extends Number> {

Builder<T> setThings(T... things);

Builder<T> setStrings(Collection<String> strings);
Builder<T> setNumbers(Collection<? extends Number> strings);

Builder<T> setMap(Map<String, T> map);

Expand All @@ -2221,7 +2221,7 @@ public void testBuilderWithCopyingSetters() {

BuilderWithCopyingSetters<Integer> 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<Integer> b = builder.setThings(Arrays.asList(1, 2)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}

/**
Expand Down

0 comments on commit 1339e40

Please sign in to comment.