generateForClass method

Future<void> generateForClass({
  1. required ClassElement classElement,
  2. required ElementAnnotation annotation,
  3. required CompilationUnit compilationUnit,
  4. required ClassDeclaration classAstNode,
  5. required PubspecData pubspecData,
  6. required File classFile,
  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> generateForClass(
    {required ClassElement classElement,
    required ElementAnnotation annotation,
    required CompilationUnit compilationUnit,
    required ClassDeclaration classAstNode,
    required PubspecData pubspecData,
    required File classFile,
    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(classFile.path)}';

  final methodAstNodes = await classElement.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,
          classAstNode: classAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          className: classElement.displayName,
          methodAstNodes: methodAstNodes));
    } else if (testcases) {
      generationFutures.add(_testcasesForMethod(
          method: method,
          compilationUnit: compilationUnit,
          classAstNode: classAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          subjectFile: classFile,
          className: classElement.displayName,
          methodAstNodes: methodAstNodes));
    } else if (testability) {
      generationFutures.add(_testabilityForMethod(
          method: method,
          compilationUnit: compilationUnit,
          classAstNode: classAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          className: classElement.displayName,
          methodAstNodes: methodAstNodes));
    } else {
      generationFutures.add(_generateTestsForMethod(
          method: method,
          compilationUnit: compilationUnit,
          classAstNode: classAstNode,
          fileImport: fileImport,
          excludedMethods: excludedMethods,
          subjectFile: classFile,
          testRunInfo: testRunInfo,
          className: classElement.displayName,
          methodAstNodes: methodAstNodes));
    }
  }
  await Future.wait(generationFutures);
}