| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// **docgen** is a tool for creating machine readable representations of Dart | 5 /// **docgen** is a tool for creating machine readable representations of Dart |
| 6 /// code metadata, including: classes, members, comments and annotations. | 6 /// code metadata, including: classes, members, comments and annotations. |
| 7 /// | 7 /// |
| 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. | 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 9 /// | 9 /// |
| 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] | 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 'functions': functions.toMap(), | 897 'functions': functions.toMap(), |
| 898 'classes': classes.toMap(), | 898 'classes': classes.toMap(), |
| 899 'packageName': packageName, | 899 'packageName': packageName, |
| 900 'packageIntro' : packageIntro | 900 'packageIntro' : packageIntro |
| 901 }; | 901 }; |
| 902 | 902 |
| 903 String get typeName => 'library'; | 903 String get typeName => 'library'; |
| 904 } | 904 } |
| 905 | 905 |
| 906 /// A class containing contents of a Dart class. | 906 /// A class containing contents of a Dart class. |
| 907 class Class extends Indexable { | 907 class Class extends Indexable implements Comparable { |
| 908 | 908 |
| 909 /// List of the names of interfaces that this class implements. | 909 /// List of the names of interfaces that this class implements. |
| 910 List<Class> interfaces = []; | 910 List<Class> interfaces = []; |
| 911 | 911 |
| 912 /// Names of classes that extends or implements this class. | 912 /// Names of classes that extends or implements this class. |
| 913 Set<String> subclasses = new Set<String>(); | 913 Set<Class> subclasses = new Set<Class>(); |
| 914 | 914 |
| 915 /// Top-level variables in the class. | 915 /// Top-level variables in the class. |
| 916 Map<String, Variable> variables; | 916 Map<String, Variable> variables; |
| 917 | 917 |
| 918 /// Inherited variables in the class. | 918 /// Inherited variables in the class. |
| 919 Map<String, Variable> inheritedVariables = {}; | 919 Map<String, Variable> inheritedVariables = {}; |
| 920 | 920 |
| 921 /// Methods in the class. | 921 /// Methods in the class. |
| 922 MethodGroup methods; | 922 MethodGroup methods; |
| 923 | 923 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 /// | 962 /// |
| 963 /// If [this] is private, it will add the subclass to the list of subclasses i
n | 963 /// If [this] is private, it will add the subclass to the list of subclasses i
n |
| 964 /// the superclasses. | 964 /// the superclasses. |
| 965 void addSubclass(Class subclass) { | 965 void addSubclass(Class subclass) { |
| 966 if (!_includePrivate && isPrivate) { | 966 if (!_includePrivate && isPrivate) { |
| 967 if (superclass != null) superclass.addSubclass(subclass); | 967 if (superclass != null) superclass.addSubclass(subclass); |
| 968 interfaces.forEach((interface) { | 968 interfaces.forEach((interface) { |
| 969 interface.addSubclass(subclass); | 969 interface.addSubclass(subclass); |
| 970 }); | 970 }); |
| 971 } else { | 971 } else { |
| 972 subclasses.add(subclass.qualifiedName); | 972 subclasses.add(subclass); |
| 973 } | 973 } |
| 974 } | 974 } |
| 975 | 975 |
| 976 /// Check if this [Class] is an error or exception. | 976 /// Check if this [Class] is an error or exception. |
| 977 bool isError() { | 977 bool isError() { |
| 978 if (qualifiedName == 'dart-core.Error' || | 978 if (qualifiedName == 'dart-core.Error' || |
| 979 qualifiedName == 'dart-core.Exception') | 979 qualifiedName == 'dart-core.Exception') |
| 980 return true; | 980 return true; |
| 981 for (var interface in interfaces) { | 981 for (var interface in interfaces) { |
| 982 if (interface.isError()) return true; | 982 if (interface.isError()) return true; |
| 983 } | 983 } |
| 984 if (superclass == null) return false; | 984 if (superclass == null) return false; |
| 985 return superclass.isError(); | 985 return superclass.isError(); |
| 986 } | 986 } |
| 987 | 987 |
| 988 /// Check that the class exists in the owner library. | 988 /// Check that the class exists in the owner library. |
| 989 /// | 989 /// |
| 990 /// If it does not exist in the owner library, it is a mixin applciation and | 990 /// If it does not exist in the owner library, it is a mixin applciation and |
| 991 /// should be removed. | 991 /// should be removed. |
| 992 void makeValid() { | 992 void makeValid() { |
| 993 var library = entityMap[owner]; | 993 var library = entityMap[owner]; |
| 994 if (library != null && !library.classes.containsKey(name)) { | 994 if (library != null && !library.classes.containsKey(name)) { |
| 995 this.isPrivate = true; | 995 this.isPrivate = true; |
| 996 // Since we are now making the mixin a private class, make all elements | 996 // Since we are now making the mixin a private class, make all elements |
| 997 // with the mixin as an owner private too. | 997 // with the mixin as an owner private too. |
| 998 entityMap.values.where((e) => e.owner == qualifiedName) | 998 entityMap.values.where((e) => e.owner == qualifiedName) |
| 999 .forEach((element) => element.isPrivate = true); | 999 .forEach((element) => element.isPrivate = true); |
| 1000 // Move the subclass up to the next public superclass | 1000 // Move the subclass up to the next public superclass |
| 1001 subclasses.forEach((subclass) => addSubclass(entityMap[subclass])); | 1001 subclasses.forEach((subclass) => addSubclass(subclass)); |
| 1002 } | 1002 } |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 /// Makes sure that all methods with inherited equivalents have comments. | 1005 /// Makes sure that all methods with inherited equivalents have comments. |
| 1006 void ensureComments() { | 1006 void ensureComments() { |
| 1007 inheritedMethods.forEach((qualifiedName, inheritedMethod) { | 1007 inheritedMethods.forEach((qualifiedName, inheritedMethod) { |
| 1008 var method = methods[qualifiedName]; | 1008 var method = methods[qualifiedName]; |
| 1009 if (method != null) method.ensureCommentFor(inheritedMethod); | 1009 if (method != null) method.ensureCommentFor(inheritedMethod); |
| 1010 }); | 1010 }); |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 /// If a class extends a private superclass, find the closest public superclas
s | 1013 /// If a class extends a private superclass, find the closest public superclas
s |
| 1014 /// of the private superclass. | 1014 /// of the private superclass. |
| 1015 String validSuperclass() { | 1015 String validSuperclass() { |
| 1016 if (superclass == null) return 'dart.core.Object'; | 1016 if (superclass == null) return 'dart.core.Object'; |
| 1017 if (_isVisible(superclass)) return superclass.qualifiedName; | 1017 if (_isVisible(superclass)) return superclass.qualifiedName; |
| 1018 return superclass.validSuperclass(); | 1018 return superclass.validSuperclass(); |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 /// Generates a map describing the [Class] object. | 1021 /// Generates a map describing the [Class] object. |
| 1022 Map toMap() => { | 1022 Map toMap() => { |
| 1023 'name': name, | 1023 'name': name, |
| 1024 'qualifiedName': qualifiedName, | 1024 'qualifiedName': qualifiedName, |
| 1025 'comment': comment, | 1025 'comment': comment, |
| 1026 'isAbstract' : isAbstract, | 1026 'isAbstract' : isAbstract, |
| 1027 'superclass': validSuperclass(), | 1027 'superclass': validSuperclass(), |
| 1028 'implements': interfaces.where(_isVisible) | 1028 'implements': interfaces.where(_isVisible) |
| 1029 .map((e) => e.qualifiedName).toList(), | 1029 .map((e) => e.qualifiedName).toList(), |
| 1030 'subclass': subclasses.toList(), | 1030 'subclass': (subclasses.toList()..sort()) |
| 1031 .map((x) => x.qualifiedName).toList(), |
| 1031 'variables': recurseMap(variables), | 1032 'variables': recurseMap(variables), |
| 1032 'inheritedVariables': recurseMap(inheritedVariables), | 1033 'inheritedVariables': recurseMap(inheritedVariables), |
| 1033 'methods': methods.toMap(), | 1034 'methods': methods.toMap(), |
| 1034 'inheritedMethods': inheritedMethods.toMap(), | 1035 'inheritedMethods': inheritedMethods.toMap(), |
| 1035 'annotations': annotations.map((a) => a.toMap()).toList(), | 1036 'annotations': annotations.map((a) => a.toMap()).toList(), |
| 1036 'generics': recurseMap(generics) | 1037 'generics': recurseMap(generics) |
| 1037 }; | 1038 }; |
| 1039 |
| 1040 int compareTo(aClass) => name.compareTo(aClass.name); |
| 1038 } | 1041 } |
| 1039 | 1042 |
| 1040 /// A container to categorize classes into the following groups: abstract | 1043 /// A container to categorize classes into the following groups: abstract |
| 1041 /// classes, regular classes, typedefs, and errors. | 1044 /// classes, regular classes, typedefs, and errors. |
| 1042 class ClassGroup { | 1045 class ClassGroup { |
| 1043 Map<String, Class> classes = {}; | 1046 Map<String, Class> classes = {}; |
| 1044 Map<String, Typedef> typedefs = {}; | 1047 Map<String, Typedef> typedefs = {}; |
| 1045 Map<String, Class> errors = {}; | 1048 Map<String, Class> errors = {}; |
| 1046 | 1049 |
| 1047 void addClass(ClassMirror mirror) { | 1050 void addClass(ClassMirror mirror) { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 /// Remove statics from the map of inherited items before adding them. | 1396 /// Remove statics from the map of inherited items before adding them. |
| 1394 Map _filterStatics(Map items) { | 1397 Map _filterStatics(Map items) { |
| 1395 var result = {}; | 1398 var result = {}; |
| 1396 items.forEach((name, item) { | 1399 items.forEach((name, item) { |
| 1397 if (!item.isStatic) { | 1400 if (!item.isStatic) { |
| 1398 result[name] = item; | 1401 result[name] = item; |
| 1399 } | 1402 } |
| 1400 }); | 1403 }); |
| 1401 return result; | 1404 return result; |
| 1402 } | 1405 } |
| OLD | NEW |