示例#1
0
 /** Initialize this index with information from the user libraries. */
 private boolean indexUserLibraries() {
   boolean librariesIndexed = true;
   try {
     AnalysisServer analysisServer = PackageLibraryManagerProvider.getDefaultAnalysisServer();
     SavedContext savedContext = analysisServer.getSavedContext();
     DartModel model = DartCore.create(ResourcesPlugin.getWorkspace().getRoot());
     for (DartProject project : model.getDartProjects()) {
       for (DartLibrary library : project.getDartLibraries()) {
         CompilationUnit compilationUnit = library.getDefiningCompilationUnit();
         if (compilationUnit == null) {
           continue;
         }
         IResource libraryResource = compilationUnit.getResource();
         if (libraryResource == null) {
           continue;
         }
         IPath libraryLocation = libraryResource.getLocation();
         if (libraryLocation == null) {
           continue;
         }
         File libraryFile = libraryLocation.toFile();
         savedContext.resolve(libraryFile, null);
       }
     }
   } catch (Exception exception) {
     librariesIndexed = false;
     DartCore.logError("Could not index user libraries", exception);
   }
   return librariesIndexed;
 }
示例#2
0
 /**
  * Initialize this index with information from the bundled libraries.
  *
  * @return <code>true</code> if the bundled libraries were successfully indexed
  */
 private boolean indexBundledLibraries() {
   boolean librariesIndexed = true;
   long startTime = System.currentTimeMillis();
   PackageLibraryManager libraryManager = PackageLibraryManagerProvider.getPackageLibraryManager();
   ArrayList<String> librarySpecs = new ArrayList<String>(libraryManager.getAllLibrarySpecs());
   if (librarySpecs.remove("dart:html")) {
     librarySpecs.add("dart:html");
   }
   AnalysisServer analysisServer = PackageLibraryManagerProvider.getDefaultAnalysisServer();
   analysisServer.reanalyze();
   SavedContext savedContext = analysisServer.getSavedContext();
   for (String urlSpec : librarySpecs) {
     try {
       URI libraryUri = new URI(urlSpec);
       File libraryFile = new File(libraryManager.resolveDartUri(libraryUri));
       savedContext.resolve(libraryFile, null);
     } catch (URISyntaxException exception) {
       librariesIndexed = false;
       DartCore.logError(
           "Invalid URI returned from the system library manager: \"" + urlSpec + "\"", exception);
     } catch (Exception exception) {
       librariesIndexed = false;
       DartCore.logError("Could not index bundled libraries", exception);
     }
   }
   if (DartCoreDebug.PERF_INDEX) {
     long endTime = System.currentTimeMillis();
     DartCore.logInformation(
         "Initializing the index with information from bundled libraries took "
             + (endTime - startTime)
             + " ms ("
             + initIndexingTime
             + " ms indexing)");
   }
   return librariesIndexed;
 }