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

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

Issue 119913002: Align source mirrors with runtime mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments + small fix. Created 6 years, 11 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/test/multi_library_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/docgen/lib/docgen.dart
diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart
index fb4238fdcc564e832291007e6935810cc70f06b3..4da28a676bb24169c44d4b9cd73e2cb7018dcf0e 100644
--- a/pkg/docgen/lib/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -26,9 +26,11 @@ import 'dart2yaml.dart';
import 'src/io.dart';
import '../../../sdk/lib/_internal/compiler/compiler.dart' as api;
import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart';
-import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart'
+import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart'
as dart2js;
-import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
+import '../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.dart'
+ as dart2js;
+import '../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirrors.dart';
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart'
as dart2js_util;
import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.dart';
@@ -122,7 +124,7 @@ Map<String, Map<String, Set<MirrorBased>>> mirrorToDocgen =
/// a MirrorBased object.
MirrorBased getDocgenObject(DeclarationMirror mirror, [Indexable owner]) {
Map<String, Set<MirrorBased>> docgenObj =
- mirrorToDocgen[mirror.qualifiedName];
+ mirrorToDocgen[dart2js_util.qualifiedNameOf(mirror)];
if (docgenObj == null) {
return new DummyMirror(mirror, owner);
}
@@ -177,15 +179,15 @@ class DummyMirror implements MirrorBased {
String get docName {
if (mirror == null) return '';
if (mirror is LibraryMirror) {
- return mirror.qualifiedName.replaceAll('.','-');
+ return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-');
}
var mirrorOwner = mirror.owner;
- if (mirrorOwner == null) return mirror.qualifiedName;
- var simpleName = mirror.simpleName;
+ if (mirrorOwner == null) return dart2js_util.qualifiedNameOf(mirror);
+ var simpleName = dart2js_util.nameOf(mirror);
if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) {
// We name constructors specially -- including the class name again and a
// "-" to separate the constructor from its name (if any).
- simpleName = '${mirrorOwner.simpleName}-$simpleName';
+ simpleName = '${dart2js_util.nameOf(mirrorOwner)}-$simpleName';
}
return getDocgenObject(mirrorOwner, owner).docName + '.' + simpleName;
}
@@ -202,7 +204,7 @@ abstract class MirrorBased {
/// Returns this object's qualified name, but following the conventions
/// we're using in Dartdoc, which is that library names with dots in them
/// have them replaced with hyphens.
- String get docName => owner.docName + '.' + mirror.simpleName;
+ String get docName => owner.docName + '.' + dart2js_util.nameOf(mirror);
/// Returns a list of meta annotations assocated with a mirror.
List<Annotation> _createAnnotations(DeclarationMirror mirror,
@@ -213,7 +215,7 @@ abstract class MirrorBased {
annotationMirrors.forEach((annotation) {
var docgenAnnotation = new Annotation(annotation, owningLibrary);
if (!_SKIPPED_ANNOTATIONS.contains(
- docgenAnnotation.mirror.qualifiedName)) {
+ dart2js_util.qualifiedNameOf(docgenAnnotation.mirror))) {
annotations.add(docgenAnnotation);
}
});
@@ -324,7 +326,7 @@ class _Generator {
librariesToDocument.addAll(
(includeSdk || parseSdk) ? Indexable._sdkLibraries : []);
librariesToDocument.removeWhere(
- (x) => _excluded.contains(x.simpleName));
+ (x) => _excluded.contains(dart2js_util.nameOf(x)));
_documentLibraries(librariesToDocument, includeSdk: includeSdk,
outputToYaml: outputToYaml, append: append, parseSdk: parseSdk,
introFileName: introFileName);
@@ -673,21 +675,23 @@ class Indexable extends MirrorBased {
Indexable(this.mirror) {
this.isPrivate = _isHidden(mirror);
- var map = mirrorToDocgen[this.mirror.qualifiedName];
+ var map = mirrorToDocgen[dart2js_util.qualifiedNameOf(this.mirror)];
if (map == null) map = new Map<String, Set<MirrorBased>>();
var set = map[owner.docName];
if (set == null) set = new Set<MirrorBased>();
set.add(this);
map[owner.docName] = set;
- mirrorToDocgen[this.mirror.qualifiedName] = map;
+ mirrorToDocgen[dart2js_util.qualifiedNameOf(this.mirror)] = map;
}
/** Walk up the owner chain to find the owning library. */
Library _getOwningLibrary(Indexable indexable) {
if (indexable is Library) return indexable;
// TODO: is this needed?
- if (indexable is DummyMirror) return getDocgenObject(indexable.mirror.library);
+ if (indexable is DummyMirror) {
+ return getDocgenObject(dart2js_util.getLibrary(indexable.mirror));
+ }
return _getOwningLibrary(indexable.owner);
}
@@ -745,7 +749,7 @@ class Indexable extends MirrorBased {
set comment(x) => _comment = x;
- String get name => mirror.simpleName;
+ String get name => dart2js_util.nameOf(mirror);
MirrorBased get owner => new DummyMirror(mirror.owner);
@@ -761,7 +765,7 @@ class Indexable extends MirrorBased {
// TODO: refactor OOP
if (this is Library) return '';
var domAnnotation = this.annotations.firstWhere(
- (e) => e.mirror.qualifiedName == 'metadata.DomName',
+ (e) => dart2js_util.qualifiedNameOf(e.mirror) == 'metadata.DomName',
orElse: () => null);
if (domAnnotation == null) return '';
var domName = domAnnotation.parameters.single;
@@ -848,13 +852,14 @@ class Indexable extends MirrorBased {
/// 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(Map<String, VariableMirror> mirrorMap,
+ 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).
- mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
+ mirrors.forEach((VariableMirror mirror) {
if (_Generator._includePrivate || !_isHidden(mirror)) {
+ var mirrorName = dart2js_util.nameOf(mirror);
var variable = new Variable(mirrorName, mirror, owner);
entityMap[variable.docName] = variable;
data[mirrorName] = entityMap[variable.docName];
@@ -867,14 +872,14 @@ class Indexable extends MirrorBased {
/// 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(Map<String, MethodMirror> mirrorMap,
+ Map<String, Method> _createMethods(Iterable<MethodMirror> mirrors,
Indexable owner) {
var group = new Map<String, Method>();
- mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
+ mirrors.forEach((MethodMirror mirror) {
if (_Generator._includePrivate || !mirror.isPrivate) {
var method = new Method(mirror, owner);
entityMap[method.docName] = method;
- group[mirror.simpleName] = method;
+ group[dart2js_util.nameOf(mirror)] = method;
}
});
return group;
@@ -885,13 +890,14 @@ class Indexable extends MirrorBased {
Indexable owner) {
var data = {};
mirrorList.forEach((ParameterMirror mirror) {
- data[mirror.simpleName] = new Parameter(mirror, _getOwningLibrary(owner));
+ data[dart2js_util.nameOf(mirror)] =
+ new Parameter(mirror, _getOwningLibrary(owner));
});
return data;
}
/// Returns a map of [Generic] objects constructed from the class mirror.
- Map<String, Generic> _createGenerics(ClassMirror mirror) {
+ Map<String, Generic> _createGenerics(TypeMirror mirror) {
return new Map.fromIterable(mirror.typeVariables,
key: (e) => e.toString(),
value: (e) => new Generic(e));
@@ -925,11 +931,11 @@ class Indexable extends MirrorBased {
/// An example that contains ._ is dart._collection.dev
// This is because LibraryMirror.isPrivate returns `false` all the time.
bool _isLibraryPrivate(LibraryMirror mirror) {
- var sdkLibrary = LIBRARIES[mirror.simpleName];
+ var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)];
if (sdkLibrary != null) {
return !sdkLibrary.documented;
- } else if (mirror.simpleName.startsWith('_') ||
- mirror.simpleName.contains('._')) {
+ } else if (dart2js_util.nameOf(mirror).startsWith('_') ||
+ dart2js_util.nameOf(mirror).contains('._')) {
return true;
}
return false;
@@ -1115,39 +1121,39 @@ class Library extends Indexable {
Library._(LibraryMirror libraryMirror) : super(libraryMirror) {
var exported = _calcExportedItems(libraryMirror);
- var exportedClasses = exported['classes']..addAll(libraryMirror.classes);
+ var exportedClasses = _addAll(exported['classes'],
+ dart2js_util.typesOf(libraryMirror.declarations));
_findPackage(mirror);
classes = {};
typedefs = {};
errors = {};
- exportedClasses.forEach((String mirrorName, ClassMirror classMirror) {
- if (classMirror.isTypedef) {
+ exportedClasses.forEach((String mirrorName, TypeMirror mirror) {
+ if (mirror is TypedefMirror) {
// This is actually a Dart2jsTypedefMirror, and it does define value,
// but we don't have visibility to that type.
- var mirror = classMirror;
if (_Generator._includePrivate || !mirror.isPrivate) {
entityMap[getDocgenObject(mirror).docName] =
new Typedef(mirror, this);
- typedefs[mirror.simpleName] =
+ typedefs[dart2js_util.nameOf(mirror)] =
entityMap[getDocgenObject(mirror).docName];
}
- } else {
- var clazz = new Class(classMirror, this);
+ } else if (mirror is ClassMirror) {
+ var clazz = new Class(mirror, this);
if (clazz.isError()) {
- errors[classMirror.simpleName] = clazz;
- } else if (classMirror.isClass) {
- classes[classMirror.simpleName] = clazz;
+ errors[dart2js_util.nameOf(mirror)] = clazz;
} else {
- throw new ArgumentError(
- '${classMirror.simpleName} - no class type match. ');
+ classes[dart2js_util.nameOf(mirror)] = clazz;
}
+ } else {
+ throw new ArgumentError(
+ '${dart2js_util.nameOf(mirror)} - no class type match. ');
}
});
- this.functions = _createMethods(exported['methods']
- ..addAll(libraryMirror.functions), this);
- this.variables = _createVariables(exported['variables']
- ..addAll(libraryMirror.variables), this);
+ this.functions = _createMethods(_addAll(exported['methods'],
+ dart2js_util.methodsOf(libraryMirror.declarations)).values, this);
+ this.variables = _createVariables(_addAll(exported['variables'],
+ dart2js_util.variablesOf(libraryMirror.declarations)).values, this);
}
/// Look for the specified name starting with the current member, and
@@ -1163,6 +1169,14 @@ class Library extends Indexable {
return super.findElementInScope(name);
}
+ /// 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 a library's [mirror], determine the name of the package (if any) we
/// believe it came from (because of its file URI).
///
@@ -1226,7 +1240,9 @@ class Library extends Indexable {
String get name => docName;
- String get docName => mirror.qualifiedName.replaceAll('.','-');
+ String get docName {
+ return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-');
+ }
/// For the given library determine what items (if any) are exported.
///
@@ -1246,9 +1262,12 @@ class Library extends Indexable {
if (!showExport) {
// Add all items, and then remove the hidden ones.
// Ex: "export foo hide bar"
- exports['classes'].addAll(export.targetLibrary.classes);
- exports['methods'].addAll(export.targetLibrary.functions);
- exports['variables'].addAll(export.targetLibrary.variables);
+ _addAll(exports['classes'],
+ dart2js_util.typesOf(export.targetLibrary.declarations));
+ _addAll(exports['methods'],
+ dart2js_util.methodsOf(export.targetLibrary.declarations));
+ _addAll(exports['variables'],
+ dart2js_util.variablesOf(export.targetLibrary.declarations));
}
for (CombinatorMirror combinator in export.combinators) {
for (String identifier in combinator.identifiers) {
@@ -1259,7 +1278,7 @@ class Library extends Indexable {
// (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 '
- '${export.targetLibrary.qualifiedName}');
+ '${dart2js_util.qualifiedNameOf(export.targetLibrary)}');
} else {
var subMap = exports['classes'];
if (declaration is MethodMirror) {
@@ -1390,8 +1409,10 @@ class Class extends Indexable implements Comparable {
new Class._possiblyDifferentOwner(classMirror.superclass, owner);
interfaces = superinterfaces.toList();
- variables = _createVariables(classMirror.variables, this);
- methods = _createMethods(classMirror.methods, this);
+ variables = _createVariables(
+ dart2js_util.variablesOf(classMirror.declarations), this);
+ methods = _createMethods(
+ dart2js_util.methodsOf(classMirror.declarations), this);
annotations = _createAnnotations(classMirror, _getOwningLibrary(owner));
generics = _createGenerics(classMirror);
isAbstract = classMirror.isAbstract;
@@ -1537,7 +1558,7 @@ class Class extends Indexable implements Comparable {
/// superclass of the private superclass.
String validSuperclass() {
if (superclass == null) return 'dart.core.Object';
- if (superclass._isVisible) return superclass.qualifiedName;
+ if (superclass._isVisible) return dart2js_util.qualifiedNameOf(superclass);
return superclass.validSuperclass();
}
@@ -1586,9 +1607,9 @@ class Typedef extends Indexable {
Typedef._(TypedefMirror mirror, Library owningLibrary) : super(mirror) {
owner = owningLibrary;
- returnType = getDocgenObject(mirror.value.returnType).docName;
+ returnType = getDocgenObject(mirror.referent.returnType).docName;
generics = _createGenerics(mirror);
- parameters = _createParameters(mirror.value.parameters, owningLibrary);
+ parameters = _createParameters(mirror.referent.parameters, owningLibrary);
annotations = _createAnnotations(mirror, owningLibrary);
}
@@ -1768,7 +1789,8 @@ class Method extends Indexable {
if ((mirror as MethodMirror).isConstructor) {
// We name constructors specially -- including the class name again and a
// "-" to separate the constructor from its name (if any).
- return '${owner.docName}.${mirror.owner.simpleName}-${mirror.simpleName}';
+ return '${owner.docName}.${dart2js_util.nameOf(mirror.owner)}-'
+ '${dart2js_util.nameOf(mirror)}';
}
return super.docName;
}
@@ -1843,11 +1865,11 @@ class Parameter extends MirrorBased {
List<Annotation> annotations;
Parameter(this.mirror, Library owningLibrary) {
- name = mirror.simpleName;
+ name = dart2js_util.nameOf(mirror);
isOptional = mirror.isOptional;
isNamed = mirror.isNamed;
hasDefaultValue = mirror.hasDefaultValue;
- defaultValue = mirror.defaultValue;
+ defaultValue = '${mirror.defaultValue}';
type = new Type(mirror.type, owningLibrary);
annotations = _createAnnotations(mirror, owningLibrary);
}
@@ -1870,7 +1892,7 @@ class Generic extends MirrorBased {
Generic(this.mirror);
Map toMap() => {
'name': mirror.toString(),
- 'type': mirror.upperBound.qualifiedName
+ 'type': dart2js_util.qualifiedNameOf(mirror.upperBound)
};
}
@@ -1911,7 +1933,7 @@ class Type extends MirrorBased {
/// Returns a list of [Type] objects constructed from TypeMirrors.
List<Type> _createTypeGenerics(TypeMirror mirror) {
- if (mirror is ClassMirror && !mirror.isTypedef) {
+ if (mirror is ClassMirror) {
var innerList = [];
mirror.typeArguments.forEach((e) {
innerList.add(new Type(e, owningLibrary));
@@ -1938,7 +1960,7 @@ class Annotation extends MirrorBased {
Annotation(InstanceMirror originalMirror, this.owningLibrary) {
mirror = originalMirror.type;
- parameters = originalMirror.type.variables.values
+ parameters = dart2js_util.variablesOf(originalMirror.type.declarations)
.where((e) => e.isFinal)
.map((e) => originalMirror.getField(e.simpleName).reflectee)
.where((e) => e != null)
« no previous file with comments | « no previous file | pkg/docgen/test/multi_library_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698