generateForClass method
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,
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);
}