parseClasses method

  1. @override
Future<List<ClassElement>> parseClasses(
  1. ProjectConfiguration configuration,
  2. String projectPath
)
override

Implementation

@override
Future<List<ClassElement>> parseClasses(
  ProjectConfiguration configuration,
  String projectPath,
) async {
  printer.printInfo('Parsing starts with path $projectPath');
  final dartFilesPaths = _getDartFilesPaths(projectPath, configuration);
  final contextCollection = getAnalysisContextCollection(projectPath, dartFilesPaths);
  final collector = _ClassElementCollector();

  for (var i = 0; i < dartFilesPaths.length; i++) {
    final filePath = dartFilesPaths[i];
    AnalysisContext context;
    try {
      context = contextCollection.contextFor(filePath);
    } on StateError catch (_) {
      context = AnalysisContextCollectionImpl(includedPaths: [filePath]).contextFor(filePath);
    } catch (e) {
      //TODO logging files that throws exception and save to file
      continue;
    }

    final unitResult = await context.currentSession.getResolvedUnit2(filePath) as ResolvedUnitResult;
    if (!unitResult.isPart) {
      unitResult.libraryElement.accept(collector);
    }
    if (printEveryFoundedClass) {
      final short = filePath..replaceAll(projectPath, '');
      print('Parsing ${i + 1} of ${dartFilesPaths.length} files  - $short');
    }
  }
  final classes = collector.classElements;
  print('Parsing ${dartFilesPaths.length} files done - founded ${classes.length} class');

  return classes;
}