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

Side by Side Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1136673002: Progress toward new AnalysisContextImpl (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | pkg/analyzer/lib/src/generated/engine.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.src.context.context; 5 library analyzer.src.context.context;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/cancelable_future.dart'; 10 import 'package:analyzer/src/cancelable_future.dart';
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 @override 541 @override
542 List<Source> computeExportedLibraries(Source source) => 542 List<Source> computeExportedLibraries(Source source) =>
543 _computeResult(source, EXPORTED_LIBRARIES); 543 _computeResult(source, EXPORTED_LIBRARIES);
544 544
545 @override 545 @override
546 // TODO(brianwilkerson) Implement this. 546 // TODO(brianwilkerson) Implement this.
547 HtmlElement computeHtmlElement(Source source) => null; 547 HtmlElement computeHtmlElement(Source source) => null;
548 548
549 @override 549 @override
550 List<Source> computeImportedLibraries(Source source) => 550 List<Source> computeImportedLibraries(Source source) =>
551 _computeResult(source, IMPORTED_LIBRARIES); 551 _computeResult(source, EXPLICITLY_IMPORTED_LIBRARIES);
552 552
553 @override 553 @override
554 SourceKind computeKindOf(Source source) { 554 SourceKind computeKindOf(Source source) {
555 String name = source.shortName; 555 String name = source.shortName;
556 if (AnalysisEngine.isDartFileName(name)) { 556 if (AnalysisEngine.isDartFileName(name)) {
557 return _computeResult(source, SOURCE_KIND); 557 return _computeResult(source, SOURCE_KIND);
558 } else if (AnalysisEngine.isHtmlFileName(name)) { 558 } else if (AnalysisEngine.isHtmlFileName(name)) {
559 return SourceKind.HTML; 559 return SourceKind.HTML;
560 } 560 }
561 return SourceKind.UNKNOWN; 561 return SourceKind.UNKNOWN;
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 */ 1408 */
1409 cache.CacheEntry _createCacheEntry(Source source, bool explicitlyAdded) { 1409 cache.CacheEntry _createCacheEntry(Source source, bool explicitlyAdded) {
1410 cache.CacheEntry entry = new cache.CacheEntry(source); 1410 cache.CacheEntry entry = new cache.CacheEntry(source);
1411 entry.modificationTime = getModificationStamp(source); 1411 entry.modificationTime = getModificationStamp(source);
1412 entry.explicitlyAdded = explicitlyAdded; 1412 entry.explicitlyAdded = explicitlyAdded;
1413 _cache.put(entry); 1413 _cache.put(entry);
1414 return entry; 1414 return entry;
1415 } 1415 }
1416 1416
1417 /** 1417 /**
1418 * Return a list containing all of the cache entries for targets associated
1419 * with the given [source].
1420 */
1421 List<cache.CacheEntry> _entriesFor(Source source) {
1422 List<cache.CacheEntry> entries = <cache.CacheEntry>[];
1423 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator();
1424 while (iterator.moveNext()) {
1425 if (iterator.key.source == source) {
1426 entries.add(iterator.value);
1427 }
1428 }
1429 return entries;
1430 }
1431
1432 /**
1418 * Return a list containing all of the change notices that are waiting to be 1433 * Return a list containing all of the change notices that are waiting to be
1419 * returned. If there are no notices, then return either `null` or an empty 1434 * returned. If there are no notices, then return either `null` or an empty
1420 * list, depending on the value of [nullIfEmpty]. 1435 * list, depending on the value of [nullIfEmpty].
1421 */ 1436 */
1422 List<ChangeNotice> _getChangeNotices(bool nullIfEmpty) { 1437 List<ChangeNotice> _getChangeNotices(bool nullIfEmpty) {
1423 if (_pendingNotices.isEmpty) { 1438 if (_pendingNotices.isEmpty) {
1424 if (nullIfEmpty) { 1439 if (nullIfEmpty) {
1425 return null; 1440 return null;
1426 } 1441 }
1427 return ChangeNoticeImpl.EMPTY_LIST; 1442 return ChangeNoticeImpl.EMPTY_LIST;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 return; 1759 return;
1745 } 1760 }
1746 // Check whether the content of the source is the same as it was the last 1761 // Check whether the content of the source is the same as it was the last
1747 // time. 1762 // time.
1748 String sourceContent = entry.getValue(CONTENT); 1763 String sourceContent = entry.getValue(CONTENT);
1749 if (sourceContent != null) { 1764 if (sourceContent != null) {
1750 entry.setState(CONTENT, CacheState.FLUSHED); 1765 entry.setState(CONTENT, CacheState.FLUSHED);
1751 try { 1766 try {
1752 TimestampedData<String> fileContents = getContents(source); 1767 TimestampedData<String> fileContents = getContents(source);
1753 if (fileContents.data == sourceContent) { 1768 if (fileContents.data == sourceContent) {
1769 int time = fileContents.modificationTime;
1770 for (cache.CacheEntry entry in _entriesFor(source)) {
1771 entry.modificationTime = time;
1772 }
1754 return; 1773 return;
1755 } 1774 }
1756 } catch (e) {} 1775 } catch (e) {}
1757 } 1776 }
1758 // We need to invalidate the cache. 1777 // We need to invalidate the cache.
1759 // TODO(brianwilkerson) Implement this. 1778 // TODO(brianwilkerson) Implement this.
1760 // _propagateInvalidation(source, entry); 1779 // _propagateInvalidation(source, entry);
1761 } 1780 }
1762 1781
1763 /** 1782 /**
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 } 1897 }
1879 1898
1880 /** 1899 /**
1881 * Check the cache for any invalid entries (entries whose modification time 1900 * Check the cache for any invalid entries (entries whose modification time
1882 * does not match the modification time of the source associated with the 1901 * does not match the modification time of the source associated with the
1883 * entry). Invalid entries will be marked as invalid so that the source will 1902 * entry). Invalid entries will be marked as invalid so that the source will
1884 * be re-analyzed. Return `true` if at least one entry was invalid. 1903 * be re-analyzed. Return `true` if at least one entry was invalid.
1885 */ 1904 */
1886 bool _validateCacheConsistency() { 1905 bool _validateCacheConsistency() {
1887 int consistencyCheckStart = JavaSystem.nanoTime(); 1906 int consistencyCheckStart = JavaSystem.nanoTime();
1888 List<AnalysisTarget> changedTargets = new List<AnalysisTarget>(); 1907 HashSet<Source> changedSources = new HashSet<Source>();
1889 List<AnalysisTarget> missingTargets = new List<AnalysisTarget>(); 1908 HashSet<Source> missingSources = new HashSet<Source>();
1890 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator(); 1909 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator();
1891 while (iterator.moveNext()) { 1910 while (iterator.moveNext()) {
1892 AnalysisTarget target = iterator.key; 1911 Source source = iterator.key.source;
1893 cache.CacheEntry entry = iterator.value; 1912 if (source != null) {
1894 if (target is Source) { 1913 cache.CacheEntry entry = iterator.value;
1895 int sourceTime = getModificationStamp(target); 1914 int sourceTime = getModificationStamp(source);
1896 if (sourceTime != entry.modificationTime) { 1915 if (sourceTime != entry.modificationTime) {
1897 changedTargets.add(target); 1916 changedSources.add(source);
1898 } 1917 }
1899 } 1918 if (entry.exception != null) {
1900 if (entry.exception != null) { 1919 if (!exists(source)) {
1901 if (!exists(target)) { 1920 missingSources.add(source);
1902 missingTargets.add(target); 1921 }
1903 } 1922 }
1904 } 1923 }
1905 } 1924 }
1906 int count = changedTargets.length; 1925 for (Source source in changedSources) {
1907 for (int i = 0; i < count; i++) { 1926 _sourceChanged(source);
1908 _sourceChanged(changedTargets[i]);
1909 } 1927 }
1910 int removalCount = 0; 1928 int removalCount = 0;
1911 for (AnalysisTarget target in missingTargets) { 1929 for (Source source in missingSources) {
1912 if (target is Source && 1930 if (getLibrariesContaining(source).isEmpty &&
1913 getLibrariesContaining(target).isEmpty && 1931 getLibrariesDependingOn(source).isEmpty) {
1914 getLibrariesDependingOn(target).isEmpty) { 1932 _cache.remove(source);
1915 _cache.remove(target);
1916 removalCount++; 1933 removalCount++;
1917 } 1934 }
1918 } 1935 }
1919 int consistencyCheckEnd = JavaSystem.nanoTime(); 1936 int consistencyCheckEnd = JavaSystem.nanoTime();
1920 if (changedTargets.length > 0 || missingTargets.length > 0) { 1937 if (changedSources.length > 0 || missingSources.length > 0) {
1921 StringBuffer buffer = new StringBuffer(); 1938 StringBuffer buffer = new StringBuffer();
1922 buffer.write("Consistency check took "); 1939 buffer.write("Consistency check took ");
1923 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0); 1940 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
1924 buffer.writeln(" ms and found"); 1941 buffer.writeln(" ms and found");
1925 buffer.write(" "); 1942 buffer.write(" ");
1926 buffer.write(changedTargets.length); 1943 buffer.write(changedSources.length);
1927 buffer.writeln(" inconsistent entries"); 1944 buffer.writeln(" inconsistent entries");
1928 buffer.write(" "); 1945 buffer.write(" ");
1929 buffer.write(missingTargets.length); 1946 buffer.write(missingSources.length);
1930 buffer.write(" missing sources ("); 1947 buffer.write(" missing sources (");
1931 buffer.write(removalCount); 1948 buffer.write(removalCount);
1932 buffer.writeln(" removed"); 1949 buffer.writeln(" removed");
1933 for (Source source in missingTargets) { 1950 for (Source source in missingSources) {
1934 buffer.write(" "); 1951 buffer.write(" ");
1935 buffer.writeln(source.fullName); 1952 buffer.writeln(source.fullName);
1936 } 1953 }
1937 _logInformation(buffer.toString()); 1954 _logInformation(buffer.toString());
1938 } 1955 }
1939 return changedTargets.length > 0; 1956 return changedSources.length > 0;
1940 } 1957 }
1941 } 1958 }
1942 1959
1943 /** 1960 /**
1944 * An object that manages the partitions that can be shared between analysis 1961 * An object that manages the partitions that can be shared between analysis
1945 * contexts. 1962 * contexts.
1946 */ 1963 */
1947 class PartitionManager { 1964 class PartitionManager {
1948 /** 1965 /**
1949 * A table mapping SDK's to the partitions used for those SDK's. 1966 * A table mapping SDK's to the partitions used for those SDK's.
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 PendingFuture pendingFuture = 2116 PendingFuture pendingFuture =
2100 new PendingFuture<T>(_context, target, computeValue); 2117 new PendingFuture<T>(_context, target, computeValue);
2101 if (!pendingFuture.evaluate(entry)) { 2118 if (!pendingFuture.evaluate(entry)) {
2102 _context._pendingFutureTargets 2119 _context._pendingFutureTargets
2103 .putIfAbsent(target, () => <PendingFuture>[]) 2120 .putIfAbsent(target, () => <PendingFuture>[])
2104 .add(pendingFuture); 2121 .add(pendingFuture);
2105 } 2122 }
2106 return pendingFuture.future; 2123 return pendingFuture.future;
2107 } 2124 }
2108 } 2125 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698