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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 } | 637 } |
638 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet)); | 638 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet)); |
639 return new ApplyChangesStatus(changeSet.addedSources.isNotEmpty || | 639 return new ApplyChangesStatus(changeSet.addedSources.isNotEmpty || |
640 changeSet.changedContents.isNotEmpty || | 640 changeSet.changedContents.isNotEmpty || |
641 changeSet.deletedSources.isNotEmpty || | 641 changeSet.deletedSources.isNotEmpty || |
642 changedSources.isNotEmpty || | 642 changedSources.isNotEmpty || |
643 removedSources.isNotEmpty); | 643 removedSources.isNotEmpty); |
644 } | 644 } |
645 | 645 |
646 @override | 646 @override |
| 647 AnalysisTarget canonicalizeTarget(AnalysisTarget target) { |
| 648 if (target is LibrarySpecificUnit) { |
| 649 return getLibrarySpecificUnit(target.library, target.unit); |
| 650 } |
| 651 return target; |
| 652 } |
| 653 |
| 654 @override |
647 String computeDocumentationComment(Element element) => | 655 String computeDocumentationComment(Element element) => |
648 element?.documentationComment; | 656 element?.documentationComment; |
649 | 657 |
650 @override | 658 @override |
651 List<AnalysisError> computeErrors(Source source) { | 659 List<AnalysisError> computeErrors(Source source) { |
652 String name = source.shortName; | 660 String name = source.shortName; |
653 if (AnalysisEngine.isHtmlFileName(name)) { | 661 if (AnalysisEngine.isHtmlFileName(name)) { |
654 return computeResult(source, HTML_ERRORS); | 662 return computeResult(source, HTML_ERRORS); |
655 } | 663 } |
656 return computeResult(source, DART_ERRORS); | 664 return computeResult(source, DART_ERRORS); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 if (_contentCache.getContents(source) != null) { | 857 if (_contentCache.getContents(source) != null) { |
850 return true; | 858 return true; |
851 } | 859 } |
852 return source.exists(); | 860 return source.exists(); |
853 } | 861 } |
854 | 862 |
855 @override | 863 @override |
856 CacheEntry getCacheEntry(AnalysisTarget target) { | 864 CacheEntry getCacheEntry(AnalysisTarget target) { |
857 CacheEntry entry = _cache.get(target); | 865 CacheEntry entry = _cache.get(target); |
858 if (entry == null) { | 866 if (entry == null) { |
| 867 target = canonicalizeTarget(target); |
859 entry = new CacheEntry(target); | 868 entry = new CacheEntry(target); |
860 ImplicitAnalysisEvent event = null; | 869 ImplicitAnalysisEvent event = null; |
861 if (target is Source) { | 870 if (target is Source) { |
862 entry.modificationTime = getModificationStamp(target); | 871 entry.modificationTime = getModificationStamp(target); |
863 event = new ImplicitAnalysisEvent(target, true); | 872 event = new ImplicitAnalysisEvent(target, true); |
864 } | 873 } |
865 _cache.put(entry); | 874 _cache.put(entry); |
866 if (event != null) { | 875 if (event != null) { |
867 _implicitAnalysisEventsController.add(event); | 876 _implicitAnalysisEventsController.add(event); |
868 } | 877 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 return entry.getValue(REFERENCED_LIBRARIES); | 1009 return entry.getValue(REFERENCED_LIBRARIES); |
1001 } | 1010 } |
1002 return Source.EMPTY_LIST; | 1011 return Source.EMPTY_LIST; |
1003 } | 1012 } |
1004 | 1013 |
1005 @override | 1014 @override |
1006 LibraryElement getLibraryElement(Source source) => | 1015 LibraryElement getLibraryElement(Source source) => |
1007 getResult(source, LIBRARY_ELEMENT); | 1016 getResult(source, LIBRARY_ELEMENT); |
1008 | 1017 |
1009 @override | 1018 @override |
| 1019 LibrarySpecificUnit getLibrarySpecificUnit(Source library, Source unit) { |
| 1020 CacheEntry entry = analysisCache.get(unit); |
| 1021 if (entry != null) { |
| 1022 LibrarySpecificUnit lsu = entry.librarySpecificUnit; |
| 1023 if (lsu == null) { |
| 1024 lsu = new LibrarySpecificUnit(library, unit); |
| 1025 entry.librarySpecificUnit = lsu; |
| 1026 return lsu; |
| 1027 } else if (lsu.library == library && lsu.unit == unit) { |
| 1028 return lsu; |
| 1029 } |
| 1030 } |
| 1031 return new LibrarySpecificUnit(library, unit); |
| 1032 } |
| 1033 |
| 1034 @override |
1010 LineInfo getLineInfo(Source source) => getResult(source, LINE_INFO); | 1035 LineInfo getLineInfo(Source source) => getResult(source, LINE_INFO); |
1011 | 1036 |
1012 @override | 1037 @override |
1013 int getModificationStamp(Source source) { | 1038 int getModificationStamp(Source source) { |
1014 int stamp = _contentCache.getModificationStamp(source); | 1039 int stamp = _contentCache.getModificationStamp(source); |
1015 if (stamp != null) { | 1040 if (stamp != null) { |
1016 return stamp; | 1041 return stamp; |
1017 } | 1042 } |
1018 return source.modificationStamp; | 1043 return source.modificationStamp; |
1019 } | 1044 } |
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 } | 2321 } |
2297 DartSdk sdk = factory.dartSdk; | 2322 DartSdk sdk = factory.dartSdk; |
2298 if (sdk == null) { | 2323 if (sdk == null) { |
2299 throw new IllegalArgumentException( | 2324 throw new IllegalArgumentException( |
2300 "The source factory for an SDK analysis context must have a DartUriRes
olver"); | 2325 "The source factory for an SDK analysis context must have a DartUriRes
olver"); |
2301 } | 2326 } |
2302 return new AnalysisCache( | 2327 return new AnalysisCache( |
2303 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 2328 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
2304 } | 2329 } |
2305 } | 2330 } |
OLD | NEW |