Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: pkg/analyzer/lib/src/generated/engine.dart

Issue 137863002: Issue 8742. Preserve leading line comments during java2dart translation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Test for block-style comment translation. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine; 8 library engine;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 * The logger that should receive information about errors within the analysis engine. 87 * The logger that should receive information about errors within the analysis engine.
88 */ 88 */
89 Logger _logger = Logger.NULL; 89 Logger _logger = Logger.NULL;
90 90
91 /** 91 /**
92 * Create a new context in which analysis can be performed. 92 * Create a new context in which analysis can be performed.
93 * 93 *
94 * @return the analysis context that was created 94 * @return the analysis context that was created
95 */ 95 */
96 AnalysisContext createAnalysisContext() { 96 AnalysisContext createAnalysisContext() {
97 //
98 // If instrumentation is ignoring data, return an uninstrumented analysis co ntext.
99 //
97 if (Instrumentation.isNullLogger) { 100 if (Instrumentation.isNullLogger) {
98 return new DelegatingAnalysisContextImpl(); 101 return new DelegatingAnalysisContextImpl();
99 } 102 }
100 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisContex tImpl()); 103 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisContex tImpl());
101 } 104 }
102 105
103 /** 106 /**
104 * Return the logger that should receive information about errors within the a nalysis engine. 107 * Return the logger that should receive information about errors within the a nalysis engine.
105 * 108 *
106 * @return the logger that should receive information about errors within the analysis engine 109 * @return the logger that should receive information about errors within the analysis engine
(...skipping 2079 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 * 2189 *
2187 * @param state the state to which the data is being transitioned 2190 * @param state the state to which the data is being transitioned
2188 * @param currentValue the value of the flags before the transition 2191 * @param currentValue the value of the flags before the transition
2189 * @param bitMask the mask used to access the bit whose state is being set 2192 * @param bitMask the mask used to access the bit whose state is being set
2190 * @return the value of the data that should be kept in the cache 2193 * @return the value of the data that should be kept in the cache
2191 */ 2194 */
2192 int updatedValue2(CacheState state, int currentValue, int bitIndex) { 2195 int updatedValue2(CacheState state, int currentValue, int bitIndex) {
2193 if (identical(state, CacheState.VALID)) { 2196 if (identical(state, CacheState.VALID)) {
2194 throw new IllegalArgumentException("Use setValue() to set the state to VAL ID"); 2197 throw new IllegalArgumentException("Use setValue() to set the state to VAL ID");
2195 } else if (identical(state, CacheState.IN_PROCESS)) { 2198 } else if (identical(state, CacheState.IN_PROCESS)) {
2199 //
2200 // We can leave the current value in the cache for any 'get' methods to ac cess.
2201 //
2196 return currentValue; 2202 return currentValue;
2197 } 2203 }
2198 return BooleanArray.set2(currentValue, bitIndex, false); 2204 return BooleanArray.set2(currentValue, bitIndex, false);
2199 } 2205 }
2200 } 2206 }
2201 2207
2202 /** 2208 /**
2203 * Instances of the class `ResolutionState` represent the information produced b y resolving 2209 * Instances of the class `ResolutionState` represent the information produced b y resolving
2204 * a compilation unit as part of a specific library. 2210 * a compilation unit as part of a specific library.
2205 */ 2211 */
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
2905 * 2911 *
2906 * @param state the state to which the data is being transitioned 2912 * @param state the state to which the data is being transitioned
2907 * @param currentValue the value of the data before the transition 2913 * @param currentValue the value of the data before the transition
2908 * @param defaultValue the value to be used if the current value is to be remo ved from the cache 2914 * @param defaultValue the value to be used if the current value is to be remo ved from the cache
2909 * @return the value of the data that should be kept in the cache 2915 * @return the value of the data that should be kept in the cache
2910 */ 2916 */
2911 Object updatedValue(CacheState state, Object currentValue, Object defaultValue ) { 2917 Object updatedValue(CacheState state, Object currentValue, Object defaultValue ) {
2912 if (identical(state, CacheState.VALID)) { 2918 if (identical(state, CacheState.VALID)) {
2913 throw new IllegalArgumentException("Use setValue() to set the state to VAL ID"); 2919 throw new IllegalArgumentException("Use setValue() to set the state to VAL ID");
2914 } else if (identical(state, CacheState.IN_PROCESS)) { 2920 } else if (identical(state, CacheState.IN_PROCESS)) {
2921 //
2922 // We can leave the current value in the cache for any 'get' methods to ac cess.
2923 //
2915 return currentValue; 2924 return currentValue;
2916 } 2925 }
2917 return defaultValue; 2926 return defaultValue;
2918 } 2927 }
2919 2928
2920 /** 2929 /**
2921 * Write a textual representation of this entry to the given builder. The resu lt will only be used 2930 * Write a textual representation of this entry to the given builder. The resu lt will only be used
2922 * for debugging purposes. 2931 * for debugging purposes.
2923 * 2932 *
2924 * @param builder the builder to which the text should be written 2933 * @param builder the builder to which the text should be written
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 3093
3085 /** 3094 /**
3086 * Initialize a newly created analysis context. 3095 * Initialize a newly created analysis context.
3087 */ 3096 */
3088 AnalysisContextImpl() : super() { 3097 AnalysisContextImpl() : super() {
3089 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); 3098 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this);
3090 _cache = new AnalysisCache(AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, new Analy sisContextImpl_ContextRetentionPolicy(this)); 3099 _cache = new AnalysisCache(AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, new Analy sisContextImpl_ContextRetentionPolicy(this));
3091 } 3100 }
3092 3101
3093 void addSourceInfo(Source source, SourceEntry info) { 3102 void addSourceInfo(Source source, SourceEntry info) {
3103 // This implementation assumes that the access to the cache does not need to be synchronized
3104 // because no other object can have access to this context while this method is being invoked.
3094 _cache.put(source, info); 3105 _cache.put(source, info);
3095 } 3106 }
3096 3107
3097 void applyChanges(ChangeSet changeSet) { 3108 void applyChanges(ChangeSet changeSet) {
3098 if (changeSet.isEmpty) { 3109 if (changeSet.isEmpty) {
3099 return; 3110 return;
3100 } 3111 }
3101 { 3112 {
3113 //
3114 // First, compute the list of sources that have been removed.
3115 //
3102 List<Source> removedSources = new List<Source>.from(changeSet.removed3); 3116 List<Source> removedSources = new List<Source>.from(changeSet.removed3);
3103 for (SourceContainer container in changeSet.removedContainers) { 3117 for (SourceContainer container in changeSet.removedContainers) {
3104 addSourcesInContainer(removedSources, container); 3118 addSourcesInContainer(removedSources, container);
3105 } 3119 }
3120 //
3121 // Then determine which cached results are no longer valid.
3122 //
3106 bool addedDartSource = false; 3123 bool addedDartSource = false;
3107 for (Source source in changeSet.added3) { 3124 for (Source source in changeSet.added3) {
3108 if (sourceAvailable(source)) { 3125 if (sourceAvailable(source)) {
3109 addedDartSource = true; 3126 addedDartSource = true;
3110 } 3127 }
3111 } 3128 }
3112 for (Source source in changeSet.changed3) { 3129 for (Source source in changeSet.changed3) {
3113 sourceChanged(source); 3130 sourceChanged(source);
3114 } 3131 }
3115 for (Source source in removedSources) { 3132 for (Source source in removedSources) {
3116 sourceRemoved(source); 3133 sourceRemoved(source);
3117 } 3134 }
3118 if (addedDartSource) { 3135 if (addedDartSource) {
3136 // TODO(brianwilkerson) This is hugely inefficient, but we need to re-an alyze any libraries
3137 // that might have been referencing the not-yet-existing source that was just added. Longer
3138 // term we need to keep track of which libraries are referencing non-exi sting sources and
3139 // only re-analyze those libraries.
3119 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) { 3140 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
3120 SourceEntry sourceEntry = mapEntry.getValue(); 3141 SourceEntry sourceEntry = mapEntry.getValue();
3121 if (!mapEntry.getKey().isInSystemLibrary && sourceEntry is DartEntry) { 3142 if (!mapEntry.getKey().isInSystemLibrary && sourceEntry is DartEntry) {
3122 DartEntryImpl dartCopy = sourceEntry.writableCopy; 3143 DartEntryImpl dartCopy = sourceEntry.writableCopy;
3123 dartCopy.invalidateAllResolutionInformation(); 3144 dartCopy.invalidateAllResolutionInformation();
3124 mapEntry.setValue(dartCopy); 3145 mapEntry.setValue(dartCopy);
3125 } 3146 }
3126 } 3147 }
3127 } 3148 }
3128 } 3149 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3259 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) { 3280 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) {
3260 HtmlEntry htmlEntry = getReadableHtmlEntry(source); 3281 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
3261 if (htmlEntry == null) { 3282 if (htmlEntry == null) {
3262 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}"); 3283 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}");
3263 } 3284 }
3264 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT); 3285 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT);
3265 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT); 3286 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
3266 if (unit == null) { 3287 if (unit == null) {
3267 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}"); 3288 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}");
3268 } 3289 }
3290 // If the unit is ever modified by resolution then we will need to create a copy of it.
3269 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit); 3291 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
3270 } 3292 }
3271 3293
3272 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context); 3294 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context);
3273 3295
3274 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) { 3296 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
3275 List<Source> sourcesToRemove = new List<Source>(); 3297 List<Source> sourcesToRemove = new List<Source>();
3276 { 3298 {
3299 // Move sources in the specified directory to the new context
3277 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 3300 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3278 Source source = entry.getKey(); 3301 Source source = entry.getKey();
3279 if (container.contains(source)) { 3302 if (container.contains(source)) {
3280 sourcesToRemove.add(source); 3303 sourcesToRemove.add(source);
3281 newContext.addSourceInfo(source, entry.getValue().writableCopy); 3304 newContext.addSourceInfo(source, entry.getValue().writableCopy);
3282 } 3305 }
3283 } 3306 }
3284 } 3307 }
3285 return newContext; 3308 return newContext;
3286 } 3309 }
3287 3310
3288 AnalysisOptions get analysisOptions => _options; 3311 AnalysisOptions get analysisOptions => _options;
3289 3312
3290 Element getElement(ElementLocation location) { 3313 Element getElement(ElementLocation location) {
3314 // TODO(brianwilkerson) This should not be a "get" method.
3291 try { 3315 try {
3292 List<String> components = (location as ElementLocationImpl).components; 3316 List<String> components = (location as ElementLocationImpl).components;
3293 Source librarySource = computeSourceFromEncoding(components[0]); 3317 Source librarySource = computeSourceFromEncoding(components[0]);
3294 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl; 3318 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl;
3295 for (int i = 1; i < components.length; i++) { 3319 for (int i = 1; i < components.length; i++) {
3296 if (element == null) { 3320 if (element == null) {
3297 return null; 3321 return null;
3298 } 3322 }
3299 element = element.getChild(components[i]); 3323 element = element.getChild(components[i]);
3300 } 3324 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3358 3382
3359 SourceKind getKindOf(Source source) { 3383 SourceKind getKindOf(Source source) {
3360 SourceEntry sourceEntry = getReadableSourceEntry(source); 3384 SourceEntry sourceEntry = getReadableSourceEntry(source);
3361 if (sourceEntry == null) { 3385 if (sourceEntry == null) {
3362 return SourceKind.UNKNOWN; 3386 return SourceKind.UNKNOWN;
3363 } 3387 }
3364 return sourceEntry.kind; 3388 return sourceEntry.kind;
3365 } 3389 }
3366 3390
3367 List<Source> get launchableClientLibrarySources { 3391 List<Source> get launchableClientLibrarySources {
3392 // TODO(brianwilkerson) This needs to filter out libraries that do not refer ence dart:html,
3393 // either directly or indirectly.
3368 List<Source> sources = new List<Source>(); 3394 List<Source> sources = new List<Source>();
3369 { 3395 {
3370 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 3396 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3371 Source source = entry.getKey(); 3397 Source source = entry.getKey();
3372 SourceEntry sourceEntry = entry.getValue(); 3398 SourceEntry sourceEntry = entry.getValue();
3373 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) { 3399 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
3400 // DartEntry dartEntry = (DartEntry) sourceEntry;
3401 // if (dartEntry.getValue(DartEntry.IS_LAUNCHABLE) && dartEnt ry.getValue(DartEntry.IS_CLIENT)) {
3374 sources.add(source); 3402 sources.add(source);
3375 } 3403 }
3376 } 3404 }
3377 } 3405 }
3378 return new List.from(sources); 3406 return new List.from(sources);
3379 } 3407 }
3380 3408
3381 List<Source> get launchableServerLibrarySources { 3409 List<Source> get launchableServerLibrarySources {
3410 // TODO(brianwilkerson) This needs to filter out libraries that reference da rt:html, either
3411 // directly or indirectly.
3382 List<Source> sources = new List<Source>(); 3412 List<Source> sources = new List<Source>();
3383 { 3413 {
3384 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 3414 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3385 Source source = entry.getKey(); 3415 Source source = entry.getKey();
3386 SourceEntry sourceEntry = entry.getValue(); 3416 SourceEntry sourceEntry = entry.getValue();
3387 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) { 3417 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
3418 // DartEntry dartEntry = (DartEntry) sourceEntry;
3419 // if (dartEntry.getValue(DartEntry.IS_LAUNCHABLE) && !dartEn try.getValue(DartEntry.IS_CLIENT)) {
3388 sources.add(source); 3420 sources.add(source);
3389 } 3421 }
3390 } 3422 }
3391 } 3423 }
3392 return new List.from(sources); 3424 return new List.from(sources);
3393 } 3425 }
3394 3426
3395 List<Source> getLibrariesContaining(Source source) { 3427 List<Source> getLibrariesContaining(Source source) {
3396 { 3428 {
3397 SourceEntry sourceEntry = _cache.get(source); 3429 SourceEntry sourceEntry = _cache.get(source);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3447 3479
3448 LineInfo getLineInfo(Source source) { 3480 LineInfo getLineInfo(Source source) {
3449 SourceEntry sourceEntry = getReadableSourceEntry(source); 3481 SourceEntry sourceEntry = getReadableSourceEntry(source);
3450 if (sourceEntry != null) { 3482 if (sourceEntry != null) {
3451 return sourceEntry.getValue(SourceEntry.LINE_INFO); 3483 return sourceEntry.getValue(SourceEntry.LINE_INFO);
3452 } 3484 }
3453 return null; 3485 return null;
3454 } 3486 }
3455 3487
3456 Namespace getPublicNamespace(LibraryElement library) { 3488 Namespace getPublicNamespace(LibraryElement library) {
3489 // TODO(brianwilkerson) Rename this to not start with 'get'. Note that this is not part of the
3490 // API of the interface.
3457 Source source = library.definingCompilationUnit.source; 3491 Source source = library.definingCompilationUnit.source;
3458 DartEntry dartEntry = getReadableDartEntry(source); 3492 DartEntry dartEntry = getReadableDartEntry(source);
3459 if (dartEntry == null) { 3493 if (dartEntry == null) {
3460 return null; 3494 return null;
3461 } 3495 }
3462 Namespace namespace = null; 3496 Namespace namespace = null;
3463 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { 3497 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
3464 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); 3498 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
3465 } 3499 }
3466 if (namespace == null) { 3500 if (namespace == null) {
3467 NamespaceBuilder builder = new NamespaceBuilder(); 3501 NamespaceBuilder builder = new NamespaceBuilder();
3468 namespace = builder.createPublicNamespace(library); 3502 namespace = builder.createPublicNamespace(library);
3469 { 3503 {
3470 dartEntry = getReadableDartEntry(source); 3504 dartEntry = getReadableDartEntry(source);
3471 if (dartEntry == null) { 3505 if (dartEntry == null) {
3472 AnalysisEngine.instance.logger.logError3(new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}")); 3506 AnalysisEngine.instance.logger.logError3(new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}"));
3473 return null; 3507 return null;
3474 } 3508 }
3475 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { 3509 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
3476 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy; 3510 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
3477 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); 3511 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
3478 _cache.put(source, dartCopy); 3512 _cache.put(source, dartCopy);
3479 } 3513 }
3480 } 3514 }
3481 } 3515 }
3482 return namespace; 3516 return namespace;
3483 } 3517 }
3484 3518
3485 Namespace getPublicNamespace2(Source source) { 3519 Namespace getPublicNamespace2(Source source) {
3520 // TODO(brianwilkerson) Rename this to not start with 'get'. Note that this is not part of the
3521 // API of the interface.
3486 DartEntry dartEntry = getReadableDartEntry(source); 3522 DartEntry dartEntry = getReadableDartEntry(source);
3487 if (dartEntry == null) { 3523 if (dartEntry == null) {
3488 return null; 3524 return null;
3489 } 3525 }
3490 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); 3526 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
3491 if (namespace == null) { 3527 if (namespace == null) {
3492 LibraryElement library = computeLibraryElement(source); 3528 LibraryElement library = computeLibraryElement(source);
3493 if (library == null) { 3529 if (library == null) {
3494 return null; 3530 return null;
3495 } 3531 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3557 * Return a list of the sources that would be processed by [performAnalysisTas k]. This 3593 * Return a list of the sources that would be processed by [performAnalysisTas k]. This
3558 * method duplicates, and must therefore be kept in sync with, [getNextTaskAna lysisTask]. 3594 * method duplicates, and must therefore be kept in sync with, [getNextTaskAna lysisTask].
3559 * This method is intended to be used for testing purposes only. 3595 * This method is intended to be used for testing purposes only.
3560 * 3596 *
3561 * @return a list of the sources that would be processed by [performAnalysisTa sk] 3597 * @return a list of the sources that would be processed by [performAnalysisTa sk]
3562 */ 3598 */
3563 List<Source> get sourcesNeedingProcessing { 3599 List<Source> get sourcesNeedingProcessing {
3564 Set<Source> sources = new Set<Source>(); 3600 Set<Source> sources = new Set<Source>();
3565 { 3601 {
3566 bool hintsEnabled = _options.hint; 3602 bool hintsEnabled = _options.hint;
3603 //
3604 // Look for priority sources that need to be analyzed.
3605 //
3567 for (Source source in _priorityOrder) { 3606 for (Source source in _priorityOrder) {
3568 getSourcesNeedingProcessing2(source, _cache.get(source), true, hintsEnab led, sources); 3607 getSourcesNeedingProcessing2(source, _cache.get(source), true, hintsEnab led, sources);
3569 } 3608 }
3609 //
3610 // Look for non-priority sources that need to be analyzed.
3611 //
3570 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 3612 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3571 getSourcesNeedingProcessing2(entry.getKey(), entry.getValue(), false, hi ntsEnabled, sources); 3613 getSourcesNeedingProcessing2(entry.getKey(), entry.getValue(), false, hi ntsEnabled, sources);
3572 } 3614 }
3573 } 3615 }
3574 return new List<Source>.from(sources); 3616 return new List<Source>.from(sources);
3575 } 3617 }
3576 3618
3577 AnalysisContentStatistics get statistics { 3619 AnalysisContentStatistics get statistics {
3578 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl (); 3620 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl ();
3579 { 3621 {
3580 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) { 3622 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
3581 SourceEntry entry = mapEntry.getValue(); 3623 SourceEntry entry = mapEntry.getValue();
3582 if (entry is DartEntry) { 3624 if (entry is DartEntry) {
3583 Source source = mapEntry.getKey(); 3625 Source source = mapEntry.getKey();
3584 DartEntry dartEntry = entry; 3626 DartEntry dartEntry = entry;
3585 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND); 3627 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND);
3628 // get library independent values
3586 statistics.putCacheItem(dartEntry, DartEntry.PARSE_ERRORS); 3629 statistics.putCacheItem(dartEntry, DartEntry.PARSE_ERRORS);
3587 statistics.putCacheItem(dartEntry, DartEntry.PARSED_UNIT); 3630 statistics.putCacheItem(dartEntry, DartEntry.PARSED_UNIT);
3588 statistics.putCacheItem(dartEntry, DartEntry.SOURCE_KIND); 3631 statistics.putCacheItem(dartEntry, DartEntry.SOURCE_KIND);
3589 statistics.putCacheItem(dartEntry, SourceEntry.LINE_INFO); 3632 statistics.putCacheItem(dartEntry, SourceEntry.LINE_INFO);
3590 if (identical(kind, SourceKind.LIBRARY)) { 3633 if (identical(kind, SourceKind.LIBRARY)) {
3591 statistics.putCacheItem(dartEntry, DartEntry.ELEMENT); 3634 statistics.putCacheItem(dartEntry, DartEntry.ELEMENT);
3592 statistics.putCacheItem(dartEntry, DartEntry.EXPORTED_LIBRARIES); 3635 statistics.putCacheItem(dartEntry, DartEntry.EXPORTED_LIBRARIES);
3593 statistics.putCacheItem(dartEntry, DartEntry.IMPORTED_LIBRARIES); 3636 statistics.putCacheItem(dartEntry, DartEntry.IMPORTED_LIBRARIES);
3594 statistics.putCacheItem(dartEntry, DartEntry.INCLUDED_PARTS); 3637 statistics.putCacheItem(dartEntry, DartEntry.INCLUDED_PARTS);
3595 statistics.putCacheItem(dartEntry, DartEntry.IS_CLIENT); 3638 statistics.putCacheItem(dartEntry, DartEntry.IS_CLIENT);
3596 statistics.putCacheItem(dartEntry, DartEntry.IS_LAUNCHABLE); 3639 statistics.putCacheItem(dartEntry, DartEntry.IS_LAUNCHABLE);
3597 } 3640 }
3641 // get library-specific values
3598 List<Source> librarySources = getLibrariesContaining(source); 3642 List<Source> librarySources = getLibrariesContaining(source);
3599 for (Source librarySource in librarySources) { 3643 for (Source librarySource in librarySources) {
3600 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.HINTS); 3644 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.HINTS);
3601 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLUT ION_ERRORS); 3645 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLUT ION_ERRORS);
3602 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLVE D_UNIT); 3646 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLVE D_UNIT);
3603 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.VERIFIC ATION_ERRORS); 3647 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.VERIFIC ATION_ERRORS);
3604 } 3648 }
3605 } 3649 }
3606 } 3650 }
3607 } 3651 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3642 } 3686 }
3643 3687
3644 void mergeContext(AnalysisContext context) { 3688 void mergeContext(AnalysisContext context) {
3645 if (context is InstrumentedAnalysisContextImpl) { 3689 if (context is InstrumentedAnalysisContextImpl) {
3646 context = (context as InstrumentedAnalysisContextImpl).basis; 3690 context = (context as InstrumentedAnalysisContextImpl).basis;
3647 } 3691 }
3648 if (context is! AnalysisContextImpl) { 3692 if (context is! AnalysisContextImpl) {
3649 return; 3693 return;
3650 } 3694 }
3651 { 3695 {
3696 // TODO(brianwilkerson) This does not lock against the other context's cac heLock.
3652 for (MapEntry<Source, SourceEntry> entry in (context as AnalysisContextImp l)._cache.entrySet()) { 3697 for (MapEntry<Source, SourceEntry> entry in (context as AnalysisContextImp l)._cache.entrySet()) {
3653 Source newSource = entry.getKey(); 3698 Source newSource = entry.getKey();
3654 SourceEntry existingEntry = getReadableSourceEntry(newSource); 3699 SourceEntry existingEntry = getReadableSourceEntry(newSource);
3655 if (existingEntry == null) { 3700 if (existingEntry == null) {
3701 // TODO(brianwilkerson) Decide whether we really need to copy the info .
3656 _cache.put(newSource, entry.getValue().writableCopy); 3702 _cache.put(newSource, entry.getValue().writableCopy);
3657 } else { 3703 } else {
3658 } 3704 }
3659 } 3705 }
3660 } 3706 }
3661 } 3707 }
3662 3708
3663 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null); 3709 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null);
3664 3710
3665 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA RSED_UNIT, null); 3711 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA RSED_UNIT, null);
3666 3712
3667 AnalysisResult performAnalysisTask() { 3713 AnalysisResult performAnalysisTask() {
3668 int getStart = JavaSystem.currentTimeMillis(); 3714 int getStart = JavaSystem.currentTimeMillis();
3669 AnalysisTask task = nextTaskAnalysisTask; 3715 AnalysisTask task = nextTaskAnalysisTask;
3670 int getEnd = JavaSystem.currentTimeMillis(); 3716 int getEnd = JavaSystem.currentTimeMillis();
3671 if (task == null) { 3717 if (task == null) {
3672 return new AnalysisResult(getChangeNotices(true), getEnd - getStart, null, -1); 3718 return new AnalysisResult(getChangeNotices(true), getEnd - getStart, null, -1);
3673 } 3719 }
3720 //System.out.println(task);
3674 int performStart = JavaSystem.currentTimeMillis(); 3721 int performStart = JavaSystem.currentTimeMillis();
3675 try { 3722 try {
3676 task.perform(_resultRecorder); 3723 task.perform(_resultRecorder);
3677 } on AnalysisException catch (exception) { 3724 } on AnalysisException catch (exception) {
3678 if (exception.cause is! JavaIOException) { 3725 if (exception.cause is! JavaIOException) {
3679 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception); 3726 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception);
3680 } 3727 }
3681 } 3728 }
3682 int performEnd = JavaSystem.currentTimeMillis(); 3729 int performEnd = JavaSystem.currentTimeMillis();
3683 return new AnalysisResult(getChangeNotices(false), getEnd - getStart, task.r untimeType.toString(), performEnd - performStart); 3730 return new AnalysisResult(getChangeNotices(false), getEnd - getStart, task.r untimeType.toString(), performEnd - performStart);
3684 } 3731 }
3685 3732
3686 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 3733 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
3687 { 3734 {
3688 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); 3735 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML);
3689 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) { 3736 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
3690 Source librarySource = entry.getKey(); 3737 Source librarySource = entry.getKey();
3691 LibraryElement library = entry.getValue(); 3738 LibraryElement library = entry.getValue();
3739 //
3740 // Cache the element in the library's info.
3741 //
3692 DartEntry dartEntry = getReadableDartEntry(librarySource); 3742 DartEntry dartEntry = getReadableDartEntry(librarySource);
3693 if (dartEntry != null) { 3743 if (dartEntry != null) {
3694 DartEntryImpl dartCopy = dartEntry.writableCopy; 3744 DartEntryImpl dartCopy = dartEntry.writableCopy;
3695 recordElementData(dartCopy, library, htmlSource); 3745 recordElementData(dartCopy, library, htmlSource);
3696 _cache.put(librarySource, dartCopy); 3746 _cache.put(librarySource, dartCopy);
3697 } 3747 }
3698 } 3748 }
3699 } 3749 }
3700 } 3750 }
3701 3751
(...skipping 11 matching lines...) Expand all
3713 return parseHtmlUnit(htmlSource); 3763 return parseHtmlUnit(htmlSource);
3714 } 3764 }
3715 3765
3716 void set analysisOptions(AnalysisOptions options) { 3766 void set analysisOptions(AnalysisOptions options) {
3717 { 3767 {
3718 bool needsRecompute = this._options.analyzeFunctionBodies != options.analy zeFunctionBodies || this._options.dart2jsHint != options.dart2jsHint || (this._o ptions.hint && !options.hint) || this._options.preserveComments != options.prese rveComments; 3768 bool needsRecompute = this._options.analyzeFunctionBodies != options.analy zeFunctionBodies || this._options.dart2jsHint != options.dart2jsHint || (this._o ptions.hint && !options.hint) || this._options.preserveComments != options.prese rveComments;
3719 int cacheSize = options.cacheSize; 3769 int cacheSize = options.cacheSize;
3720 if (this._options.cacheSize != cacheSize) { 3770 if (this._options.cacheSize != cacheSize) {
3721 this._options.cacheSize = cacheSize; 3771 this._options.cacheSize = cacheSize;
3722 _cache.maxCacheSize = cacheSize; 3772 _cache.maxCacheSize = cacheSize;
3773 //
3774 // Cap the size of the priority list to being less than the cache size. Failure to do so can
3775 // result in an infinite loop in performAnalysisTask() because re-cachin g one AST structure
3776 // can cause another priority source's AST structure to be flushed.
3777 //
3723 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA; 3778 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA;
3724 if (_priorityOrder.length > maxPriorityOrderSize) { 3779 if (_priorityOrder.length > maxPriorityOrderSize) {
3725 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize) ; 3780 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize) ;
3726 JavaSystem.arraycopy(_priorityOrder, 0, newPriorityOrder, 0, maxPriori tyOrderSize); 3781 JavaSystem.arraycopy(_priorityOrder, 0, newPriorityOrder, 0, maxPriori tyOrderSize);
3727 _priorityOrder = newPriorityOrder; 3782 _priorityOrder = newPriorityOrder;
3728 } 3783 }
3729 } 3784 }
3730 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies; 3785 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies;
3731 this._options.dart2jsHint = options.dart2jsHint; 3786 this._options.dart2jsHint = options.dart2jsHint;
3732 this._options.hint = options.hint; 3787 this._options.hint = options.hint;
3733 this._options.incremental = options.incremental; 3788 this._options.incremental = options.incremental;
3734 this._options.preserveComments = options.preserveComments; 3789 this._options.preserveComments = options.preserveComments;
3735 if (needsRecompute) { 3790 if (needsRecompute) {
3736 invalidateAllResolutionInformation(); 3791 invalidateAllResolutionInformation();
3737 } 3792 }
3738 } 3793 }
3739 } 3794 }
3740 3795
3741 void set analysisPriorityOrder(List<Source> sources) { 3796 void set analysisPriorityOrder(List<Source> sources) {
3742 { 3797 {
3743 if (sources == null || sources.isEmpty) { 3798 if (sources == null || sources.isEmpty) {
3744 _priorityOrder = Source.EMPTY_ARRAY; 3799 _priorityOrder = Source.EMPTY_ARRAY;
3745 } else { 3800 } else {
3746 while (sources.remove(null)) { 3801 while (sources.remove(null)) {
3747 } 3802 }
3748 if (sources.isEmpty) { 3803 if (sources.isEmpty) {
3749 _priorityOrder = Source.EMPTY_ARRAY; 3804 _priorityOrder = Source.EMPTY_ARRAY;
3750 } 3805 }
3806 //
3807 // Cap the size of the priority list to being less than the cache size. Failure to do so can
3808 // result in an infinite loop in performAnalysisTask() because re-cachin g one AST structure
3809 // can cause another priority source's AST structure to be flushed.
3810 //
3751 int count = Math.min(sources.length, _options.cacheSize - _PRIORITY_ORDE R_SIZE_DELTA); 3811 int count = Math.min(sources.length, _options.cacheSize - _PRIORITY_ORDE R_SIZE_DELTA);
3752 _priorityOrder = new List<Source>(count); 3812 _priorityOrder = new List<Source>(count);
3753 for (int i = 0; i < count; i++) { 3813 for (int i = 0; i < count; i++) {
3754 _priorityOrder[i] = sources[i]; 3814 _priorityOrder[i] = sources[i];
3755 } 3815 }
3756 } 3816 }
3757 } 3817 }
3758 } 3818 }
3759 3819
3760 void setChangedContents(Source source, String contents, int offset, int oldLen gth, int newLength) { 3820 void setChangedContents(Source source, String contents, int offset, int oldLen gth, int newLength) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3822 * @param task the task that was performed 3882 * @param task the task that was performed
3823 * @return an entry containing the computed results 3883 * @return an entry containing the computed results
3824 * @throws AnalysisException if the results could not be recorded 3884 * @throws AnalysisException if the results could not be recorded
3825 */ 3885 */
3826 DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibraryTask task) { 3886 DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibraryTask task) {
3827 LibraryResolver resolver = task.libraryResolver; 3887 LibraryResolver resolver = task.libraryResolver;
3828 AnalysisException thrownException = task.exception; 3888 AnalysisException thrownException = task.exception;
3829 DartEntry unitEntry = null; 3889 DartEntry unitEntry = null;
3830 Source unitSource = task.unitSource; 3890 Source unitSource = task.unitSource;
3831 if (resolver != null) { 3891 if (resolver != null) {
3892 //
3893 // The resolver should only be null if an exception was thrown before (or while) it was
3894 // being created.
3895 //
3832 Set<Library> resolvedLibraries = resolver.resolvedLibraries; 3896 Set<Library> resolvedLibraries = resolver.resolvedLibraries;
3833 if (resolvedLibraries == null) { 3897 if (resolvedLibraries == null) {
3898 //
3899 // The resolved libraries should only be null if an exception was thrown during resolution.
3900 //
3834 unitEntry = getReadableDartEntry(unitSource); 3901 unitEntry = getReadableDartEntry(unitSource);
3835 if (unitEntry == null) { 3902 if (unitEntry == null) {
3836 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${unitSource.fullName}"); 3903 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${unitSource.fullName}");
3837 } 3904 }
3838 DartEntryImpl dartCopy = unitEntry.writableCopy; 3905 DartEntryImpl dartCopy = unitEntry.writableCopy;
3839 dartCopy.recordResolutionError(); 3906 dartCopy.recordResolutionError();
3840 dartCopy.exception = thrownException; 3907 dartCopy.exception = thrownException;
3841 _cache.put(unitSource, dartCopy); 3908 _cache.put(unitSource, dartCopy);
3842 if (thrownException != null) { 3909 if (thrownException != null) {
3843 throw thrownException; 3910 throw thrownException;
3844 } 3911 }
3845 return dartCopy; 3912 return dartCopy;
3846 } 3913 }
3847 { 3914 {
3848 if (allModificationTimesMatch(resolvedLibraries)) { 3915 if (allModificationTimesMatch(resolvedLibraries)) {
3849 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 3916 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
3850 RecordingErrorListener errorListener = resolver.errorListener; 3917 RecordingErrorListener errorListener = resolver.errorListener;
3851 for (Library library in resolvedLibraries) { 3918 for (Library library in resolvedLibraries) {
3852 Source librarySource = library.librarySource; 3919 Source librarySource = library.librarySource;
3853 for (Source source in library.compilationUnitSources) { 3920 for (Source source in library.compilationUnitSources) {
3854 CompilationUnit unit = library.getAST(source); 3921 CompilationUnit unit = library.getAST(source);
3855 List<AnalysisError> errors = errorListener.getErrors2(source); 3922 List<AnalysisError> errors = errorListener.getErrors2(source);
3856 LineInfo lineInfo = getLineInfo(source); 3923 LineInfo lineInfo = getLineInfo(source);
3857 DartEntry dartEntry = _cache.get(source) as DartEntry; 3924 DartEntry dartEntry = _cache.get(source) as DartEntry;
3858 int sourceTime = source.modificationStamp; 3925 int sourceTime = source.modificationStamp;
3859 if (dartEntry.modificationTime != sourceTime) { 3926 if (dartEntry.modificationTime != sourceTime) {
3927 // The source has changed without the context being notified. Si mulate notification.
3860 sourceChanged(source); 3928 sourceChanged(source);
3861 dartEntry = getReadableDartEntry(source); 3929 dartEntry = getReadableDartEntry(source);
3862 if (dartEntry == null) { 3930 if (dartEntry == null) {
3863 throw new AnalysisException.con1("A Dart file became a non-Dar t file: ${source.fullName}"); 3931 throw new AnalysisException.con1("A Dart file became a non-Dar t file: ${source.fullName}");
3864 } 3932 }
3865 } 3933 }
3866 DartEntryImpl dartCopy = dartEntry.writableCopy; 3934 DartEntryImpl dartCopy = dartEntry.writableCopy;
3867 if (thrownException == null) { 3935 if (thrownException == null) {
3868 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 3936 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
3869 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); 3937 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
(...skipping 16 matching lines...) Expand all
3886 } 3954 }
3887 } 3955 }
3888 } else { 3956 } else {
3889 for (Library library in resolvedLibraries) { 3957 for (Library library in resolvedLibraries) {
3890 for (Source source in library.compilationUnitSources) { 3958 for (Source source in library.compilationUnitSources) {
3891 DartEntry dartEntry = getReadableDartEntry(source); 3959 DartEntry dartEntry = getReadableDartEntry(source);
3892 if (dartEntry != null) { 3960 if (dartEntry != null) {
3893 int resultTime = library.getModificationTime(source); 3961 int resultTime = library.getModificationTime(source);
3894 DartEntryImpl dartCopy = dartEntry.writableCopy; 3962 DartEntryImpl dartCopy = dartEntry.writableCopy;
3895 if (thrownException == null || resultTime >= 0) { 3963 if (thrownException == null || resultTime >= 0) {
3964 //
3965 // The analysis was performed on out-of-date sources. Mark the cache so that the
3966 // sources will be re-analyzed using the up-to-date sources.
3967 //
3896 dartCopy.recordResolutionNotInProcess(); 3968 dartCopy.recordResolutionNotInProcess();
3897 } else { 3969 } else {
3970 //
3971 // We could not determine whether the sources were up-to-date or out-of-date. Mark
3972 // the cache so that we won't attempt to re-analyze the source s until there's a
3973 // good chance that we'll be able to do so without error.
3974 //
3898 dartCopy.recordResolutionError(); 3975 dartCopy.recordResolutionError();
3899 } 3976 }
3900 dartCopy.exception = thrownException; 3977 dartCopy.exception = thrownException;
3901 _cache.put(source, dartCopy); 3978 _cache.put(source, dartCopy);
3902 if (source == unitSource) { 3979 if (source == unitSource) {
3903 unitEntry = dartCopy; 3980 unitEntry = dartCopy;
3904 } 3981 }
3905 } 3982 }
3906 } 3983 }
3907 } 3984 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3945 * @return `true` if we should record the results of the resolution 4022 * @return `true` if we should record the results of the resolution
3946 * @throws AnalysisException if any of the modification times could not be det ermined (this should 4023 * @throws AnalysisException if any of the modification times could not be det ermined (this should
3947 * not happen) 4024 * not happen)
3948 */ 4025 */
3949 bool allModificationTimesMatch(Set<Library> resolvedLibraries) { 4026 bool allModificationTimesMatch(Set<Library> resolvedLibraries) {
3950 bool allTimesMatch = true; 4027 bool allTimesMatch = true;
3951 for (Library library in resolvedLibraries) { 4028 for (Library library in resolvedLibraries) {
3952 for (Source source in library.compilationUnitSources) { 4029 for (Source source in library.compilationUnitSources) {
3953 DartEntry dartEntry = getReadableDartEntry(source); 4030 DartEntry dartEntry = getReadableDartEntry(source);
3954 if (dartEntry == null) { 4031 if (dartEntry == null) {
4032 // This shouldn't be possible because we should never have performed t he task if the
4033 // source didn't represent a Dart file, but check to be safe.
3955 throw new AnalysisException.con1("Internal error: attempting to reolve non-Dart file as a Dart file: ${source.fullName}"); 4034 throw new AnalysisException.con1("Internal error: attempting to reolve non-Dart file as a Dart file: ${source.fullName}");
3956 } 4035 }
3957 int sourceTime = source.modificationStamp; 4036 int sourceTime = source.modificationStamp;
3958 int resultTime = library.getModificationTime(source); 4037 int resultTime = library.getModificationTime(source);
3959 if (sourceTime != resultTime) { 4038 if (sourceTime != resultTime) {
4039 // The source has changed without the context being notified. Simulate notification.
3960 sourceChanged(source); 4040 sourceChanged(source);
3961 allTimesMatch = false; 4041 allTimesMatch = false;
3962 } 4042 }
3963 } 4043 }
3964 } 4044 }
3965 return allTimesMatch; 4045 return allTimesMatch;
3966 } 4046 }
3967 4047
3968 /** 4048 /**
3969 * Given a source for a Dart file and the library that contains it, return a c ache entry in which 4049 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
3970 * the data represented by the given descriptor is available. This method assu mes that the data 4050 * the data represented by the given descriptor is available. This method assu mes that the data
3971 * can be produced by generating hints for the library if the data is not alre ady cached. 4051 * can be produced by generating hints for the library if the data is not alre ady cached.
3972 * 4052 *
3973 * @param unitSource the source representing the Dart file 4053 * @param unitSource the source representing the Dart file
3974 * @param librarySource the source representing the library containing the Dar t file 4054 * @param librarySource the source representing the library containing the Dar t file
3975 * @param dartEntry the cache entry associated with the Dart file 4055 * @param dartEntry the cache entry associated with the Dart file
3976 * @param descriptor the descriptor representing the data to be returned 4056 * @param descriptor the descriptor representing the data to be returned
3977 * @return a cache entry containing the required data 4057 * @return a cache entry containing the required data
3978 * @throws AnalysisException if data could not be returned because the source could not be parsed 4058 * @throws AnalysisException if data could not be returned because the source could not be parsed
3979 */ 4059 */
3980 DartEntry cacheDartHintData(Source unitSource, Source librarySource, DartEntry dartEntry, DataDescriptor descriptor) { 4060 DartEntry cacheDartHintData(Source unitSource, Source librarySource, DartEntry dartEntry, DataDescriptor descriptor) {
4061 //
4062 // Check to see whether we already have the information being requested.
4063 //
3981 CacheState state = dartEntry.getState2(descriptor, librarySource); 4064 CacheState state = dartEntry.getState2(descriptor, librarySource);
3982 while (state != CacheState.ERROR && state != CacheState.VALID) { 4065 while (state != CacheState.ERROR && state != CacheState.VALID) {
4066 //
4067 // If not, compute the information. Unless the modification date of the so urce continues to
4068 // change, this loop will eventually terminate.
4069 //
3983 dartEntry = new GenerateDartHintsTask(this, getLibraryElement(librarySourc e)).perform(_resultRecorder) as DartEntry; 4070 dartEntry = new GenerateDartHintsTask(this, getLibraryElement(librarySourc e)).perform(_resultRecorder) as DartEntry;
3984 state = dartEntry.getState2(descriptor, librarySource); 4071 state = dartEntry.getState2(descriptor, librarySource);
3985 } 4072 }
3986 return dartEntry; 4073 return dartEntry;
3987 } 4074 }
3988 4075
3989 /** 4076 /**
3990 * Given a source for a Dart file, return a cache entry in which the data repr esented by the given 4077 * Given a source for a Dart file, return a cache entry in which the data repr esented by the given
3991 * descriptor is available. This method assumes that the data can be produced by parsing the 4078 * descriptor is available. This method assumes that the data can be produced by parsing the
3992 * source if it is not already cached. 4079 * source if it is not already cached.
3993 * 4080 *
3994 * @param source the source representing the Dart file 4081 * @param source the source representing the Dart file
3995 * @param dartEntry the cache entry associated with the Dart file 4082 * @param dartEntry the cache entry associated with the Dart file
3996 * @param descriptor the descriptor representing the data to be returned 4083 * @param descriptor the descriptor representing the data to be returned
3997 * @return a cache entry containing the required data 4084 * @return a cache entry containing the required data
3998 * @throws AnalysisException if data could not be returned because the source could not be 4085 * @throws AnalysisException if data could not be returned because the source could not be
3999 * resolved 4086 * resolved
4000 */ 4087 */
4001 DartEntry cacheDartParseData(Source source, DartEntry dartEntry, DataDescripto r descriptor) { 4088 DartEntry cacheDartParseData(Source source, DartEntry dartEntry, DataDescripto r descriptor) {
4002 if (identical(descriptor, DartEntry.PARSED_UNIT)) { 4089 if (identical(descriptor, DartEntry.PARSED_UNIT)) {
4003 CompilationUnit unit = dartEntry.anyParsedCompilationUnit; 4090 CompilationUnit unit = dartEntry.anyParsedCompilationUnit;
4004 if (unit != null) { 4091 if (unit != null) {
4005 return dartEntry; 4092 return dartEntry;
4006 } 4093 }
4007 } 4094 }
4095 //
4096 // Check to see whether we already have the information being requested.
4097 //
4008 CacheState state = dartEntry.getState(descriptor); 4098 CacheState state = dartEntry.getState(descriptor);
4009 while (state != CacheState.ERROR && state != CacheState.VALID) { 4099 while (state != CacheState.ERROR && state != CacheState.VALID) {
4100 //
4101 // If not, compute the information. Unless the modification date of the so urce continues to
4102 // change, this loop will eventually terminate.
4103 //
4010 dartEntry = new ParseDartTask(this, source).perform(_resultRecorder) as Da rtEntry; 4104 dartEntry = new ParseDartTask(this, source).perform(_resultRecorder) as Da rtEntry;
4011 state = dartEntry.getState(descriptor); 4105 state = dartEntry.getState(descriptor);
4012 } 4106 }
4013 return dartEntry; 4107 return dartEntry;
4014 } 4108 }
4015 4109
4016 /** 4110 /**
4017 * Given a source for a Dart file and the library that contains it, return a c ache entry in which 4111 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
4018 * the data represented by the given descriptor is available. This method assu mes that the data 4112 * the data represented by the given descriptor is available. This method assu mes that the data
4019 * can be produced by resolving the source in the context of the library if it is not already 4113 * can be produced by resolving the source in the context of the library if it is not already
4020 * cached. 4114 * cached.
4021 * 4115 *
4022 * @param unitSource the source representing the Dart file 4116 * @param unitSource the source representing the Dart file
4023 * @param librarySource the source representing the library containing the Dar t file 4117 * @param librarySource the source representing the library containing the Dar t file
4024 * @param dartEntry the cache entry associated with the Dart file 4118 * @param dartEntry the cache entry associated with the Dart file
4025 * @param descriptor the descriptor representing the data to be returned 4119 * @param descriptor the descriptor representing the data to be returned
4026 * @return a cache entry containing the required data 4120 * @return a cache entry containing the required data
4027 * @throws AnalysisException if data could not be returned because the source could not be parsed 4121 * @throws AnalysisException if data could not be returned because the source could not be parsed
4028 */ 4122 */
4029 DartEntry cacheDartResolutionData(Source unitSource, Source librarySource, Dar tEntry dartEntry, DataDescriptor descriptor) { 4123 DartEntry cacheDartResolutionData(Source unitSource, Source librarySource, Dar tEntry dartEntry, DataDescriptor descriptor) {
4124 //
4125 // Check to see whether we already have the information being requested.
4126 //
4030 CacheState state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.ge tState(descriptor) : dartEntry.getState2(descriptor, librarySource); 4127 CacheState state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.ge tState(descriptor) : dartEntry.getState2(descriptor, librarySource);
4031 while (state != CacheState.ERROR && state != CacheState.VALID) { 4128 while (state != CacheState.ERROR && state != CacheState.VALID) {
4129 //
4130 // If not, compute the information. Unless the modification date of the so urce continues to
4131 // change, this loop will eventually terminate.
4132 //
4133 // TODO(brianwilkerson) As an optimization, if we already have the element model for the
4134 // library we can use ResolveDartUnitTask to produce the resolved AST stru cture much faster.
4032 dartEntry = new ResolveDartLibraryTask(this, unitSource, librarySource).pe rform(_resultRecorder) as DartEntry; 4135 dartEntry = new ResolveDartLibraryTask(this, unitSource, librarySource).pe rform(_resultRecorder) as DartEntry;
4033 state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.getState(de scriptor) : dartEntry.getState2(descriptor, librarySource); 4136 state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.getState(de scriptor) : dartEntry.getState2(descriptor, librarySource);
4034 } 4137 }
4035 return dartEntry; 4138 return dartEntry;
4036 } 4139 }
4037 4140
4038 /** 4141 /**
4039 * Given a source for a Dart file and the library that contains it, return a c ache entry in which 4142 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
4040 * the data represented by the given descriptor is available. This method assu mes that the data 4143 * the data represented by the given descriptor is available. This method assu mes that the data
4041 * can be produced by verifying the source in the given library if the data is not already cached. 4144 * can be produced by verifying the source in the given library if the data is not already cached.
4042 * 4145 *
4043 * @param unitSource the source representing the Dart file 4146 * @param unitSource the source representing the Dart file
4044 * @param librarySource the source representing the library containing the Dar t file 4147 * @param librarySource the source representing the library containing the Dar t file
4045 * @param dartEntry the cache entry associated with the Dart file 4148 * @param dartEntry the cache entry associated with the Dart file
4046 * @param descriptor the descriptor representing the data to be returned 4149 * @param descriptor the descriptor representing the data to be returned
4047 * @return a cache entry containing the required data 4150 * @return a cache entry containing the required data
4048 * @throws AnalysisException if data could not be returned because the source could not be parsed 4151 * @throws AnalysisException if data could not be returned because the source could not be parsed
4049 */ 4152 */
4050 DartEntry cacheDartVerificationData(Source unitSource, Source librarySource, D artEntry dartEntry, DataDescriptor descriptor) { 4153 DartEntry cacheDartVerificationData(Source unitSource, Source librarySource, D artEntry dartEntry, DataDescriptor descriptor) {
4154 //
4155 // Check to see whether we already have the information being requested.
4156 //
4051 CacheState state = dartEntry.getState2(descriptor, librarySource); 4157 CacheState state = dartEntry.getState2(descriptor, librarySource);
4052 while (state != CacheState.ERROR && state != CacheState.VALID) { 4158 while (state != CacheState.ERROR && state != CacheState.VALID) {
4159 //
4160 // If not, compute the information. Unless the modification date of the so urce continues to
4161 // change, this loop will eventually terminate.
4162 //
4053 dartEntry = new GenerateDartErrorsTask(this, unitSource, getLibraryElement (librarySource)).perform(_resultRecorder) as DartEntry; 4163 dartEntry = new GenerateDartErrorsTask(this, unitSource, getLibraryElement (librarySource)).perform(_resultRecorder) as DartEntry;
4054 state = dartEntry.getState2(descriptor, librarySource); 4164 state = dartEntry.getState2(descriptor, librarySource);
4055 } 4165 }
4056 return dartEntry; 4166 return dartEntry;
4057 } 4167 }
4058 4168
4059 /** 4169 /**
4060 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by 4170 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by
4061 * the given descriptors is available. This method assumes that the data can b e produced by 4171 * the given descriptors is available. This method assumes that the data can b e produced by
4062 * parsing the source if it is not already cached. 4172 * parsing the source if it is not already cached.
4063 * 4173 *
4064 * @param source the source representing the HTML file 4174 * @param source the source representing the HTML file
4065 * @param htmlEntry the cache entry associated with the HTML file 4175 * @param htmlEntry the cache entry associated with the HTML file
4066 * @param descriptor the descriptor representing the data to be returned 4176 * @param descriptor the descriptor representing the data to be returned
4067 * @return a cache entry containing the required data 4177 * @return a cache entry containing the required data
4068 * @throws AnalysisException if data could not be returned because the source could not be 4178 * @throws AnalysisException if data could not be returned because the source could not be
4069 * resolved 4179 * resolved
4070 */ 4180 */
4071 HtmlEntry cacheHtmlParseData(Source source, HtmlEntry htmlEntry, DataDescripto r descriptor) { 4181 HtmlEntry cacheHtmlParseData(Source source, HtmlEntry htmlEntry, DataDescripto r descriptor) {
4182 //
4183 // Check to see whether we already have the information being requested.
4184 //
4072 CacheState state = htmlEntry.getState(descriptor); 4185 CacheState state = htmlEntry.getState(descriptor);
4073 while (state != CacheState.ERROR && state != CacheState.VALID) { 4186 while (state != CacheState.ERROR && state != CacheState.VALID) {
4187 //
4188 // If not, compute the information. Unless the modification date of the so urce continues to
4189 // change, this loop will eventually terminate.
4190 //
4074 htmlEntry = new ParseHtmlTask(this, source).perform(_resultRecorder) as Ht mlEntry; 4191 htmlEntry = new ParseHtmlTask(this, source).perform(_resultRecorder) as Ht mlEntry;
4075 state = htmlEntry.getState(descriptor); 4192 state = htmlEntry.getState(descriptor);
4076 } 4193 }
4077 return htmlEntry; 4194 return htmlEntry;
4078 } 4195 }
4079 4196
4080 /** 4197 /**
4081 * Given a source for an HTML file, return a cache entry in which the the data represented by the 4198 * Given a source for an HTML file, return a cache entry in which the the data represented by the
4082 * given descriptor is available. This method assumes that the data can be pro duced by resolving 4199 * given descriptor is available. This method assumes that the data can be pro duced by resolving
4083 * the source if it is not already cached. 4200 * the source if it is not already cached.
4084 * 4201 *
4085 * @param source the source representing the HTML file 4202 * @param source the source representing the HTML file
4086 * @param dartEntry the cache entry associated with the HTML file 4203 * @param dartEntry the cache entry associated with the HTML file
4087 * @param descriptor the descriptor representing the data to be returned 4204 * @param descriptor the descriptor representing the data to be returned
4088 * @return a cache entry containing the required data 4205 * @return a cache entry containing the required data
4089 * @throws AnalysisException if data could not be returned because the source could not be 4206 * @throws AnalysisException if data could not be returned because the source could not be
4090 * resolved 4207 * resolved
4091 */ 4208 */
4092 HtmlEntry cacheHtmlResolutionData(Source source, HtmlEntry htmlEntry, DataDesc riptor descriptor) { 4209 HtmlEntry cacheHtmlResolutionData(Source source, HtmlEntry htmlEntry, DataDesc riptor descriptor) {
4210 //
4211 // Check to see whether we already have the information being requested.
4212 //
4093 CacheState state = htmlEntry.getState(descriptor); 4213 CacheState state = htmlEntry.getState(descriptor);
4094 while (state != CacheState.ERROR && state != CacheState.VALID) { 4214 while (state != CacheState.ERROR && state != CacheState.VALID) {
4215 //
4216 // If not, compute the information. Unless the modification date of the so urce continues to
4217 // change, this loop will eventually terminate.
4218 //
4095 htmlEntry = new ResolveHtmlTask(this, source).perform(_resultRecorder) as HtmlEntry; 4219 htmlEntry = new ResolveHtmlTask(this, source).perform(_resultRecorder) as HtmlEntry;
4096 state = htmlEntry.getState(descriptor); 4220 state = htmlEntry.getState(descriptor);
4097 } 4221 }
4098 return htmlEntry; 4222 return htmlEntry;
4099 } 4223 }
4100 4224
4101 /** 4225 /**
4102 * Given the encoded form of a source, use the source factory to reconstitute the original source. 4226 * Given the encoded form of a source, use the source factory to reconstitute the original source.
4103 * 4227 *
4104 * @param encoding the encoded form of a source 4228 * @param encoding the encoded form of a source
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
4366 4490
4367 /** 4491 /**
4368 * Look through the cache for a task that needs to be performed. Return the ta sk that was found, 4492 * Look through the cache for a task that needs to be performed. Return the ta sk that was found,
4369 * or `null` if there is no more work to be done. 4493 * or `null` if there is no more work to be done.
4370 * 4494 *
4371 * @return the next task that needs to be performed 4495 * @return the next task that needs to be performed
4372 */ 4496 */
4373 AnalysisTask get nextTaskAnalysisTask { 4497 AnalysisTask get nextTaskAnalysisTask {
4374 { 4498 {
4375 bool hintsEnabled = _options.hint; 4499 bool hintsEnabled = _options.hint;
4500 //
4501 // Look for incremental analysis
4502 //
4376 if (_incrementalAnalysisCache != null && _incrementalAnalysisCache.hasWork ()) { 4503 if (_incrementalAnalysisCache != null && _incrementalAnalysisCache.hasWork ()) {
4377 AnalysisTask task = new IncrementalAnalysisTask(this, _incrementalAnalys isCache); 4504 AnalysisTask task = new IncrementalAnalysisTask(this, _incrementalAnalys isCache);
4378 _incrementalAnalysisCache = null; 4505 _incrementalAnalysisCache = null;
4379 return task; 4506 return task;
4380 } 4507 }
4508 //
4509 // Look for a priority source that needs to be analyzed.
4510 //
4381 for (Source source in _priorityOrder) { 4511 for (Source source in _priorityOrder) {
4382 AnalysisTask task = getNextTaskAnalysisTask2(source, _cache.get(source), true, hintsEnabled); 4512 AnalysisTask task = getNextTaskAnalysisTask2(source, _cache.get(source), true, hintsEnabled);
4383 if (task != null) { 4513 if (task != null) {
4384 return task; 4514 return task;
4385 } 4515 }
4386 } 4516 }
4517 //
4518 // Look for a non-priority source that needs to be analyzed.
4519 //
4387 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4520 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4388 AnalysisTask task = getNextTaskAnalysisTask2(entry.getKey(), entry.getVa lue(), false, hintsEnabled); 4521 AnalysisTask task = getNextTaskAnalysisTask2(entry.getKey(), entry.getVa lue(), false, hintsEnabled);
4389 if (task != null) { 4522 if (task != null) {
4390 return task; 4523 return task;
4391 } 4524 }
4392 } 4525 }
4393 return null; 4526 return null;
4394 } 4527 }
4395 } 4528 }
4396 4529
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4438 if (libraryEntry is DartEntry) { 4571 if (libraryEntry is DartEntry) {
4439 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT); 4572 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT);
4440 if (identical(elementState, CacheState.INVALID) || (isPriority && iden tical(elementState, CacheState.FLUSHED))) { 4573 if (identical(elementState, CacheState.INVALID) || (isPriority && iden tical(elementState, CacheState.FLUSHED))) {
4441 DartEntryImpl libraryCopy = libraryEntry.writableCopy; 4574 DartEntryImpl libraryCopy = libraryEntry.writableCopy;
4442 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS); 4575 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
4443 _cache.put(librarySource, libraryCopy); 4576 _cache.put(librarySource, libraryCopy);
4444 return new ResolveDartLibraryTask(this, source, librarySource); 4577 return new ResolveDartLibraryTask(this, source, librarySource);
4445 } 4578 }
4446 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOLVED_ UNIT, librarySource); 4579 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOLVED_ UNIT, librarySource);
4447 if (identical(resolvedUnitState, CacheState.INVALID) || (isPriority && identical(resolvedUnitState, CacheState.FLUSHED))) { 4580 if (identical(resolvedUnitState, CacheState.INVALID) || (isPriority && identical(resolvedUnitState, CacheState.FLUSHED))) {
4581 //
4582 // The commented out lines below are an optimization that doesn't qu ite work yet. The
4583 // problem is that if the source was not resolved because it wasn't part of any library,
4584 // then there won't be any elements in the element model that we can use to resolve it.
4585 //
4586 //LibraryElement libraryElement = libraryEntry.getValue(DartEntry.EL EMENT);
4587 //if (libraryElement != null) {
4448 DartEntryImpl dartCopy = dartEntry.writableCopy; 4588 DartEntryImpl dartCopy = dartEntry.writableCopy;
4449 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheStat e.IN_PROCESS); 4589 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheStat e.IN_PROCESS);
4450 _cache.put(source, dartCopy); 4590 _cache.put(source, dartCopy);
4591 //return new ResolveDartUnitTask(this, source, libraryElement);
4451 return new ResolveDartLibraryTask(this, source, librarySource); 4592 return new ResolveDartLibraryTask(this, source, librarySource);
4452 } 4593 }
4453 CacheState verificationErrorsState = dartEntry.getState2(DartEntry.VER IFICATION_ERRORS, librarySource); 4594 CacheState verificationErrorsState = dartEntry.getState2(DartEntry.VER IFICATION_ERRORS, librarySource);
4454 if (identical(verificationErrorsState, CacheState.INVALID) || (isPrior ity && identical(verificationErrorsState, CacheState.FLUSHED))) { 4595 if (identical(verificationErrorsState, CacheState.INVALID) || (isPrior ity && identical(verificationErrorsState, CacheState.FLUSHED))) {
4455 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEM ENT); 4596 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEM ENT);
4456 if (libraryElement != null) { 4597 if (libraryElement != null) {
4457 DartEntryImpl dartCopy = dartEntry.writableCopy; 4598 DartEntryImpl dartCopy = dartEntry.writableCopy;
4458 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, C acheState.IN_PROCESS); 4599 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, C acheState.IN_PROCESS);
4459 _cache.put(source, dartCopy); 4600 _cache.put(source, dartCopy);
4460 return new GenerateDartErrorsTask(this, source, libraryElement); 4601 return new GenerateDartErrorsTask(this, source, libraryElement);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
4699 4840
4700 /** 4841 /**
4701 * In response to a change to at least one of the compilation units in the giv en library, 4842 * In response to a change to at least one of the compilation units in the giv en library,
4702 * invalidate any results that are dependent on the result of resolving that l ibrary. 4843 * invalidate any results that are dependent on the result of resolving that l ibrary.
4703 * 4844 *
4704 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4845 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4705 * 4846 *
4706 * @param librarySource the source of the library being invalidated 4847 * @param librarySource the source of the library being invalidated
4707 */ 4848 */
4708 void invalidateLibraryResolution(Source librarySource) { 4849 void invalidateLibraryResolution(Source librarySource) {
4850 // TODO(brianwilkerson) This could be optimized. There's no need to flush al l of these caches if
4851 // the public namespace hasn't changed, which will be a fairly common case. The question is
4852 // whether we can afford the time to compute the namespace to look for diffe rences.
4709 DartEntry libraryEntry = getReadableDartEntry(librarySource); 4853 DartEntry libraryEntry = getReadableDartEntry(librarySource);
4710 if (libraryEntry != null) { 4854 if (libraryEntry != null) {
4711 List<Source> includedParts = libraryEntry.getValue(DartEntry.INCLUDED_PART S); 4855 List<Source> includedParts = libraryEntry.getValue(DartEntry.INCLUDED_PART S);
4712 DartEntryImpl libraryCopy = libraryEntry.writableCopy; 4856 DartEntryImpl libraryCopy = libraryEntry.writableCopy;
4713 libraryCopy.invalidateAllResolutionInformation(); 4857 libraryCopy.invalidateAllResolutionInformation();
4714 libraryCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID); 4858 libraryCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID);
4715 _cache.put(librarySource, libraryCopy); 4859 _cache.put(librarySource, libraryCopy);
4716 for (Source partSource in includedParts) { 4860 for (Source partSource in includedParts) {
4717 SourceEntry partEntry = _cache.get(partSource); 4861 SourceEntry partEntry = _cache.get(partSource);
4718 if (partEntry is DartEntry) { 4862 if (partEntry is DartEntry) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
4783 * @throws AnalysisException if the results could not be recorded 4927 * @throws AnalysisException if the results could not be recorded
4784 */ 4928 */
4785 DartEntry recordGenerateDartErrorsTask(GenerateDartErrorsTask task) { 4929 DartEntry recordGenerateDartErrorsTask(GenerateDartErrorsTask task) {
4786 Source source = task.source; 4930 Source source = task.source;
4787 Source librarySource = task.libraryElement.source; 4931 Source librarySource = task.libraryElement.source;
4788 AnalysisException thrownException = task.exception; 4932 AnalysisException thrownException = task.exception;
4789 DartEntry dartEntry = null; 4933 DartEntry dartEntry = null;
4790 { 4934 {
4791 SourceEntry sourceEntry = _cache.get(source); 4935 SourceEntry sourceEntry = _cache.get(source);
4792 if (sourceEntry is! DartEntry) { 4936 if (sourceEntry is! DartEntry) {
4937 // This shouldn't be possible because we should never have performed the task if the source
4938 // didn't represent a Dart file, but check to be safe.
4793 throw new AnalysisException.con1("Internal error: attempting to verify n on-Dart file as a Dart file: ${source.fullName}"); 4939 throw new AnalysisException.con1("Internal error: attempting to verify n on-Dart file as a Dart file: ${source.fullName}");
4794 } 4940 }
4795 dartEntry = sourceEntry as DartEntry; 4941 dartEntry = sourceEntry as DartEntry;
4796 _cache.accessed(source); 4942 _cache.accessed(source);
4797 int sourceTime = source.modificationStamp; 4943 int sourceTime = source.modificationStamp;
4798 int resultTime = task.modificationTime; 4944 int resultTime = task.modificationTime;
4799 if (sourceTime == resultTime) { 4945 if (sourceTime == resultTime) {
4800 if (dartEntry.modificationTime != sourceTime) { 4946 if (dartEntry.modificationTime != sourceTime) {
4947 // The source has changed without the context being notified. Simulate notification.
4801 sourceChanged(source); 4948 sourceChanged(source);
4802 dartEntry = getReadableDartEntry(source); 4949 dartEntry = getReadableDartEntry(source);
4803 if (dartEntry == null) { 4950 if (dartEntry == null) {
4804 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}"); 4951 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
4805 } 4952 }
4806 } 4953 }
4807 DartEntryImpl dartCopy = dartEntry.writableCopy; 4954 DartEntryImpl dartCopy = dartEntry.writableCopy;
4808 if (thrownException == null) { 4955 if (thrownException == null) {
4809 dartCopy.setValue2(DartEntry.VERIFICATION_ERRORS, librarySource, task. errors); 4956 dartCopy.setValue2(DartEntry.VERIFICATION_ERRORS, librarySource, task. errors);
4810 ChangeNoticeImpl notice = getNotice(source); 4957 ChangeNoticeImpl notice = getNotice(source);
4811 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.LIN E_INFO)); 4958 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.LIN E_INFO));
4812 } else { 4959 } else {
4813 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.ERROR); 4960 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.ERROR);
4814 } 4961 }
4815 dartCopy.exception = thrownException; 4962 dartCopy.exception = thrownException;
4816 _cache.put(source, dartCopy); 4963 _cache.put(source, dartCopy);
4817 dartEntry = dartCopy; 4964 dartEntry = dartCopy;
4818 } else { 4965 } else {
4819 DartEntryImpl dartCopy = dartEntry.writableCopy; 4966 DartEntryImpl dartCopy = dartEntry.writableCopy;
4820 if (thrownException == null || resultTime >= 0) { 4967 if (thrownException == null || resultTime >= 0) {
4968 //
4969 // The analysis was performed on out-of-date sources. Mark the cache s o that the source
4970 // will be re-verified using the up-to-date sources.
4971 //
4821 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.INVALID); 4972 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.INVALID);
4822 } else { 4973 } else {
4974 //
4975 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
4976 // cache so that we won't attempt to re-verify the source until there' s a good chance
4977 // that we'll be able to do so without error.
4978 //
4823 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.ERROR); 4979 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.ERROR);
4824 } 4980 }
4825 dartCopy.exception = thrownException; 4981 dartCopy.exception = thrownException;
4826 _cache.put(source, dartCopy); 4982 _cache.put(source, dartCopy);
4827 dartEntry = dartCopy; 4983 dartEntry = dartCopy;
4828 } 4984 }
4829 } 4985 }
4830 if (thrownException != null) { 4986 if (thrownException != null) {
4831 throw thrownException; 4987 throw thrownException;
4832 } 4988 }
4833 return dartEntry; 4989 return dartEntry;
4834 } 4990 }
4835 4991
4836 /** 4992 /**
4837 * Record the results produced by performing a [GenerateDartHintsTask]. If the results were 4993 * Record the results produced by performing a [GenerateDartHintsTask]. If the results were
4838 * computed from data that is now out-of-date, then the results will not be re corded. 4994 * computed from data that is now out-of-date, then the results will not be re corded.
4839 * 4995 *
4840 * @param task the task that was performed 4996 * @param task the task that was performed
4841 * @return an entry containing the computed results 4997 * @return an entry containing the computed results
4842 * @throws AnalysisException if the results could not be recorded 4998 * @throws AnalysisException if the results could not be recorded
4843 */ 4999 */
4844 DartEntry recordGenerateDartHintsTask(GenerateDartHintsTask task) { 5000 DartEntry recordGenerateDartHintsTask(GenerateDartHintsTask task) {
4845 Source librarySource = task.libraryElement.source; 5001 Source librarySource = task.libraryElement.source;
4846 AnalysisException thrownException = task.exception; 5002 AnalysisException thrownException = task.exception;
4847 DartEntry libraryEntry = null; 5003 DartEntry libraryEntry = null;
4848 Map<Source, TimestampedData<List<AnalysisError>>> hintMap = task.hintMap; 5004 Map<Source, TimestampedData<List<AnalysisError>>> hintMap = task.hintMap;
4849 if (hintMap == null) { 5005 if (hintMap == null) {
4850 { 5006 {
5007 // We don't have any information about which sources to mark as invalid other than the library
5008 // source.
4851 SourceEntry sourceEntry = _cache.get(librarySource); 5009 SourceEntry sourceEntry = _cache.get(librarySource);
4852 if (sourceEntry is! DartEntry) { 5010 if (sourceEntry is! DartEntry) {
5011 // This shouldn't be possible because we should never have performed t he task if the source
5012 // didn't represent a Dart file, but check to be safe.
4853 throw new AnalysisException.con1("Internal error: attempting to genera te hints for non-Dart file as a Dart file: ${librarySource.fullName}"); 5013 throw new AnalysisException.con1("Internal error: attempting to genera te hints for non-Dart file as a Dart file: ${librarySource.fullName}");
4854 } 5014 }
4855 if (thrownException == null) { 5015 if (thrownException == null) {
4856 thrownException = new AnalysisException.con1("GenerateDartHintsTask re turned a null hint map without throwing an exception: ${librarySource.fullName}" ); 5016 thrownException = new AnalysisException.con1("GenerateDartHintsTask re turned a null hint map without throwing an exception: ${librarySource.fullName}" );
4857 } 5017 }
4858 DartEntryImpl dartCopy = (sourceEntry as DartEntry).writableCopy; 5018 DartEntryImpl dartCopy = (sourceEntry as DartEntry).writableCopy;
4859 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR); 5019 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR);
4860 dartCopy.exception = thrownException; 5020 dartCopy.exception = thrownException;
4861 _cache.put(librarySource, dartCopy); 5021 _cache.put(librarySource, dartCopy);
4862 } 5022 }
4863 throw thrownException; 5023 throw thrownException;
4864 } 5024 }
4865 for (MapEntry<Source, TimestampedData<List<AnalysisError>>> entry in getMapE ntrySet(hintMap)) { 5025 for (MapEntry<Source, TimestampedData<List<AnalysisError>>> entry in getMapE ntrySet(hintMap)) {
4866 Source unitSource = entry.getKey(); 5026 Source unitSource = entry.getKey();
4867 TimestampedData<List<AnalysisError>> results = entry.getValue(); 5027 TimestampedData<List<AnalysisError>> results = entry.getValue();
4868 { 5028 {
4869 SourceEntry sourceEntry = _cache.get(unitSource); 5029 SourceEntry sourceEntry = _cache.get(unitSource);
4870 if (sourceEntry is! DartEntry) { 5030 if (sourceEntry is! DartEntry) {
5031 // This shouldn't be possible because we should never have performed t he task if the source
5032 // didn't represent a Dart file, but check to be safe.
4871 throw new AnalysisException.con1("Internal error: attempting to parse non-Dart file as a Dart file: ${unitSource.fullName}"); 5033 throw new AnalysisException.con1("Internal error: attempting to parse non-Dart file as a Dart file: ${unitSource.fullName}");
4872 } 5034 }
4873 DartEntry dartEntry = sourceEntry as DartEntry; 5035 DartEntry dartEntry = sourceEntry as DartEntry;
4874 if (unitSource == librarySource) { 5036 if (unitSource == librarySource) {
4875 libraryEntry = dartEntry; 5037 libraryEntry = dartEntry;
4876 } 5038 }
4877 _cache.accessed(unitSource); 5039 _cache.accessed(unitSource);
4878 int sourceTime = unitSource.modificationStamp; 5040 int sourceTime = unitSource.modificationStamp;
4879 int resultTime = results.modificationTime; 5041 int resultTime = results.modificationTime;
4880 if (sourceTime == resultTime) { 5042 if (sourceTime == resultTime) {
4881 if (dartEntry.modificationTime != sourceTime) { 5043 if (dartEntry.modificationTime != sourceTime) {
5044 // The source has changed without the context being notified. Simula te notification.
4882 sourceChanged(unitSource); 5045 sourceChanged(unitSource);
4883 dartEntry = getReadableDartEntry(unitSource); 5046 dartEntry = getReadableDartEntry(unitSource);
4884 if (dartEntry == null) { 5047 if (dartEntry == null) {
4885 throw new AnalysisException.con1("A Dart file became a non-Dart fi le: ${unitSource.fullName}"); 5048 throw new AnalysisException.con1("A Dart file became a non-Dart fi le: ${unitSource.fullName}");
4886 } 5049 }
4887 } 5050 }
4888 DartEntryImpl dartCopy = dartEntry.writableCopy; 5051 DartEntryImpl dartCopy = dartEntry.writableCopy;
4889 if (thrownException == null) { 5052 if (thrownException == null) {
4890 dartCopy.setValue2(DartEntry.HINTS, librarySource, results.data); 5053 dartCopy.setValue2(DartEntry.HINTS, librarySource, results.data);
4891 ChangeNoticeImpl notice = getNotice(unitSource); 5054 ChangeNoticeImpl notice = getNotice(unitSource);
4892 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.L INE_INFO)); 5055 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.L INE_INFO));
4893 } else { 5056 } else {
4894 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR) ; 5057 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR) ;
4895 } 5058 }
4896 dartCopy.exception = thrownException; 5059 dartCopy.exception = thrownException;
4897 _cache.put(unitSource, dartCopy); 5060 _cache.put(unitSource, dartCopy);
4898 dartEntry = dartCopy; 5061 dartEntry = dartCopy;
4899 } else { 5062 } else {
4900 if (identical(dartEntry.getState2(DartEntry.HINTS, librarySource), Cac heState.IN_PROCESS)) { 5063 if (identical(dartEntry.getState2(DartEntry.HINTS, librarySource), Cac heState.IN_PROCESS)) {
4901 DartEntryImpl dartCopy = dartEntry.writableCopy; 5064 DartEntryImpl dartCopy = dartEntry.writableCopy;
4902 if (thrownException == null || resultTime >= 0) { 5065 if (thrownException == null || resultTime >= 0) {
5066 //
5067 // The analysis was performed on out-of-date sources. Mark the cac he so that the sources
5068 // will be re-analyzed using the up-to-date sources.
5069 //
4903 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.INVA LID); 5070 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.INVA LID);
4904 } else { 5071 } else {
5072 //
5073 // We could not determine whether the sources were up-to-date or o ut-of-date. Mark the
5074 // cache so that we won't attempt to re-analyze the sources until there's a good chance
5075 // that we'll be able to do so without error.
5076 //
4905 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERRO R); 5077 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERRO R);
4906 } 5078 }
4907 dartCopy.exception = thrownException; 5079 dartCopy.exception = thrownException;
4908 _cache.put(unitSource, dartCopy); 5080 _cache.put(unitSource, dartCopy);
4909 dartEntry = dartCopy; 5081 dartEntry = dartCopy;
4910 } 5082 }
4911 } 5083 }
4912 } 5084 }
4913 } 5085 }
4914 if (thrownException != null) { 5086 if (thrownException != null) {
(...skipping 29 matching lines...) Expand all
4944 * @return an entry containing the computed results 5116 * @return an entry containing the computed results
4945 * @throws AnalysisException if the results could not be recorded 5117 * @throws AnalysisException if the results could not be recorded
4946 */ 5118 */
4947 DartEntry recordParseDartTaskResults(ParseDartTask task) { 5119 DartEntry recordParseDartTaskResults(ParseDartTask task) {
4948 Source source = task.source; 5120 Source source = task.source;
4949 AnalysisException thrownException = task.exception; 5121 AnalysisException thrownException = task.exception;
4950 DartEntry dartEntry = null; 5122 DartEntry dartEntry = null;
4951 { 5123 {
4952 SourceEntry sourceEntry = _cache.get(source); 5124 SourceEntry sourceEntry = _cache.get(source);
4953 if (sourceEntry is! DartEntry) { 5125 if (sourceEntry is! DartEntry) {
5126 // This shouldn't be possible because we should never have performed the task if the source
5127 // didn't represent a Dart file, but check to be safe.
4954 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}"); 5128 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}");
4955 } 5129 }
4956 dartEntry = sourceEntry as DartEntry; 5130 dartEntry = sourceEntry as DartEntry;
4957 _cache.accessed(source); 5131 _cache.accessed(source);
4958 int sourceTime = source.modificationStamp; 5132 int sourceTime = source.modificationStamp;
4959 int resultTime = task.modificationTime; 5133 int resultTime = task.modificationTime;
4960 if (sourceTime == resultTime) { 5134 if (sourceTime == resultTime) {
4961 if (dartEntry.modificationTime != sourceTime) { 5135 if (dartEntry.modificationTime != sourceTime) {
5136 // The source has changed without the context being notified. Simulate notification.
4962 sourceChanged(source); 5137 sourceChanged(source);
4963 dartEntry = getReadableDartEntry(source); 5138 dartEntry = getReadableDartEntry(source);
4964 if (dartEntry == null) { 5139 if (dartEntry == null) {
4965 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}"); 5140 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
4966 } 5141 }
4967 } 5142 }
4968 DartEntryImpl dartCopy = dartEntry.writableCopy; 5143 DartEntryImpl dartCopy = dartEntry.writableCopy;
4969 if (thrownException == null) { 5144 if (thrownException == null) {
4970 LineInfo lineInfo = task.lineInfo; 5145 LineInfo lineInfo = task.lineInfo;
4971 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 5146 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
4972 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) { 5147 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) {
4973 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); 5148 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
4974 } else { 5149 } else {
4975 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); 5150 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
4976 } 5151 }
4977 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit); 5152 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit);
4978 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors); 5153 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors);
4979 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources); 5154 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
4980 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources); 5155 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
4981 dartCopy.setValue(DartEntry.INCLUDED_PARTS, task.includedSources); 5156 dartCopy.setValue(DartEntry.INCLUDED_PARTS, task.includedSources);
4982 ChangeNoticeImpl notice = getNotice(source); 5157 ChangeNoticeImpl notice = getNotice(source);
4983 notice.setErrors(dartEntry.allErrors, lineInfo); 5158 notice.setErrors(dartEntry.allErrors, lineInfo);
5159 // Verify that the incrementally parsed and resolved unit in the incre mental cache
5160 // is structurally equivalent to the fully parsed unit
4984 _incrementalAnalysisCache = IncrementalAnalysisCache.verifyStructure(_ incrementalAnalysisCache, source, task.compilationUnit); 5161 _incrementalAnalysisCache = IncrementalAnalysisCache.verifyStructure(_ incrementalAnalysisCache, source, task.compilationUnit);
4985 } else { 5162 } else {
4986 dartCopy.recordParseError(); 5163 dartCopy.recordParseError();
4987 } 5164 }
4988 dartCopy.exception = thrownException; 5165 dartCopy.exception = thrownException;
4989 _cache.put(source, dartCopy); 5166 _cache.put(source, dartCopy);
4990 dartEntry = dartCopy; 5167 dartEntry = dartCopy;
4991 } else { 5168 } else {
4992 DartEntryImpl dartCopy = dartEntry.writableCopy; 5169 DartEntryImpl dartCopy = dartEntry.writableCopy;
4993 if (thrownException == null || resultTime >= 0) { 5170 if (thrownException == null || resultTime >= 0) {
5171 //
5172 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
5173 // will be re-analyzed using the up-to-date sources.
5174 //
4994 dartCopy.recordParseNotInProcess(); 5175 dartCopy.recordParseNotInProcess();
4995 } else { 5176 } else {
5177 //
5178 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
5179 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
5180 // that we'll be able to do so without error.
5181 //
4996 dartCopy.recordParseError(); 5182 dartCopy.recordParseError();
4997 } 5183 }
4998 dartCopy.exception = thrownException; 5184 dartCopy.exception = thrownException;
4999 _cache.put(source, dartCopy); 5185 _cache.put(source, dartCopy);
5000 dartEntry = dartCopy; 5186 dartEntry = dartCopy;
5001 } 5187 }
5002 } 5188 }
5003 if (thrownException != null) { 5189 if (thrownException != null) {
5004 throw thrownException; 5190 throw thrownException;
5005 } 5191 }
5006 return dartEntry; 5192 return dartEntry;
5007 } 5193 }
5008 5194
5009 /** 5195 /**
5010 * Record the results produced by performing a [ParseHtmlTask]. If the results were computed 5196 * Record the results produced by performing a [ParseHtmlTask]. If the results were computed
5011 * from data that is now out-of-date, then the results will not be recorded. 5197 * from data that is now out-of-date, then the results will not be recorded.
5012 * 5198 *
5013 * @param task the task that was performed 5199 * @param task the task that was performed
5014 * @return an entry containing the computed results 5200 * @return an entry containing the computed results
5015 * @throws AnalysisException if the results could not be recorded 5201 * @throws AnalysisException if the results could not be recorded
5016 */ 5202 */
5017 HtmlEntry recordParseHtmlTaskResults(ParseHtmlTask task) { 5203 HtmlEntry recordParseHtmlTaskResults(ParseHtmlTask task) {
5018 Source source = task.source; 5204 Source source = task.source;
5019 AnalysisException thrownException = task.exception; 5205 AnalysisException thrownException = task.exception;
5020 HtmlEntry htmlEntry = null; 5206 HtmlEntry htmlEntry = null;
5021 { 5207 {
5022 SourceEntry sourceEntry = _cache.get(source); 5208 SourceEntry sourceEntry = _cache.get(source);
5023 if (sourceEntry is! HtmlEntry) { 5209 if (sourceEntry is! HtmlEntry) {
5210 // This shouldn't be possible because we should never have performed the task if the source
5211 // didn't represent an HTML file, but check to be safe.
5024 throw new AnalysisException.con1("Internal error: attempting to parse no n-HTML file as a HTML file: ${source.fullName}"); 5212 throw new AnalysisException.con1("Internal error: attempting to parse no n-HTML file as a HTML file: ${source.fullName}");
5025 } 5213 }
5026 htmlEntry = sourceEntry as HtmlEntry; 5214 htmlEntry = sourceEntry as HtmlEntry;
5027 _cache.accessed(source); 5215 _cache.accessed(source);
5028 int sourceTime = source.modificationStamp; 5216 int sourceTime = source.modificationStamp;
5029 int resultTime = task.modificationTime; 5217 int resultTime = task.modificationTime;
5030 if (sourceTime == resultTime) { 5218 if (sourceTime == resultTime) {
5031 if (htmlEntry.modificationTime != sourceTime) { 5219 if (htmlEntry.modificationTime != sourceTime) {
5220 // The source has changed without the context being notified. Simulate notification.
5032 sourceChanged(source); 5221 sourceChanged(source);
5033 htmlEntry = getReadableHtmlEntry(source); 5222 htmlEntry = getReadableHtmlEntry(source);
5034 if (htmlEntry == null) { 5223 if (htmlEntry == null) {
5035 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}"); 5224 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
5036 } 5225 }
5037 } 5226 }
5038 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy; 5227 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy;
5039 if (thrownException == null) { 5228 if (thrownException == null) {
5040 LineInfo lineInfo = task.lineInfo; 5229 LineInfo lineInfo = task.lineInfo;
5041 HtmlUnit unit = task.htmlUnit; 5230 HtmlUnit unit = task.htmlUnit;
5042 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 5231 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
5043 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit); 5232 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit);
5044 htmlCopy.setValue(HtmlEntry.PARSE_ERRORS, task.errors); 5233 htmlCopy.setValue(HtmlEntry.PARSE_ERRORS, task.errors);
5045 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries); 5234 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries);
5046 ChangeNoticeImpl notice = getNotice(source); 5235 ChangeNoticeImpl notice = getNotice(source);
5047 notice.setErrors(htmlEntry.allErrors, lineInfo); 5236 notice.setErrors(htmlEntry.allErrors, lineInfo);
5048 } else { 5237 } else {
5049 htmlCopy.recordParseError(); 5238 htmlCopy.recordParseError();
5050 } 5239 }
5051 htmlCopy.exception = thrownException; 5240 htmlCopy.exception = thrownException;
5052 _cache.put(source, htmlCopy); 5241 _cache.put(source, htmlCopy);
5053 htmlEntry = htmlCopy; 5242 htmlEntry = htmlCopy;
5054 } else { 5243 } else {
5055 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy; 5244 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy;
5056 if (thrownException == null || resultTime >= 0) { 5245 if (thrownException == null || resultTime >= 0) {
5246 //
5247 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
5248 // will be re-analyzed using the up-to-date sources.
5249 //
5057 if (identical(htmlCopy.getState(SourceEntry.LINE_INFO), CacheState.IN_ PROCESS)) { 5250 if (identical(htmlCopy.getState(SourceEntry.LINE_INFO), CacheState.IN_ PROCESS)) {
5058 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID); 5251 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID);
5059 } 5252 }
5060 if (identical(htmlCopy.getState(HtmlEntry.PARSED_UNIT), CacheState.IN_ PROCESS)) { 5253 if (identical(htmlCopy.getState(HtmlEntry.PARSED_UNIT), CacheState.IN_ PROCESS)) {
5061 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID); 5254 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID);
5062 } 5255 }
5063 if (identical(htmlCopy.getState(HtmlEntry.REFERENCED_LIBRARIES), Cache State.IN_PROCESS)) { 5256 if (identical(htmlCopy.getState(HtmlEntry.REFERENCED_LIBRARIES), Cache State.IN_PROCESS)) {
5064 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID ); 5257 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID );
5065 } 5258 }
5066 } else { 5259 } else {
5260 //
5261 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
5262 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
5263 // that we'll be able to do so without error.
5264 //
5067 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR); 5265 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR);
5068 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR); 5266 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
5069 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR); 5267 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
5070 } 5268 }
5071 htmlCopy.exception = thrownException; 5269 htmlCopy.exception = thrownException;
5072 _cache.put(source, htmlCopy); 5270 _cache.put(source, htmlCopy);
5073 htmlEntry = htmlCopy; 5271 htmlEntry = htmlCopy;
5074 } 5272 }
5075 } 5273 }
5076 if (thrownException != null) { 5274 if (thrownException != null) {
(...skipping 11 matching lines...) Expand all
5088 * @throws AnalysisException if the results could not be recorded 5286 * @throws AnalysisException if the results could not be recorded
5089 */ 5287 */
5090 SourceEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) { 5288 SourceEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) {
5091 Source unitSource = task.source; 5289 Source unitSource = task.source;
5092 Source librarySource = task.librarySource; 5290 Source librarySource = task.librarySource;
5093 AnalysisException thrownException = task.exception; 5291 AnalysisException thrownException = task.exception;
5094 DartEntry dartEntry = null; 5292 DartEntry dartEntry = null;
5095 { 5293 {
5096 SourceEntry sourceEntry = _cache.get(unitSource); 5294 SourceEntry sourceEntry = _cache.get(unitSource);
5097 if (sourceEntry is! DartEntry) { 5295 if (sourceEntry is! DartEntry) {
5296 // This shouldn't be possible because we should never have performed the task if the source
5297 // didn't represent a Dart file, but check to be safe.
5098 throw new AnalysisException.con1("Internal error: attempting to reolve n on-Dart file as a Dart file: ${unitSource.fullName}"); 5298 throw new AnalysisException.con1("Internal error: attempting to reolve n on-Dart file as a Dart file: ${unitSource.fullName}");
5099 } 5299 }
5100 dartEntry = sourceEntry as DartEntry; 5300 dartEntry = sourceEntry as DartEntry;
5101 _cache.accessed(unitSource); 5301 _cache.accessed(unitSource);
5102 int sourceTime = unitSource.modificationStamp; 5302 int sourceTime = unitSource.modificationStamp;
5103 int resultTime = task.modificationTime; 5303 int resultTime = task.modificationTime;
5104 if (sourceTime == resultTime) { 5304 if (sourceTime == resultTime) {
5105 if (dartEntry.modificationTime != sourceTime) { 5305 if (dartEntry.modificationTime != sourceTime) {
5306 // The source has changed without the context being notified. Simulate notification.
5106 sourceChanged(unitSource); 5307 sourceChanged(unitSource);
5107 dartEntry = getReadableDartEntry(unitSource); 5308 dartEntry = getReadableDartEntry(unitSource);
5108 if (dartEntry == null) { 5309 if (dartEntry == null) {
5109 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${unitSource.fullName}"); 5310 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${unitSource.fullName}");
5110 } 5311 }
5111 } 5312 }
5112 DartEntryImpl dartCopy = dartEntry.writableCopy; 5313 DartEntryImpl dartCopy = dartEntry.writableCopy;
5113 if (thrownException == null) { 5314 if (thrownException == null) {
5114 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, task.resolv edUnit); 5315 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, task.resolv edUnit);
5115 } else { 5316 } else {
5116 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR); 5317 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR);
5117 } 5318 }
5118 dartCopy.exception = thrownException; 5319 dartCopy.exception = thrownException;
5119 _cache.put(unitSource, dartCopy); 5320 _cache.put(unitSource, dartCopy);
5120 dartEntry = dartCopy; 5321 dartEntry = dartCopy;
5121 } else { 5322 } else {
5122 DartEntryImpl dartCopy = dartEntry.writableCopy; 5323 DartEntryImpl dartCopy = dartEntry.writableCopy;
5123 if (thrownException == null || resultTime >= 0) { 5324 if (thrownException == null || resultTime >= 0) {
5325 //
5326 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
5327 // will be re-analyzed using the up-to-date sources.
5328 //
5124 if (identical(dartCopy.getState(DartEntry.RESOLVED_UNIT), CacheState.I N_PROCESS)) { 5329 if (identical(dartCopy.getState(DartEntry.RESOLVED_UNIT), CacheState.I N_PROCESS)) {
5125 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheStat e.INVALID); 5330 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheStat e.INVALID);
5126 } 5331 }
5127 } else { 5332 } else {
5333 //
5334 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
5335 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
5336 // that we'll be able to do so without error.
5337 //
5128 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR); 5338 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR);
5129 } 5339 }
5130 dartCopy.exception = thrownException; 5340 dartCopy.exception = thrownException;
5131 _cache.put(unitSource, dartCopy); 5341 _cache.put(unitSource, dartCopy);
5132 dartEntry = dartCopy; 5342 dartEntry = dartCopy;
5133 } 5343 }
5134 } 5344 }
5135 if (thrownException != null) { 5345 if (thrownException != null) {
5136 throw thrownException; 5346 throw thrownException;
5137 } 5347 }
5138 return dartEntry; 5348 return dartEntry;
5139 } 5349 }
5140 5350
5141 /** 5351 /**
5142 * Record the results produced by performing a [ResolveHtmlTask]. If the resul ts were 5352 * Record the results produced by performing a [ResolveHtmlTask]. If the resul ts were
5143 * computed from data that is now out-of-date, then the results will not be re corded. 5353 * computed from data that is now out-of-date, then the results will not be re corded.
5144 * 5354 *
5145 * @param task the task that was performed 5355 * @param task the task that was performed
5146 * @return an entry containing the computed results 5356 * @return an entry containing the computed results
5147 * @throws AnalysisException if the results could not be recorded 5357 * @throws AnalysisException if the results could not be recorded
5148 */ 5358 */
5149 SourceEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) { 5359 SourceEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) {
5150 Source source = task.source; 5360 Source source = task.source;
5151 AnalysisException thrownException = task.exception; 5361 AnalysisException thrownException = task.exception;
5152 HtmlEntry htmlEntry = null; 5362 HtmlEntry htmlEntry = null;
5153 { 5363 {
5154 SourceEntry sourceEntry = _cache.get(source); 5364 SourceEntry sourceEntry = _cache.get(source);
5155 if (sourceEntry is! HtmlEntry) { 5365 if (sourceEntry is! HtmlEntry) {
5366 // This shouldn't be possible because we should never have performed the task if the source
5367 // didn't represent an HTML file, but check to be safe.
5156 throw new AnalysisException.con1("Internal error: attempting to reolve n on-HTML file as an HTML file: ${source.fullName}"); 5368 throw new AnalysisException.con1("Internal error: attempting to reolve n on-HTML file as an HTML file: ${source.fullName}");
5157 } 5369 }
5158 htmlEntry = sourceEntry as HtmlEntry; 5370 htmlEntry = sourceEntry as HtmlEntry;
5159 _cache.accessed(source); 5371 _cache.accessed(source);
5160 int sourceTime = source.modificationStamp; 5372 int sourceTime = source.modificationStamp;
5161 int resultTime = task.modificationTime; 5373 int resultTime = task.modificationTime;
5162 if (sourceTime == resultTime) { 5374 if (sourceTime == resultTime) {
5163 if (htmlEntry.modificationTime != sourceTime) { 5375 if (htmlEntry.modificationTime != sourceTime) {
5376 // The source has changed without the context being notified. Simulate notification.
5164 sourceChanged(source); 5377 sourceChanged(source);
5165 htmlEntry = getReadableHtmlEntry(source); 5378 htmlEntry = getReadableHtmlEntry(source);
5166 if (htmlEntry == null) { 5379 if (htmlEntry == null) {
5167 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}"); 5380 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
5168 } 5381 }
5169 } 5382 }
5170 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy; 5383 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
5171 if (thrownException == null) { 5384 if (thrownException == null) {
5172 htmlCopy.setValue(HtmlEntry.ELEMENT, task.element); 5385 htmlCopy.setValue(HtmlEntry.ELEMENT, task.element);
5173 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, task.resolutionErrors); 5386 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, task.resolutionErrors);
5174 ChangeNoticeImpl notice = getNotice(source); 5387 ChangeNoticeImpl notice = getNotice(source);
5175 notice.htmlUnit = task.resolvedUnit; 5388 notice.htmlUnit = task.resolvedUnit;
5176 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LIN E_INFO)); 5389 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LIN E_INFO));
5177 } else { 5390 } else {
5178 htmlCopy.recordResolutionError(); 5391 htmlCopy.recordResolutionError();
5179 } 5392 }
5180 htmlCopy.exception = thrownException; 5393 htmlCopy.exception = thrownException;
5181 _cache.put(source, htmlCopy); 5394 _cache.put(source, htmlCopy);
5182 htmlEntry = htmlCopy; 5395 htmlEntry = htmlCopy;
5183 } else { 5396 } else {
5184 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy; 5397 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
5185 if (thrownException == null || resultTime >= 0) { 5398 if (thrownException == null || resultTime >= 0) {
5399 //
5400 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
5401 // will be re-analyzed using the up-to-date sources.
5402 //
5186 if (identical(htmlCopy.getState(HtmlEntry.ELEMENT), CacheState.IN_PROC ESS)) { 5403 if (identical(htmlCopy.getState(HtmlEntry.ELEMENT), CacheState.IN_PROC ESS)) {
5187 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID); 5404 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
5188 } 5405 }
5189 if (identical(htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS), CacheSta te.IN_PROCESS)) { 5406 if (identical(htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS), CacheSta te.IN_PROCESS)) {
5190 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.INVALID); 5407 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.INVALID);
5191 } 5408 }
5192 } else { 5409 } else {
5410 //
5411 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
5412 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
5413 // that we'll be able to do so without error.
5414 //
5193 htmlCopy.recordResolutionError(); 5415 htmlCopy.recordResolutionError();
5194 } 5416 }
5195 htmlCopy.exception = thrownException; 5417 htmlCopy.exception = thrownException;
5196 _cache.put(source, htmlCopy); 5418 _cache.put(source, htmlCopy);
5197 htmlEntry = htmlCopy; 5419 htmlEntry = htmlCopy;
5198 } 5420 }
5199 } 5421 }
5200 if (thrownException != null) { 5422 if (thrownException != null) {
5201 throw thrownException; 5423 throw thrownException;
5202 } 5424 }
(...skipping 22 matching lines...) Expand all
5225 } 5447 }
5226 5448
5227 /** 5449 /**
5228 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 5450 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
5229 * 5451 *
5230 * @param source the source that has been changed 5452 * @param source the source that has been changed
5231 */ 5453 */
5232 void sourceChanged(Source source) { 5454 void sourceChanged(Source source) {
5233 SourceEntry sourceEntry = _cache.get(source); 5455 SourceEntry sourceEntry = _cache.get(source);
5234 if (sourceEntry == null || sourceEntry.modificationTime == source.modificati onStamp) { 5456 if (sourceEntry == null || sourceEntry.modificationTime == source.modificati onStamp) {
5457 // Either we have removed this source, in which case we don't care that it is changed, or we
5458 // have already invalidated the cache and don't need to invalidate it agai n.
5235 return; 5459 return;
5236 } 5460 }
5237 if (sourceEntry is HtmlEntry) { 5461 if (sourceEntry is HtmlEntry) {
5238 HtmlEntryImpl htmlCopy = sourceEntry.writableCopy; 5462 HtmlEntryImpl htmlCopy = sourceEntry.writableCopy;
5239 htmlCopy.modificationTime = source.modificationStamp; 5463 htmlCopy.modificationTime = source.modificationStamp;
5240 htmlCopy.invalidateAllInformation(); 5464 htmlCopy.invalidateAllInformation();
5241 _cache.put(source, htmlCopy); 5465 _cache.put(source, htmlCopy);
5242 } else if (sourceEntry is DartEntry) { 5466 } else if (sourceEntry is DartEntry) {
5243 List<Source> containingLibraries = getLibrariesContaining(source); 5467 List<Source> containingLibraries = getLibrariesContaining(source);
5244 Set<Source> librariesToInvalidate = new Set<Source>(); 5468 Set<Source> librariesToInvalidate = new Set<Source>();
5245 for (Source containingLibrary in containingLibraries) { 5469 for (Source containingLibrary in containingLibraries) {
5246 librariesToInvalidate.add(containingLibrary); 5470 librariesToInvalidate.add(containingLibrary);
5247 for (Source dependentLibrary in getLibrariesDependingOn(containingLibrar y)) { 5471 for (Source dependentLibrary in getLibrariesDependingOn(containingLibrar y)) {
5248 librariesToInvalidate.add(dependentLibrary); 5472 librariesToInvalidate.add(dependentLibrary);
5249 } 5473 }
5250 } 5474 }
5251 for (Source library in librariesToInvalidate) { 5475 for (Source library in librariesToInvalidate) {
5476 // for (Source library : containingLibraries) {
5252 invalidateLibraryResolution(library); 5477 invalidateLibraryResolution(library);
5253 } 5478 }
5254 DartEntryImpl dartCopy = sourceEntry.writableCopy; 5479 DartEntryImpl dartCopy = sourceEntry.writableCopy;
5255 dartCopy.modificationTime = source.modificationStamp; 5480 dartCopy.modificationTime = source.modificationStamp;
5256 dartCopy.invalidateAllInformation(); 5481 dartCopy.invalidateAllInformation();
5257 _cache.put(source, dartCopy); 5482 _cache.put(source, dartCopy);
5258 } 5483 }
5259 } 5484 }
5260 5485
5261 /** 5486 /**
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
5700 return _sdkAnalysisContext.parseHtmlUnit(source); 5925 return _sdkAnalysisContext.parseHtmlUnit(source);
5701 } else { 5926 } else {
5702 return super.parseHtmlUnit(source); 5927 return super.parseHtmlUnit(source);
5703 } 5928 }
5704 } 5929 }
5705 5930
5706 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 5931 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
5707 if (elementMap.isEmpty) { 5932 if (elementMap.isEmpty) {
5708 return; 5933 return;
5709 } 5934 }
5935 // TODO(jwren) we are making the assumption here that the elementMap will ha ve sources from only
5936 // one library, while this is true with our use of the Analysis Engine, it i s not required by
5937 // the API, revisit to fix cases where the elementMap can have sources both in the sdk and other
5938 // libraries
5710 Source source = new JavaIterator(elementMap.keys.toSet()).next(); 5939 Source source = new JavaIterator(elementMap.keys.toSet()).next();
5711 if (source.isInSystemLibrary) { 5940 if (source.isInSystemLibrary) {
5712 _sdkAnalysisContext.recordLibraryElements(elementMap); 5941 _sdkAnalysisContext.recordLibraryElements(elementMap);
5713 } else { 5942 } else {
5714 super.recordLibraryElements(elementMap); 5943 super.recordLibraryElements(elementMap);
5715 } 5944 }
5716 } 5945 }
5717 5946
5718 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) { 5947 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) {
5719 if (source.isInSystemLibrary) { 5948 if (source.isInSystemLibrary) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
5815 * @param oldContents the original source contents prior to this update (may b e `null`) 6044 * @param oldContents the original source contents prior to this update (may b e `null`)
5816 * @param newContents the new contents after this incremental change (not `nul l`) 6045 * @param newContents the new contents after this incremental change (not `nul l`)
5817 * @param offset the offset at which the change occurred 6046 * @param offset the offset at which the change occurred
5818 * @param oldLength the length of the text being replaced 6047 * @param oldLength the length of the text being replaced
5819 * @param newLength the length of the replacement text 6048 * @param newLength the length of the replacement text
5820 * @param sourceEntry the cached entry for the given source or `null` if none 6049 * @param sourceEntry the cached entry for the given source or `null` if none
5821 * @return the cache used for incremental analysis or `null` if incremental an alysis cannot 6050 * @return the cache used for incremental analysis or `null` if incremental an alysis cannot
5822 * be performed 6051 * be performed
5823 */ 6052 */
5824 static IncrementalAnalysisCache update(IncrementalAnalysisCache cache, Source source, String oldContents, String newContents, int offset, int oldLength, int n ewLength, SourceEntry sourceEntry) { 6053 static IncrementalAnalysisCache update(IncrementalAnalysisCache cache, Source source, String oldContents, String newContents, int offset, int oldLength, int n ewLength, SourceEntry sourceEntry) {
6054 // Determine the cache resolved unit
5825 Source librarySource = null; 6055 Source librarySource = null;
5826 CompilationUnit unit = null; 6056 CompilationUnit unit = null;
5827 if (sourceEntry is DartEntryImpl) { 6057 if (sourceEntry is DartEntryImpl) {
5828 DartEntryImpl dartEntry = sourceEntry; 6058 DartEntryImpl dartEntry = sourceEntry;
5829 List<Source> librarySources = dartEntry.librariesContaining; 6059 List<Source> librarySources = dartEntry.librariesContaining;
5830 if (librarySources.length == 1) { 6060 if (librarySources.length == 1) {
5831 librarySource = librarySources[0]; 6061 librarySource = librarySources[0];
5832 if (librarySource != null) { 6062 if (librarySource != null) {
5833 unit = dartEntry.getValue2(DartEntry.RESOLVED_UNIT, librarySource); 6063 unit = dartEntry.getValue2(DartEntry.RESOLVED_UNIT, librarySource);
5834 } 6064 }
5835 } 6065 }
5836 } 6066 }
6067 // Create a new cache if there is not an existing cache or the source is dif ferent
6068 // or a new resolved compilation unit is available
5837 if (cache == null || cache.source != source || unit != null) { 6069 if (cache == null || cache.source != source || unit != null) {
5838 if (unit == null) { 6070 if (unit == null) {
5839 return null; 6071 return null;
5840 } 6072 }
5841 if (oldContents == null) { 6073 if (oldContents == null) {
5842 if (oldLength != 0) { 6074 if (oldLength != 0) {
5843 return null; 6075 return null;
5844 } 6076 }
5845 oldContents = "${newContents.substring(0, offset)}${newContents.substrin g(offset + newLength)}"; 6077 oldContents = "${newContents.substring(0, offset)}${newContents.substrin g(offset + newLength)}";
5846 } 6078 }
5847 return new IncrementalAnalysisCache(librarySource, source, unit, oldConten ts, newContents, offset, oldLength, newLength); 6079 return new IncrementalAnalysisCache(librarySource, source, unit, oldConten ts, newContents, offset, oldLength, newLength);
5848 } 6080 }
6081 // Update the existing cache if the change is contiguous
5849 if (cache._oldLength == 0 && cache._newLength == 0) { 6082 if (cache._oldLength == 0 && cache._newLength == 0) {
5850 cache._offset = offset; 6083 cache._offset = offset;
5851 cache._oldLength = oldLength; 6084 cache._oldLength = oldLength;
5852 cache._newLength = newLength; 6085 cache._newLength = newLength;
5853 } else { 6086 } else {
5854 if (cache._offset > offset || offset > cache._offset + cache._newLength) { 6087 if (cache._offset > offset || offset > cache._offset + cache._newLength) {
5855 return null; 6088 return null;
5856 } 6089 }
5857 cache._newLength += newLength - oldLength; 6090 cache._newLength += newLength - oldLength;
5858 } 6091 }
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
7125 void internalPerform() { 7358 void internalPerform() {
7126 InternalAnalysisContext context = this.context; 7359 InternalAnalysisContext context = this.context;
7127 TimestampedData<CompilationUnit> data = context.internalResolveCompilationUn it(source, libraryElement); 7360 TimestampedData<CompilationUnit> data = context.internalResolveCompilationUn it(source, libraryElement);
7128 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.errors.sta rt(); 7361 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.errors.sta rt();
7129 try { 7362 try {
7130 _modificationTime = data.modificationTime; 7363 _modificationTime = data.modificationTime;
7131 CompilationUnit unit = data.data; 7364 CompilationUnit unit = data.data;
7132 RecordingErrorListener errorListener = new RecordingErrorListener(); 7365 RecordingErrorListener errorListener = new RecordingErrorListener();
7133 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 7366 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
7134 TypeProvider typeProvider = context.typeProvider; 7367 TypeProvider typeProvider = context.typeProvider;
7368 //
7369 // Use the ConstantVerifier to verify the use of constants. This needs to happen before using
7370 // the ErrorVerifier because some error codes need the computed constant v alues.
7371 //
7135 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty peProvider); 7372 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty peProvider);
7136 unit.accept(constantVerifier); 7373 unit.accept(constantVerifier);
7374 //
7375 // Use the ErrorVerifier to compute the rest of the errors.
7376 //
7137 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libraryElem ent, typeProvider, new InheritanceManager(libraryElement)); 7377 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libraryElem ent, typeProvider, new InheritanceManager(libraryElement));
7138 unit.accept(errorVerifier); 7378 unit.accept(errorVerifier);
7139 _errors = errorListener.getErrors2(source); 7379 _errors = errorListener.getErrors2(source);
7140 } finally { 7380 } finally {
7141 timeCounter.stop(); 7381 timeCounter.stop();
7142 } 7382 }
7143 } 7383 }
7144 } 7384 }
7145 7385
7146 /** 7386 /**
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
7185 } 7425 }
7186 return "generate Dart hints for ${librarySource.fullName}"; 7426 return "generate Dart hints for ${librarySource.fullName}";
7187 } 7427 }
7188 7428
7189 void internalPerform() { 7429 void internalPerform() {
7190 RecordingErrorListener errorListener = new RecordingErrorListener(); 7430 RecordingErrorListener errorListener = new RecordingErrorListener();
7191 List<CompilationUnitElement> parts = libraryElement.parts; 7431 List<CompilationUnitElement> parts = libraryElement.parts;
7192 int partCount = parts.length; 7432 int partCount = parts.length;
7193 List<CompilationUnit> compilationUnits = new List<CompilationUnit>(partCount + 1); 7433 List<CompilationUnit> compilationUnits = new List<CompilationUnit>(partCount + 1);
7194 Map<Source, TimestampedData<CompilationUnit>> timestampMap = new Map<Source, TimestampedData<CompilationUnit>>(); 7434 Map<Source, TimestampedData<CompilationUnit>> timestampMap = new Map<Source, TimestampedData<CompilationUnit>>();
7435 //
7436 // Get all of the (fully resolved) compilation units that will be analyzed.
7437 //
7195 Source unitSource = libraryElement.definingCompilationUnit.source; 7438 Source unitSource = libraryElement.definingCompilationUnit.source;
7196 TimestampedData<CompilationUnit> resolvedUnit = getCompilationUnit(unitSourc e); 7439 TimestampedData<CompilationUnit> resolvedUnit = getCompilationUnit(unitSourc e);
7197 timestampMap[unitSource] = resolvedUnit; 7440 timestampMap[unitSource] = resolvedUnit;
7198 CompilationUnit unit = resolvedUnit.data; 7441 CompilationUnit unit = resolvedUnit.data;
7199 if (unit == null) { 7442 if (unit == null) {
7200 throw new AnalysisException.con1("Internal error: GenerateDartHintsTask fa iled to access resolved compilation unit for ${unitSource.fullName}"); 7443 throw new AnalysisException.con1("Internal error: GenerateDartHintsTask fa iled to access resolved compilation unit for ${unitSource.fullName}");
7201 } 7444 }
7202 compilationUnits[0] = unit; 7445 compilationUnits[0] = unit;
7203 for (int i = 0; i < partCount; i++) { 7446 for (int i = 0; i < partCount; i++) {
7204 unitSource = parts[i].source; 7447 unitSource = parts[i].source;
7205 resolvedUnit = getCompilationUnit(unitSource); 7448 resolvedUnit = getCompilationUnit(unitSource);
7206 timestampMap[unitSource] = resolvedUnit; 7449 timestampMap[unitSource] = resolvedUnit;
7207 unit = resolvedUnit.data; 7450 unit = resolvedUnit.data;
7208 if (unit == null) { 7451 if (unit == null) {
7209 throw new AnalysisException.con1("Internal error: GenerateDartHintsTask failed to access resolved compilation unit for ${unitSource.fullName}"); 7452 throw new AnalysisException.con1("Internal error: GenerateDartHintsTask failed to access resolved compilation unit for ${unitSource.fullName}");
7210 } 7453 }
7211 compilationUnits[i + 1] = unit; 7454 compilationUnits[i + 1] = unit;
7212 } 7455 }
7456 //
7457 // Analyze all of the units.
7458 //
7213 HintGenerator hintGenerator = new HintGenerator(compilationUnits, context, e rrorListener); 7459 HintGenerator hintGenerator = new HintGenerator(compilationUnits, context, e rrorListener);
7214 hintGenerator.generateForLibrary(); 7460 hintGenerator.generateForLibrary();
7461 //
7462 // Store the results.
7463 //
7215 _hintMap = new Map<Source, TimestampedData<List<AnalysisError>>>(); 7464 _hintMap = new Map<Source, TimestampedData<List<AnalysisError>>>();
7216 for (MapEntry<Source, TimestampedData<CompilationUnit>> entry in getMapEntry Set(timestampMap)) { 7465 for (MapEntry<Source, TimestampedData<CompilationUnit>> entry in getMapEntry Set(timestampMap)) {
7217 Source source = entry.getKey(); 7466 Source source = entry.getKey();
7218 TimestampedData<CompilationUnit> unitData = entry.getValue(); 7467 TimestampedData<CompilationUnit> unitData = entry.getValue();
7219 List<AnalysisError> errors = errorListener.getErrors2(source); 7468 List<AnalysisError> errors = errorListener.getErrors2(source);
7220 _hintMap[source] = new TimestampedData<List<AnalysisError>>(unitData.modif icationTime, errors); 7469 _hintMap[source] = new TimestampedData<List<AnalysisError>>(unitData.modif icationTime, errors);
7221 } 7470 }
7222 } 7471 }
7223 7472
7224 /** 7473 /**
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
7270 * @return the source 7519 * @return the source
7271 */ 7520 */
7272 Source get source => cache != null ? cache.source : null; 7521 Source get source => cache != null ? cache.source : null;
7273 7522
7274 String get taskDescription => "incremental analysis ${(cache != null ? cache.s ource : "null")}"; 7523 String get taskDescription => "incremental analysis ${(cache != null ? cache.s ource : "null")}";
7275 7524
7276 void internalPerform() { 7525 void internalPerform() {
7277 if (cache == null) { 7526 if (cache == null) {
7278 return; 7527 return;
7279 } 7528 }
7529 // Only handle small changes
7280 if (cache.oldLength > 0 || cache.newLength > 30) { 7530 if (cache.oldLength > 0 || cache.newLength > 30) {
7281 return; 7531 return;
7282 } 7532 }
7533 // Produce an updated token stream
7283 CharacterReader reader = new CharSequenceReader(new CharSequence(cache.newCo ntents)); 7534 CharacterReader reader = new CharSequenceReader(new CharSequence(cache.newCo ntents));
7284 BooleanErrorListener errorListener = new BooleanErrorListener(); 7535 BooleanErrorListener errorListener = new BooleanErrorListener();
7285 IncrementalScanner scanner = new IncrementalScanner(cache.source, reader, er rorListener); 7536 IncrementalScanner scanner = new IncrementalScanner(cache.source, reader, er rorListener);
7286 scanner.rescan(cache.resolvedUnit.beginToken, cache.offset, cache.oldLength, cache.newLength); 7537 scanner.rescan(cache.resolvedUnit.beginToken, cache.offset, cache.oldLength, cache.newLength);
7287 if (errorListener.errorReported) { 7538 if (errorListener.errorReported) {
7288 return; 7539 return;
7289 } 7540 }
7541 // Produce an updated AST
7290 IncrementalParser parser = new IncrementalParser(cache.source, scanner.token Map, AnalysisErrorListener.NULL_LISTENER); 7542 IncrementalParser parser = new IncrementalParser(cache.source, scanner.token Map, AnalysisErrorListener.NULL_LISTENER);
7291 _updatedUnit = parser.reparse(cache.resolvedUnit, scanner.leftToken, scanner .rightToken, cache.offset, cache.offset + cache.oldLength); 7543 _updatedUnit = parser.reparse(cache.resolvedUnit, scanner.leftToken, scanner .rightToken, cache.offset, cache.offset + cache.oldLength);
7544 // Update the resolution
7292 TypeProvider typeProvider = this.typeProvider; 7545 TypeProvider typeProvider = this.typeProvider;
7293 if (_updatedUnit != null && typeProvider != null) { 7546 if (_updatedUnit != null && typeProvider != null) {
7294 CompilationUnitElement element = _updatedUnit.element; 7547 CompilationUnitElement element = _updatedUnit.element;
7295 if (element != null) { 7548 if (element != null) {
7296 LibraryElement library = element.library; 7549 LibraryElement library = element.library;
7297 if (library != null) { 7550 if (library != null) {
7298 IncrementalResolver resolver = new IncrementalResolver(library, cache. source, typeProvider, errorListener); 7551 IncrementalResolver resolver = new IncrementalResolver(library, cache. source, typeProvider, errorListener);
7299 resolver.resolve(parser.updatedNode); 7552 resolver.resolve(parser.updatedNode);
7300 } 7553 }
7301 } 7554 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
7455 String get taskDescription { 7708 String get taskDescription {
7456 if (source == null) { 7709 if (source == null) {
7457 return "parse as dart null source"; 7710 return "parse as dart null source";
7458 } 7711 }
7459 return "parse as dart ${source.fullName}"; 7712 return "parse as dart ${source.fullName}";
7460 } 7713 }
7461 7714
7462 void internalPerform() { 7715 void internalPerform() {
7463 RecordingErrorListener errorListener = new RecordingErrorListener(); 7716 RecordingErrorListener errorListener = new RecordingErrorListener();
7464 List<Token> token = [null]; 7717 List<Token> token = [null];
7718 //
7719 // Scan the contents of the file.
7720 //
7465 Source_ContentReceiver receiver = new Source_ContentReceiver_ParseDartTask_i nternalPerform(this, errorListener, token); 7721 Source_ContentReceiver receiver = new Source_ContentReceiver_ParseDartTask_i nternalPerform(this, errorListener, token);
7466 try { 7722 try {
7467 source.getContents(receiver); 7723 source.getContents(receiver);
7468 } on JavaException catch (exception) { 7724 } on JavaException catch (exception) {
7469 _modificationTime = source.modificationStamp; 7725 _modificationTime = source.modificationStamp;
7470 throw new AnalysisException.con3(exception); 7726 throw new AnalysisException.con3(exception);
7471 } 7727 }
7472 if (token[0] == null) { 7728 if (token[0] == null) {
7473 throw new AnalysisException.con1("Could not get contents for '${source.ful lName}'"); 7729 throw new AnalysisException.con1("Could not get contents for '${source.ful lName}'");
7474 } 7730 }
7731 //
7732 // Then parse the token stream.
7733 //
7475 TimeCounter_TimeCounterHandle timeCounterParse = PerformanceStatistics.parse .start(); 7734 TimeCounter_TimeCounterHandle timeCounterParse = PerformanceStatistics.parse .start();
7476 try { 7735 try {
7477 Parser parser = new Parser(source, errorListener); 7736 Parser parser = new Parser(source, errorListener);
7478 parser.parseFunctionBodies = context.analysisOptions.analyzeFunctionBodies ; 7737 parser.parseFunctionBodies = context.analysisOptions.analyzeFunctionBodies ;
7479 _unit = parser.parseCompilationUnit(token[0]); 7738 _unit = parser.parseCompilationUnit(token[0]);
7480 _errors = errorListener.getErrors2(source); 7739 _errors = errorListener.getErrors2(source);
7481 for (Directive directive in _unit.directives) { 7740 for (Directive directive in _unit.directives) {
7482 if (directive is ExportDirective) { 7741 if (directive is ExportDirective) {
7483 Source exportSource = resolveSource(source, directive); 7742 Source exportSource = resolveSource(source, directive);
7484 if (exportSource != null) { 7743 if (exportSource != null) {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
7868 } 8127 }
7869 8128
7870 void internalPerform() { 8129 void internalPerform() {
7871 TypeProvider typeProvider = (_libraryElement.context as InternalAnalysisCont ext).typeProvider; 8130 TypeProvider typeProvider = (_libraryElement.context as InternalAnalysisCont ext).typeProvider;
7872 ResolvableCompilationUnit resolvableUnit = context.computeResolvableCompilat ionUnit(source); 8131 ResolvableCompilationUnit resolvableUnit = context.computeResolvableCompilat ionUnit(source);
7873 _modificationTime = resolvableUnit.modificationTime; 8132 _modificationTime = resolvableUnit.modificationTime;
7874 CompilationUnit unit = resolvableUnit.compilationUnit; 8133 CompilationUnit unit = resolvableUnit.compilationUnit;
7875 if (unit == null) { 8134 if (unit == null) {
7876 throw new AnalysisException.con1("Internal error: computeResolvableCompila tionUnit returned a value without a parsed Dart unit"); 8135 throw new AnalysisException.con1("Internal error: computeResolvableCompila tionUnit returned a value without a parsed Dart unit");
7877 } 8136 }
8137 //
8138 // Resolve names in declarations.
8139 //
7878 new DeclarationResolver().resolve(unit, find(_libraryElement, source)); 8140 new DeclarationResolver().resolve(unit, find(_libraryElement, source));
8141 //
8142 // Resolve the type names.
8143 //
7879 RecordingErrorListener errorListener = new RecordingErrorListener(); 8144 RecordingErrorListener errorListener = new RecordingErrorListener();
7880 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(_libr aryElement, source, typeProvider, errorListener); 8145 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(_libr aryElement, source, typeProvider, errorListener);
7881 unit.accept(typeResolverVisitor); 8146 unit.accept(typeResolverVisitor);
8147 //
8148 // Resolve the rest of the structure
8149 //
7882 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt); 8150 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt);
7883 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(_libraryElement, source, typeProvider, inheritanceManager, errorListener); 8151 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(_libraryElement, source, typeProvider, inheritanceManager, errorListener);
7884 unit.accept(resolverVisitor); 8152 unit.accept(resolverVisitor);
8153 // TODO (jwren) Move this logic/ loop into the ResolverVisitor and then make the reportError protected again.
7885 for (ProxyConditionalAnalysisError conditionalCode in resolverVisitor.proxyC onditionalAnalysisErrors) { 8154 for (ProxyConditionalAnalysisError conditionalCode in resolverVisitor.proxyC onditionalAnalysisErrors) {
7886 if (conditionalCode.shouldIncludeErrorCode()) { 8155 if (conditionalCode.shouldIncludeErrorCode()) {
7887 resolverVisitor.reportError(conditionalCode.analysisError); 8156 resolverVisitor.reportError(conditionalCode.analysisError);
7888 } 8157 }
7889 } 8158 }
8159 //
8160 // Perform additional error checking.
8161 //
7890 TimeCounter_TimeCounterHandle counterHandleErrors = PerformanceStatistics.er rors.start(); 8162 TimeCounter_TimeCounterHandle counterHandleErrors = PerformanceStatistics.er rors.start();
7891 try { 8163 try {
7892 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 8164 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
7893 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEle ment, typeProvider, inheritanceManager); 8165 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEle ment, typeProvider, inheritanceManager);
7894 unit.accept(errorVerifier); 8166 unit.accept(errorVerifier);
7895 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty peProvider); 8167 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty peProvider);
7896 unit.accept(constantVerifier); 8168 unit.accept(constantVerifier);
7897 } finally { 8169 } finally {
7898 counterHandleErrors.stop(); 8170 counterHandleErrors.stop();
7899 } 8171 }
8172 //
8173 // Capture the results.
8174 //
7900 _resolvedUnit = unit; 8175 _resolvedUnit = unit;
7901 } 8176 }
7902 8177
7903 /** 8178 /**
7904 * Search the compilation units that are part of the given library and return the element 8179 * Search the compilation units that are part of the given library and return the element
7905 * representing the compilation unit with the given source. Return `null` if t here is no 8180 * representing the compilation unit with the given source. Return `null` if t here is no
7906 * such compilation unit. 8181 * such compilation unit.
7907 * 8182 *
7908 * @param libraryElement the element representing the library being searched t hrough 8183 * @param libraryElement the element representing the library being searched t hrough
7909 * @param unitSource the source for the compilation unit whose element is to b e returned 8184 * @param unitSource the source for the compilation unit whose element is to b e returned
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
7988 return "resolve as html ${source.fullName}"; 8263 return "resolve as html ${source.fullName}";
7989 } 8264 }
7990 8265
7991 void internalPerform() { 8266 void internalPerform() {
7992 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(so urce); 8267 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(so urce);
7993 HtmlUnit unit = resolvableHtmlUnit.compilationUnit; 8268 HtmlUnit unit = resolvableHtmlUnit.compilationUnit;
7994 if (unit == null) { 8269 if (unit == null) {
7995 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit"); 8270 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit");
7996 } 8271 }
7997 _modificationTime = resolvableHtmlUnit.modificationTime; 8272 _modificationTime = resolvableHtmlUnit.modificationTime;
8273 // build standard HTML element
7998 HtmlUnitBuilder builder = new HtmlUnitBuilder(context); 8274 HtmlUnitBuilder builder = new HtmlUnitBuilder(context);
7999 _element = builder.buildHtmlElement2(source, _modificationTime, unit); 8275 _element = builder.buildHtmlElement2(source, _modificationTime, unit);
8276 // resolve toolkit-specific features
8000 LineInfo lineInfo = context.getLineInfo(source); 8277 LineInfo lineInfo = context.getLineInfo(source);
8001 // new AngularHtmlUnitResolver(context, builder.errorListener, source, lineIn fo).resolve(unit); 8278 // new AngularHtmlUnitResolver(context, builder.errorListener, source, lineIn fo).resolve(unit);
8279 // record all resolution errors
8002 _resolutionErrors = builder.errorListener.getErrors2(source); 8280 _resolutionErrors = builder.errorListener.getErrors2(source);
8281 // remember resolved unit
8003 _resolvedUnit = unit; 8282 _resolvedUnit = unit;
8004 } 8283 }
8005 } 8284 }
8006 8285
8007 /** 8286 /**
8008 * The interface `Logger` defines the behavior of objects that can be used to re ceive 8287 * The interface `Logger` defines the behavior of objects that can be used to re ceive
8009 * information about errors within the analysis engine. Implementations usually write this 8288 * information about errors within the analysis engine. Implementations usually write this
8010 * information to a file, but can also record the information for later use (suc h as during testing) 8289 * information to a file, but can also record the information for later use (suc h as during testing)
8011 * or even ignore the information. 8290 * or even ignore the information.
8012 * 8291 *
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
8066 8345
8067 void logError3(Exception exception) { 8346 void logError3(Exception exception) {
8068 } 8347 }
8069 8348
8070 void logInformation(String message) { 8349 void logInformation(String message) {
8071 } 8350 }
8072 8351
8073 void logInformation2(String message, Exception exception) { 8352 void logInformation2(String message, Exception exception) {
8074 } 8353 }
8075 } 8354 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698