collectChildren method

  1. @override
void collectChildren(
  1. InspectionCache cache, {
  2. required String stdlibPath,
  3. required Module parentModule,
})
override

Collects all children of this entry during the inspection process.

Implementation

@override
void collectChildren(
  InspectionCache cache, {
  required String stdlibPath,
  required Module parentModule,
}) {
  final inspect inspectModule = inspect.import();
  final InspectEntry? selfCached = cache[value];
  if (selfCached == null) {
    cache[value] = this;
  }
  for (final (String name, Object? value) in _members) {
    if (name.startsWith("_") &&
        !_explicitlyAllowedChildNames.contains(name)) {
      continue;
    }
    try {
      if (inspectModule.isbuiltin(value)) {
        continue;
      }
    } on PythonExceptionInterface<PythonFfiDelegate<Object?>,
        Object?> catch (_) {
      // ignore
    }
    try {
      if (inspectModule.ismethodwrapper(value)) {
        continue;
      }
    } on PythonExceptionInterface<PythonFfiDelegate<Object?>,
        Object?> catch (_) {
      // ignore
    }
    final String sanitizedName =
        sanitizeName(name, extraKeywords: _sanitizationExtraKeywords);
    final InspectEntry? cached = cache[value];
    final InspectEntry child = cached ??
        switch (value) {
          PythonModuleInterface<PythonFfiDelegate<Object?>, Object?>()
              when inspectModule.ismodule(value) =>
            Module.from(value, name: name, sanitizedName: sanitizedName),
          PythonModuleInterface<PythonFfiDelegate<Object?>, Object?>() =>
            throw Exception("'$name' is not a module: $value"),
          PythonClassDefinitionInterface<PythonFfiDelegate<Object?>,
                  Object?>()
              when inspectModule.isclass(value) =>
            ClassDefinition.from(value),
          PythonClassInterface<PythonFfiDelegate<Object?>, Object?>() =>
            ClassInstance.from(value),
          PythonFunctionInterface<PythonFfiDelegate<Object?>, Object?>()
              when inspectModule.isfunction(value) =>
            Function_.from(value),
          PythonFunctionInterface<PythonFfiDelegate<Object?>, Object?>() =>
            throw Exception("'$name' is not a function: $value"),
          PythonObjectInterface<PythonFfiDelegate<Object?>, Object?>() =>
            Object_.from(value),
          _ => Primitive(name, sanitizedName, value),
        } as InspectEntry;
    if (!_isTypedef(child) && _isStdlibEntry(child, stdlibPath: stdlibPath)) {
      continue;
    }
    final InspectEntryModuleConnection connection =
        InspectEntryModuleConnection(
      name: name,
      sanitizedName: sanitizedName,
      parentModule: parentModule,
    );
    final bool didAddConnection = child.addModuleConnection(connection);
    _setChild(name, child);
    if (cached == null) {
      cache[value] = child;
    }
    if (didAddConnection) {
      child.collectChildren(
        cache,
        stdlibPath: stdlibPath,
        parentModule: parentModule,
      );
    }
  }
}