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 |
11 export 'src/common.dart' show minArgs, maxArgs, SUPPORTED_ARGS; | 11 export 'src/common.dart' show minArgs, maxArgs, SUPPORTED_ARGS; |
| 12 import 'src/common.dart' show compareLists; |
12 | 13 |
13 /// Configures this library to use [objectAccessor] for all read/write/invoke | 14 /// Configures this library to use [objectAccessor] for all read/write/invoke |
14 /// APIs, [typeInspector] for all type query APIs, and [symbolConverter] for all | 15 /// APIs, [typeInspector] for all type query APIs, and [symbolConverter] for all |
15 /// symbol convertion operations. | 16 /// symbol convertion operations. |
16 /// | 17 /// |
17 /// This function doesn't need to be called during development, but frameworks | 18 /// This function doesn't need to be called during development, but frameworks |
18 /// should autogenerate a call to this function when running in deployment. | 19 /// should autogenerate a call to this function when running in deployment. |
19 void configure(ObjectAccessorService objectAccessor, | 20 void configure(ObjectAccessorService objectAccessor, |
20 TypeInspectorService typeInspector, | 21 TypeInspectorService typeInspector, |
21 SymbolConverterService symbolConverter) { | 22 SymbolConverterService symbolConverter) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 final bool excludeFinal; | 115 final bool excludeFinal; |
115 | 116 |
116 /// Whether to include methods (default is false). | 117 /// Whether to include methods (default is false). |
117 final bool includeMethods; | 118 final bool includeMethods; |
118 | 119 |
119 /// If [withAnnotation] is not null, then it should be a list of types, so | 120 /// If [withAnnotation] is not null, then it should be a list of types, so |
120 /// only symbols that are annotated with instances of those types are | 121 /// only symbols that are annotated with instances of those types are |
121 /// included. | 122 /// included. |
122 final List withAnnotations; | 123 final List withAnnotations; |
123 | 124 |
| 125 /// If [matches] is not null, then include only those fields, properties, or |
| 126 /// methods that match the predicate. |
| 127 final NameMatcher matches; |
| 128 |
124 const QueryOptions({ | 129 const QueryOptions({ |
125 this.includeFields: true, | 130 this.includeFields: true, |
126 this.includeProperties: true, | 131 this.includeProperties: true, |
127 this.includeInherited: true, | 132 this.includeInherited: true, |
128 this.includeUpTo: Object, | 133 this.includeUpTo: Object, |
129 this.excludeFinal: false, | 134 this.excludeFinal: false, |
130 this.includeMethods: false, | 135 this.includeMethods: false, |
131 this.withAnnotations: null}); | 136 this.withAnnotations: null, |
| 137 this.matches: null}); |
| 138 |
| 139 String toString() => (new StringBuffer() |
| 140 ..write('(options:') |
| 141 ..write(includeFields ? 'fields ' : '') |
| 142 ..write(includeProperties ? 'properties ' : '') |
| 143 ..write(includeMethods ? 'methods ' : '') |
| 144 ..write(includeInherited ? 'inherited ' : '_') |
| 145 ..write(excludeFinal ? 'no finals ' : '') |
| 146 ..write('annotations: $withAnnotations') |
| 147 ..write(matches != null ? 'with matcher' : '') |
| 148 ..write(')')).toString(); |
132 } | 149 } |
133 | 150 |
| 151 /// Used to filter query results based on a predicate on [name]. Returns true if |
| 152 /// [name] should be included in the query results. |
| 153 typedef bool NameMatcher(Symbol name); |
| 154 |
134 /// Information associated with a symbol declaration (like a property or | 155 /// Information associated with a symbol declaration (like a property or |
135 /// method). | 156 /// method). |
136 class Declaration { | 157 class Declaration { |
137 /// Name of the property or method | 158 /// Name of the property or method |
138 final Symbol name; | 159 final Symbol name; |
139 | 160 |
140 /// Kind of declaration (field, property, or method). | 161 /// Kind of declaration (field, property, or method). |
141 final DeclarationKind kind; | 162 final DeclarationKind kind; |
142 | 163 |
143 /// Whether the symbol is a field (and not a getter/setter property). | 164 /// Whether the symbol is a field (and not a getter/setter property). |
(...skipping 15 matching lines...) Expand all Loading... |
159 | 180 |
160 /// Whether this symbol is static. | 181 /// Whether this symbol is static. |
161 final bool isStatic; | 182 final bool isStatic; |
162 | 183 |
163 /// List of annotations in this declaration. | 184 /// List of annotations in this declaration. |
164 final List annotations; | 185 final List annotations; |
165 | 186 |
166 const Declaration(this.name, this.type, {this.kind: FIELD, | 187 const Declaration(this.name, this.type, {this.kind: FIELD, |
167 this.isFinal: false, this.isStatic: false, this.annotations: const []}); | 188 this.isFinal: false, this.isStatic: false, this.annotations: const []}); |
168 | 189 |
| 190 int get hashCode => name.hashCode; |
| 191 operator ==(other) => other is Declaration && name == other.name && |
| 192 kind == other.kind && isFinal == other.isFinal && |
| 193 type == other.type && isStatic == other.isStatic && |
| 194 compareLists(annotations, other.annotations); |
| 195 |
169 String toString() { | 196 String toString() { |
170 return (new StringBuffer() | 197 return (new StringBuffer() |
171 ..write('[declaration ') | 198 ..write('(declaration ') |
172 ..write(name) | 199 ..write(name) |
173 ..write(isProperty ? ' (property) ' : ' (method) ') | 200 ..write(isProperty ? ' (property) ' : ' (method) ') |
174 ..write(isFinal ? 'final ' : '') | 201 ..write(isFinal ? 'final ' : '') |
175 ..write(isStatic ? 'static ' : '') | 202 ..write(isStatic ? 'static ' : '') |
176 ..write(annotations) | 203 ..write(annotations) |
177 ..write(']')).toString(); | 204 ..write(')')).toString(); |
178 } | 205 } |
179 } | 206 } |
180 | 207 |
181 /// Enumeration for declaration kinds (field, property, or method) | 208 /// Enumeration for declaration kinds (field, property, or method) |
182 class DeclarationKind { | 209 class DeclarationKind { |
183 final int kind; | 210 final int kind; |
184 const DeclarationKind(this.kind); | 211 const DeclarationKind(this.kind); |
185 } | 212 } |
186 | 213 |
187 /// Declaration kind used to denote a raw field. | 214 /// Declaration kind used to denote a raw field. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 264 |
238 | 265 |
239 /// A service that converts between [Symbol]s and [String]s. | 266 /// A service that converts between [Symbol]s and [String]s. |
240 abstract class SymbolConverterService { | 267 abstract class SymbolConverterService { |
241 /// Returns the name associated with a [symbol]. | 268 /// Returns the name associated with a [symbol]. |
242 String symbolToName(Symbol symbol); | 269 String symbolToName(Symbol symbol); |
243 | 270 |
244 /// Returns the symbol associated with a [name]. | 271 /// Returns the symbol associated with a [name]. |
245 Symbol nameToSymbol(String name); | 272 Symbol nameToSymbol(String name); |
246 } | 273 } |
OLD | NEW |