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

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: Created 7 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
Index: pkg/docgen/lib/docgen.dart
diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart
index d86bf7131529f4df4f7ac38adb39b8788418a4b0..ba3c6f172ad1c2d0ad8505f06cd6e935ef2c8b8f 100644
--- a/pkg/docgen/lib/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -17,6 +17,7 @@ import 'dart:convert';
import 'dart:io';
import 'dart:async';
+
import 'package:logging/logging.dart';
import 'package:markdown/markdown.dart' as markdown;
import 'package:path/path.dart' as path;
@@ -26,9 +27,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/analyze.dart'
as dart2js;
-import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
+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';
@@ -58,7 +61,7 @@ LibraryMirror _currentLibrary;
ClassMirror _currentClass;
/// Current member being documented to be used for comment links.
-MemberMirror _currentMember;
+DeclarationMirror _currentMember;
/// Support for [:foo:]-style code comments to the markdown parser.
List<markdown.InlineSyntax> markdownSyntaxes =
@@ -380,9 +383,9 @@ void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false,
Library generateLibrary(dart2js.Dart2JsLibraryMirror library) {
_currentLibrary = library;
var result = new Library(docName(library), _commentToHtml(library),
- _classes(library.classes),
- _methods(library.functions),
- _variables(library.variables),
+ _classes(dart2js_util.typesOf(library.declarations)),
+ _methods(dart2js_util.methodsOf(library.declarations)),
+ _variables(dart2js_util.variablesOf(library.declarations)),
_isHidden(library));
_findPackage(result, library);
logger.fine('Generated library for ${result.name}');
@@ -409,11 +412,11 @@ void _writeIndexableToFile(Indexable result, bool outputToYaml) {
/// 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;
@@ -441,7 +444,7 @@ List<Annotation> _annotations(DeclarationMirror mirror) {
e is dart2js.Dart2JsConstructedConstantMirror);
var annotations = [];
annotationMirrors.forEach((annotation) {
- var parameterList = annotation.type.variables.values
+ var parameterList = dart2js_util.variablesOf(annotation.type.declarations)
.where((e) => e.isFinal)
.map((e) => annotation.getField(e.simpleName).reflectee)
.where((e) => e != null)
@@ -538,7 +541,8 @@ String _htmlMdn(String content, String url) {
/// Look for the specified name starting with the current member, and
/// progressively working outward to the current library scope.
String findElementInScope(String name, LibraryMirror currentLibrary,
- ClassMirror currentClass, MemberMirror currentMember) {
+ ClassMirror currentClass,
+ DeclarationMirror currentMember) {
determineLookupFunc(name) => name.contains('.') ?
dart2js_util.lookupQualifiedInScope :
(mirror, name) => mirror.lookupInScope(name);
@@ -627,7 +631,8 @@ List<String> _tokenizeComplexReference(String name) {
/// <a>resolvedFoo</a>&lt;<a>resolved_bar_</a>> rather than an italicized
/// version of resolvedBar.
markdown.Node _fixComplexReference(String name, LibraryMirror currentLibrary,
- ClassMirror currentClass, MemberMirror currentMember) {
+ ClassMirror currentClass,
+ DeclarationMirror currentMember) {
// Parse into multiple elements we can try to resolve.
var tokens = _tokenizeComplexReference(name);
@@ -656,7 +661,8 @@ markdown.Node _fixComplexReference(String name, LibraryMirror currentLibrary,
/// Converts all [foo] references in comments to <a>libraryName.foo</a>.
markdown.Node fixReference(String name, LibraryMirror currentLibrary,
- ClassMirror currentClass, MemberMirror currentMember) {
+ ClassMirror currentClass,
+ DeclarationMirror currentMember) {
// Attempt the look up the whole name up in the scope.
String elementName =
findElementInScope(name, currentLibrary, currentClass, currentMember);
@@ -667,13 +673,14 @@ markdown.Node fixReference(String name, LibraryMirror currentLibrary,
}
/// Returns a map of [Variable] objects constructed from [mirrorMap].
-Map<String, Variable> _variables(Map<String, VariableMirror> mirrorMap) {
+Map<String, Variable> _variables(Iterable<VariableMirror> mirrors) {
var data = {};
// TODO(janicejl): When map to map feature is created, replace the below with
// a filter. Issue(#9590).
floitsch 2014/01/28 19:21:53 Either rewrite TODO, or just do the switch.
- mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
+ mirrors.forEach((VariableMirror mirror) {
_currentMember = mirror;
if (_includePrivate || !_isHidden(mirror)) {
+ var mirrorName = dart2js_util.nameOf(mirror);
entityMap[docName(mirror)] = new Variable(mirrorName, mirror.isFinal,
mirror.isStatic, mirror.isConst, _type(mirror.type),
_commentToHtml(mirror), _annotations(mirror), docName(mirror),
@@ -685,9 +692,9 @@ Map<String, Variable> _variables(Map<String, VariableMirror> mirrorMap) {
}
/// Returns a map of [Method] objects constructed from [mirrorMap].
-MethodGroup _methods(Map<String, MethodMirror> mirrorMap) {
+MethodGroup _methods(Iterable<MethodMirror> mirrors) {
var group = new MethodGroup();
- mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
+ mirrors.forEach((MethodMirror mirror) {
if (_includePrivate || !mirror.isPrivate) {
group.addMethod(mirror);
}
@@ -697,16 +704,19 @@ MethodGroup _methods(Map<String, MethodMirror> mirrorMap) {
/// Returns the [Class] for the given [mirror] has already been created, and if
/// it does not exist, creates it.
-Class _class(ClassMirror mirror) {
+Class _class(ClassSourceMirror mirror) {
var clazz = entityMap[docName(mirror)];
if (clazz == null) {
+ var mirrorName = dart2js_util.nameOf(mirror);
var superclass = mirror.superclass != null ?
_class(mirror.superclass) : null;
var interfaces =
mirror.superinterfaces.map((interface) => _class(interface));
- clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror),
- interfaces.toList(), _variables(mirror.variables),
- _methods(mirror.methods), _annotations(mirror), _generics(mirror),
+ clazz = new Class(mirrorName, superclass, _commentToHtml(mirror),
+ interfaces.toList(),
+ _variables(dart2js_util.variablesOf(mirror.declarations)),
+ _methods(dart2js_util.methodsOf(mirror.declarations)),
+ _annotations(mirror), _generics(mirror),
docName(mirror), _isHidden(mirror), docName(mirror.owner),
mirror.isAbstract);
if (superclass != null) clazz.addInherited(superclass);
@@ -717,11 +727,9 @@ Class _class(ClassMirror mirror) {
}
/// Returns a map of [Class] objects constructed from [mirrorMap].
-ClassGroup _classes(Map<String, ClassMirror> mirrorMap) {
+ClassGroup _classes(Iterable<TypeMirror> mirrors) {
var group = new ClassGroup();
- mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
- group.addClass(mirror);
- });
+ mirrors.forEach(group.addClass);
return group;
}
@@ -729,17 +737,18 @@ ClassGroup _classes(Map<String, ClassMirror> mirrorMap) {
Map<String, Parameter> _parameters(List<ParameterMirror> mirrorList) {
var data = {};
mirrorList.forEach((ParameterMirror mirror) {
+ var mirrorName = dart2js_util.nameOf(mirror);
_currentMember = mirror;
- data[mirror.simpleName] = new Parameter(mirror.simpleName,
+ data[mirrorName] = new Parameter(mirrorName,
mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue,
- _type(mirror.type), mirror.defaultValue,
+ _type(mirror.type), '${mirror.defaultValue}',
_annotations(mirror));
});
return data;
}
/// Returns a map of [Generic] objects constructed from the class mirror.
floitsch 2014/01/28 19:21:53 from the type mirror.
-Map<String, Generic> _generics(ClassMirror mirror) {
+Map<String, Generic> _generics(TypeMirror mirror) {
return new Map.fromIterable(mirror.typeVariables,
key: (e) => e.toString(),
value: (e) => new Generic(e.toString(), e.upperBound.qualifiedName));
@@ -753,7 +762,7 @@ Type _type(TypeMirror mirror) {
/// Returns a list of [Type] objects constructed from TypeMirrors.
List<Type> _typeGenerics(TypeMirror mirror) {
- if (mirror is ClassMirror && !mirror.isTypedef) {
+ if (mirror is ClassMirror) {
var innerList = [];
mirror.typeArguments.forEach((e) {
innerList.add(new Type(docName(e), _typeGenerics(e)));
@@ -1035,21 +1044,22 @@ class ClassGroup {
Map<String, Typedef> typedefs = {};
Map<String, Class> errors = {};
- void addClass(ClassMirror mirror) {
+ void addClass(TypeMirror mirror) {
_currentClass = mirror;
- if (mirror.isTypedef) {
+ var mirrorName = dart2js_util.nameOf(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 = _currentClass;
+ //var mirror = _currentClass;
if (_includePrivate || !mirror.isPrivate) {
- entityMap[docName(mirror)] = new Typedef(mirror.simpleName,
- docName(mirror.value.returnType), _commentToHtml(mirror),
- _generics(mirror), _parameters(mirror.value.parameters),
+ entityMap[docName(mirror)] = new Typedef(mirrorName,
+ docName(mirror.referent.returnType), _commentToHtml(mirror),
+ _generics(mirror), _parameters(mirror.referent.parameters),
_annotations(mirror), docName(mirror), _isHidden(mirror),
docName(mirror.owner));
- typedefs[mirror.simpleName] = entityMap[docName(mirror)];
+ typedefs[mirrorName] = entityMap[docName(mirror)];
}
- } else {
+ } else if (mirror is ClassMirror) {
var clazz = _class(mirror);
// Adding inherited parent variables and methods.
@@ -1062,12 +1072,12 @@ class ClassGroup {
clazz.ensureComments();
if (clazz.isError()) {
- errors[mirror.simpleName] = clazz;
- } else if (mirror.isClass) {
- classes[mirror.simpleName] = clazz;
+ errors[mirrorName] = clazz;
} else {
- throw new ArgumentError('${mirror.simpleName} - no class type match. ');
+ classes[mirrorName] = clazz;
}
+ } else {
+ throw new ArgumentError('${mirrorName} - no class type match. ');
}
}
@@ -1213,7 +1223,8 @@ class MethodGroup {
Map<String, Method> regularMethods = {};
void addMethod(MethodMirror mirror) {
- var method = new Method(mirror.simpleName, mirror.isStatic,
+ var methodName = dart2js_util.nameOf(mirror);
+ var method = new Method(methodName, mirror.isStatic,
mirror.isAbstract, mirror.isConstConstructor, _type(mirror.returnType),
_commentToHtml(mirror), _parameters(mirror.parameters),
_annotations(mirror), docName(mirror), _isHidden(mirror),
@@ -1222,17 +1233,17 @@ class MethodGroup {
entityMap[docName(mirror)] = method;
_currentMember = mirror;
if (mirror.isSetter) {
- setters[mirror.simpleName] = method;
+ setters[methodName] = method;
} else if (mirror.isGetter) {
- getters[mirror.simpleName] = method;
+ getters[methodName] = method;
} else if (mirror.isConstructor) {
- constructors[mirror.simpleName] = method;
+ constructors[methodName] = method;
} else if (mirror.isOperator) {
- operators[mirror.simpleName] = method;
+ operators[methodName] = method;
} else if (mirror.isRegularMethod) {
- regularMethods[mirror.simpleName] = method;
+ regularMethods[methodName] = method;
} else {
- throw new ArgumentError('${mirror.simpleName} - no method type match');
+ throw new ArgumentError('${methodName} - no method type match');
}
}
@@ -1372,13 +1383,13 @@ class Annotation {
/// have them replaced with hyphens.
String docName(DeclarationMirror m) {
if (m is LibraryMirror) {
- return (m as LibraryMirror).qualifiedName.replaceAll('.','-');
+ return dart2js_util.qualifiedNameOf(m).replaceAll('.','-');
}
var owner = m.owner;
- if (owner == null) return m.qualifiedName;
+ if (owner == null) return dart2js_util.qualifiedNameOf(m);
// For the unnamed constructor we just return the class name.
if (m.simpleName == '') return docName(owner);
- return docName(owner) + '.' + m.simpleName;
+ return docName(owner) + '.' + dart2js_util.nameOf(m);
}
/// Remove statics from the map of inherited items before adding them.

Powered by Google App Engine
This is Rietveld 408576698