Chromium Code Reviews| Index: pkg/dartdoc/lib/dartdoc.dart |
| diff --git a/pkg/dartdoc/lib/dartdoc.dart b/pkg/dartdoc/lib/dartdoc.dart |
| index 5acdba1c74cd346624ab0728e272858cb4173fc5..3a0a15379f5818c615062f01ed07fa1591d6ad57 100644 |
| --- a/pkg/dartdoc/lib/dartdoc.dart |
| +++ b/pkg/dartdoc/lib/dartdoc.dart |
| @@ -195,6 +195,12 @@ class Dartdoc { |
| /** Set this to generate links to the online API. */ |
| bool linkToApi = false; |
| + /** Set this to generate docs for private types and members. */ |
| + bool showPrivate = false; |
| + |
| + /** Set this to inherit from Object. */ |
| + bool inheritFromObject = false; |
| + |
| /** Set this to select the libraries to include in the documentation. */ |
| List<String> includedLibraries = const <String>[]; |
| @@ -572,7 +578,7 @@ class Dartdoc { |
| final types = []; |
| for (InterfaceMirror type in orderByName(library.types.getValues())) { |
| - if (type.isPrivate) continue; |
| + if (!showPrivate && type.isPrivate) continue; |
| var typeInfo = {}; |
| typeInfo[NAME] = type.displayName; |
| @@ -608,7 +614,7 @@ class Dartdoc { |
| List docMembersJson(Map<Object,MemberMirror> memberMap) { |
| final members = []; |
| for (MemberMirror member in orderByName(memberMap.getValues())) { |
| - if (member.isPrivate) continue; |
| + if (!showPrivate && member.isPrivate) continue; |
| var memberInfo = {}; |
| if (member.isField) { |
| @@ -670,7 +676,7 @@ class Dartdoc { |
| final exceptions = <InterfaceMirror>[]; |
| for (InterfaceMirror type in orderByName(library.types.getValues())) { |
| - if (type.isPrivate) continue; |
| + if (!showPrivate && type.isPrivate) continue; |
| if (isException(type)) { |
| exceptions.add(type); |
| @@ -736,7 +742,7 @@ class Dartdoc { |
| final exceptions = <InterfaceMirror>[]; |
| for (InterfaceMirror type in orderByName(library.types.getValues())) { |
| - if (type.isPrivate) continue; |
| + if (!showPrivate && type.isPrivate) continue; |
| if (isException(type)) { |
| exceptions.add(type); |
| @@ -760,7 +766,7 @@ class Dartdoc { |
| endFile(); |
| for (final type in library.types.getValues()) { |
| - if (type.isPrivate) continue; |
| + if (!showPrivate && type.isPrivate) continue; |
| docType(type); |
| } |
| @@ -827,7 +833,6 @@ class Dartdoc { |
| docInheritance(type); |
| docTypedef(type); |
| - docConstructors(type); |
| docMembers(type); |
| writeTypeFooter(); |
| @@ -876,8 +881,13 @@ class Dartdoc { |
| listTypes(types, header) { |
| if (types == null) return; |
| - // Skip private types. |
| - final publicTypes = new List.from(types.filter((t) => !t.isPrivate)); |
| + var publicTypes; |
| + if (showPrivate) { |
| + publicTypes = types; |
| + } else { |
| + // Skip private types. |
| + publicTypes = new List.from(types.filter((t) => !t.isPrivate)); |
| + } |
| if (publicTypes.length == 0) return; |
| writeln('<h3>$header</h3>'); |
| @@ -975,28 +985,6 @@ class Dartdoc { |
| writeln('</div>'); |
| } |
| - /** Document the constructors for [Type], if any. */ |
| - void docConstructors(InterfaceMirror type) { |
| - final constructors = <MethodMirror>[]; |
| - for (var constructor in type.constructors.getValues()) { |
| - if (!constructor.isPrivate) { |
| - constructors.add(constructor); |
| - } |
| - } |
| - |
| - if (constructors.length > 0) { |
| - writeln('<div>'); |
| - writeln('<h3>Constructors</h3>'); |
| - constructors.sort((x, y) => x.constructorName.toUpperCase().compareTo( |
| - y.constructorName.toUpperCase())); |
| - |
| - for (final constructor in constructors) { |
| - docMethod(type, constructor); |
| - } |
| - writeln('</div>'); |
| - } |
| - } |
| - |
| static const operatorOrder = const <String>[ |
| '[]', '[]=', // Indexing. |
| '+', Mirror.UNARY_MINUS, '-', '*', '/', '~/', '%', // Arithmetic. |
| @@ -1025,9 +1013,10 @@ class Dartdoc { |
| final instanceOperators = []; |
| final instanceGetters = new Map<String,MemberMirror>(); |
| final instanceSetters = new Map<String,MemberMirror>(); |
| + final constructors = []; |
| host.declaredMembers.forEach((_, MemberMirror member) { |
| - if (member.isPrivate) return; |
| + if (!showPrivate && member.isPrivate) return; |
| if (host is LibraryMirror || member.isStatic) { |
| if (member is MethodMirror) { |
| if (member.isGetter) { |
| @@ -1046,34 +1035,65 @@ class Dartdoc { |
| if (host is InterfaceMirror) { |
| var iterable = new HierarchyIterable(host, includeType: true); |
| for (InterfaceMirror type in iterable) { |
| + if (!host.isObject && !inheritFromObject && type.isObject) continue; |
| + |
| type.declaredMembers.forEach((_, MemberMirror member) { |
| - if (member.isPrivate) return; |
| - if (!member.isStatic) { |
| - if (member.isField) { |
| - // Fields override both getters and setters. |
| - memberMap.putIfAbsent(member.simpleName, () => member); |
| - memberMap.putIfAbsent('${member.simpleName}=', () => member); |
| - } else { |
| - memberMap.putIfAbsent(member.simpleName, () => member); |
| + if (member.isStatic) return; |
| + if (!showPrivate && member.isPrivate) return; |
| + if (type !== host) { |
| + if (member.isPrivate) { |
| + // Don't inherit private members. |
| + return; |
|
Lasse Reichstein Nielsen
2012/10/17 10:27:50
Returns inside parameter functions are hard to rea
Johnni Winther
2012/10/17 10:47:08
Changed to use flag instead.
|
| + } |
| + if (member.isConstructor) { |
| + // Don't inherit constructors. |
| + return; |
| } |
| } |
| + if (member.isField) { |
| + // Fields override both getters and setters. |
| + memberMap.putIfAbsent(member.simpleName, () => member); |
| + memberMap.putIfAbsent('${member.simpleName}=', () => member); |
| + } else if (member.isConstructor) { |
| + constructors.add(member); |
| + } else { |
| + memberMap.putIfAbsent(member.simpleName, () => member); |
| + } |
| }); |
| } |
| } |
| + bool allMethodsInherited = true; |
| + bool allPropertiesInherited = true; |
| + bool allOperatorsInherited = true; |
| memberMap.forEach((_, MemberMirror member) { |
| if (member is MethodMirror) { |
| if (member.isGetter) { |
| instanceGetters[member.displayName] = member; |
| + if (member.surroundingDeclaration === host) { |
|
Lasse Reichstein Nielsen
2012/10/17 10:27:50
Just use ==, unless there is a compelling reason n
Johnni Winther
2012/10/17 10:47:08
Done.
|
| + allPropertiesInherited = false; |
| + } |
| } else if (member.isSetter) { |
| instanceSetters[member.displayName] = member; |
| + if (member.surroundingDeclaration === host) { |
| + allPropertiesInherited = false; |
| + } |
| } else if (member.isOperator) { |
| instanceOperators.add(member); |
| + if (member.surroundingDeclaration === host) { |
| + allOperatorsInherited = false; |
| + } |
| } else { |
| instanceMethods.add(member); |
| + if (member.surroundingDeclaration === host) { |
| + allMethodsInherited = false; |
| + } |
| } |
| } else if (member is FieldMirror) { |
| instanceGetters[member.displayName] = member; |
| + if (member.surroundingDeclaration === host) { |
| + allPropertiesInherited = false; |
| + } |
| } |
| }); |
| @@ -1084,14 +1104,17 @@ class Dartdoc { |
| docProperties(host, |
| host is LibraryMirror ? 'Properties' : 'Static Properties', |
| - staticGetters, staticSetters); |
| + staticGetters, staticSetters, false); |
|
Lasse Reichstein Nielsen
2012/10/17 10:27:50
"false" is a magic constant. Make it a named param
Johnni Winther
2012/10/17 10:47:08
Done.
|
| docMethods(host, |
| host is LibraryMirror ? 'Functions' : 'Static Methods', |
| - staticMethods); |
| + staticMethods, false); |
| - docProperties(host, 'Properties', instanceGetters, instanceSetters); |
| - docMethods(host, 'Operators', instanceOperators); |
| - docMethods(host, 'Methods', orderByName(instanceMethods)); |
| + docMethods(host, 'Constructors', orderByName(constructors), false); |
| + docProperties(host, 'Properties', instanceGetters, instanceSetters, |
| + allPropertiesInherited); |
| + docMethods(host, 'Operators', instanceOperators, allOperatorsInherited); |
| + docMethods(host, 'Methods', orderByName(instanceMethods), |
| + allMethodsInherited); |
| } |
| /** |
| @@ -1099,7 +1122,8 @@ class Dartdoc { |
| */ |
| void docProperties(ObjectMirror host, String title, |
| Map<String,MemberMirror> getters, |
| - Map<String,MemberMirror> setters) { |
| + Map<String,MemberMirror> setters, |
| + bool allInherited) { |
| if (getters.isEmpty() && setters.isEmpty()) return; |
| var nameSet = new Set<String>.from(getters.getKeys()); |
| @@ -1109,7 +1133,7 @@ class Dartdoc { |
| return a.toLowerCase().compareTo(b.toLowerCase()); |
| }); |
| - writeln('<div>'); |
| + writeln('<div${allInherited ? ' class="inherited"' : ''}>'); |
| writeln('<h3>$title</h3>'); |
| for (String name in nameList) { |
| MemberMirror getter = getters[name]; |
| @@ -1155,9 +1179,10 @@ class Dartdoc { |
| writeln('</div>'); |
| } |
| - void docMethods(ObjectMirror host, String title, List<MethodMirror> methods) { |
| + void docMethods(ObjectMirror host, String title, List<MethodMirror> methods, |
| + bool allInherited) { |
| if (methods.length > 0) { |
| - writeln('<div>'); |
| + writeln('<div${allInherited ? ' class="inherited"' : ''}>'); |
| writeln('<h3>$title</h3>'); |
| for (final method in methods) { |
| docMethod(host, method); |