generateForExtension method

Future<void> generateForExtension({
  1. required ExtensionElement extElement,
  2. required ElementAnnotation annotation,
  3. required CompilationUnit compilationUnit,
  4. required ExtensionDeclaration extAstNode,
  5. required PubspecData pubspecData,
  6. required File extFile,
  7. required List<String> requestedFunctions,
  8. required TestRunInfo testRunInfo,
  9. required bool dryrun,
  10. required bool testcases,
  11. required bool testability,
  12. required FlagGenerationRunInfo flagGenerationRunInfo,
})

Implementation

Future<void> generateForExtension(
    {required ExtensionElement extElement,
    required ElementAnnotation annotation,
    required CompilationUnit compilationUnit,
    required ExtensionDeclaration extAstNode,
    required PubspecData pubspecData,
    required File extFile,
    required List<String> requestedFunctions,
    required TestRunInfo testRunInfo,
    required bool dryrun,
    required bool testcases,
    required bool testability,
    required FlagGenerationRunInfo flagGenerationRunInfo}) async {
  final List<String> excludedMethods = annotation.excludeMethods;
  final fileImport =
      'package:${pubspecData.packageName}/${PathUtils.relatetiveLibFilePath(extFile.path)}';

  final methodAstNodes = await extElement.getMethodDeclarations;

  List<Future> generationFutures = [];
  for (int i = 0; i < methodAstNodes.entries.length; i++) {
    final method = methodAstNodes.entries.elementAt(i);

    if (requestedFunctions.isNotEmpty) {
      final methodName = method.key.toLowerCase();
      if (!requestedFunctions.contains(methodName)) continue;

      flagGenerationRunInfo.popFromQueue(FlagType.methodName, methodName);
    }

    if (dryrun) {
      generationFutures.add(_dryrunForMethod(
          method: method,
          compilationUnit: compilationUnit,
          extAstNode: extAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          className: extElement.displayName,
          methodAstNodes: methodAstNodes));
    } else if (testability) {
      generationFutures.add(_testabilityForMethod(
          method: method,
          compilationUnit: compilationUnit,
          extAstNode: extAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          className: extElement.displayName,
          methodAstNodes: methodAstNodes));
    } else if (testcases) {
      generationFutures.add(_testcasesForMethod(
          method: method,
          compilationUnit: compilationUnit,
          extAstNode: extAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          subjectFile: extFile,
          className: extElement.displayName,
          methodAstNodes: methodAstNodes));
    } else {
      generationFutures.add(_generateTestsForMethod(
          method: method,
          compilationUnit: compilationUnit,
          extAstNode: extAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          subjectFile: extFile,
          testRunInfo: testRunInfo,
          className: extElement.displayName,
          methodAstNodes: methodAstNodes));
    }
  }
  await Future.wait(generationFutures);
}