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

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

Issue 1131853003: Fix methods for getting source kind (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/test/src/context/context_test.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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 * Return a list of the sources that would be processed by 362 * Return a list of the sources that would be processed by
363 * [performAnalysisTask]. This method duplicates, and must therefore be kept 363 * [performAnalysisTask]. This method duplicates, and must therefore be kept
364 * in sync with, [getNextAnalysisTask]. This method is intended to be used for 364 * in sync with, [getNextAnalysisTask]. This method is intended to be used for
365 * testing purposes only. 365 * testing purposes only.
366 */ 366 */
367 List<Source> get sourcesNeedingProcessing { 367 List<Source> get sourcesNeedingProcessing {
368 HashSet<Source> sources = new HashSet<Source>(); 368 HashSet<Source> sources = new HashSet<Source>();
369 bool hintsEnabled = _options.hint; 369 bool hintsEnabled = _options.hint;
370 bool lintsEnabled = _options.lint; 370 bool lintsEnabled = _options.lint;
371 371
372 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator(); 372 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _privatePartition.i terator();
373 while (iterator.moveNext()) { 373 while (iterator.moveNext()) {
374 AnalysisTarget target = iterator.key; 374 AnalysisTarget target = iterator.key;
375 if (target is Source) { 375 if (target is Source) {
376 _getSourcesNeedingProcessing( 376 _getSourcesNeedingProcessing(
377 target, iterator.value, false, hintsEnabled, lintsEnabled, sources); 377 target, iterator.value, false, hintsEnabled, lintsEnabled, sources);
378 } 378 }
379 } 379 }
380 return new List<Source>.from(sources); 380 return new List<Source>.from(sources);
381 } 381 }
382 382
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 550
551 @override 551 @override
552 // TODO(brianwilkerson) Implement this. 552 // TODO(brianwilkerson) Implement this.
553 HtmlElement computeHtmlElement(Source source) => null; 553 HtmlElement computeHtmlElement(Source source) => null;
554 554
555 @override 555 @override
556 List<Source> computeImportedLibraries(Source source) => 556 List<Source> computeImportedLibraries(Source source) =>
557 _computeResult(source, IMPORTED_LIBRARIES); 557 _computeResult(source, IMPORTED_LIBRARIES);
558 558
559 @override 559 @override
560 SourceKind computeKindOf(Source source) => 560 SourceKind computeKindOf(Source source) {
561 _computeResult(source, SOURCE_KIND); 561 String name = source.shortName;
562 if (AnalysisEngine.isDartFileName(name)) {
563 return _computeResult(source, SOURCE_KIND);
564 } else if (AnalysisEngine.isHtmlFileName(name)) {
565 return SourceKind.HTML;
566 }
567 return SourceKind.UNKNOWN;
568 }
562 569
563 @override 570 @override
564 LibraryElement computeLibraryElement(Source source) => _computeResult( 571 LibraryElement computeLibraryElement(Source source) => _computeResult(
565 source, LIBRARY_ELEMENT); //_computeResult(source, HtmlEntry.ELEMENT); 572 source, LIBRARY_ELEMENT); //_computeResult(source, HtmlEntry.ELEMENT);
566 573
567 @override 574 @override
568 LineInfo computeLineInfo(Source source) => _computeResult(source, LINE_INFO); 575 LineInfo computeLineInfo(Source source) => _computeResult(source, LINE_INFO);
569 576
570 @override 577 @override
571 @deprecated 578 @deprecated
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 } 817 }
811 break; 818 break;
812 } 819 }
813 if (htmlSources.isEmpty) { 820 if (htmlSources.isEmpty) {
814 return Source.EMPTY_LIST; 821 return Source.EMPTY_LIST;
815 } 822 }
816 return htmlSources; 823 return htmlSources;
817 } 824 }
818 825
819 @override 826 @override
820 SourceKind getKindOf(Source source) => _getResult(source, SOURCE_KIND); 827 SourceKind getKindOf(Source source) {
828 String name = source.shortName;
829 if (AnalysisEngine.isDartFileName(name)) {
830 return _getResult(source, SOURCE_KIND);
831 } else if (AnalysisEngine.isHtmlFileName(name)) {
832 return SourceKind.HTML;
833 }
834 return SourceKind.UNKNOWN;
835 }
821 836
822 @override 837 @override
823 List<Source> getLibrariesContaining(Source source) { 838 List<Source> getLibrariesContaining(Source source) {
824 // TODO(brianwilkerson) Implement this. 839 SourceKind kind = getKindOf(source);
825 // cache.CacheEntry sourceEntry = _cache.get(source); 840 if (kind == SourceKind.LIBRARY) {
826 // if (sourceEntry is DartEntry) { 841 return <Source>[source];
827 // return sourceEntry.containingLibraries; 842 } else if (kind == SourceKind.PART) {
828 // } 843 List<Source> libraries = <Source>[];
829 return Source.EMPTY_LIST; 844 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator() ;
845 while (iterator.moveNext()) {
846 AnalysisTarget target = iterator.key;
847 if (target is Source && getKindOf(target) == SourceKind.LIBRARY) {
848 List<Source> parts = _getResult(target, INCLUDED_PARTS);
849 if (parts.contains(source)) {
850 libraries.add(target);
851 }
852 }
853 }
854 if (libraries.isNotEmpty) {
855 return libraries;
856 }
857 }
858 return Source.EMPTY_ARRAY;
830 } 859 }
831 860
832 @override 861 @override
833 List<Source> getLibrariesDependingOn(Source librarySource) { 862 List<Source> getLibrariesDependingOn(Source librarySource) {
834 List<Source> dependentLibraries = new List<Source>(); 863 List<Source> dependentLibraries = new List<Source>();
835 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator(); 864 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator();
836 while (iterator.moveNext()) { 865 while (iterator.moveNext()) {
837 cache.CacheEntry entry = iterator.value; 866 cache.CacheEntry entry = iterator.value;
838 if (entry.getValue(SOURCE_KIND) == SourceKind.LIBRARY) { 867 if (entry.getValue(SOURCE_KIND) == SourceKind.LIBRARY) {
839 if (_contains(entry.getValue(EXPORTED_LIBRARIES), librarySource)) { 868 if (_contains(entry.getValue(EXPORTED_LIBRARIES), librarySource)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 // TODO(brianwilkerson) The public namespace used to be cached, but no 913 // TODO(brianwilkerson) The public namespace used to be cached, but no
885 // longer is. Konstantin adds: 914 // longer is. Konstantin adds:
886 // The only client of this method is NamespaceBuilder._createExportMapping() , 915 // The only client of this method is NamespaceBuilder._createExportMapping() ,
887 // and it is not used with tasks - instead we compute export namespace once 916 // and it is not used with tasks - instead we compute export namespace once
888 // using BuildExportNamespaceTask and reuse in scopes. 917 // using BuildExportNamespaceTask and reuse in scopes.
889 NamespaceBuilder builder = new NamespaceBuilder(); 918 NamespaceBuilder builder = new NamespaceBuilder();
890 return builder.createPublicNamespaceForLibrary(library); 919 return builder.createPublicNamespaceForLibrary(library);
891 } 920 }
892 921
893 /** 922 /**
894 * Return the cache entry associated with the given [source], or `null` if 923 * Return the cache entry associated with the given [target], or `null` if
895 * there is no entry associated with the source. 924 * there is no entry associated with the target.
896 */ 925 */
897 cache.CacheEntry getReadableSourceEntryOrNull(Source source) => 926 cache.CacheEntry getReadableSourceEntryOrNull(AnalysisTarget target) =>
898 _cache.get(source); 927 _cache.get(target);
899 928
900 @override 929 @override
901 CompilationUnit getResolvedCompilationUnit( 930 CompilationUnit getResolvedCompilationUnit(
902 Source unitSource, LibraryElement library) { 931 Source unitSource, LibraryElement library) {
903 if (library == null || 932 if (library == null ||
904 !AnalysisEngine.isDartFileName(unitSource.shortName)) { 933 !AnalysisEngine.isDartFileName(unitSource.shortName)) {
905 return null; 934 return null;
906 } 935 }
907 return getResolvedCompilationUnit2(unitSource, library.source); 936 return getResolvedCompilationUnit2(unitSource, library.source);
908 } 937 }
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 PendingFuture pendingFuture = 2170 PendingFuture pendingFuture =
2142 new PendingFuture<T>(_context, target, computeValue); 2171 new PendingFuture<T>(_context, target, computeValue);
2143 if (!pendingFuture.evaluate(entry)) { 2172 if (!pendingFuture.evaluate(entry)) {
2144 _context._pendingFutureTargets 2173 _context._pendingFutureTargets
2145 .putIfAbsent(target, () => <PendingFuture>[]) 2174 .putIfAbsent(target, () => <PendingFuture>[])
2146 .add(pendingFuture); 2175 .add(pendingFuture);
2147 } 2176 }
2148 return pendingFuture.future; 2177 return pendingFuture.future;
2149 } 2178 }
2150 } 2179 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698