aboutsummaryrefslogtreecommitdiff
path: root/value/src/main/java/com/google/auto
diff options
context:
space:
mode:
authoremcmanus <emcmanus@google.com>2019-05-13 07:22:28 -0700
committerRon Shapiro <ronshapiro@google.com>2019-05-13 21:16:04 -0400
commit3854a6508a8cc72eda1ae15b08ab3949d1cc778d (patch)
tree1bbcfee6b5b0de12ded9ffcd299a55a0e75ef3b7 /value/src/main/java/com/google/auto
parent5724c0db1331698389b2da12d650151d1e605b4a (diff)
downloadauto-3854a6508a8cc72eda1ae15b08ab3949d1cc778d.tar.gz
Work around an ecj bug in Elements.getAllMembers(). It incorrectly returns static methods from superinterfaces, even though those aren't inherited. This causes AutoValueTest not to compile with ecj on Java 9+, because the MyMap and MyStringMap classes are wrongly shown to contain the static "of()" method that was added to Map in Java 9. AutoValue then tries to use MyMap.of() to construct a default instance of MyMap.
RELNOTES=Worked around an Eclipse compiler bug where static interface methods are incorrectly shown as being inherited. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=247929781
Diffstat (limited to 'value/src/main/java/com/google/auto')
-rw-r--r--value/src/main/java/com/google/auto/value/processor/PropertyBuilderClassifier.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/value/src/main/java/com/google/auto/value/processor/PropertyBuilderClassifier.java b/value/src/main/java/com/google/auto/value/processor/PropertyBuilderClassifier.java
index 0bdc47be..520a8be5 100644
--- a/value/src/main/java/com/google/auto/value/processor/PropertyBuilderClassifier.java
+++ b/value/src/main/java/com/google/auto/value/processor/PropertyBuilderClassifier.java
@@ -356,13 +356,23 @@ class PropertyBuilderClassifier {
// with the same name.
Map<String, ExecutableElement> methods = new LinkedHashMap<String, ExecutableElement>();
for (ExecutableElement method : ElementFilter.methodsIn(elementUtils.getAllMembers(type))) {
- if (method.getParameters().isEmpty()) {
+ if (method.getParameters().isEmpty() && !isStaticInterfaceMethodNotIn(method, type)) {
methods.put(method.getSimpleName().toString(), method);
}
}
return methods;
}
+ // Work around an Eclipse compiler bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=547185
+ // The result of Elements.getAllMembers includes static methods declared in superinterfaces.
+ // That's wrong because those aren't inherited. So this method checks whether the given method is
+ // a static interface method not in the given type.
+ private static boolean isStaticInterfaceMethodNotIn(ExecutableElement method, TypeElement type) {
+ return method.getModifiers().contains(Modifier.STATIC)
+ && !method.getEnclosingElement().equals(type)
+ && method.getEnclosingElement().getKind().equals(ElementKind.INTERFACE);
+ }
+
private Optional<ExecutableElement> addAllPutAll(TypeElement barBuilderTypeElement) {
for (ExecutableElement method :
MoreElements.getLocalAndInheritedMethods(barBuilderTypeElement, typeUtils, elementUtils)) {