Skip to content

Commit 62b1f47

Browse files
committed
Catergorized classes to abstract, class, typedef, and error/exception
[email protected] Review URL: https://codereview.chromium.org//19708003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25160 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 1cfac5f commit 62b1f47

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

pkg/docgen/lib/docgen.dart

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -344,38 +344,61 @@ Map<String, Map<String, Method>> _getMethods
344344
} else if (mirror.isRegularMethod) {
345345
methods[mirrorName] = method;
346346
} else {
347-
throw new StateError('${mirror.qualifiedName} - no method type match');
347+
throw new ArgumentError('$mirrorName - no method type match');
348348
}
349349
}
350350
});
351-
return {'setters' : setters,
352-
'getters' : getters,
353-
'constructors' : constructors,
354-
'operators' : operators,
355-
'methods' : methods};
351+
return {
352+
'setters': setters,
353+
'getters': getters,
354+
'constructors': constructors,
355+
'operators': operators,
356+
'methods': methods
357+
};
356358
}
357359

358360
/**
359361
* Returns a map of [Class] objects constructed from inputted mirrors.
360362
*/
361363
Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap,
362364
bool includePrivate) {
363-
var data = {};
365+
366+
var abstract = {};
367+
var classes = {};
368+
var typedefs = {};
369+
var errors = {};
370+
364371
mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
365372
if (includePrivate || !mirror.isPrivate) {
366-
_currentClass = mirror;
367373
var superclass = (mirror.superclass != null) ?
368374
mirror.superclass.qualifiedName : '';
369375
var interfaces =
370376
mirror.superinterfaces.map((interface) => interface.qualifiedName);
371-
data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
372-
mirror.isTypedef, _getComment(mirror), interfaces.toList(),
373-
_getVariables(mirror.variables, includePrivate),
377+
var clazz = new Class(mirrorName, superclass, _getComment(mirror),
378+
interfaces.toList(), _getVariables(mirror.variables, includePrivate),
374379
_getMethods(mirror.methods, includePrivate),
375380
_getAnnotations(mirror), mirror.qualifiedName);
381+
_currentClass = mirror;
382+
383+
if (isError(mirror.qualifiedName)) {
384+
errors[mirrorName] = clazz;
385+
} else if (mirror.isTypedef) {
386+
typedefs[mirrorName] = clazz;
387+
} else if (mirror.isAbstract) {
388+
abstract[mirrorName] = clazz;
389+
} else if (mirror.isClass) {
390+
classes[mirrorName] = clazz;
391+
} else {
392+
throw new ArgumentError('$mirrorName - no class style match. ');
393+
}
376394
}
377395
});
378-
return data;
396+
return {
397+
'abstract': abstract,
398+
'class': classes,
399+
'typedef': typedefs,
400+
'error': errors
401+
};
379402
}
380403

381404
/**
@@ -424,6 +447,11 @@ Map recurseMap(Map inputMap) {
424447
return outputMap;
425448
}
426449

450+
bool isError(String qualifiedName) {
451+
return qualifiedName.toLowerCase().contains('error') ||
452+
qualifiedName.toLowerCase().contains('exception');
453+
}
454+
427455
/**
428456
* A class representing all programming constructs, like library or class.
429457
*/
@@ -489,24 +517,20 @@ class Class extends Indexable {
489517

490518
String name;
491519
String superclass;
492-
bool isAbstract;
493-
bool isTypedef;
494520

495521
/// List of the meta annotations on the class.
496522
List<String> annotations;
497523

498-
Class(this.name, this.superclass, this.isAbstract, this.isTypedef,
499-
this.comment, this.interfaces, this.variables, this.methods,
500-
this.annotations, String qualifiedName) : super(qualifiedName) {}
524+
Class(this.name, this.superclass, this.comment, this.interfaces,
525+
this.variables, this.methods, this.annotations,
526+
String qualifiedName) : super(qualifiedName) {}
501527

502528
/// Generates a map describing the [Class] object.
503529
Map toMap() {
504530
var classMap = {};
505531
classMap['name'] = name;
506532
classMap['comment'] = comment;
507533
classMap['superclass'] = superclass;
508-
classMap['abstract'] = isAbstract.toString();
509-
classMap['typedef'] = isTypedef.toString();
510534
classMap['implements'] = new List.from(interfaces);
511535
classMap['variables'] = recurseMap(variables);
512536
classMap['methods'] = recurseMap(methods);

pkg/docgen/test/single_library_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ main() {
5454
includePrivate: true);
5555
expect(library is Library, isTrue);
5656

57-
var classes = library.classes.values;
57+
var classTypes = library.classes.values;
58+
expect(classTypes.every((e) => e is Map), isTrue);
59+
60+
var classes = [];
61+
classTypes.forEach((e) => classes.addAll(e.values));
5862
expect(classes.every((e) => e is Class), isTrue);
5963

6064
var classMethodTypes = [];

0 commit comments

Comments
 (0)