boolean hasProblem = false;
// method declared in the enclosing class vs. inherited getter
for (MethodElement method : enclosingClass.getMethods()) {
String name = method.getName();
// find inherited property accessor (and can be only getter)
ExecutableElement inherited = inheritanceManager.lookupInheritance(enclosingClass, name);
if (!(inherited instanceof PropertyAccessorElement)) {
continue;
}
// report problem
hasProblem = true;
errorReporter.reportErrorForOffset(
CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD,
method.getNameOffset(),
name.length(),
enclosingClass.getDisplayName(),
inherited.getEnclosingElement().getDisplayName(),
name);
}
// getter declared in the enclosing class vs. inherited method
for (PropertyAccessorElement accessor : enclosingClass.getAccessors()) {
if (!accessor.isGetter()) {
continue;
}
String name = accessor.getName();
// find inherited method
ExecutableElement inherited = inheritanceManager.lookupInheritance(enclosingClass, name);
if (!(inherited instanceof MethodElement)) {
continue;
}
// report problem
hasProblem = true;
errorReporter.reportErrorForOffset(
CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER,
accessor.getNameOffset(),
name.length(),
enclosingClass.getDisplayName(),
inherited.getEnclosingElement().getDisplayName(),
name);
}
// done
return hasProblem;
}