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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/file_state.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 9381aa264841a98ad2a004f0ba0b366ed7c57946..514828423ce55b7b3a9fe6d53885a5ff6f02c01d 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -102,6 +102,7 @@ class FileState {
String _transitiveSignature;
List<TopLevelDeclaration> _topLevelDeclarations;
+ List<TopLevelDeclaration> _exportTopLevelDeclarations;
FileState._(this._fsState, this.path, this.uri, this.source);
@@ -131,6 +132,52 @@ class FileState {
*/
List<FileState> get exportedFiles => _exportedFiles;
+ /**
+ * Return [TopLevelDeclaration]s exported from the this library file.
+ */
+ 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.
+ if (_exportTopLevelDeclarations == null) {
+ _exportTopLevelDeclarations = <TopLevelDeclaration>[];
+
+ Set<FileState> seenLibraries = new Set<FileState>();
+
+ /**
+ * Compute [TopLevelDeclaration]s exported from the [library].
+ */
+ 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.
+ var declarations = <String, TopLevelDeclaration>{};
+ if (seenLibraries.add(library)) {
+ // Append the library declarations.
+ for (TopLevelDeclaration t in library.topLevelDeclarations) {
+ 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.
+ }
+ for (FileState part in library.partedFiles) {
+ for (TopLevelDeclaration t in part.topLevelDeclarations) {
+ declarations[t.name] = t;
+ }
+ }
+
+ // Append the exported declarations.
+ for (int i = 0; i < library._exportedFiles.length; i++) {
+ List<TopLevelDeclaration> exported =
+ computeExported(library._exportedFiles[i]);
+ for (TopLevelDeclaration t in exported) {
+ if (!declarations.containsKey(t.name) &&
+ library._exportFilters[i].accepts(t.name)) {
+ declarations[t.name] = t;
+ }
+ }
+ }
+ }
+
+ return declarations.values.toList();
+ }
+
+ _exportTopLevelDeclarations = computeExported(this);
+ }
+ return _exportTopLevelDeclarations;
+ }
+
@override
int get hashCode => uri.hashCode;
@@ -352,18 +399,24 @@ class FileState {
_referencedNames = new Set<String>.from(driverUnlinkedUnit.referencedNames);
_unlinked = driverUnlinkedUnit.unit;
_lineInfo = new LineInfo(_unlinked.lineStarts);
+ _topLevelDeclarations = null;
+
+ // Prepare API signature.
List<int> newApiSignature = _unlinked.apiSignature;
bool apiSignatureChanged = _apiSignature != null &&
!_equalByteLists(_apiSignature, newApiSignature);
_apiSignature = newApiSignature;
- // If the API signature changed, flush transitive signatures.
+ // The API signature changed.
+ // Flush transitive signatures of affected files.
+ // Flush exported top-level declarations of all files.
if (apiSignatureChanged) {
for (FileState file in _fsState._uriToFile.values) {
if (file._transitiveFiles != null &&
file._transitiveFiles.contains(this)) {
file._transitiveSignature = null;
}
+ file._exportTopLevelDeclarations = null;
}
}
« 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