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;
  // Allow dart source files with inappropriate suffixes (#1897).
  final library = await session.getResolvedLibrary2(filePath);
  if (library is ResolvedLibraryResult) {
    final libraryElement = library.element;
    var restoredUri = libraryElement.source.uri.toString();
    return DartDocResolvedLibrary(library, restoredUri);
  }
  return null;
}