declarations property
Returns an immutable map of the declarations actually given in the library.
This map includes all regular methods, getters, setters, fields, classes and typedefs actually declared in the library. The map is keyed by the simple names of the declarations.
Required capabilities: declarations requires a DeclarationsCapability. Note that the available invocation capabilities determine which declarations are included. E.g., in order to obtain a declaration mirror for a given instance method as part of the value returned from declarations there must be a matching InstanceInvokeCapability or InstanceInvokeMetaCapability, and similarly for static methods and top-level functions.
Implementation
@override
Map<String, DeclarationMirror> get declarations {
Map<String, DeclarationMirror>? declarations = _declarations;
if (declarations == null) {
var result = <String, DeclarationMirror>{};
for (int declarationIndex in _declarationIndices) {
// We encode a missing `declarations` capability as an index with
// the value noCapabilityIndex. Note that [declarations] will not be
// initialized and hence we will come here repeatedly if that is the
// case; however, performing operations for which there is no capability
// need not have stellar performance, it is almost always a bug to do
// that.
if (declarationIndex == noCapabilityIndex) {
throw NoSuchCapabilityError(
'Requesting declarations of `$qualifiedName` without capability',
);
}
DeclarationMirror declarationMirror =
_data.memberMirrors![declarationIndex];
result[declarationMirror.simpleName] = declarationMirror;
}
for (TypeMirror typeMirror in _data.typeMirrors) {
if (typeMirror is ClassMirror && typeMirror.owner == this) {
result[typeMirror.simpleName] = typeMirror;
}
}
_declarations = declarations =
UnmodifiableMapView<String, DeclarationMirror>(result);
}
return declarations;
}