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