generateForClass static method

Future generateForClass(
  1. ClassElement element,
  2. SubjectGenContext<Element> genContext,
  3. SubjectCodeContext codeContext
)

Implementation

static Future generateForClass(
    ClassElement element,
    SubjectGenContext<Element> genContext,
    SubjectCodeContext codeContext) async {
  codeContext.additionalImports
      .add(AliasImport.gen("package:lyell/lyell.dart"));

  var constructorName = "";
  var constructor = element.unnamedConstructor;
  if (element.getNamedConstructor("dog") != null) {
    constructorName = ".dog";
    constructor = element.getNamedConstructor("dog");
  }
  StructurizeResult structurized;
  if (constructor != null && constructor.parameters.isNotEmpty) {
    // Create constructor based serializable
    structurized = await structurizeConstructor(
        element.thisType, constructor, genContext, codeContext.cachedCounter);
    codeContext.additionalImports.addAll(structurized.imports);
  } else if (constructor != null) {
    // Create bean like property based serializable
    structurized = await structurizeBean(
        element.thisType, element, genContext, codeContext.cachedCounter);
    codeContext.additionalImports.addAll(structurized.imports);
    writeBeanFactory(element, structurized, codeContext);
  } else {
    throw Exception("No accessible constructor");
  }

  writeGeneratedConverter(
      element, structurized, constructorName, codeContext);
  if (structurized.fieldNames.isNotEmpty &&
      structurized.structure.conformity != StructureConformity.bean) {
    writeGeneratedBuilder(
        element, structurized, constructorName, codeContext);
    writeGeneratedExtension(
        element, structurized, constructorName, codeContext);
  }
}