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

Unified Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1002393004: Move PublicNamespaceBuilder into tasks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index 1fb498e39bb926fc55d0841a761f310e15f5eec6..f9e7705febc1ae21bb2e94b6ea19c0f83288e798 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -889,10 +889,7 @@ class BuildPublicNamespaceTask extends SourceBasedAnalysisTask {
@override
void internalPerform() {
LibraryElement library = getRequiredInput(BUILT_LIBRARY_ELEMENT_INPUT_NAME);
-
- NamespaceBuilder builder = new NamespaceBuilder();
- Namespace namespace = builder.createPublicNamespaceForLibrary(library);
-
+ Namespace namespace = new PublicNamespaceBuilder().build(library);
outputs[PUBLIC_NAMESPACE] = namespace;
}
@@ -1169,6 +1166,45 @@ class ParseDartTask extends SourceBasedAnalysisTask {
}
/**
+ * The helper for building the public [Namespace] of a [LibraryElement].
+ */
+class PublicNamespaceBuilder {
+ final HashMap<String, Element> definedNames = new HashMap<String, Element>();
+
+ /**
+ * Build a public [Namespace] of the given [library].
+ */
+ Namespace build(LibraryElement library) {
+ definedNames.clear();
+ _addPublicNames(library.definingCompilationUnit);
+ library.parts.forEach(_addPublicNames);
+ return new Namespace(definedNames);
+ }
+
+ /**
+ * Add the given [element] if it has a publicly visible name.
+ */
+ void _addIfPublic(Element element) {
+ String name = element.name;
+ if (name != null && !Scope.isPrivateName(name)) {
+ definedNames[name] = element;
+ }
+ }
+
+ /**
+ * Add all of the public top-level names that are defined in the given
+ * [compilationUnit].
+ */
+ void _addPublicNames(CompilationUnitElement compilationUnit) {
+ compilationUnit.accessors.forEach(_addIfPublic);
+ compilationUnit.enums.forEach(_addIfPublic);
+ compilationUnit.functions.forEach(_addIfPublic);
+ compilationUnit.functionTypeAliases.forEach(_addIfPublic);
+ compilationUnit.types.forEach(_addIfPublic);
+ }
+}
+
+/**
* A task that scans the content of a file, producing a set of Dart tokens.
*/
class ScanDartTask extends SourceBasedAnalysisTask {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698