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

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

Issue 22327007: Class and abstract class merge, preview comments, and error/exception checking (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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/docgen/lib/docgen.dart
diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart
index 4fab37f6b19bc285c587b2d4ebf1aeaac8771807..b31ef40f1c58755ec4783406f84c374de6bdc8b3 100644
--- a/pkg/docgen/lib/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -402,7 +402,8 @@ Class _class(ClassMirror mirror) {
clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror),
interfaces.toList(), _variables(mirror.variables),
_methods(mirror.methods), _annotations(mirror), _generics(mirror),
- mirror.qualifiedName, _isHidden(mirror), mirror.owner.qualifiedName);
+ mirror.qualifiedName, _isHidden(mirror), mirror.owner.qualifiedName,
+ mirror.isAbstract);
if (superclass != null)
clazz.addInherited(superclass);
interfaces.forEach((interface) {
@@ -500,11 +501,6 @@ Map recurseMap(Map inputMap) {
return outputMap;
}
-bool isError(String qualifiedName) {
- return qualifiedName.toLowerCase().contains('error') ||
- qualifiedName.toLowerCase().contains('exception');
-}
-
/**
* A class representing all programming constructs, like library or class.
*/
@@ -580,14 +576,15 @@ class Class extends Indexable {
Map<String, Generic> generics;
Class superclass;
+ bool isAbstract;
/// List of the meta annotations on the class.
List<String> annotations;
Class(String name, this.superclass, String comment, this.interfaces,
this.variables, this.methods, this.annotations, this.generics,
- String qualifiedName, bool isPrivate, String owner) : super(name, comment,
- qualifiedName, isPrivate, owner) {}
+ String qualifiedName, bool isPrivate, String owner, this.isAbstract)
+ : super(name, comment, qualifiedName, isPrivate, owner);
/**
* Returns a list of all the parent classes.
@@ -627,6 +624,20 @@ class Class extends Indexable {
subclasses.add(subclass.qualifiedName);
}
}
+
+ /**
+ * Check if this [Class] is an error or exception.
+ */
+ bool isError() {
+ if (qualifiedName == 'dart.core.Error' ||
+ qualifiedName == 'dart.core.Exception')
+ return true;
+ for (var interface in interfaces) {
+ if (interface.isError()) return true;
+ }
+ if (superclass == null) return false;
+ return superclass.isError();
+ }
/**
* Check that the class exists in the owner library.
@@ -672,6 +683,7 @@ class Class extends Indexable {
'name': name,
'qualifiedName': qualifiedName,
'comment': comment,
+ 'isAbstract' : isAbstract,
'superclass': validSuperclass(),
'implements': interfaces.where(_isVisible)
.map((e) => e.qualifiedName).toList(),
@@ -690,8 +702,7 @@ class Class extends Indexable {
* classes, regular classes, typedefs, and errors.
*/
class ClassGroup {
- Map<String, Class> abstractClasses = {};
- Map<String, Class> regularClasses = {};
+ Map<String, Class> classes = {};
Map<String, Typedef> typedefs = {};
Map<String, Class> errors = {};
@@ -708,7 +719,7 @@ class ClassGroup {
clazz.ensureComments();
- if (isError(mirror.qualifiedName)) {
+ if (clazz.isError()) {
errors[mirror.simpleName] = clazz;
} else if (mirror.isTypedef) {
if (_includePrivate || !mirror.isPrivate) {
@@ -719,10 +730,8 @@ class ClassGroup {
mirror.owner.qualifiedName);
typedefs[mirror.simpleName] = entityMap[mirror.qualifiedName];
}
- } else if (mirror.isAbstract) {
- abstractClasses[mirror.simpleName] = clazz;
} else if (mirror.isClass) {
- regularClasses[mirror.simpleName] = clazz;
+ classes[mirror.simpleName] = clazz;
} else {
throw new ArgumentError('${mirror.simpleName} - no class type match. ');
}
@@ -732,19 +741,27 @@ class ClassGroup {
* Checks if the given name is a key for any of the Class Maps.
*/
bool containsKey(String name) {
- return abstractClasses.containsKey(name) ||
- regularClasses.containsKey(name) ||
- errors.containsKey(name);
+ return classes.containsKey(name) || errors.containsKey(name);
}
+ /**
+ * Creates a [Map] with [Class] names and a preview comment.
+ */
+ Map classMap(Class clazz) {
+ var finalMap = { 'name' : clazz.qualifiedName };
+ if (clazz.comment != '') {
+ var index = clazz.comment.indexOf('</p>');
+ finalMap['preview'] = '${clazz.comment.substring(0, index)}</p>';
+ }
+ return finalMap;
+ }
+
Map toMap() => {
- 'abstract': abstractClasses.values.where(_isVisible)
- .map((e) => e.qualifiedName).toList(),
- 'class': regularClasses.values.where(_isVisible)
- .map((e) => e.qualifiedName).toList(),
+ 'class': classes.values.where(_isVisible)
+ .map((e) => classMap(e)).toList(),
'typedef': recurseMap(typedefs),
'error': errors.values.where(_isVisible)
- .map((e) => e.qualifiedName).toList()
+ .map((e) => classMap(e)).toList()
};
}
@@ -761,8 +778,8 @@ class Typedef extends Indexable {
Typedef(String name, this.returnType, String comment, this.generics,
this.parameters, this.annotations,
- String qualifiedName, bool isPrivate, String owner) : super(name, comment,
- qualifiedName, isPrivate, owner) {}
+ String qualifiedName, bool isPrivate, String owner)
+ : super(name, comment, qualifiedName, isPrivate, owner);
Map toMap() => {
'name': name,
« 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