/**
   * Parse the specified source. Any exceptions thrown by the {@link DartParser} will be logged and
   * a {@link DartModelException} thrown.
   *
   * @param librarySource the source for the library containing the compilation unit being parsed
   * @param unitUri the URI of the compilation unit being parsed
   * @param parseErrors a collection to which parse errors are appended or <code>null</code> if
   *     parse errors should be ignored
   * @return the parse result
   */
  public static DartUnit resolveUnit(
      LibrarySource librarySource,
      URI unitUri,
      Map<URI, String> suppliedSources,
      final Collection<DartCompilationError> parseErrors)
      throws DartModelException {

    long start = System.currentTimeMillis();

    ResolverRunnable runnable =
        new ResolverRunnable(librarySource, unitUri, suppliedSources, false, parseErrors);
    runnable.runSafe();

    long elapsed = System.currentTimeMillis() - start;
    Instrumentation.metric("DartCompilerUtils-resolveUnit", elapsed).log();

    Instrumentation.operation("DartCompilerUtils-resolveUnit", elapsed)
        .with("librarySource-ElementName", librarySource.getName())
        .with("librarySource.LastModified", librarySource.getLastModified())
        .log();

    if (runnable.exception != null) {
      throw new DartModelException(
          new CoreException(
              new Status(
                  IStatus.ERROR,
                  DartCore.PLUGIN_ID,
                  "Failed to parse " + unitUri,
                  runnable.exception)));
    }
    return runnable.unitResult;
  }
  /**
   * Parse the compilation units in the specified library. Any exceptions thrown by the {@link
   * DartParser} will be logged and a {@link DartModelException} thrown.
   *
   * @param library the library to be parsed (not <code>null</code>)
   * @param parseErrors a collection to which parse errors are appended or <code>null</code> if
   *     parse errors should be ignored
   * @return the parse result
   * @throws DartModelException if the library could not be parsed
   */
  public static LibraryUnit resolveLibrary(
      LibrarySource library,
      Collection<DartUnit> suppliedUnits,
      final Collection<DartCompilationError> parseErrors)
      throws DartModelException {

    long start = System.currentTimeMillis();

    ResolverRunnable runnable =
        new ResolverRunnable(library, createMap(suppliedUnits), false, parseErrors);
    runnable.runSafe();

    long elapsed = System.currentTimeMillis() - start;
    Instrumentation.metric("DartCompilerUtils-resolveLibrary", elapsed).log();
    Instrumentation.operation("DartCompilerUtils-resolveLibrary", elapsed)
        .with("librarySource.Name", library.getName())
        .with("librarySource.LastModified", library.getLastModified())
        .log();

    if (runnable.exception != null) {
      throw new DartModelException(
          new CoreException(
              new Status(
                  IStatus.ERROR,
                  DartCore.PLUGIN_ID,
                  "Failed to parse " + library.getName(),
                  runnable.exception)));
    }
    return runnable.libraryResult;
  }