generateSubject method

  1. @override
FutureOr<void> generateSubject(
  1. SubjectGenContext<Element> genContext,
  2. SubjectCodeContext codeContext
)

Implementation

@override
FutureOr<void> generateSubject(
    SubjectGenContext<Element> genContext, SubjectCodeContext codeContext) async {
  var libraries = getSerializableLibraries(genContext);
  var resolvedTypeSets = await Future.wait(libraries.map((e) => getSerializedTypes(genContext.step, e)));
  var allTypes = resolvedTypeSets.expand((e) => e).toSet();
  var passTypes = allTypes.toSet();
  if (hasBuiltInterop) {
    for (var element in allTypes) {
      if (!builtChecker.isAssignableFrom(element)) {
        continue;
      }
      passTypes.remove(element);
      log.fine("Generating built_value dogs interop for '${element.name}'");
      try {
        await writeBuiltInteropConverter(element as ClassElement, codeContext, genContext);
      } catch (ex) {
        log.severe("Can't generate built_value dogs interop for '${element.name}' with error: $ex");
      }
    }
  }

  for (var element in passTypes) {
    log.fine("Generating dogs converter for '${element.name}'");
    try {
      if (element is ClassElement) {
        await ConverterBuilder.generateForClass(element, genContext, codeContext);
      } else if (element is EnumElement) {
        await ConverterBuilder.generateForEnum(element, genContext, codeContext);
      }
    } catch (ex) {
      log.severe("Can't generate converter for '${element.name}' with error: $ex");
    }
  }
}