JsonModel constructor

JsonModel(
  1. String fileName,
  2. List<DartDeclaration> dartDeclarations, {
  3. String? packageName,
  4. String? indexPath,
  5. String? relativePath,
})

Implementation

JsonModel(
  this.fileName,
  List<DartDeclaration> dartDeclarations, {
  this.packageName,
  this.indexPath,
  this.relativePath,
}) {
  final extendsClass = dartDeclarations.where((element) => element.extendsClass != null).toList();
  mixinClass = dartDeclarations
      .where(
        (element) => element.mixinClass != null,
      )
      .map((element) => element.mixinClass)
      .join(', ');

  className = fileName.toTitleCase();

  constructor = dartDeclarations.toConstructor(
    className,
    hasExtends: extendsClass.isNotEmpty,
    hasMixin: mixinClass.isNotEmpty,
  );

  declaration = dartDeclarations.toDeclarationStrings(className);
  mockDeclaration = dartDeclarations.toMockDeclarationStrings(className);
  copyWith = dartDeclarations.toCopyWith(className);
  cloneFunction = dartDeclarations.toCloneFunction(className);
  jsonFunctions = dartDeclarations.toJsonFunctions(className);
  equalsDeclarations = dartDeclarations.toEqualsDeclarationString();
  hashDeclarations = dartDeclarations.toHashDeclarationString();
  imports = dartDeclarations.toImportStrings(relativePath);
  enums = dartDeclarations.getEnums(className);
  nestedClasses = dartDeclarations.getNestedModelClasses();
  nestedFactoryClasses = dartDeclarations.getNestedFactoryClasses();

  if (extendsClass.isNotEmpty) {
    this.extendsClass = extendsClass[0].extendsClass;
  }
}