Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library docgen.models.method; | 5 library docgen.models.method; |
| 6 | 6 |
| 7 import 'package:markdown/markdown.dart' as markdown; | 7 import 'package:markdown/markdown.dart' as markdown; |
| 8 | 8 |
| 9 import '../exports/mirrors_util.dart' as dart2js_util; | 9 import '../exports/mirrors_util.dart' as dart2js_util; |
| 10 import '../exports/source_mirrors.dart'; | 10 import '../exports/source_mirrors.dart'; |
| 11 | 11 |
| 12 import '../library_helpers.dart'; | 12 import '../library_helpers.dart'; |
| 13 | 13 |
| 14 import 'class.dart'; | 14 import 'class.dart'; |
| 15 import 'doc_gen_type.dart'; | 15 import 'doc_gen_type.dart'; |
| 16 import 'dummy_mirror.dart'; | 16 import 'dummy_mirror.dart'; |
| 17 import 'indexable.dart'; | 17 import 'indexable.dart'; |
| 18 import 'model_helpers.dart'; | 18 import 'model_helpers.dart'; |
| 19 import 'owned_indexable.dart'; | 19 import 'owned_indexable.dart'; |
| 20 import 'parameter.dart'; | 20 import 'parameter.dart'; |
| 21 | 21 |
| 22 | 22 |
| 23 /// A class containing properties of a Dart method. | 23 /// A class containing properties of a Dart method. |
| 24 class Method extends OwnedIndexable { | 24 class Method extends OwnedIndexable<MethodMirror> { |
| 25 | 25 |
| 26 /// Parameters for this method. | 26 /// Parameters for this method. |
| 27 final Map<String, Parameter> parameters; | 27 final Map<String, Parameter> parameters; |
| 28 | 28 |
| 29 final bool isStatic; | 29 final bool isStatic; |
| 30 final bool isAbstract; | 30 final bool isAbstract; |
| 31 final bool isConst; | 31 final bool isConst; |
| 32 final DocGenType returnType; | 32 final DocGenType returnType; |
| 33 Method methodInheritedFrom; | 33 Method methodInheritedFrom; |
| 34 | 34 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (owner != null) { | 78 if (owner != null) { |
| 79 var result = owner.findElementInScope(name); | 79 var result = owner.findElementInScope(name); |
| 80 if (result != null) return result; | 80 if (result != null) return result; |
| 81 } | 81 } |
| 82 return super.findElementInScope(name); | 82 return super.findElementInScope(name); |
| 83 } | 83 } |
| 84 | 84 |
| 85 String get docName { | 85 String get docName { |
| 86 if ((mirror as MethodMirror).isConstructor) { | 86 if (mirror.isConstructor) { |
|
kevmoo
2014/04/20 21:34:54
Benefit of defining the generic type of 'mirror'
| |
| 87 // We name constructors specially -- including the class name again and a | 87 // We name constructors specially -- including the class name again and a |
| 88 // "-" to separate the constructor from its name (if any). | 88 // "-" to separate the constructor from its name (if any). |
| 89 return '${owner.docName}.${dart2js_util.nameOf(mirror.owner)}-' | 89 return '${owner.docName}.${dart2js_util.nameOf(mirror.owner)}-' |
| 90 '${dart2js_util.nameOf(mirror)}'; | 90 '${dart2js_util.nameOf(mirror)}'; |
| 91 } | 91 } |
| 92 return super.docName; | 92 return super.docName; |
| 93 } | 93 } |
| 94 | 94 |
| 95 String get fileName => packagePrefix + docName; | 95 String get fileName => packagePrefix + docName; |
| 96 | 96 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 117 originallyInheritedFrom.docName), | 117 originallyInheritedFrom.docName), |
| 118 'static': isStatic, | 118 'static': isStatic, |
| 119 'abstract': isAbstract, | 119 'abstract': isAbstract, |
| 120 'constant': isConst, | 120 'constant': isConst, |
| 121 'return': [returnType.toMap()], | 121 'return': [returnType.toMap()], |
| 122 'parameters': recurseMap(parameters), | 122 'parameters': recurseMap(parameters), |
| 123 'annotations': annotations.map((a) => a.toMap()).toList() | 123 'annotations': annotations.map((a) => a.toMap()).toList() |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 String get typeName { | 126 String get typeName { |
| 127 MethodMirror theMirror = mirror; | 127 if (mirror.isConstructor) return 'constructor'; |
|
kevmoo
2014/04/20 21:34:54
Benefit of defining the generic type of 'mirror'
| |
| 128 if (theMirror.isConstructor) return 'constructor'; | 128 if (mirror.isGetter) return 'getter'; |
| 129 if (theMirror.isGetter) return 'getter'; | 129 if (mirror.isSetter) return 'setter'; |
| 130 if (theMirror.isSetter) return 'setter'; | 130 if (mirror.isOperator) return 'operator'; |
| 131 if (theMirror.isOperator) return 'operator'; | |
| 132 return 'method'; | 131 return 'method'; |
| 133 } | 132 } |
| 134 | 133 |
| 135 String get comment { | 134 String get comment { |
| 136 if (commentField != null) return commentField; | 135 if (commentField != null) return commentField; |
| 137 if (owner is Class) { | 136 if (owner is Class) { |
| 138 (owner as Class).ensureComments(); | 137 (owner as Class).ensureComments(); |
| 139 } | 138 } |
| 140 var result = super.comment; | 139 var result = super.comment; |
| 141 if (result == '' && methodInheritedFrom != null) { | 140 if (result == '' && methodInheritedFrom != null) { |
| 142 // This should be NOT from the MIRROR, but from the COMMENT. | 141 // This should be NOT from the MIRROR, but from the COMMENT. |
| 143 methodInheritedFrom.comment; // Ensure comment field has been populated. | 142 methodInheritedFrom.comment; // Ensure comment field has been populated. |
| 144 unresolvedComment = methodInheritedFrom.unresolvedComment; | 143 unresolvedComment = methodInheritedFrom.unresolvedComment; |
| 145 | 144 |
| 146 comment = unresolvedComment == null ? '' : | 145 comment = unresolvedComment == null ? '' : |
| 147 markdown.markdownToHtml(unresolvedComment.trim(), | 146 markdown.markdownToHtml(unresolvedComment.trim(), |
| 148 linkResolver: fixReference, inlineSyntaxes: MARKDOWN_SYNTAXES); | 147 linkResolver: fixReference, inlineSyntaxes: MARKDOWN_SYNTAXES); |
| 149 commentInheritedFrom = comment != '' ? | 148 commentInheritedFrom = comment != '' ? |
| 150 methodInheritedFrom.commentInheritedFrom : ''; | 149 methodInheritedFrom.commentInheritedFrom : ''; |
| 151 result = comment; | 150 result = comment; |
| 152 } | 151 } |
| 153 return result; | 152 return result; |
| 154 } | 153 } |
| 155 | 154 |
| 156 bool isValidMirror(DeclarationMirror mirror) => mirror is MethodMirror; | 155 bool isValidMirror(DeclarationMirror mirror) => mirror is MethodMirror; |
| 157 } | 156 } |
| OLD | NEW |