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

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

Issue 1308033008: Add AnalysisContext.getResult()/computeResult() (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
« 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/instrumentation/instrumentation.dart'; 10 import 'package:analyzer/instrumentation/instrumentation.dart';
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 throw entry.exception; 651 throw entry.exception;
652 } else if (state == CacheState.INVALID) { 652 } else if (state == CacheState.INVALID) {
653 return null; 653 return null;
654 } 654 }
655 return entry.getValue(RESOLVED_UNIT); 655 return entry.getValue(RESOLVED_UNIT);
656 }, () { 656 }, () {
657 dartWorkManager.addPriorityResult(unitTarget, RESOLVED_UNIT); 657 dartWorkManager.addPriorityResult(unitTarget, RESOLVED_UNIT);
658 }); 658 });
659 } 659 }
660 660
661 @override
661 Object /*V*/ computeResult( 662 Object /*V*/ computeResult(
662 AnalysisTarget target, ResultDescriptor /*<V>*/ descriptor) { 663 AnalysisTarget target, ResultDescriptor /*<V>*/ descriptor) {
663 CacheEntry entry = getCacheEntry(target); 664 CacheEntry entry = getCacheEntry(target);
664 CacheState state = entry.getState(descriptor); 665 CacheState state = entry.getState(descriptor);
665 if (state == CacheState.FLUSHED || state == CacheState.INVALID) { 666 if (state == CacheState.FLUSHED || state == CacheState.INVALID) {
666 driver.computeResult(target, descriptor); 667 driver.computeResult(target, descriptor);
667 } 668 }
668 state = entry.getState(descriptor); 669 state = entry.getState(descriptor);
669 if (state == CacheState.ERROR) { 670 if (state == CacheState.ERROR) {
670 throw new AnalysisException( 671 throw new AnalysisException(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 } 704 }
704 705
705 @override 706 @override
706 List<CompilationUnit> ensureResolvedDartUnits(Source unitSource) { 707 List<CompilationUnit> ensureResolvedDartUnits(Source unitSource) {
707 // Check every library. 708 // Check every library.
708 List<CompilationUnit> units = <CompilationUnit>[]; 709 List<CompilationUnit> units = <CompilationUnit>[];
709 List<Source> containingLibraries = getLibrariesContaining(unitSource); 710 List<Source> containingLibraries = getLibrariesContaining(unitSource);
710 for (Source librarySource in containingLibraries) { 711 for (Source librarySource in containingLibraries) {
711 LibrarySpecificUnit target = 712 LibrarySpecificUnit target =
712 new LibrarySpecificUnit(librarySource, unitSource); 713 new LibrarySpecificUnit(librarySource, unitSource);
713 CompilationUnit unit = _cache.getValue(target, RESOLVED_UNIT); 714 CompilationUnit unit = getResult(target, RESOLVED_UNIT);
714 if (unit == null) { 715 if (unit == null) {
715 units = null; 716 units = null;
716 break; 717 break;
717 } 718 }
718 units.add(unit); 719 units.add(unit);
719 } 720 }
720 // If we have results, then we're done. 721 // If we have results, then we're done.
721 if (units != null) { 722 if (units != null) {
722 return units; 723 return units;
723 } 724 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 .add(new ImplicitAnalysisEvent(target, true)); 758 .add(new ImplicitAnalysisEvent(target, true));
758 } 759 }
759 } 760 }
760 return entry; 761 return entry;
761 } 762 }
762 763
763 @override 764 @override
764 CompilationUnitElement getCompilationUnitElement( 765 CompilationUnitElement getCompilationUnitElement(
765 Source unitSource, Source librarySource) { 766 Source unitSource, Source librarySource) {
766 AnalysisTarget target = new LibrarySpecificUnit(librarySource, unitSource); 767 AnalysisTarget target = new LibrarySpecificUnit(librarySource, unitSource);
767 return _cache.getValue(target, COMPILATION_UNIT_ELEMENT); 768 return getResult(target, COMPILATION_UNIT_ELEMENT);
768 } 769 }
769 770
770 @override 771 @override
771 TimestampedData<String> getContents(Source source) { 772 TimestampedData<String> getContents(Source source) {
772 String contents = _contentCache.getContents(source); 773 String contents = _contentCache.getContents(source);
773 if (contents != null) { 774 if (contents != null) {
774 return new TimestampedData<String>( 775 return new TimestampedData<String>(
775 _contentCache.getModificationStamp(source), contents); 776 _contentCache.getModificationStamp(source), contents);
776 } 777 }
777 return source.contents; 778 return source.contents;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 @override 831 @override
831 List<Source> getHtmlFilesReferencing(Source source) { 832 List<Source> getHtmlFilesReferencing(Source source) {
832 if (!AnalysisEngine.isDartFileName(source.shortName)) { 833 if (!AnalysisEngine.isDartFileName(source.shortName)) {
833 return Source.EMPTY_LIST; 834 return Source.EMPTY_LIST;
834 } 835 }
835 List<Source> htmlSources = <Source>[]; 836 List<Source> htmlSources = <Source>[];
836 List<Source> librarySources = getLibrariesContaining(source); 837 List<Source> librarySources = getLibrariesContaining(source);
837 for (Source source in _cache.sources) { 838 for (Source source in _cache.sources) {
838 if (AnalysisEngine.isHtmlFileName(source.shortName)) { 839 if (AnalysisEngine.isHtmlFileName(source.shortName)) {
839 List<Source> referencedLibraries = 840 List<Source> referencedLibraries =
840 analysisCache.getValue(source, REFERENCED_LIBRARIES); 841 getResult(source, REFERENCED_LIBRARIES);
841 if (_containsAny(referencedLibraries, librarySources)) { 842 if (_containsAny(referencedLibraries, librarySources)) {
842 htmlSources.add(source); 843 htmlSources.add(source);
843 } 844 }
844 } 845 }
845 } 846 }
846 if (htmlSources.isEmpty) { 847 if (htmlSources.isEmpty) {
847 return Source.EMPTY_LIST; 848 return Source.EMPTY_LIST;
848 } 849 }
849 return htmlSources; 850 return htmlSources;
850 } 851 }
851 852
852 @override 853 @override
853 SourceKind getKindOf(Source source) { 854 SourceKind getKindOf(Source source) {
854 String name = source.shortName; 855 String name = source.shortName;
855 if (AnalysisEngine.isDartFileName(name)) { 856 if (AnalysisEngine.isDartFileName(name)) {
856 return _cache.getValue(source, SOURCE_KIND); 857 return getResult(source, SOURCE_KIND);
857 } else if (AnalysisEngine.isHtmlFileName(name)) { 858 } else if (AnalysisEngine.isHtmlFileName(name)) {
858 return SourceKind.HTML; 859 return SourceKind.HTML;
859 } 860 }
860 return SourceKind.UNKNOWN; 861 return SourceKind.UNKNOWN;
861 } 862 }
862 863
863 @override 864 @override
864 List<Source> getLibrariesContaining(Source source) { 865 List<Source> getLibrariesContaining(Source source) {
865 SourceKind kind = getKindOf(source); 866 SourceKind kind = getKindOf(source);
866 if (kind == SourceKind.LIBRARY) { 867 if (kind == SourceKind.LIBRARY) {
(...skipping 26 matching lines...) Expand all
893 List<Source> getLibrariesReferencedFromHtml(Source htmlSource) { 894 List<Source> getLibrariesReferencedFromHtml(Source htmlSource) {
894 CacheEntry entry = _cache.get(htmlSource); 895 CacheEntry entry = _cache.get(htmlSource);
895 if (entry != null) { 896 if (entry != null) {
896 return entry.getValue(REFERENCED_LIBRARIES); 897 return entry.getValue(REFERENCED_LIBRARIES);
897 } 898 }
898 return Source.EMPTY_LIST; 899 return Source.EMPTY_LIST;
899 } 900 }
900 901
901 @override 902 @override
902 LibraryElement getLibraryElement(Source source) => 903 LibraryElement getLibraryElement(Source source) =>
903 _cache.getValue(source, LIBRARY_ELEMENT); 904 getResult(source, LIBRARY_ELEMENT);
904 905
905 @override 906 @override
906 LineInfo getLineInfo(Source source) => _cache.getValue(source, LINE_INFO); 907 LineInfo getLineInfo(Source source) => getResult(source, LINE_INFO);
907 908
908 @override 909 @override
909 int getModificationStamp(Source source) { 910 int getModificationStamp(Source source) {
910 int stamp = _contentCache.getModificationStamp(source); 911 int stamp = _contentCache.getModificationStamp(source);
911 if (stamp != null) { 912 if (stamp != null) {
912 return stamp; 913 return stamp;
913 } 914 }
914 return source.modificationStamp; 915 return source.modificationStamp;
915 } 916 }
916 917
(...skipping 30 matching lines...) Expand all
947 return getResolvedCompilationUnit2(unitSource, library.source); 948 return getResolvedCompilationUnit2(unitSource, library.source);
948 } 949 }
949 950
950 @override 951 @override
951 CompilationUnit getResolvedCompilationUnit2( 952 CompilationUnit getResolvedCompilationUnit2(
952 Source unitSource, Source librarySource) { 953 Source unitSource, Source librarySource) {
953 if (!AnalysisEngine.isDartFileName(unitSource.shortName) || 954 if (!AnalysisEngine.isDartFileName(unitSource.shortName) ||
954 !AnalysisEngine.isDartFileName(librarySource.shortName)) { 955 !AnalysisEngine.isDartFileName(librarySource.shortName)) {
955 return null; 956 return null;
956 } 957 }
957 return _cache.getValue( 958 return getResult(
958 new LibrarySpecificUnit(librarySource, unitSource), RESOLVED_UNIT); 959 new LibrarySpecificUnit(librarySource, unitSource), RESOLVED_UNIT);
959 } 960 }
960 961
961 @override 962 @override
962 @deprecated 963 @deprecated
963 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) { 964 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) {
964 // TODO(brianwilkerson) Remove this method after switching to the new task 965 // TODO(brianwilkerson) Remove this method after switching to the new task
965 // model. 966 // model.
966 throw new UnimplementedError('Not supported in the new task model'); 967 throw new UnimplementedError('Not supported in the new task model');
967 } 968 }
968 969
969 @override 970 @override
971 Object getResult(AnalysisTarget target, ResultDescriptor result) {
972 return _cache.getValue(target, result);
973 }
974
975 @override
970 List<Source> getSourcesWithFullName(String path) { 976 List<Source> getSourcesWithFullName(String path) {
971 return analysisCache.getSourcesWithFullName(path); 977 return analysisCache.getSourcesWithFullName(path);
972 } 978 }
973 979
974 @override 980 @override
975 bool handleContentsChanged( 981 bool handleContentsChanged(
976 Source source, String originalContents, String newContents, bool notify) { 982 Source source, String originalContents, String newContents, bool notify) {
977 CacheEntry entry = _cache.get(source); 983 CacheEntry entry = _cache.get(source);
978 if (entry == null) { 984 if (entry == null) {
979 return false; 985 return false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1019 }
1014 if (notify && changed) { 1020 if (notify && changed) {
1015 _onSourcesChangedController 1021 _onSourcesChangedController
1016 .add(new SourcesChangedEvent.changedContent(source, newContents)); 1022 .add(new SourcesChangedEvent.changedContent(source, newContents));
1017 } 1023 }
1018 return changed; 1024 return changed;
1019 } 1025 }
1020 1026
1021 @override 1027 @override
1022 void invalidateLibraryHints(Source librarySource) { 1028 void invalidateLibraryHints(Source librarySource) {
1023 List<Source> sources = _cache.getValue(librarySource, UNITS); 1029 List<Source> sources = getResult(librarySource, UNITS);
1024 if (sources != null) { 1030 if (sources != null) {
1025 for (Source source in sources) { 1031 for (Source source in sources) {
1026 getCacheEntry(source).setState(HINTS, CacheState.INVALID); 1032 getCacheEntry(source).setState(HINTS, CacheState.INVALID);
1027 } 1033 }
1028 } 1034 }
1029 } 1035 }
1030 1036
1031 @override 1037 @override
1032 bool isClientLibrary(Source librarySource) { 1038 bool isClientLibrary(Source librarySource) {
1033 CacheEntry entry = _cache.get(librarySource); 1039 CacheEntry entry = _cache.get(librarySource);
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 new PendingFuture<T>(_context, target, computeValue); 2089 new PendingFuture<T>(_context, target, computeValue);
2084 if (!pendingFuture.evaluate(entry)) { 2090 if (!pendingFuture.evaluate(entry)) {
2085 _context._pendingFutureTargets 2091 _context._pendingFutureTargets
2086 .putIfAbsent(target, () => <PendingFuture>[]) 2092 .putIfAbsent(target, () => <PendingFuture>[])
2087 .add(pendingFuture); 2093 .add(pendingFuture);
2088 scheduleComputation(); 2094 scheduleComputation();
2089 } 2095 }
2090 return pendingFuture.future; 2096 return pendingFuture.future;
2091 } 2097 }
2092 } 2098 }
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