owner property

  1. @override
DeclarationMirror get owner
inherited

A mirror on the owner of this Dart language entity.

The owner is the declaration immediately surrounding the reflectee:

  • For a library, the owner is null.
  • For a class declaration, typedef or top level function or variable, the owner is the enclosing library.
  • For a mixin application S with M, the owner is the owner of M.
  • For a constructor, the owner is the immediately enclosing class.
  • For a method, instance variable or a static variable, the owner is the immediately enclosing class, unless the class is a mixin application S with M, in which case the owner is M. Note that M may be an invocation of a generic.
  • For a parameter, local variable or local function the owner is the immediately enclosing function.

Required capabilities: owner on a ClassMirror requires a LibraryCapability; on other declarations it does not require any capabilities.

Implementation

@override
DeclarationMirror get owner {
  if (_ownerIndex == noCapabilityIndex) {
    if (!_supportsTypeRelations(_reflector)) {
      throw NoSuchCapabilityError(
        'Attempt to get `owner` of `$qualifiedName` '
        'without `typeRelationsCapability`',
      );
    }
    throw NoSuchCapabilityError(
      'Trying to get owner of class `$qualifiedName` '
      'without `libraryCapability`',
    );
  }
  return _data.libraryMirrors![_ownerIndex];
}