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.clazz; | 5 library docgen.models.clazz; |
| 6 | 6 |
| 7 import 'dart:collection'; | |
| 8 | |
| 7 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors; | 9 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors; |
| 8 import '../exports/mirrors_util.dart' as dart2js_util; | 10 import '../exports/mirrors_util.dart' as dart2js_util; |
| 9 import '../exports/source_mirrors.dart'; | 11 import '../exports/source_mirrors.dart'; |
| 10 | 12 |
| 11 import '../library_helpers.dart'; | 13 import '../library_helpers.dart'; |
| 12 | 14 |
| 13 import 'dummy_mirror.dart'; | 15 import 'dummy_mirror.dart'; |
| 14 import 'generic.dart'; | 16 import 'generic.dart'; |
| 15 import 'library.dart'; | 17 import 'library.dart'; |
| 16 import 'method.dart'; | 18 import 'method.dart'; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 // The reason we do this madness is the superclass and interface owners may | 81 // The reason we do this madness is the superclass and interface owners may |
| 80 // not be this class's owner!! Example: BaseClient in http pkg. | 82 // not be this class's owner!! Example: BaseClient in http pkg. |
| 81 var superinterfaces = classMirror.superinterfaces.map( | 83 var superinterfaces = classMirror.superinterfaces.map( |
| 82 (interface) => new Class._possiblyDifferentOwner(interface, owner)); | 84 (interface) => new Class._possiblyDifferentOwner(interface, owner)); |
| 83 this._superclass = classMirror.superclass == null? null : | 85 this._superclass = classMirror.superclass == null? null : |
| 84 new Class._possiblyDifferentOwner(classMirror.superclass, owner); | 86 new Class._possiblyDifferentOwner(classMirror.superclass, owner); |
| 85 | 87 |
| 86 interfaces = superinterfaces.toList(); | 88 interfaces = superinterfaces.toList(); |
| 87 variables = createVariables( | 89 variables = createVariables( |
| 88 dart2js_util.variablesOf(classMirror.declarations), this); | 90 dart2js_util.variablesOf(classMirror.declarations), this); |
| 89 methods = createMethods(classMirror.declarations.values.where( | 91 methods = createMethods(new TypeOfIterable<MethodMirror>( |
|
herhut
2014/04/28 08:24:41
Maybe rather expose [anyMethodOf] and use that. Wo
kevmoo
2014/04/28 09:23:01
Done.
| |
| 90 (mirror) => mirror is MethodMirror), this); | 92 classMirror.declarations.values), this); |
| 91 | 93 |
| 92 // Tell superclass that you are a subclass, unless you are not | 94 // Tell superclass that you are a subclass, unless you are not |
| 93 // visible or an intermediary mixin class. | 95 // visible or an intermediary mixin class. |
| 94 if (!classMirror.isNameSynthetic && isVisible && _superclass != null) { | 96 if (!classMirror.isNameSynthetic && isVisible && _superclass != null) { |
| 95 _superclass.addSubclass(this); | 97 _superclass.addSubclass(this); |
| 96 } | 98 } |
| 97 | 99 |
| 98 if (this._superclass != null) addInherited(_superclass); | 100 if (this._superclass != null) addInherited(_superclass); |
| 99 interfaces.forEach((interface) => addInherited(interface)); | 101 interfaces.forEach((interface) => addInherited(interface)); |
| 100 } | 102 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 'methods': expandMethodMap(methods), | 238 'methods': expandMethodMap(methods), |
| 237 'inheritedMethods': expandMethodMap(inheritedMethods), | 239 'inheritedMethods': expandMethodMap(inheritedMethods), |
| 238 'annotations': annotations.map((a) => a.toMap()).toList(), | 240 'annotations': annotations.map((a) => a.toMap()).toList(), |
| 239 'generics': recurseMap(generics) | 241 'generics': recurseMap(generics) |
| 240 }; | 242 }; |
| 241 | 243 |
| 242 int compareTo(Class other) => name.compareTo(other.name); | 244 int compareTo(Class other) => name.compareTo(other.name); |
| 243 | 245 |
| 244 bool isValidMirror(DeclarationMirror mirror) => mirror is ClassMirror; | 246 bool isValidMirror(DeclarationMirror mirror) => mirror is ClassMirror; |
| 245 } | 247 } |
| 248 | |
| 249 class TypeOfIterable<TTarget> extends IterableBase<TTarget> { | |
|
herhut
2014/04/28 08:24:41
Nit: I prefer using just T for the type variable b
| |
| 250 final Iterable _source; | |
| 251 | |
| 252 TypeOfIterable(this._source); | |
| 253 | |
| 254 Iterator<TTarget> get iterator => | |
| 255 new _TypeOfIterator<TTarget>(_source.iterator); | |
| 256 } | |
| 257 | |
| 258 class _TypeOfIterator<TTarget> implements Iterator<TTarget> { | |
| 259 final Iterator _source; | |
| 260 | |
| 261 TTarget get current => _source.current as TTarget; | |
|
herhut
2014/04/28 08:24:41
Do you really need the runtime check via as here?
| |
| 262 | |
| 263 _TypeOfIterator(this._source); | |
| 264 | |
| 265 bool moveNext() { | |
| 266 while(_source.moveNext()) { | |
| 267 if (_source.current is TTarget) { | |
| 268 return true; | |
| 269 } | |
| 270 } | |
| 271 return false; | |
| 272 } | |
| 273 } | |
| OLD | NEW |