*/
// TODO (jwren) In future nit CL, rename this method (and tests) to be consistent with name of error enum
// TODO (jwren) Revisit error code messages, to add more clarity, we may need the pair split into four codes
private boolean checkForMismatchedAccessorTypes(Declaration accessorDeclaration,
String accessorTextName) {
ExecutableElement accessorElement = (ExecutableElement) accessorDeclaration.getElement();
if (!(accessorElement instanceof PropertyAccessorElement)) {
return false;
}
PropertyAccessorElement propertyAccessorElement = (PropertyAccessorElement) accessorElement;
PropertyAccessorElement counterpartAccessor = null;
ClassElement enclosingClassForCounterpart = null;
if (propertyAccessorElement.isGetter()) {
counterpartAccessor = propertyAccessorElement.getCorrespondingSetter();
} else {
counterpartAccessor = propertyAccessorElement.getCorrespondingGetter();
// If the setter and getter are in the same enclosing element, return, this prevents having
// MISMATCHED_GETTER_AND_SETTER_TYPES reported twice.
if (counterpartAccessor != null
&& counterpartAccessor.getEnclosingElement() == propertyAccessorElement.getEnclosingElement()) {
return false;
}
}
if (counterpartAccessor == null) {
// If the accessor is declared in a class, check the superclasses.
if (enclosingClass != null) {
// Figure out the correct identifier to lookup in the inheritance graph, if 'x', then 'x=',
// or if 'x=', then 'x'.
String lookupIdentifier = propertyAccessorElement.getName();
if (StringUtilities.endsWithChar(lookupIdentifier, '=')) {
lookupIdentifier = lookupIdentifier.substring(0, lookupIdentifier.length() - 1);
} else {
lookupIdentifier += "=";
}
// lookup with the identifier.
ExecutableElement elementFromInheritance = inheritanceManager.lookupInheritance(
enclosingClass,
lookupIdentifier);
// Verify that we found something, and that it is an accessor
if (elementFromInheritance != null
&& elementFromInheritance instanceof PropertyAccessorElement) {
enclosingClassForCounterpart = (ClassElement) elementFromInheritance.getEnclosingElement();
counterpartAccessor = (PropertyAccessorElement) elementFromInheritance;
}
}
if (counterpartAccessor == null) {
return false;