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

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

Issue 909493004: Stop re-analyzing everything when adding a file (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « no previous file | no next file » | 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 "dart:math" as math; 10 import "dart:math" as math;
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 // First, compute the list of sources that have been removed. 1530 // First, compute the list of sources that have been removed.
1531 // 1531 //
1532 List<Source> removedSources = 1532 List<Source> removedSources =
1533 new List<Source>.from(changeSet.removedSources); 1533 new List<Source>.from(changeSet.removedSources);
1534 for (SourceContainer container in changeSet.removedContainers) { 1534 for (SourceContainer container in changeSet.removedContainers) {
1535 _addSourcesInContainer(removedSources, container); 1535 _addSourcesInContainer(removedSources, container);
1536 } 1536 }
1537 // 1537 //
1538 // Then determine which cached results are no longer valid. 1538 // Then determine which cached results are no longer valid.
1539 // 1539 //
1540 bool addedDartSource = false;
1541 for (Source source in changeSet.addedSources) { 1540 for (Source source in changeSet.addedSources) {
1542 if (_sourceAvailable(source)) { 1541 _sourceAvailable(source);
1543 addedDartSource = true;
1544 }
1545 } 1542 }
1546 for (Source source in changeSet.changedSources) { 1543 for (Source source in changeSet.changedSources) {
1547 if (_contentCache.getContents(source) != null) { 1544 if (_contentCache.getContents(source) != null) {
1548 // This source is overridden in the content cache, so the change will 1545 // This source is overridden in the content cache, so the change will
1549 // have no effect. Just ignore it to avoid wasting time doing 1546 // have no effect. Just ignore it to avoid wasting time doing
1550 // re-analysis. 1547 // re-analysis.
1551 continue; 1548 continue;
1552 } 1549 }
1553 _sourceChanged(source); 1550 _sourceChanged(source);
1554 } 1551 }
1555 changeSet.changedContents.forEach((Source key, String value) { 1552 changeSet.changedContents.forEach((Source key, String value) {
1556 _contentsChanged(key, value, false); 1553 _contentsChanged(key, value, false);
1557 }); 1554 });
1558 changeSet.changedRanges.forEach( 1555 changeSet.changedRanges.forEach(
1559 (Source source, ChangeSet_ContentChange change) { 1556 (Source source, ChangeSet_ContentChange change) {
1560 _contentRangeChanged( 1557 _contentRangeChanged(
1561 source, 1558 source,
1562 change.contents, 1559 change.contents,
1563 change.offset, 1560 change.offset,
1564 change.oldLength, 1561 change.oldLength,
1565 change.newLength); 1562 change.newLength);
1566 }); 1563 });
1567 for (Source source in changeSet.deletedSources) { 1564 for (Source source in changeSet.deletedSources) {
1568 _sourceDeleted(source); 1565 _sourceDeleted(source);
1569 } 1566 }
1570 for (Source source in removedSources) { 1567 for (Source source in removedSources) {
1571 _sourceRemoved(source); 1568 _sourceRemoved(source);
1572 } 1569 }
1573 if (addedDartSource) {
1574 // TODO(brianwilkerson) This is hugely inefficient, but we need to
1575 // re-analyze any libraries that might have been referencing the
1576 // not-yet-existing source that was just added. Longer term we need to
1577 // keep track of which libraries are referencing non-existing sources and
1578 // only re-analyze those libraries.
1579 // logInformation("Added Dart sources, invalidating all resolution informat ion");
1580 List<Source> sourcesToInvalidate = new List<Source>();
1581 MapIterator<Source, SourceEntry> iterator = _cache.iterator();
1582 while (iterator.moveNext()) {
1583 Source source = iterator.key;
1584 SourceEntry sourceEntry = iterator.value;
1585 if (!source.isInSystemLibrary &&
1586 (sourceEntry is DartEntry || sourceEntry is HtmlEntry)) {
1587 sourcesToInvalidate.add(source);
1588 }
1589 }
1590 int count = sourcesToInvalidate.length;
1591 for (int i = 0; i < count; i++) {
1592 Source source = sourcesToInvalidate[i];
1593 SourceEntry entry = _getReadableSourceEntry(source);
1594 if (entry is DartEntry) {
1595 entry.invalidateParseInformation();
1596 _workManager.add(source, _computePriority(entry));
1597 } else if (entry is HtmlEntry) {
1598 entry.invalidateParseInformation();
1599 _workManager.add(source, SourcePriority.HTML);
1600 }
1601 }
1602 }
1603 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet)); 1570 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet));
1604 } 1571 }
1605 1572
1606 @override 1573 @override
1607 String computeDocumentationComment(Element element) { 1574 String computeDocumentationComment(Element element) {
1608 if (element == null) { 1575 if (element == null) {
1609 return null; 1576 return null;
1610 } 1577 }
1611 Source source = element.source; 1578 Source source = element.source;
1612 if (source == null) { 1579 if (source == null) {
(...skipping 2821 matching lines...) Expand 10 before | Expand all | Expand 10 after
4434 */ 4401 */
4435 void _notifyErrors(Source source, List<AnalysisError> errors, 4402 void _notifyErrors(Source source, List<AnalysisError> errors,
4436 LineInfo lineInfo) { 4403 LineInfo lineInfo) {
4437 int count = _listeners.length; 4404 int count = _listeners.length;
4438 for (int i = 0; i < count; i++) { 4405 for (int i = 0; i < count; i++) {
4439 _listeners[i].computedErrors(this, source, errors, lineInfo); 4406 _listeners[i].computedErrors(this, source, errors, lineInfo);
4440 } 4407 }
4441 } 4408 }
4442 4409
4443 /** 4410 /**
4444 * Record the results produced by performing a [task] and return the cache 4411 * Given that the given [source] (with the corresponding [sourceEntry]) has
4445 * entry associated with the results. 4412 * been invalidated, invalidate all of the libraries that depend on it.
4446 */ 4413 */
4447 DartEntry _recordBuildUnitElementTask(BuildUnitElementTask task) { 4414 void _propagateInvalidation(Source source, SourceEntry sourceEntry) {
4448 Source source = task.source; 4415 if (sourceEntry is HtmlEntry) {
4449 Source library = task.library; 4416 HtmlEntry htmlEntry = sourceEntry;
4450 DartEntry dartEntry = _cache.get(source); 4417 htmlEntry.modificationTime = getModificationStamp(source);
4451 CaughtException thrownException = task.exception; 4418 htmlEntry.invalidateAllInformation();
4452 if (thrownException != null) { 4419 _cache.removedAst(source);
4453 dartEntry.recordBuildElementErrorInLibrary(library, thrownException); 4420 _workManager.add(source, SourcePriority.HTML);
4454 throw new AnalysisException('<rethrow>', thrownException); 4421 } else if (sourceEntry is DartEntry) {
4422 List<Source> containingLibraries = getLibrariesContaining(source);
4423 List<Source> dependentLibraries = getLibrariesDependingOn(source);
4424 HashSet<Source> librariesToInvalidate = new HashSet<Source>();
4425 for (Source containingLibrary in containingLibraries) {
4426 _computeAllLibrariesDependingOn(
4427 containingLibrary,
4428 librariesToInvalidate);
4429 }
4430 for (Source dependentLibrary in dependentLibraries) {
4431 _computeAllLibrariesDependingOn(
4432 dependentLibrary,
4433 librariesToInvalidate);
4434 }
4435 for (Source library in librariesToInvalidate) {
4436 _invalidateLibraryResolution(library);
4437 }
4438 DartEntry dartEntry = _cache.get(source);
4439 _removeFromParts(source, dartEntry);
4440 dartEntry.modificationTime = getModificationStamp(source);
4441 dartEntry.invalidateAllInformation();
4442 _cache.removedAst(source);
4443 _workManager.add(source, SourcePriority.UNKNOWN);
4455 } 4444 }
4456 dartEntry.setValueInLibrary(DartEntry.BUILT_UNIT, library, task.unit); 4445 // reset unit in the notification, it is out of date now
4457 dartEntry.setValueInLibrary( 4446 ChangeNoticeImpl notice = _pendingNotices[source];
4458 DartEntry.BUILT_ELEMENT, 4447 if (notice != null) {
4459 library, 4448 notice.resolvedDartUnit = null;
4460 task.unitElement); 4449 notice.resolvedHtmlUnit = null;
4461 ChangeNoticeImpl notice = _getNotice(source); 4450 }
4462 LineInfo lineInfo = dartEntry.getValue(SourceEntry.LINE_INFO);
4463 notice.setErrors(dartEntry.allErrors, lineInfo);
4464 return dartEntry;
4465 } 4451 }
4466 4452
4467 // /** 4453 // /**
4468 // * Notify all of the analysis listeners that the given source is no longer i ncluded in the set of 4454 // * Notify all of the analysis listeners that the given source is no longer i ncluded in the set of
4469 // * sources that are being analyzed. 4455 // * sources that are being analyzed.
4470 // * 4456 // *
4471 // * @param source the source that is no longer being analyzed 4457 // * @param source the source that is no longer being analyzed
4472 // */ 4458 // */
4473 // void _notifyExcludedSource(Source source) { 4459 // void _notifyExcludedSource(Source source) {
4474 // int count = _listeners.length; 4460 // int count = _listeners.length;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4536 // * @param unit the result of resolving the source 4522 // * @param unit the result of resolving the source
4537 // */ 4523 // */
4538 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) { 4524 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) {
4539 // int count = _listeners.length; 4525 // int count = _listeners.length;
4540 // for (int i = 0; i < count; i++) { 4526 // for (int i = 0; i < count; i++) {
4541 // _listeners[i].resolvedHtml(this, source, unit); 4527 // _listeners[i].resolvedHtml(this, source, unit);
4542 // } 4528 // }
4543 // } 4529 // }
4544 4530
4545 /** 4531 /**
4532 * Record the results produced by performing a [task] and return the cache
4533 * entry associated with the results.
4534 */
4535 DartEntry _recordBuildUnitElementTask(BuildUnitElementTask task) {
4536 Source source = task.source;
4537 Source library = task.library;
4538 DartEntry dartEntry = _cache.get(source);
4539 CaughtException thrownException = task.exception;
4540 if (thrownException != null) {
4541 dartEntry.recordBuildElementErrorInLibrary(library, thrownException);
4542 throw new AnalysisException('<rethrow>', thrownException);
4543 }
4544 dartEntry.setValueInLibrary(DartEntry.BUILT_UNIT, library, task.unit);
4545 dartEntry.setValueInLibrary(
4546 DartEntry.BUILT_ELEMENT,
4547 library,
4548 task.unitElement);
4549 ChangeNoticeImpl notice = _getNotice(source);
4550 LineInfo lineInfo = dartEntry.getValue(SourceEntry.LINE_INFO);
4551 notice.setErrors(dartEntry.allErrors, lineInfo);
4552 return dartEntry;
4553 }
4554
4555 /**
4546 * Given a cache entry and a library element, record the library element and o ther information 4556 * Given a cache entry and a library element, record the library element and o ther information
4547 * gleaned from the element in the cache entry. 4557 * gleaned from the element in the cache entry.
4548 * 4558 *
4549 * @param dartCopy the cache entry in which data is to be recorded 4559 * @param dartCopy the cache entry in which data is to be recorded
4550 * @param library the library element used to record information 4560 * @param library the library element used to record information
4551 * @param librarySource the source for the library used to record information 4561 * @param librarySource the source for the library used to record information
4552 * @param htmlSource the source for the HTML library 4562 * @param htmlSource the source for the HTML library
4553 */ 4563 */
4554 void _recordElementData(DartEntry dartEntry, LibraryElement library, 4564 void _recordElementData(DartEntry dartEntry, LibraryElement library,
4555 Source librarySource, Source htmlSource) { 4565 Source librarySource, Source htmlSource) {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
4941 if (_priorityOrder[i] != source) { 4951 if (_priorityOrder[i] != source) {
4942 newOrder.add(_priorityOrder[i]); 4952 newOrder.add(_priorityOrder[i]);
4943 } 4953 }
4944 } 4954 }
4945 if (newOrder.length < count) { 4955 if (newOrder.length < count) {
4946 analysisPriorityOrder = newOrder; 4956 analysisPriorityOrder = newOrder;
4947 } 4957 }
4948 } 4958 }
4949 4959
4950 /** 4960 /**
4951 * Create an entry for the newly added source. Return `true` if the new source is a Dart 4961 * Create an entry for the newly added source. Return `true` if the new source is a Dart
scheglov 2015/02/12 16:54:50 Update the comment, remove the @return line.
Brian Wilkerson 2015/02/12 19:03:37 Done
4952 * file. 4962 * file.
4953 * 4963 *
4954 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4964 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4955 * 4965 *
4956 * @param source the source that has been added 4966 * @param source the source that has been added
4957 * @return `true` if the new source is a Dart file 4967 * @return `true` if the new source is a Dart file
4958 */ 4968 */
4959 bool _sourceAvailable(Source source) { 4969 void _sourceAvailable(Source source) {
4960 SourceEntry sourceEntry = _cache.get(source); 4970 SourceEntry sourceEntry = _cache.get(source);
4961 if (sourceEntry == null) { 4971 if (sourceEntry == null) {
4962 sourceEntry = _createSourceEntry(source, true); 4972 sourceEntry = _createSourceEntry(source, true);
4963 } else { 4973 } else {
4964 _sourceChanged(source); 4974 _propagateInvalidation(source, sourceEntry);
4965 sourceEntry = _cache.get(source); 4975 sourceEntry = _cache.get(source);
4966 } 4976 }
4967 if (sourceEntry is HtmlEntry) { 4977 if (sourceEntry is HtmlEntry) {
4968 _workManager.add(source, SourcePriority.HTML); 4978 _workManager.add(source, SourcePriority.HTML);
4969 } else if (sourceEntry is DartEntry) { 4979 } else if (sourceEntry is DartEntry) {
4970 _workManager.add(source, _computePriority(sourceEntry as DartEntry)); 4980 _workManager.add(source, _computePriority(sourceEntry as DartEntry));
4971 } 4981 }
4972 return sourceEntry is DartEntry;
4973 } 4982 }
4974 4983
4975 /** 4984 /**
4976 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4985 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4977 * 4986 *
4978 * @param source the source that has been changed 4987 * @param source the source that has been changed
4979 */ 4988 */
4980 void _sourceChanged(Source source) { 4989 void _sourceChanged(Source source) {
4981 SourceEntry sourceEntry = _cache.get(source); 4990 SourceEntry sourceEntry = _cache.get(source);
4982 if (sourceEntry == null || 4991 if (sourceEntry == null ||
4983 sourceEntry.modificationTime == getModificationStamp(source)) { 4992 sourceEntry.modificationTime == getModificationStamp(source)) {
4984 // Either we have removed this source, in which case we don't care that 4993 // Either we have removed this source, in which case we don't care that
4985 // it is changed, or we have already invalidated the cache and don't need 4994 // it is changed, or we have already invalidated the cache and don't need
4986 // to invalidate it again. 4995 // to invalidate it again.
4987 return; 4996 return;
4988 } 4997 }
4989 if (sourceEntry is HtmlEntry) { 4998 _propagateInvalidation(source, sourceEntry);
4990 HtmlEntry htmlEntry = sourceEntry;
4991 htmlEntry.modificationTime = getModificationStamp(source);
4992 htmlEntry.invalidateAllInformation();
4993 _cache.removedAst(source);
4994 _workManager.add(source, SourcePriority.HTML);
4995 } else if (sourceEntry is DartEntry) {
4996 List<Source> containingLibraries = getLibrariesContaining(source);
4997 HashSet<Source> librariesToInvalidate = new HashSet<Source>();
4998 for (Source containingLibrary in containingLibraries) {
4999 _computeAllLibrariesDependingOn(
5000 containingLibrary,
5001 librariesToInvalidate);
5002 }
5003 for (Source library in librariesToInvalidate) {
5004 _invalidateLibraryResolution(library);
5005 }
5006 DartEntry dartEntry = _cache.get(source);
5007 _removeFromParts(source, dartEntry);
5008 dartEntry.modificationTime = getModificationStamp(source);
5009 dartEntry.invalidateAllInformation();
5010 _cache.removedAst(source);
5011 _workManager.add(source, SourcePriority.UNKNOWN);
5012 }
5013 // reset unit in the notification, it is out of date now
5014 ChangeNoticeImpl notice = _pendingNotices[source];
5015 if (notice != null) {
5016 notice.resolvedDartUnit = null;
5017 notice.resolvedHtmlUnit = null;
5018 }
5019 } 4999 }
5020 5000
5021 /** 5001 /**
5022 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 5002 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
5023 * 5003 *
5024 * @param source the source that has been deleted 5004 * @param source the source that has been deleted
5025 */ 5005 */
5026 void _sourceDeleted(Source source) { 5006 void _sourceDeleted(Source source) {
5027 SourceEntry sourceEntry = _cache.get(source); 5007 SourceEntry sourceEntry = _cache.get(source);
5028 if (sourceEntry is HtmlEntry) { 5008 if (sourceEntry is HtmlEntry) {
(...skipping 6808 matching lines...) Expand 10 before | Expand all | Expand 10 after
11837 throw new ArgumentError("Invalid descriptor: $descriptor"); 11817 throw new ArgumentError("Invalid descriptor: $descriptor");
11838 } 11818 }
11839 _validateStateChange(descriptor, CacheState.VALID); 11819 _validateStateChange(descriptor, CacheState.VALID);
11840 CachedResult result = 11820 CachedResult result =
11841 resultMap.putIfAbsent(descriptor, () => new CachedResult(descriptor)); 11821 resultMap.putIfAbsent(descriptor, () => new CachedResult(descriptor));
11842 countTransition(descriptor, result); 11822 countTransition(descriptor, result);
11843 result.state = CacheState.VALID; 11823 result.state = CacheState.VALID;
11844 result.value = value == null ? descriptor.defaultValue : value; 11824 result.value = value == null ? descriptor.defaultValue : value;
11845 } 11825 }
11846 11826
11847 /**
11848 * Increment the count of the number of times that data represented by the
11849 * given [descriptor] was transitioned from the current state (as found in the
11850 * given [result] to a valid state.
11851 */
11852 static void countTransition(DataDescriptor descriptor, CachedResult result) {
11853 Map<CacheState, int> countMap =
11854 transitionMap.putIfAbsent(descriptor, () => new HashMap<CacheState, int> ());
11855 int count = countMap[result.state];
11856 countMap[result.state] = count == null ? 1 : count + 1;
11857 }
11858
11859 @override 11827 @override
11860 String toString() { 11828 String toString() {
11861 StringBuffer buffer = new StringBuffer(); 11829 StringBuffer buffer = new StringBuffer();
11862 _writeOn(buffer); 11830 _writeOn(buffer);
11863 return buffer.toString(); 11831 return buffer.toString();
11864 } 11832 }
11865 11833
11866 /** 11834 /**
11867 * Flush the value of the data described by the [descriptor]. 11835 * Flush the value of the data described by the [descriptor].
11868 */ 11836 */
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
11999 * the given [buffer]. 11967 * the given [buffer].
12000 */ 11968 */
12001 void _writeStateOn(StringBuffer buffer, String label, 11969 void _writeStateOn(StringBuffer buffer, String label,
12002 DataDescriptor descriptor) { 11970 DataDescriptor descriptor) {
12003 CachedResult result = resultMap[descriptor]; 11971 CachedResult result = resultMap[descriptor];
12004 buffer.write("; "); 11972 buffer.write("; ");
12005 buffer.write(label); 11973 buffer.write(label);
12006 buffer.write(" = "); 11974 buffer.write(" = ");
12007 buffer.write(result == null ? CacheState.INVALID : result.state); 11975 buffer.write(result == null ? CacheState.INVALID : result.state);
12008 } 11976 }
11977
11978 /**
11979 * Increment the count of the number of times that data represented by the
11980 * given [descriptor] was transitioned from the current state (as found in the
11981 * given [result] to a valid state.
11982 */
11983 static void countTransition(DataDescriptor descriptor, CachedResult result) {
11984 Map<CacheState, int> countMap =
11985 transitionMap.putIfAbsent(descriptor, () => new HashMap<CacheState, int> ());
11986 int count = countMap[result.state];
11987 countMap[result.state] = count == null ? 1 : count + 1;
11988 }
12009 } 11989 }
12010 11990
12011 /** 11991 /**
12012 * The enumerated type `Priority` defines the priority levels used to return sou rces in an 11992 * The enumerated type `Priority` defines the priority levels used to return sou rces in an
12013 * optimal order. A smaller ordinal value equates to a higher priority. 11993 * optimal order. A smaller ordinal value equates to a higher priority.
12014 */ 11994 */
12015 class SourcePriority extends Enum<SourcePriority> { 11995 class SourcePriority extends Enum<SourcePriority> {
12016 /** 11996 /**
12017 * Used for a Dart source that is known to be a part contained in a library th at was recently 11997 * Used for a Dart source that is known to be a part contained in a library th at was recently
12018 * resolved. These parts are given a higher priority because there is a high p robability that 11998 * resolved. These parts are given a higher priority because there is a high p robability that
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
12435 if (element.id == _id) { 12415 if (element.id == _id) {
12436 result = element; 12416 result = element;
12437 throw new _ElementByIdFinderException(); 12417 throw new _ElementByIdFinderException();
12438 } 12418 }
12439 super.visitElement(element); 12419 super.visitElement(element);
12440 } 12420 }
12441 } 12421 }
12442 12422
12443 class _ElementByIdFinderException { 12423 class _ElementByIdFinderException {
12444 } 12424 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698