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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2545753003: Compute top-level declarations in a file. (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/lib/src/dart/analysis/top_level_declarations.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 3a88ed6aafa1ed2f4ca9d76944a18d5ac2b49d9c..26a1df70b31b49e92bd3cd3f688f6568de00940c 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -12,6 +12,7 @@ import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/analysis/referenced_names.dart';
+import 'package:analyzer/src/dart/analysis/top_level_declarations.dart';
import 'package:analyzer/src/dart/scanner/reader.dart';
import 'package:analyzer/src/dart/scanner/scanner.dart';
import 'package:analyzer/src/generated/engine.dart';
@@ -22,6 +23,7 @@ import 'package:analyzer/src/source/source_resource.dart';
import 'package:analyzer/src/summary/api_signature.dart';
import 'package:analyzer/src/summary/format.dart';
import 'package:analyzer/src/summary/idl.dart';
+import 'package:analyzer/src/summary/name_filter.dart';
import 'package:analyzer/src/summary/summarize_ast.dart';
import 'package:analyzer/src/util/fast_uri.dart';
import 'package:convert/convert.dart';
@@ -93,10 +95,14 @@ class FileState {
List<FileState> _importedFiles;
List<FileState> _exportedFiles;
List<FileState> _partedFiles;
+ List<NameFilter> _exportFilters;
+
Set<FileState> _directReferencedFiles = new Set<FileState>();
Set<FileState> _transitiveFiles;
String _transitiveSignature;
+ List<TopLevelDeclaration> _topLevelDeclarations;
+
FileState._(this._fsState, this.path, this.uri, this.source);
/**
@@ -168,6 +174,54 @@ class FileState {
Set<String> get referencedNames => _referencedNames;
/**
+ * Return top-level declarations declared in the file.
+ */
+ List<TopLevelDeclaration> get topLevelDeclarations {
+ if (_topLevelDeclarations == null) {
+ _topLevelDeclarations = <TopLevelDeclaration>[];
+ // Add types.
+ for (UnlinkedClass type in unlinked.classes) {
+ _topLevelDeclarations.add(
+ new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name));
+ }
+ for (UnlinkedEnum type in unlinked.enums) {
+ _topLevelDeclarations.add(
+ new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name));
+ }
+ for (UnlinkedTypedef type in unlinked.typedefs) {
+ _topLevelDeclarations.add(
+ new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name));
+ }
+ // Add functions and variables.
+ Set<String> addedVariableNames = new Set<String>();
+ for (UnlinkedExecutable executable in unlinked.executables) {
+ String name = executable.name;
+ if (executable.kind == UnlinkedExecutableKind.functionOrMethod) {
+ _topLevelDeclarations.add(
+ new TopLevelDeclaration(TopLevelDeclarationKind.function, name));
+ } else if (executable.kind == UnlinkedExecutableKind.getter ||
+ executable.kind == UnlinkedExecutableKind.setter) {
+ if (executable.kind == UnlinkedExecutableKind.setter) {
+ name = name.substring(0, name.length - 1);
+ }
+ if (addedVariableNames.add(name)) {
+ _topLevelDeclarations.add(new TopLevelDeclaration(
+ TopLevelDeclarationKind.variable, name));
+ }
+ }
+ }
+ for (UnlinkedVariable variable in unlinked.variables) {
+ String name = variable.name;
+ if (addedVariableNames.add(name)) {
+ _topLevelDeclarations.add(
+ new TopLevelDeclaration(TopLevelDeclarationKind.variable, name));
+ }
+ }
+ }
+ return _topLevelDeclarations;
+ }
+
+ /**
* Return the set of transitive files - the file itself and all of the
* directly or indirectly referenced files.
*/
@@ -324,6 +378,7 @@ class FileState {
_importedFiles = <FileState>[];
_exportedFiles = <FileState>[];
_partedFiles = <FileState>[];
+ _exportFilters = <NameFilter>[];
for (UnlinkedImport import in _unlinked.imports) {
if (!import.isImplicit) {
String uri = import.uri;
@@ -341,6 +396,8 @@ class FileState {
FileState file = _fileForRelativeUri(uri);
if (file != null) {
_exportedFiles.add(file);
+ _exportFilters
+ .add(new NameFilter.forUnlinkedCombinators(export.combinators));
}
}
}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/analysis/top_level_declarations.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698