From 3854a6508a8cc72eda1ae15b08ab3949d1cc778d Mon Sep 17 00:00:00 2001 From: emcmanus Date: Mon, 13 May 2019 07:22:28 -0700 Subject: 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 --- .../auto/value/processor/PropertyBuilderClassifier.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'value/src/main/java/com/google') 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 methods = new LinkedHashMap(); 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 addAllPutAll(TypeElement barBuilderTypeElement) { for (ExecutableElement method : MoreElements.getLocalAndInheritedMethods(barBuilderTypeElement, typeUtils, elementUtils)) { -- cgit v1.2.3