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

Unified Diff: pkg/docgen/lib/src/model_helpers.dart

Issue 222223004: pkg/docgen: continue the refactoring (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/docgen/lib/src/models.dart » ('j') | pkg/docgen/lib/src/models.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/docgen/lib/src/model_helpers.dart
diff --git a/pkg/docgen/lib/src/model_helpers.dart b/pkg/docgen/lib/src/model_helpers.dart
index 95bd31725695b74235e1e49f05fd6bf3e705ac68..1c8a25521e50ec98a4a4614148852c19c41116be 100644
--- a/pkg/docgen/lib/src/model_helpers.dart
+++ b/pkg/docgen/lib/src/model_helpers.dart
@@ -11,14 +11,15 @@ import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut
import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirrors.dart';
import '../../../../sdk/lib/_internal/libraries.dart';
+import 'library_helpers.dart' show includePrivateMembers;
import 'models.dart';
import 'package_helpers.dart';
/// Returns a list of meta annotations assocated with a mirror.
-List<Annotation> createAnnotations(DeclarationMirror mirror, Library
- owningLibrary) {
- var annotationMirrors = mirror.metadata.where((e) => e is
- dart2js_mirrors.Dart2JsConstructedConstantMirror);
+List<Annotation> createAnnotations(DeclarationMirror mirror,
+ Library owningLibrary) {
+ var annotationMirrors = mirror.metadata
+ .where((e) => e is dart2js_mirrors.Dart2JsConstructedConstantMirror);
var annotations = [];
annotationMirrors.forEach((annotation) {
var docgenAnnotation = new Annotation(annotation, owningLibrary);
@@ -73,6 +74,134 @@ String getPackageName(LibraryMirror mirror) {
return packageNameFor(rootdir);
}
+
+/// Helper that maps [mirrors] to their simple name in map.
+Map addAll(Map map, Iterable<DeclarationMirror> mirrors) {
+ for (var mirror in mirrors) {
+ map[dart2js_util.nameOf(mirror)] = mirror;
+ }
+ return map;
+}
+
+/// For the given library determine what items (if any) are exported.
+///
+/// Returns a Map with three keys: "classes", "methods", and "variables" the
+/// values of which point to a map of exported name identifiers with values
+/// corresponding to the actual DeclarationMirror.
+Map<String, Map<String, DeclarationMirror>> calcExportedItems(
+ LibrarySourceMirror library) {
+ var exports = {};
+ exports['classes'] = {};
+ exports['methods'] = {};
+ exports['variables'] = {};
+
+ // Determine the classes, variables and methods that are exported for a
+ // specific dependency.
+ void _populateExports(LibraryDependencyMirror export, bool showExport) {
+ if (!showExport) {
+ // Add all items, and then remove the hidden ones.
+ // Ex: "export foo hide bar"
+ addAll(exports['classes'],
+ dart2js_util.typesOf(export.targetLibrary.declarations));
+ addAll(exports['methods'],
+ export.targetLibrary.declarations.values.where(
+ (mirror) => mirror is MethodMirror));
+ addAll(exports['variables'],
+ dart2js_util.variablesOf(export.targetLibrary.declarations));
+ }
+ for (CombinatorMirror combinator in export.combinators) {
+ for (String identifier in combinator.identifiers) {
+ var librarySourceMirror =
+ export.targetLibrary as DeclarationSourceMirror;
+ var declaration = librarySourceMirror.lookupInScope(identifier);
+ if (declaration == null) {
+ // Technically this should be a bug, but some of our packages
+ // (such as the polymer package) are curently broken in this
+ // way, so we just produce a warning.
+ print('Warning identifier $identifier not found in library '
+ '${dart2js_util.qualifiedNameOf(export.targetLibrary)}');
+ } else {
+ var subMap = exports['classes'];
+ if (declaration is MethodMirror) {
+ subMap = exports['methods'];
+ } else if (declaration is VariableMirror) {
+ subMap = exports['variables'];
+ }
+ if (showExport) {
+ subMap[identifier] = declaration;
+ } else {
+ subMap.remove(identifier);
+ }
+ }
+ }
+ }
+ }
+
+ Iterable<LibraryDependencyMirror> exportList =
+ library.libraryDependencies.where((lib) => lib.isExport);
+ for (LibraryDependencyMirror export in exportList) {
+ // If there is a show in the export, add only the show items to the
+ // library. Ex: "export foo show bar"
+ // Otherwise, add all items, and then remove the hidden ones.
+ // Ex: "export foo hide bar"
+ _populateExports(export,
+ export.combinators.any((combinator) => combinator.isShow));
+ }
+ return exports;
+}
+
+
+/// Returns a map of [Variable] objects constructed from [mirrorMap].
+/// The optional parameter [containingLibrary] is contains data for variables
+/// defined at the top level of a library (potentially for exporting
+/// purposes).
+Map<String, Variable> createVariables(Iterable<VariableMirror> mirrors,
+ Indexable owner) {
+ var data = {};
+ // TODO(janicejl): When map to map feature is created, replace the below
+ // with a filter. Issue(#9590).
+ mirrors.forEach((dart2js_mirrors.Dart2JsFieldMirror mirror) {
+ if (includePrivateMembers || !isHidden(mirror)) {
+ var mirrorName = dart2js_util.nameOf(mirror);
+ data[mirrorName] = new Variable(mirrorName, mirror, owner);
+ }
+ });
+ return data;
+}
+
+/// Returns a map of [Method] objects constructed from [mirrorMap].
+/// The optional parameter [containingLibrary] is contains data for variables
+/// defined at the top level of a library (potentially for exporting
+/// purposes).
+Map<String, Method> createMethods(Iterable<MethodMirror> mirrors,
+ Indexable owner) {
+ var group = new Map<String, Method>();
+ mirrors.forEach((MethodMirror mirror) {
+ if (includePrivateMembers || !mirror.isPrivate) {
+ group[dart2js_util.nameOf(mirror)] = new Method(mirror, owner);
+ }
+ });
+ return group;
+}
+
+/// Returns a map of [Parameter] objects constructed from [mirrorList].
+Map<String, Parameter> createParameters(List<ParameterMirror> mirrorList,
+ Indexable owner) {
+ var data = {};
+ mirrorList.forEach((ParameterMirror mirror) {
+ data[dart2js_util.nameOf(mirror)] =
+ new Parameter(mirror, owner.owningLibrary);
+ });
+ return data;
+}
+
+/// Returns a map of [Generic] objects constructed from the class mirror.
+Map<String, Generic> createGenerics(TypeMirror mirror) {
+ return new Map.fromIterable(mirror.typeVariables,
+ key: (e) => dart2js_util.nameOf(e),
+ value: (e) => new Generic(e));
+}
+
/// Annotations that we do not display in the viewer.
const List<String> _SKIPPED_ANNOTATIONS = const [
'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates',
« no previous file with comments | « no previous file | pkg/docgen/lib/src/models.dart » ('j') | pkg/docgen/lib/src/models.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698