generate method

Future<String> generate()

Implementation

Future<String> generate() async {

  timer.start('composer');
  try {
    output.writeSplit();
    output.writeLn('// generated by swift_composer at ' + timer.starts.first.toString());
    output.writeSplit();
    timer.start('config');
    output.writeLn('// CONFIG');
    await _loadLibraryFiles();
    await _loadConfig();
    output.writeSplit();
    output.writeLn('// MERGED CONFIG');
    this.config.config.forEach((key, value) {
      output.writeLn("// ${key}: ${value}".replaceAll('\n', '\\n'));
    });
    output.writeSplit();
    timer.end();

    for (var importElement in library.element.libraryImports) {
      if (!importElement.importedLibrary!.isDartCore) {
        importElement.namespace.definedNames.forEach((key, value) {
          //output.writeLn('//' + key + ' ' + value.displayName + ' ' + value.getExtendedDisplayName('test') + " ${value.hashCode}");
        });
        //importedLibrariesMap[importElement!.importedLibrary!] = importElement.prefix == null ? null : importElement.prefix!.name;
        //output.writeLn('// import ' + (importElement.importedLibrary?.identifier ?? 'null') + (importElement.prefix == null ? '' : ' as ' + importElement.prefix!.name));
        importElement.namespace.definedNames.forEach(typeMap.registerClassElement);
      }
    }
    library.allElements.forEach((element) => (element.name != null) ? typeMap.registerClassElement(element.name!, element) : null);

    //DEBUG INFO

    new Map<String, TypeInfo>.from(typeMap.allTypes).forEach((key, value) {
      value.preAnaliseAllUsedTypes();
    });

    if (debug) {
      output.writeLn('// ALL TYPES INFO');
      output.writeSplit();
      typeMap.allTypes.forEach((key, value) {
        output.writeLn('// ' + key + ' => ' + value.debugInfo);
      });
    }

    timer.start('interceptors');
    for (int i=0; i < typeMap.allTypes.keys.length; i++) {
      TypeInfo type = typeMap.allTypes[typeMap.allTypes.keys.elementAt(i)]!;
      if (type.hasInterceptor() && !type.isNullable) {
        output.writeSplit();
        if (debug) {
          output.writeLn("// interceptor for [${type.uniqueName}]");
          await type.writeDebugInfo(output);
        }
        await type.generateInterceptor(output, this);
      } else {
        if (debug) {
          output.writeLn("// no interceptor for [${type.uniqueName}]");
          await type.writeDebugInfo(output);
        }
      }
    }
    timer.end();
    /*List<String> allTypes = [];
    allTypes.addAll(typeMap.allTypes.keys);
    for (var s in allTypes) {
      output.writeSplit();
      if (typeMap.allTypes[s]!.hasInterceptor()) {
          output.writeLn("//interceptor for [${typeMap.allTypes[s]!.fullName}]");
          await typeMap.allTypes[s]!.generateInterceptor(output, this);
      } else {
        output.writeLn("//no interceptor for [${typeMap.allTypes[s]!.fullName}]");
      }
    };*/
    timer.start('om');
    output.writeSplit();
    generateSubtypesOf();
    output.writeSplit();
    generateCompiledMethodsParts();
    output.writeSplit();
    generateObjectManager();
    timer.end();

  } catch(e, stacktrace) {
    output.writeLn('/* unhandled code generator exception: \n' + e.toString() + '\n' + stacktrace.toString() + '*/');
  }
  timer.start('index');
  await _buildWidgetsIndex();
  timer.end();
  timer.end();
  timer.print(output, debug);
  return output.getOutput();
}