isOverride property

bool isOverride

True if this Inheritable is overriding a superclass.

Implementation

bool get isOverride {
  if (_isOverride == null) {
    // The canonical version of the enclosing element -- not canonicalEnclosingElement,
    // as that is the element enclosing the canonical version of this element,
    // two different things.  Defaults to the enclosing element.
    //
    // We use canonical elements here where possible to deal with reexports
    // as seen in Flutter.
    if (enclosingElement is Extension) {
      _isOverride = false;
      return _isOverride;
    }
    Class enclosingCanonical = enclosingElement.canonicalModelElement;
    // The container in which this element was defined, canonical if available.
    Container definingCanonical =
        definingEnclosingContainer.canonicalModelElement ??
            definingEnclosingContainer;
    // The canonical version of the element we're overriding, if available.
    var overriddenCanonical =
        overriddenElement?.canonicalModelElement ?? overriddenElement;

    // We have to have an overridden element for it to be possible for this
    // element to be an override.
    _isOverride = overriddenElement != null &&
        // The defining class and the enclosing class for this element
        // must be the same (element is defined here).
        enclosingCanonical == definingCanonical &&
        // If the overridden element isn't public, we shouldn't be an
        // override in most cases.  Approximation until #1623 is fixed.
        overriddenCanonical.isPublic;
    assert(!(_isOverride && isInherited));
  }
  return _isOverride;
}