| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library docgen.models.variable; | |
| 6 | |
| 7 import '../exports/source_mirrors.dart'; | |
| 8 | |
| 9 import '../library_helpers.dart'; | |
| 10 | |
| 11 import 'class.dart'; | |
| 12 import 'doc_gen_type.dart'; | |
| 13 import 'dummy_mirror.dart'; | |
| 14 import 'indexable.dart'; | |
| 15 import 'owned_indexable.dart'; | |
| 16 | |
| 17 | |
| 18 /// A class containing properties of a Dart variable. | |
| 19 class Variable extends OwnedIndexable<VariableMirror> { | |
| 20 final bool isFinal; | |
| 21 final bool isStatic; | |
| 22 final bool isConst; | |
| 23 final DocGenType type; | |
| 24 final String name; | |
| 25 | |
| 26 factory Variable(String name, VariableMirror mirror, Indexable owner) { | |
| 27 var variable = getDocgenObject(mirror, owner); | |
| 28 if (variable is DummyMirror) { | |
| 29 return new Variable._(name, mirror, owner); | |
| 30 } | |
| 31 return variable; | |
| 32 } | |
| 33 | |
| 34 Variable._(this.name, VariableMirror mirror, Indexable owner) | |
| 35 : isFinal = mirror.isFinal, | |
| 36 isStatic = mirror.isStatic, | |
| 37 isConst = mirror.isConst, | |
| 38 type = new DocGenType(mirror.type, owner.owningLibrary), | |
| 39 super(mirror, owner); | |
| 40 | |
| 41 /// Generates a map describing the [Variable] object. | |
| 42 Map toMap() => { | |
| 43 'name': name, | |
| 44 'qualifiedName': qualifiedName, | |
| 45 'comment': comment, | |
| 46 'final': isFinal, | |
| 47 'static': isStatic, | |
| 48 'constant': isConst, | |
| 49 'type': new List.filled(1, type.toMap()), | |
| 50 'annotations': annotations.map((a) => a.toMap()).toList() | |
| 51 }; | |
| 52 | |
| 53 String get typeName => 'property'; | |
| 54 | |
| 55 String get comment { | |
| 56 if (commentField != null) return commentField; | |
| 57 if (owner is Class) { | |
| 58 (owner as Class).ensureComments(); | |
| 59 } | |
| 60 return super.comment; | |
| 61 } | |
| 62 | |
| 63 bool isValidMirror(DeclarationMirror mirror) => mirror is VariableMirror; | |
| 64 } | |
| OLD | NEW |