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

Side by Side Diff: pkg/code_transformers/lib/src/resolver_impl.dart

Issue 208623008: Include exports in resolver.libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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/code_transformers/test/resolver_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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 code_transformer.src.resolver_impl; 5 library code_transformer.src.resolver_impl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'package:analyzer/analyzer.dart' show parseCompilationUnit; 8 import 'package:analyzer/analyzer.dart' show parseCompilationUnit;
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 26 matching lines...) Expand all
37 <AssetId, _AssetBasedSource>{}; 37 <AssetId, _AssetBasedSource>{};
38 38
39 final AnalysisContext _context = 39 final AnalysisContext _context =
40 AnalysisEngine.instance.createAnalysisContext(); 40 AnalysisEngine.instance.createAnalysisContext();
41 41
42 /// Transform for which this is currently updating, or null when not updating. 42 /// Transform for which this is currently updating, or null when not updating.
43 Transform _currentTransform; 43 Transform _currentTransform;
44 44
45 /// The currently resolved entry libraries, or null if nothing is resolved. 45 /// The currently resolved entry libraries, or null if nothing is resolved.
46 List<LibraryElement> _entryLibraries; 46 List<LibraryElement> _entryLibraries;
47 Set<LibraryElement> _libraries;
47 48
48 /// Future indicating when this resolver is done in the current phase. 49 /// Future indicating when this resolver is done in the current phase.
49 Future _lastPhaseComplete = new Future.value(); 50 Future _lastPhaseComplete = new Future.value();
50 51
51 /// Completer for wrapping up the current phase. 52 /// Completer for wrapping up the current phase.
52 Completer _currentPhaseComplete; 53 Completer _currentPhaseComplete;
53 54
54 /// Handler for all Dart SDK (dart:) sources. 55 /// Handler for all Dart SDK (dart:) sources.
55 DirectoryBasedDartSdk _dartSdk; 56 DirectoryBasedDartSdk _dartSdk;
56 57
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 void release() { 96 void release() {
96 if (_currentPhaseComplete == null) { 97 if (_currentPhaseComplete == null) {
97 throw new StateError('Releasing without current lock.'); 98 throw new StateError('Releasing without current lock.');
98 } 99 }
99 _currentPhaseComplete.complete(null); 100 _currentPhaseComplete.complete(null);
100 _currentPhaseComplete = null; 101 _currentPhaseComplete = null;
101 102
102 // Clear out libraries since they should not be referenced after release. 103 // Clear out libraries since they should not be referenced after release.
103 _entryLibraries = null; 104 _entryLibraries = null;
105 _libraries = null;
104 _currentTransform = null; 106 _currentTransform = null;
105 } 107 }
106 108
107 Future _performResolve(Transform transform, List<AssetId> entryPoints) { 109 Future _performResolve(Transform transform, List<AssetId> entryPoints) {
108 if (_currentTransform != null) { 110 if (_currentTransform != null) {
109 throw new StateError('Cannot be accessed by concurrent transforms'); 111 throw new StateError('Cannot be accessed by concurrent transforms');
110 } 112 }
111 _currentTransform = transform; 113 _currentTransform = transform;
112 114
113 // Basic approach is to start at the first file, update it's contents 115 // Basic approach is to start at the first file, update it's contents
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 151
150 // Update the analyzer context with the latest sources 152 // Update the analyzer context with the latest sources
151 _context.applyChanges(changeSet); 153 _context.applyChanges(changeSet);
152 // Force resolve each entry point (the getter will ensure the library is 154 // Force resolve each entry point (the getter will ensure the library is
153 // computed first). 155 // computed first).
154 _entryLibraries = entryPoints 156 _entryLibraries = entryPoints
155 .map((id) => _context.computeLibraryElement(sources[id])).toList(); 157 .map((id) => _context.computeLibraryElement(sources[id])).toList();
156 }); 158 });
157 } 159 }
158 160
159 Iterable<LibraryElement> get libraries => 161 Iterable<LibraryElement> get libraries {
160 _entryLibraries.expand((lib) => lib.visibleLibraries).toSet(); 162 if (_libraries == null) {
163 // Note: we don't use `lib.visibleLibraries` because that excludes the
164 // exports seen in the entry libraries.
165 _libraries = new Set<LibraryElement>();
166 _entryLibraries.forEach(_collectLibraries);
167 }
168 return _libraries;
169 }
170
171 void _collectLibraries(LibraryElement lib) {
172 if (lib == null || _libraries.contains(lib)) return;
173 _libraries.add(lib);
174 lib.importedLibraries.forEach(_collectLibraries);
175 lib.exportedLibraries.forEach(_collectLibraries);
176 }
161 177
162 LibraryElement getLibraryByName(String libraryName) => 178 LibraryElement getLibraryByName(String libraryName) =>
163 libraries.firstWhere((l) => l.name == libraryName, orElse: () => null); 179 libraries.firstWhere((l) => l.name == libraryName, orElse: () => null);
164 180
165 LibraryElement getLibraryByUri(Uri uri) => 181 LibraryElement getLibraryByUri(Uri uri) =>
166 libraries.firstWhere((l) => getImportUri(l) == uri, orElse: () => null); 182 libraries.firstWhere((l) => getImportUri(l) == uri, orElse: () => null);
167 183
168 ClassElement getType(String typeName) { 184 ClassElement getType(String typeName) {
169 var dotIndex = typeName.lastIndexOf('.'); 185 var dotIndex = typeName.lastIndexOf('.');
170 var libraryName = dotIndex == -1 ? '' : typeName.substring(0, dotIndex); 186 var libraryName = dotIndex == -1 ? '' : typeName.substring(0, dotIndex);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 602
587 void apply(ChangeSet changeSet) { 603 void apply(ChangeSet changeSet) {
588 if (!source.updateContents(content)) return; 604 if (!source.updateContents(content)) return;
589 if (source._revision == 1 && source._contents != null) { 605 if (source._revision == 1 && source._contents != null) {
590 changeSet.addedSource(source); 606 changeSet.addedSource(source);
591 } else { 607 } else {
592 changeSet.changedSource(source); 608 changeSet.changedSource(source);
593 } 609 }
594 } 610 }
595 } 611 }
OLDNEW
« no previous file with comments | « no previous file | pkg/code_transformers/test/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698