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 /// Collects services that can be used to access objects dynamically, inspect | 5 /// Collects services that can be used to access objects dynamically, inspect |
6 /// type information, and convert between symbols and strings. | 6 /// type information, and convert between symbols and strings. |
7 library smoke; | 7 library smoke; |
8 | 8 |
9 import 'src/implementation.dart' as implementation; | 9 import 'src/implementation.dart' as implementation; |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 implementation.symbolConverter.symbolToName(symbol); | 77 implementation.symbolConverter.symbolToName(symbol); |
78 | 78 |
79 /// Returns the symbol associated with a [name]. | 79 /// Returns the symbol associated with a [name]. |
80 Symbol nameToSymbol(String name) => | 80 Symbol nameToSymbol(String name) => |
81 implementation.symbolConverter.nameToSymbol(name); | 81 implementation.symbolConverter.nameToSymbol(name); |
82 | 82 |
83 /// Establishes the parameters for [query] to search for symbols in a type | 83 /// Establishes the parameters for [query] to search for symbols in a type |
84 /// hierarchy. For now only public instance symbols can be queried (no private, | 84 /// hierarchy. For now only public instance symbols can be queried (no private, |
85 /// no static). | 85 /// no static). |
86 class QueryOptions { | 86 class QueryOptions { |
87 /// Whether to include fields, getters, and setters. | 87 /// Whether to include fields (default is true). |
88 final bool includeFields; | |
89 | |
90 /// Whether to include getters and setters (default is true). | |
88 final bool includeProperties; | 91 final bool includeProperties; |
89 | 92 |
90 /// Whether to include symbols from the given type and its superclasses | 93 /// Whether to include symbols from the given type and its superclasses |
91 /// (except [Object]). | 94 /// (except [Object]). |
92 final bool includeInherited; | 95 final bool includeInherited; |
93 | 96 |
94 /// Whether to include final fields. | 97 /// Whether to include final fields. |
95 // TODO(sigmund): should this exclude getter-only properties too? | 98 // TODO(sigmund): should this exclude getter-only properties too? |
96 final bool excludeFinal; | 99 final bool excludeFinal; |
97 | 100 |
98 /// Whether to include methods (default is false). | 101 /// Whether to include methods (default is false). |
99 final bool includeMethods; | 102 final bool includeMethods; |
100 | 103 |
101 /// If [withAnnotation] is not null, then it should be a list of types, so | 104 /// If [withAnnotation] is not null, then it should be a list of types, so |
102 /// only symbols that are annotated with instances of those types are | 105 /// only symbols that are annotated with instances of those types are |
103 /// included. | 106 /// included. |
104 final List withAnnotations; | 107 final List withAnnotations; |
105 | 108 |
106 const QueryOptions({this.includeProperties: true, this.includeInherited: true, | 109 const QueryOptions({ |
107 this.excludeFinal: false, this.includeMethods: false, | 110 this.includeFields: true, |
111 this.includeProperties: true, | |
112 this.includeInherited: true, | |
113 this.excludeFinal: false, | |
114 this.includeMethods: false, | |
108 this.withAnnotations: null}); | 115 this.withAnnotations: null}); |
109 } | 116 } |
110 | 117 |
111 /// Information associated with a symbol declaration (like a property or | 118 /// Information associated with a symbol declaration (like a property or |
112 /// method). | 119 /// method). |
113 class Declaration { | 120 class Declaration { |
114 /// Name of the property or method | 121 /// Name of the property or method |
115 final Symbol name; | 122 final Symbol name; |
116 | 123 |
117 /// Whether the symbol is a property (either this or [isMethod] is true). | 124 /// Kind of declaration (field, property, or method). |
118 bool get isProperty => !isMethod; | 125 final DeclarationKind _kind; |
119 | 126 |
120 /// Whether the symbol is a method (either this or [isProperty] is true) | 127 /// Whether the symbol is a field. |
121 final bool isMethod; | 128 bool get isField => _kind == FIELD; |
129 | |
130 /// Whether the symbol is a getter/setter and not a field. | |
Siggi Cherem (dart-lang)
2014/02/21 18:02:58
I was thinking more about it this morning, and I'm
Jennifer Messerly
2014/02/21 23:29:11
Tricky. What you have right now is fairly consiste
Siggi Cherem (dart-lang)
2014/02/22 01:13:28
ok, thanks - I went with keeping them separate and
| |
131 bool get isProperty => _kind == PROPERTY; | |
132 | |
133 /// Whether the symbol is a method. | |
134 bool get isMethod => _kind == METHOD; | |
122 | 135 |
123 /// If this is a property, whether it's read only (final fields or properties | 136 /// If this is a property, whether it's read only (final fields or properties |
124 /// with no setter). | 137 /// with no setter). |
125 final bool isFinal; | 138 final bool isFinal; |
126 | 139 |
127 /// If this is a property, it's declared type (including dynamic if it's not | 140 /// If this is a property, it's declared type (including dynamic if it's not |
128 /// declared). For methods, the returned type. | 141 /// declared). For methods, the returned type. |
129 final Type type; | 142 final Type type; |
130 | 143 |
131 /// Whether this symbol is static. | 144 /// Whether this symbol is static. |
132 final bool isStatic; | 145 final bool isStatic; |
133 | 146 |
134 /// List of annotations in this declaration. | 147 /// List of annotations in this declaration. |
135 final List annotations; | 148 final List annotations; |
136 | 149 |
137 const Declaration(this.name, this.type, {this.isMethod:false, | 150 const Declaration(this.name, this.type, {DeclarationKind kind: FIELD, |
138 this.isFinal: false, this.isStatic: false, this.annotations: const []}); | 151 this.isFinal: false, this.isStatic: false, this.annotations: const []}) |
152 : _kind = kind; | |
139 | 153 |
140 String toString() { | 154 String toString() { |
141 return (new StringBuffer() | 155 return (new StringBuffer() |
142 ..write('[declaration ') | 156 ..write('[declaration ') |
143 ..write(name) | 157 ..write(name) |
144 ..write(isProperty ? ' (property) ' : ' (method) ') | 158 ..write(isProperty ? ' (property) ' : ' (method) ') |
145 ..write(isFinal ? 'final ' : '') | 159 ..write(isFinal ? 'final ' : '') |
146 ..write(isStatic ? 'static ' : '') | 160 ..write(isStatic ? 'static ' : '') |
147 ..write(annotations) | 161 ..write(annotations) |
148 ..write(']')).toString(); | 162 ..write(']')).toString(); |
149 } | 163 } |
150 } | 164 } |
151 | 165 |
166 /// Enumeration for declaration kinds (field, property, or method) | |
167 class DeclarationKind { | |
Jennifer Messerly
2014/02/21 23:29:11
if _kind is private, then DeclarationKind should b
Siggi Cherem (dart-lang)
2014/02/22 01:13:28
yeah, I was ambivalent about it. I decided to expo
| |
168 final int kind; | |
169 const DeclarationKind(this.kind); | |
170 } | |
171 | |
172 /// Declaration kind used to denote a raw field. | |
173 const FIELD = const DeclarationKind(0); | |
174 | |
175 /// Declaration kind used to denote a getter/setter. | |
176 const PROPERTY = const DeclarationKind(1); | |
177 | |
178 /// Declaration kind used to denote a method. | |
179 const METHOD = const DeclarationKind(2); | |
180 | |
152 | 181 |
153 /// A service that provides a way to implement simple operations on objects like | 182 /// A service that provides a way to implement simple operations on objects like |
154 /// read, write, and invoke. | 183 /// read, write, and invoke. |
155 abstract class ObjectAccessorService { | 184 abstract class ObjectAccessorService { |
156 /// Return the value of [field] in [object]. | 185 /// Return the value of [field] in [object]. |
157 read(Object object, Symbol field); | 186 read(Object object, Symbol field); |
158 | 187 |
159 /// Update the [value] of [field] in [object]. | 188 /// Update the [value] of [field] in [object]. |
160 void write(Object object, Symbol field, value); | 189 void write(Object object, Symbol field, value); |
161 | 190 |
(...skipping 28 matching lines...) Expand all Loading... | |
190 | 219 |
191 | 220 |
192 /// A service that converts between [Symbol]s and [String]s. | 221 /// A service that converts between [Symbol]s and [String]s. |
193 abstract class SymbolConverterService { | 222 abstract class SymbolConverterService { |
194 /// Returns the name associated with a [symbol]. | 223 /// Returns the name associated with a [symbol]. |
195 String symbolToName(Symbol symbol); | 224 String symbolToName(Symbol symbol); |
196 | 225 |
197 /// Returns the symbol associated with a [name]. | 226 /// Returns the symbol associated with a [name]. |
198 Symbol nameToSymbol(String name); | 227 Symbol nameToSymbol(String name); |
199 } | 228 } |
OLD | NEW |