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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2542883003: Compute exported top-level declarations. (Closed)
Patch Set: Created 4 years 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/test/src/dart/analysis/file_state_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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:convert'; 5 import 'dart:convert';
6 import 'dart:typed_data'; 6 import 'dart:typed_data';
7 7
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 List<FileState> _importedFiles; 95 List<FileState> _importedFiles;
96 List<FileState> _exportedFiles; 96 List<FileState> _exportedFiles;
97 List<FileState> _partedFiles; 97 List<FileState> _partedFiles;
98 List<NameFilter> _exportFilters; 98 List<NameFilter> _exportFilters;
99 99
100 Set<FileState> _directReferencedFiles = new Set<FileState>(); 100 Set<FileState> _directReferencedFiles = new Set<FileState>();
101 Set<FileState> _transitiveFiles; 101 Set<FileState> _transitiveFiles;
102 String _transitiveSignature; 102 String _transitiveSignature;
103 103
104 List<TopLevelDeclaration> _topLevelDeclarations; 104 List<TopLevelDeclaration> _topLevelDeclarations;
105 List<TopLevelDeclaration> _exportTopLevelDeclarations;
105 106
106 FileState._(this._fsState, this.path, this.uri, this.source); 107 FileState._(this._fsState, this.path, this.uri, this.source);
107 108
108 /** 109 /**
109 * The unlinked API signature of the file. 110 * The unlinked API signature of the file.
110 */ 111 */
111 List<int> get apiSignature => _apiSignature; 112 List<int> get apiSignature => _apiSignature;
112 113
113 /** 114 /**
114 * The content of the file. 115 * The content of the file.
115 */ 116 */
116 String get content => _content; 117 String get content => _content;
117 118
118 /** 119 /**
119 * The MD5 hash of the [content]. 120 * The MD5 hash of the [content].
120 */ 121 */
121 String get contentHash => _contentHash; 122 String get contentHash => _contentHash;
122 123
123 /** 124 /**
124 * Return the set of all directly referenced files - imported, exported or 125 * Return the set of all directly referenced files - imported, exported or
125 * parted. 126 * parted.
126 */ 127 */
127 Set<FileState> get directReferencedFiles => _directReferencedFiles; 128 Set<FileState> get directReferencedFiles => _directReferencedFiles;
128 129
129 /** 130 /**
130 * The list of files this file exports. 131 * The list of files this file exports.
131 */ 132 */
132 List<FileState> get exportedFiles => _exportedFiles; 133 List<FileState> get exportedFiles => _exportedFiles;
133 134
135 /**
136 * Return [TopLevelDeclaration]s exported from the this library file.
137 */
138 List<TopLevelDeclaration> get exportTopLevelDeclarations {
Paul Berry 2016/12/01 21:16:10 This sounds like the name of a method with takes s
scheglov 2016/12/01 21:39:56 Done.
139 if (_exportTopLevelDeclarations == null) {
140 _exportTopLevelDeclarations = <TopLevelDeclaration>[];
141
142 Set<FileState> seenLibraries = new Set<FileState>();
143
144 /**
145 * Compute [TopLevelDeclaration]s exported from the [library].
146 */
147 List<TopLevelDeclaration> computeExported(FileState library) {
Paul Berry 2016/12/01 21:16:10 I think there's a bug. Consider the following: a
scheglov 2016/12/01 21:39:56 You're right. Fixed.
148 var declarations = <String, TopLevelDeclaration>{};
149 if (seenLibraries.add(library)) {
150 // Append the library declarations.
151 for (TopLevelDeclaration t in library.topLevelDeclarations) {
152 declarations[t.name] = t;
Brian Wilkerson 2016/12/01 21:07:47 I think we need to test for private names both her
scheglov 2016/12/01 21:39:56 Done.
153 }
154 for (FileState part in library.partedFiles) {
155 for (TopLevelDeclaration t in part.topLevelDeclarations) {
156 declarations[t.name] = t;
157 }
158 }
159
160 // Append the exported declarations.
161 for (int i = 0; i < library._exportedFiles.length; i++) {
162 List<TopLevelDeclaration> exported =
163 computeExported(library._exportedFiles[i]);
164 for (TopLevelDeclaration t in exported) {
165 if (!declarations.containsKey(t.name) &&
166 library._exportFilters[i].accepts(t.name)) {
167 declarations[t.name] = t;
168 }
169 }
170 }
171 }
172
173 return declarations.values.toList();
174 }
175
176 _exportTopLevelDeclarations = computeExported(this);
177 }
178 return _exportTopLevelDeclarations;
179 }
180
134 @override 181 @override
135 int get hashCode => uri.hashCode; 182 int get hashCode => uri.hashCode;
136 183
137 /** 184 /**
138 * The list of files this file imports. 185 * The list of files this file imports.
139 */ 186 */
140 List<FileState> get importedFiles => _importedFiles; 187 List<FileState> get importedFiles => _importedFiles;
141 188
142 /** 189 /**
143 * Return `true` if the file has a `part of` directive, so is probably a part. 190 * Return `true` if the file has a `part of` directive, so is probably a part.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 _fsState._byteStore.put(unlinkedKey, bytes); 392 _fsState._byteStore.put(unlinkedKey, bytes);
346 }); 393 });
347 } 394 }
348 } 395 }
349 396
350 // Read the unlinked bundle. 397 // Read the unlinked bundle.
351 var driverUnlinkedUnit = new AnalysisDriverUnlinkedUnit.fromBuffer(bytes); 398 var driverUnlinkedUnit = new AnalysisDriverUnlinkedUnit.fromBuffer(bytes);
352 _referencedNames = new Set<String>.from(driverUnlinkedUnit.referencedNames); 399 _referencedNames = new Set<String>.from(driverUnlinkedUnit.referencedNames);
353 _unlinked = driverUnlinkedUnit.unit; 400 _unlinked = driverUnlinkedUnit.unit;
354 _lineInfo = new LineInfo(_unlinked.lineStarts); 401 _lineInfo = new LineInfo(_unlinked.lineStarts);
402 _topLevelDeclarations = null;
403
404 // Prepare API signature.
355 List<int> newApiSignature = _unlinked.apiSignature; 405 List<int> newApiSignature = _unlinked.apiSignature;
356 bool apiSignatureChanged = _apiSignature != null && 406 bool apiSignatureChanged = _apiSignature != null &&
357 !_equalByteLists(_apiSignature, newApiSignature); 407 !_equalByteLists(_apiSignature, newApiSignature);
358 _apiSignature = newApiSignature; 408 _apiSignature = newApiSignature;
359 409
360 // If the API signature changed, flush transitive signatures. 410 // The API signature changed.
411 // Flush transitive signatures of affected files.
412 // Flush exported top-level declarations of all files.
361 if (apiSignatureChanged) { 413 if (apiSignatureChanged) {
362 for (FileState file in _fsState._uriToFile.values) { 414 for (FileState file in _fsState._uriToFile.values) {
363 if (file._transitiveFiles != null && 415 if (file._transitiveFiles != null &&
364 file._transitiveFiles.contains(this)) { 416 file._transitiveFiles.contains(this)) {
365 file._transitiveSignature = null; 417 file._transitiveSignature = null;
366 } 418 }
419 file._exportTopLevelDeclarations = null;
367 } 420 }
368 } 421 }
369 422
370 // This file is potentially not a library for its previous parts anymore. 423 // This file is potentially not a library for its previous parts anymore.
371 if (_partedFiles != null) { 424 if (_partedFiles != null) {
372 for (FileState part in _partedFiles) { 425 for (FileState part in _partedFiles) {
373 _fsState._partToLibraries[part]?.remove(this); 426 _fsState._partToLibraries[part]?.remove(this);
374 } 427 }
375 } 428 }
376 429
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 .where((f) => f._transitiveFiles == null) 665 .where((f) => f._transitiveFiles == null)
613 .toSet(); 666 .toSet();
614 } 667 }
615 668
616 Set<FileState> get filesWithoutTransitiveSignature { 669 Set<FileState> get filesWithoutTransitiveSignature {
617 return state._uriToFile.values 670 return state._uriToFile.values
618 .where((f) => f._transitiveSignature == null) 671 .where((f) => f._transitiveSignature == null)
619 .toSet(); 672 .toSet();
620 } 673 }
621 } 674 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698