resolveMultiplyInheritedElement function

ModelElement resolveMultiplyInheritedElement (
  1. MultiplyInheritedExecutableElement e,
  2. Library library,
  3. PackageGraph packageGraph,
  4. Class enclosingClass
)

Resolves this very rare case incorrectly by picking the closest element in the inheritance and interface chains from the analyzer.

Implementation

ModelElement resolveMultiplyInheritedElement(
    MultiplyInheritedExecutableElement e,
    Library library,
    PackageGraph packageGraph,
    Class enclosingClass) {
  var inheritables = e.inheritedElements
      .map((ee) => ModelElement.fromElement(ee, packageGraph) as Inheritable);
  Inheritable foundInheritable;
  var lowIndex = enclosingClass.inheritanceChain.length;
  for (var inheritable in inheritables) {
    var index =
        enclosingClass.inheritanceChain.indexOf(inheritable.enclosingElement);
    if (index < lowIndex) {
      foundInheritable = inheritable;
      lowIndex = index;
    }
  }
  return ModelElement.from(foundInheritable.element, library, packageGraph,
      enclosingContainer: enclosingClass);
}