OLD | NEW |
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/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 return null; | 1490 return null; |
1491 } | 1491 } |
1492 return ChangeNoticeImpl.EMPTY_LIST; | 1492 return ChangeNoticeImpl.EMPTY_LIST; |
1493 } | 1493 } |
1494 List<ChangeNotice> notices = new List.from(_pendingNotices.values); | 1494 List<ChangeNotice> notices = new List.from(_pendingNotices.values); |
1495 _pendingNotices.clear(); | 1495 _pendingNotices.clear(); |
1496 return notices; | 1496 return notices; |
1497 } | 1497 } |
1498 | 1498 |
1499 /** | 1499 /** |
| 1500 * Return a [CompilationUnit] for the given library and unit sources, which |
| 1501 * can be incrementally resolved. |
| 1502 */ |
| 1503 CompilationUnit _getIncrementallyResolvableUnit( |
| 1504 Source librarySource, Source unitSource) { |
| 1505 LibrarySpecificUnit target = |
| 1506 new LibrarySpecificUnit(librarySource, unitSource); |
| 1507 for (ResultDescriptor result in [ |
| 1508 RESOLVED_UNIT, |
| 1509 RESOLVED_UNIT11, |
| 1510 RESOLVED_UNIT10, |
| 1511 RESOLVED_UNIT9, |
| 1512 RESOLVED_UNIT8, |
| 1513 RESOLVED_UNIT7, |
| 1514 RESOLVED_UNIT6 |
| 1515 ]) { |
| 1516 CompilationUnit unit = getResult(target, result); |
| 1517 if (unit != null) { |
| 1518 return unit; |
| 1519 } |
| 1520 } |
| 1521 return null; |
| 1522 } |
| 1523 |
| 1524 /** |
1500 * Return a list containing all of the sources known to this context that have | 1525 * Return a list containing all of the sources known to this context that have |
1501 * the given [kind]. | 1526 * the given [kind]. |
1502 */ | 1527 */ |
1503 List<Source> _getSources(SourceKind kind) { | 1528 List<Source> _getSources(SourceKind kind) { |
1504 List<Source> sources = <Source>[]; | 1529 List<Source> sources = <Source>[]; |
1505 if (kind == SourceKind.LIBRARY || kind == SourceKind.PART) { | 1530 if (kind == SourceKind.LIBRARY || kind == SourceKind.PART) { |
1506 for (Source source in _cache.sources) { | 1531 for (Source source in _cache.sources) { |
1507 CacheEntry entry = _cache.get(source); | 1532 CacheEntry entry = _cache.get(source); |
1508 if (entry.getValue(SOURCE_KIND) == kind) { | 1533 if (entry.getValue(SOURCE_KIND) == kind) { |
1509 sources.add(source); | 1534 sources.add(source); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 } | 1861 } |
1837 | 1862 |
1838 /** | 1863 /** |
1839 * TODO(scheglov) A hackish, limited incremental resolution implementation. | 1864 * TODO(scheglov) A hackish, limited incremental resolution implementation. |
1840 */ | 1865 */ |
1841 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) { | 1866 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) { |
1842 return PerformanceStatistics.incrementalAnalysis.makeCurrentWhile(() { | 1867 return PerformanceStatistics.incrementalAnalysis.makeCurrentWhile(() { |
1843 incrementalResolutionValidation_lastUnitSource = null; | 1868 incrementalResolutionValidation_lastUnitSource = null; |
1844 incrementalResolutionValidation_lastLibrarySource = null; | 1869 incrementalResolutionValidation_lastLibrarySource = null; |
1845 incrementalResolutionValidation_lastUnit = null; | 1870 incrementalResolutionValidation_lastUnit = null; |
1846 // prepare the entry | 1871 // prepare the source entry |
1847 CacheEntry sourceEntry = _cache.get(unitSource); | 1872 CacheEntry sourceEntry = _cache.get(unitSource); |
1848 if (sourceEntry == null) { | 1873 if (sourceEntry == null) { |
1849 return false; | 1874 return false; |
1850 } | 1875 } |
1851 // prepare the (only) library source | 1876 // prepare the (only) library source |
1852 List<Source> librarySources = getLibrariesContaining(unitSource); | 1877 List<Source> librarySources = getLibrariesContaining(unitSource); |
1853 if (librarySources.length != 1) { | 1878 if (librarySources.length != 1) { |
1854 return false; | 1879 return false; |
1855 } | 1880 } |
1856 Source librarySource = librarySources[0]; | 1881 Source librarySource = librarySources[0]; |
| 1882 // prepare the unit entry |
1857 CacheEntry unitEntry = | 1883 CacheEntry unitEntry = |
1858 _cache.get(new LibrarySpecificUnit(librarySource, unitSource)); | 1884 _cache.get(new LibrarySpecificUnit(librarySource, unitSource)); |
1859 if (unitEntry == null) { | 1885 if (unitEntry == null) { |
1860 return false; | 1886 return false; |
1861 } | 1887 } |
1862 // prepare the library element | |
1863 LibraryElement libraryElement = getLibraryElement(librarySource); | |
1864 if (libraryElement == null) { | |
1865 return false; | |
1866 } | |
1867 // prepare the existing unit | 1888 // prepare the existing unit |
1868 CompilationUnit oldUnit = | 1889 CompilationUnit oldUnit = |
1869 getResolvedCompilationUnit2(unitSource, librarySource); | 1890 _getIncrementallyResolvableUnit(librarySource, unitSource); |
1870 if (oldUnit == null) { | 1891 if (oldUnit == null) { |
1871 return false; | 1892 return false; |
1872 } | 1893 } |
1873 // do resolution | 1894 // do resolution |
1874 Stopwatch perfCounter = new Stopwatch()..start(); | 1895 Stopwatch perfCounter = new Stopwatch()..start(); |
1875 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( | 1896 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( |
1876 typeProvider, | 1897 typeProvider, |
1877 unitSource, | 1898 unitSource, |
1878 _cache, | 1899 _cache, |
1879 sourceEntry, | 1900 sourceEntry, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 } | 2127 } |
2107 DartSdk sdk = factory.dartSdk; | 2128 DartSdk sdk = factory.dartSdk; |
2108 if (sdk == null) { | 2129 if (sdk == null) { |
2109 throw new IllegalArgumentException( | 2130 throw new IllegalArgumentException( |
2110 "The source factory for an SDK analysis context must have a DartUriRes
olver"); | 2131 "The source factory for an SDK analysis context must have a DartUriRes
olver"); |
2111 } | 2132 } |
2112 return new AnalysisCache( | 2133 return new AnalysisCache( |
2113 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 2134 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
2114 } | 2135 } |
2115 } | 2136 } |
OLD | NEW |