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

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

Issue 21096002: added inherited methods and variables (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 | « pkg/docgen/example/test.dart ('k') | no next file » | 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 6ad260988ed81ff2477cc6d544e4242bf6a8e149..b818b2f5c23783508c3e4e5274f107d133bb8a72 100644
--- a/pkg/docgen/lib/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -53,6 +53,14 @@ markdown.Resolver linkResolver;
/// Index of all the qualified names documented.
Set<String> qualifiedNameIndex = new Set<String>();
+/// Index of all the classes created. This is to ensure that no class is
+/// created more than once.
+Map<String, Class> classMap = new Map<String, Class>();
+
+/// Index of all the libraries that needs to be outputted after all objects are
Alan Knight 2013/07/29 20:29:01 Nit. While contemporary dictionaries seem to consi
janicejl 2013/07/30 00:41:31 Done.
+/// created and updated.
+Set<Library> libraries = new Set<Library>();
+
/**
* Docgen constructor initializes the link resolver for markdown parsing.
* Also initializes the command line arguments.
@@ -195,16 +203,18 @@ Future<MirrorSystem> _analyzeLibraries(List<String> libraries,
/**
* Creates documentation for filtered libraries.
*/
-void _documentLibraries(List<LibraryMirror> libraries,
+void _documentLibraries(List<LibraryMirror> libs,
{bool includeSdk:false, bool includePrivate:false, bool
outputToYaml:true}) {
- libraries.forEach((lib) {
+ libs.forEach((lib) {
// Files belonging to the SDK have a uri that begins with 'dart:'.
if (includeSdk || !lib.uri.toString().startsWith('dart:')) {
var library = generateLibrary(lib, includePrivate: includePrivate);
- _writeLibraryToFile(library, outputToYaml);
+ libraries.add(library);
}
});
+ // Output libraries to file after all information is generated.
+ libraries.forEach((lib) => _writeLibraryToFile(lib, outputToYaml));
// Outputs a text file with a list of files available after creating all
// the libraries. This will help the viewer know what files are available
// to read in.
@@ -232,7 +242,6 @@ void _writeLibraryToFile(Library result, bool outputToYaml) {
} else {
_writeToFile(stringify(result.toMap()), '${result.name}.json');
}
-
}
/**
@@ -360,15 +369,71 @@ Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap,
mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
if (includePrivate || !mirror.isPrivate) {
+ _currentClass = mirror;
var superclass = (mirror.superclass != null) ?
mirror.superclass.qualifiedName : '';
var interfaces =
mirror.superinterfaces.map((interface) => interface.qualifiedName);
- var clazz = new Class(mirrorName, superclass, _getComment(mirror),
- interfaces.toList(), _getVariables(mirror.variables, includePrivate),
- _getMethods(mirror.methods, includePrivate),
- _getAnnotations(mirror), _getGenerics(mirror), mirror.qualifiedName);
- _currentClass = mirror;
+ var clazz = classMap[mirror.qualifiedName];
+ if (clazz == null) {
Alan Knight 2013/07/29 20:29:01 This method is getting very long, and it looks lik
janicejl 2013/07/30 00:41:31 Done.
+ clazz = new Class(mirrorName, superclass, _getComment(mirror),
+ interfaces.toList(),
+ _getVariables(mirror.variables, includePrivate),
+ _getMethods(mirror.methods, includePrivate),
+ _getAnnotations(mirror),
+ _getGenerics(mirror), mirror.qualifiedName);
+ classMap[mirror.qualifiedName] = clazz;
+ }
+
+ // Adding inherited superclass variables and methods.
+ if (superclass != '') {
+ var superclazz = classMap[superclass];
+ if (superclazz == null) {
+ var supersuperclass = (mirror.superclass.superclass != null) ?
+ mirror.superclass.superclass.qualifiedName : '';
+ var superclassInterfaces = mirror.superclass.superinterfaces
+ .map((interface) => interface.qualifiedName);
+ superclazz = new Class(mirror.superclass.simpleName, supersuperclass,
+ _getComment(mirror.superclass), superclassInterfaces.toList(),
+ _getVariables(mirror.superclass.variables, includePrivate),
+ _getMethods(mirror.superclass.methods, includePrivate),
+ _getAnnotations(mirror.superclass),
+ _getGenerics(mirror.superclass), mirror.superclass.qualifiedName);
+ classMap[mirror.superclass.qualifiedName] = superclazz;
+ }
+ superclazz.subclasses.add(clazz.qualifiedName);
+ superclazz.methods.keys.forEach((key) {
+ if (key != 'constructors') {
Alan Knight 2013/07/29 20:29:01 This seems like it's crying out for an accessor li
janicejl 2013/07/30 00:41:31 Done.
+ clazz.inheritedMethods[key].addAll(superclazz.methods[key]);
+ }
+ });
+ }
+
+ // Adding inherited interface variables and methods.
+ mirror.superinterfaces.forEach((interface) {
+ var interfaceClass = classMap[interface.qualifiedName];
+ if (interfaceClass == null) {
+ var interfaceSuperClass = (interface.superclass != null) ?
+ interface.superclass.qualifiedName : '';
+ var interfaceInterfaces = interface.superinterfaces
+ .map((i) => i.qualifiedName);
+ interfaceClass = new Class(interface.simpleName,
+ interfaceSuperClass, _getComment(interface),
+ interfaceInterfaces.toList(),
+ _getVariables(interface.variables, includePrivate),
+ _getMethods(interface.methods, includePrivate),
+ _getAnnotations(interface), _getGenerics(interface),
+ interface.qualifiedName);
+ classMap[interface.qualifiedName] = interfaceClass;
+ }
+ interfaceClass.subclasses.add(clazz.qualifiedName);
+ clazz.inheritedVariables.addAll(interfaceClass.variables);
+ interfaceClass.methods.keys.forEach((key) {
+ if (key != 'constructors') {
+ clazz.inheritedMethods[key].addAll(interfaceClass.methods[key]);
+ }
+ });
+ });
if (isError(mirror.qualifiedName)) {
errors[mirrorName] = clazz;
@@ -527,13 +592,28 @@ class Class extends Indexable {
/// List of the names of interfaces that this class implements.
List<String> interfaces;
+
+ /// Names of classes that extends or implements this class.
+ List<String> subclasses = [];
/// Top-level variables in the class.
Map<String, Variable> variables;
+
+ /// Inherited variables in the class.
+ Map<String, Variable> inheritedVariables = {};
/// Methods in the class.
Map<String, Map<String, Method>> methods;
+ /// Inherited methods in the class.
Alan Knight 2013/07/29 20:29:01 I'm not clear why methods in the class itself seem
+ Map<String, Map<String, Method>> inheritedMethods = {
+ 'setters': {},
Alan Knight 2013/07/29 20:29:01 It seems like it might be nicer if this an object,
janicejl 2013/07/30 00:41:31 Done.
+ 'getters': {},
+ 'constructors': {},
+ 'operators': {},
+ 'methods': {}
+ };
+
/// Generic infomation about the class.
Map<String, Generic> generics;
@@ -553,8 +633,11 @@ class Class extends Indexable {
'comment': comment,
'superclass': superclass,
'implements': new List.from(interfaces),
+ 'subclass': new List.from(subclasses),
'variables': recurseMap(variables),
+ 'inheritedvariables': recurseMap(inheritedVariables),
'methods': recurseMap(methods),
+ 'inheritedmethods': recurseMap(inheritedMethods),
'annotations': new List.from(annotations),
'generics': recurseMap(generics)
};
« no previous file with comments | « pkg/docgen/example/test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698