analyzeModels function

Future<void> analyzeModels({
  1. String? fallbackDartSdkPath,
  2. required Set<String> rootDirPaths,
  3. Set<String> subDirPaths = const {},
  4. void onAnnotation(
    1. String filePath,
    2. GenerateModel annotation
    )?,
})

Implementation

Future<void> analyzeModels({
  String? fallbackDartSdkPath,
  required Set<String> rootDirPaths,
  Set<String> subDirPaths = const {},
  void Function(String filePath, GenerateModel annotation)? onAnnotation,
}) async {
  final combinedPaths = combinePathSets([rootDirPaths, subDirPaths]);
  final collection = createAnalysisContextCollection(
    combinedPaths,
    fallbackDartSdkPath,
  );
  for (final path in combinedPaths) {
    final files = await findFiles(
      path,
      extensions: {'.dart'},
      onFileFound: (dirName, folderName, filePath) async {
        final a = isMatchingFileName(filePath, '', 'dart').status;
        final b = isSourceDartFilePath(filePath);
        if (a && b) {
          return true;
        }
        return false;
      },
    );
    for (final filePath in files.map((e) => e.filePath)) {
      final annotation = await analyzeModelFromFile(
        collection: collection,
        inputFilePath: filePath,
      );
      if (annotation != null) {
        onAnnotation?.call(filePath, annotation);
      }
    }
  }
}