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.variable; | 5 library docgen.models.variable; |
| 6 | 6 |
| 7 import '../exports/source_mirrors.dart'; | 7 import '../exports/source_mirrors.dart'; |
| 8 | 8 |
| 9 import '../library_helpers.dart'; | 9 import '../library_helpers.dart'; |
| 10 | 10 |
| 11 import 'class.dart'; | 11 import 'class.dart'; |
| 12 import 'doc_gen_type.dart'; | 12 import 'doc_gen_type.dart'; |
| 13 import 'dummy_mirror.dart'; | 13 import 'dummy_mirror.dart'; |
| 14 import 'indexable.dart'; | 14 import 'indexable.dart'; |
| 15 import 'owned_indexable.dart'; | 15 import 'owned_indexable.dart'; |
| 16 | 16 |
| 17 | 17 |
| 18 /// A class containing properties of a Dart variable. | 18 /// A class containing properties of a Dart variable. |
| 19 class Variable extends OwnedIndexable { | 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; | |
| 20 | 25 |
| 21 bool isFinal; | 26 factory Variable(String name, VariableMirror mirror, Indexable owner) { |
| 22 bool isStatic; | |
| 23 bool isConst; | |
| 24 DocGenType type; | |
| 25 String _variableName; | |
| 26 | |
| 27 factory Variable(String variableName, VariableMirror mirror, | |
| 28 Indexable owner) { | |
| 29 var variable = getDocgenObject(mirror); | 27 var variable = getDocgenObject(mirror); |
| 30 if (variable is DummyMirror) { | 28 if (variable is DummyMirror) { |
| 31 return new Variable._(variableName, mirror, owner); | 29 return new Variable._(name, mirror, owner); |
| 32 } | 30 } |
| 33 return variable; | 31 return variable; |
| 34 } | 32 } |
| 35 | 33 |
| 36 Variable._(this._variableName, VariableMirror mirror, Indexable owner) : | 34 Variable._(this.name, VariableMirror mirror, Indexable owner) |
| 37 super(mirror, owner) { | 35 : isFinal = mirror.isFinal, |
| 38 isFinal = mirror.isFinal; | 36 isStatic = mirror.isStatic, |
| 39 isStatic = mirror.isStatic; | 37 isConst = mirror.isConst, |
| 40 isConst = mirror.isConst; | 38 type = new DocGenType(mirror.type, owner.owningLibrary), |
| 41 type = new DocGenType(mirror.type, owner.owningLibrary); | 39 super(mirror, owner); |
| 42 } | |
| 43 | |
| 44 String get name => _variableName; | |
|
kevmoo
2014/04/20 21:34:54
Replaced private field + getter into public field
| |
| 45 | 40 |
| 46 /// Generates a map describing the [Variable] object. | 41 /// Generates a map describing the [Variable] object. |
| 47 Map toMap() => { | 42 Map toMap() => { |
| 48 'name': name, | 43 'name': name, |
| 49 'qualifiedName': qualifiedName, | 44 'qualifiedName': qualifiedName, |
| 50 'comment': comment, | 45 'comment': comment, |
| 51 'final': isFinal, | 46 'final': isFinal, |
| 52 'static': isStatic, | 47 'static': isStatic, |
| 53 'constant': isConst, | 48 'constant': isConst, |
| 54 'type': new List.filled(1, type.toMap()), | 49 'type': new List.filled(1, type.toMap()), |
| 55 'annotations': annotations.map((a) => a.toMap()).toList() | 50 'annotations': annotations.map((a) => a.toMap()).toList() |
| 56 }; | 51 }; |
| 57 | 52 |
| 58 String get typeName => 'property'; | 53 String get typeName => 'property'; |
| 59 | 54 |
| 60 get comment { | 55 String get comment { |
| 61 if (commentField != null) return commentField; | 56 if (commentField != null) return commentField; |
| 62 if (owner is Class) { | 57 if (owner is Class) { |
| 63 (owner as Class).ensureComments(); | 58 (owner as Class).ensureComments(); |
| 64 } | 59 } |
| 65 return super.comment; | 60 return super.comment; |
| 66 } | 61 } |
| 67 | 62 |
| 68 String findElementInScope(String name) { | 63 String findElementInScope(String name) { |
| 69 var lookupFunc = determineLookupFunc(name); | 64 var lookupFunc = determineLookupFunc(name); |
| 70 var result = lookupFunc(mirror, name); | 65 var result = lookupFunc(mirror, name); |
| 71 if (result != null) { | 66 if (result != null) { |
| 72 result = getDocgenObject(result); | 67 result = getDocgenObject(result); |
| 73 if (result is DummyMirror) return packagePrefix + result.docName; | 68 if (result is DummyMirror) return packagePrefix + result.docName; |
| 74 return result.packagePrefix + result.docName; | 69 return result.packagePrefix + result.docName; |
| 75 } | 70 } |
| 76 | 71 |
| 77 if (owner != null) { | 72 if (owner != null) { |
| 78 var result = owner.findElementInScope(name); | 73 var result = owner.findElementInScope(name); |
| 79 if (result != null) { | 74 if (result != null) { |
| 80 return result; | 75 return result; |
| 81 } | 76 } |
| 82 } | 77 } |
| 83 return super.findElementInScope(name); | 78 return super.findElementInScope(name); |
| 84 } | 79 } |
| 85 | 80 |
| 86 bool isValidMirror(DeclarationMirror mirror) => mirror is VariableMirror; | 81 bool isValidMirror(DeclarationMirror mirror) => mirror is VariableMirror; |
| 87 } | 82 } |
| OLD | NEW |