Skip to content

Commit 3854a65

Browse files
eamonnmcmanusronshapiro
authored andcommitted
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
1 parent 5724c0d commit 3854a65

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

value/src/main/java/com/google/auto/value/processor/PropertyBuilderClassifier.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,23 @@ private Map<String, ExecutableElement> noArgMethodsOf(TypeElement type) {
356356
// with the same name.
357357
Map<String, ExecutableElement> methods = new LinkedHashMap<String, ExecutableElement>();
358358
for (ExecutableElement method : ElementFilter.methodsIn(elementUtils.getAllMembers(type))) {
359-
if (method.getParameters().isEmpty()) {
359+
if (method.getParameters().isEmpty() && !isStaticInterfaceMethodNotIn(method, type)) {
360360
methods.put(method.getSimpleName().toString(), method);
361361
}
362362
}
363363
return methods;
364364
}
365365

366+
// Work around an Eclipse compiler bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=547185
367+
// The result of Elements.getAllMembers includes static methods declared in superinterfaces.
368+
// That's wrong because those aren't inherited. So this method checks whether the given method is
369+
// a static interface method not in the given type.
370+
private static boolean isStaticInterfaceMethodNotIn(ExecutableElement method, TypeElement type) {
371+
return method.getModifiers().contains(Modifier.STATIC)
372+
&& !method.getEnclosingElement().equals(type)
373+
&& method.getEnclosingElement().getKind().equals(ElementKind.INTERFACE);
374+
}
375+
366376
private Optional<ExecutableElement> addAllPutAll(TypeElement barBuilderTypeElement) {
367377
for (ExecutableElement method :
368378
MoreElements.getLocalAndInheritedMethods(barBuilderTypeElement, typeUtils, elementUtils)) {

0 commit comments

Comments
 (0)