OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.core.internal.index.impl; | 14 package com.google.dart.tools.core.internal.index.impl; |
15 | 15 |
16 import com.google.dart.compiler.DartSource; | 16 import com.google.dart.compiler.DartSource; |
17 import com.google.dart.compiler.LibrarySource; | 17 import com.google.dart.compiler.LibrarySource; |
18 import com.google.dart.compiler.SystemLibraryManager; | 18 import com.google.dart.compiler.SystemLibraryManager; |
19 import com.google.dart.compiler.ast.DartUnit; | 19 import com.google.dart.compiler.ast.DartUnit; |
20 import com.google.dart.compiler.ast.LibraryUnit; | |
21 import com.google.dart.tools.core.DartCore; | 20 import com.google.dart.tools.core.DartCore; |
22 import com.google.dart.tools.core.DartCoreDebug; | 21 import com.google.dart.tools.core.DartCoreDebug; |
23 import com.google.dart.tools.core.analysis.AnalysisServer; | 22 import com.google.dart.tools.core.analysis.AnalysisServer; |
24 import com.google.dart.tools.core.analysis.ResolveCallback; | 23 import com.google.dart.tools.core.analysis.ResolveCallback; |
25 import com.google.dart.tools.core.analysis.SavedContext; | 24 import com.google.dart.tools.core.analysis.SavedContext; |
26 import com.google.dart.tools.core.index.Attribute; | 25 import com.google.dart.tools.core.index.Attribute; |
27 import com.google.dart.tools.core.index.AttributeCallback; | 26 import com.google.dart.tools.core.index.AttributeCallback; |
28 import com.google.dart.tools.core.index.Element; | 27 import com.google.dart.tools.core.index.Element; |
29 import com.google.dart.tools.core.index.Index; | 28 import com.google.dart.tools.core.index.Index; |
30 import com.google.dart.tools.core.index.NotifyCallback; | 29 import com.google.dart.tools.core.index.NotifyCallback; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 63 |
65 import java.io.File; | 64 import java.io.File; |
66 import java.io.FileInputStream; | 65 import java.io.FileInputStream; |
67 import java.io.FileOutputStream; | 66 import java.io.FileOutputStream; |
68 import java.io.IOException; | 67 import java.io.IOException; |
69 import java.io.ObjectInputStream; | 68 import java.io.ObjectInputStream; |
70 import java.io.ObjectOutputStream; | 69 import java.io.ObjectOutputStream; |
71 import java.net.URI; | 70 import java.net.URI; |
72 import java.net.URISyntaxException; | 71 import java.net.URISyntaxException; |
73 import java.util.ArrayList; | 72 import java.util.ArrayList; |
74 import java.util.HashSet; | |
75 | 73 |
76 /** | 74 /** |
77 * The unique instance of the class <code>InMemoryIndex</code> maintains an in-m
emory {@link Index | 75 * The unique instance of the class <code>InMemoryIndex</code> maintains an in-m
emory {@link Index |
78 * index}. The index is expected to be initialized once before it is used in any
given session and | 76 * index}. The index is expected to be initialized once before it is used in any
given session and |
79 * shut down at the end of the session. The index will be read from disk when it
is initialized and | 77 * shut down at the end of the session. The index will be read from disk when it
is initialized and |
80 * written to disk when it is shut down. | 78 * written to disk when it is shut down. |
81 */ | 79 */ |
82 public class InMemoryIndex implements Index { | 80 public class InMemoryIndex implements Index { |
83 /** | 81 /** |
84 * The index store used to hold the data in the index. | 82 * The index store used to hold the data in the index. |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 * Initialize this index with information from the user libraries. | 462 * Initialize this index with information from the user libraries. |
465 */ | 463 */ |
466 private boolean indexUserLibraries() { | 464 private boolean indexUserLibraries() { |
467 boolean librariesIndexed = true; | 465 boolean librariesIndexed = true; |
468 try { | 466 try { |
469 AnalysisServer analysisServer = SystemLibraryManagerProvider.getDefaultAna
lysisServer(); | 467 AnalysisServer analysisServer = SystemLibraryManagerProvider.getDefaultAna
lysisServer(); |
470 SavedContext savedContext = analysisServer.getSavedContext(); | 468 SavedContext savedContext = analysisServer.getSavedContext(); |
471 DartModel model = DartCore.create(ResourcesPlugin.getWorkspace().getRoot()
); | 469 DartModel model = DartCore.create(ResourcesPlugin.getWorkspace().getRoot()
); |
472 for (DartProject project : model.getDartProjects()) { | 470 for (DartProject project : model.getDartProjects()) { |
473 for (DartLibrary library : project.getDartLibraries()) { | 471 for (DartLibrary library : project.getDartLibraries()) { |
474 IResource libraryResource = library.getResource(); | 472 CompilationUnit compilationUnit = library.getDefiningCompilationUnit()
; |
| 473 if (compilationUnit == null) { |
| 474 continue; |
| 475 } |
| 476 IResource libraryResource = compilationUnit.getResource(); |
475 if (libraryResource == null) { | 477 if (libraryResource == null) { |
476 continue; | 478 continue; |
477 } | 479 } |
478 IPath libraryLocation = libraryResource.getLocation(); | 480 IPath libraryLocation = libraryResource.getLocation(); |
479 if (libraryLocation == null) { | 481 if (libraryLocation == null) { |
480 continue; | 482 continue; |
481 } | 483 } |
482 File libraryFile = libraryLocation.toFile(); | 484 File libraryFile = libraryLocation.toFile(); |
483 ResolveCallback.Sync callback = new ResolveCallback.Sync(); | 485 ResolveCallback.Sync callback = new ResolveCallback.Sync(); |
484 savedContext.resolve(libraryFile, callback); | 486 savedContext.resolve(libraryFile, callback); |
485 // Block until library is resolved so that we know it has been indexed | 487 // Block until library is resolved so that we know it has been indexed |
486 callback.waitForResolve(5 * 60 * 1000); // Five minutes | 488 callback.waitForResolve(5 * 60 * 1000); // Five minutes |
487 } | 489 } |
488 } | 490 } |
489 } catch (Exception exception) { | 491 } catch (Exception exception) { |
490 librariesIndexed = false; | 492 librariesIndexed = false; |
491 DartCore.logError("Could not index user libraries", exception); | 493 DartCore.logError("Could not index user libraries", exception); |
492 } | 494 } |
493 return librariesIndexed; | 495 return librariesIndexed; |
494 } | 496 } |
495 | 497 |
496 /** | 498 /** |
497 * Initialize this index with information from the given user library. | |
498 * | |
499 * @param libraryUnit the library to be used to initialize the index | |
500 * @param initializedLibraries the URI's of libraries that have already been u
sed to initialize | |
501 * the index | |
502 */ | |
503 private void indexUserLibrary(LibraryUnit libraryUnit, HashSet<URI> initialize
dLibraries) { | |
504 LibrarySource librarySource = libraryUnit.getSource(); | |
505 URI libraryUri = librarySource.getUri(); | |
506 if (SystemLibraryManager.isDartUri(libraryUri) || initializedLibraries.conta
ins(libraryUri)) { | |
507 return; | |
508 } | |
509 initializedLibraries.add(libraryUri); | |
510 DartLibraryImpl library = new DartLibraryImpl(librarySource); | |
511 for (DartUnit ast : libraryUnit.getUnits()) { | |
512 DartSource unitSource = (DartSource) ast.getSourceInfo().getSource(); | |
513 URI unitUri = unitSource.getUri(); | |
514 Resource resource = new Resource(unitUri.toString()); | |
515 CompilationUnit compilationUnit = new CompilationUnitImpl( | |
516 library, | |
517 unitUri, | |
518 DefaultWorkingCopyOwner.getInstance()); | |
519 // library.getCompilationUnit(unitUri); | |
520 long startTime = System.currentTimeMillis(); | |
521 indexResource(resource, compilationUnit, ast); | |
522 long endTime = System.currentTimeMillis(); | |
523 initIndexingTime += endTime - startTime; | |
524 } | |
525 for (LibraryUnit importedLibrary : libraryUnit.getImportedLibraries()) { | |
526 // library.getImportedLibrary(importedLibrary.getSource().getUri()); | |
527 indexUserLibrary(importedLibrary, initializedLibraries); | |
528 } | |
529 } | |
530 | |
531 /** | |
532 * Initialize this index to contain information about the bundled libraries. T
he index store is | 499 * Initialize this index to contain information about the bundled libraries. T
he index store is |
533 * expected to have been cleared before invoking this method. | 500 * expected to have been cleared before invoking this method. |
534 * | 501 * |
535 * @return {@code true} if the bundled libraries were successfully indexed | 502 * @return {@code true} if the bundled libraries were successfully indexed |
536 */ | 503 */ |
537 private boolean initializeBundledLibraries() { | 504 private boolean initializeBundledLibraries() { |
538 synchronized (indexStore) { | 505 synchronized (indexStore) { |
539 hasBeenInitialized = true; | 506 hasBeenInitialized = true; |
540 if (!initializeIndexFrom(getInitialIndexFile())) { | 507 if (!initializeIndexFrom(getInitialIndexFile())) { |
541 indexStore.clear(); | 508 indexStore.clear(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 } | 638 } |
672 } | 639 } |
673 if (!successfullyWritten) { | 640 if (!successfullyWritten) { |
674 if (!indexFile.delete()) { | 641 if (!indexFile.delete()) { |
675 DartCore.logError("Could not delete corrupted index file: \"" + indexFil
e.getAbsolutePath() | 642 DartCore.logError("Could not delete corrupted index file: \"" + indexFil
e.getAbsolutePath() |
676 + "\""); | 643 + "\""); |
677 } | 644 } |
678 } | 645 } |
679 } | 646 } |
680 } | 647 } |
OLD | NEW |