processLibrary method

Future<DartDocResolvedLibrary> processLibrary(
  1. String filePath
)

Parse a single library at filePath using the current analysis driver. If filePath is not a library, returns null.

Implementation

Future<DartDocResolvedLibrary> processLibrary(String filePath) async {
  var name = filePath;
  var directoryCurrentPath = resourceProvider.pathContext.current;

  if (name.startsWith(directoryCurrentPath)) {
    name = name.substring(directoryCurrentPath.length);
    if (name.startsWith(resourceProvider.pathContext.separator)) {
      name = name.substring(1);
    }
  }
  var javaFile = JavaFile(filePath).getAbsoluteFile();
  filePath = javaFile.getPath();

  var analysisContext = contextCollection.contextFor(config.inputDir);
  var session = analysisContext.currentSession;
  var sourceKind = await session.getSourceKind(filePath);

  // Allow dart source files with inappropriate suffixes (#1897).  Those
  // do not show up as SourceKind.LIBRARY.
  if (sourceKind != SourceKind.PART) {
    // Loading libraryElements from part files works, but is painfully slow
    // and creates many duplicates.
    final library = await session.getResolvedLibrary(filePath);
    final libraryElement = library.element;
    var restoredUri = libraryElement.source.uri.toString();
    return DartDocResolvedLibrary(library, restoredUri);
  }
  return null;
}