Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: pkg/smoke/lib/smoke.dart

Issue 173473002: Adapting observe to use smoke (this is built on top of the previous change that (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/smoke/lib/mirrors.dart ('k') | pkg/smoke/lib/static.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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). Note that to
91 /// include fields you also need to enable [includeFields].
88 final bool includeProperties; 92 final bool includeProperties;
89 93
90 /// Whether to include symbols from the given type and its superclasses 94 /// Whether to include symbols from the given type and its superclasses
91 /// (except [Object]). 95 /// (except [Object]).
92 final bool includeInherited; 96 final bool includeInherited;
93 97
94 /// Whether to include final fields. 98 /// Whether to include final fields and getter-only properties.
95 // 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 (and not a getter/setter property).
121 final bool isMethod; 128 bool get isField => kind == FIELD;
122 129
123 /// If this is a property, whether it's read only (final fields or properties 130 /// Whether the symbol is a getter/setter and not a field.
124 /// with no setter). 131 bool get isProperty => kind == PROPERTY;
132
133 /// Whether the symbol is a method.
134 bool get isMethod => kind == METHOD;
135
136 /// For fields, whether they are final, for properties, whether they are
137 /// read-only (they have 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 field or property, it's declared type (including dynamic if
128 /// declared). For methods, the returned type. 141 /// it's not 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, {this.kind: FIELD,
138 this.isFinal: false, this.isStatic: false, this.annotations: const []}); 151 this.isFinal: false, this.isStatic: false, this.annotations: const []});
139 152
140 String toString() { 153 String toString() {
141 return (new StringBuffer() 154 return (new StringBuffer()
142 ..write('[declaration ') 155 ..write('[declaration ')
143 ..write(name) 156 ..write(name)
144 ..write(isProperty ? ' (property) ' : ' (method) ') 157 ..write(isProperty ? ' (property) ' : ' (method) ')
145 ..write(isFinal ? 'final ' : '') 158 ..write(isFinal ? 'final ' : '')
146 ..write(isStatic ? 'static ' : '') 159 ..write(isStatic ? 'static ' : '')
147 ..write(annotations) 160 ..write(annotations)
148 ..write(']')).toString(); 161 ..write(']')).toString();
149 } 162 }
150 } 163 }
151 164
165 /// Enumeration for declaration kinds (field, property, or method)
166 class DeclarationKind {
167 final int kind;
168 const DeclarationKind(this.kind);
169 }
170
171 /// Declaration kind used to denote a raw field.
172 const FIELD = const DeclarationKind(0);
173
174 /// Declaration kind used to denote a getter/setter.
175 const PROPERTY = const DeclarationKind(1);
176
177 /// Declaration kind used to denote a method.
178 const METHOD = const DeclarationKind(2);
179
152 180
153 /// A service that provides a way to implement simple operations on objects like 181 /// A service that provides a way to implement simple operations on objects like
154 /// read, write, and invoke. 182 /// read, write, and invoke.
155 abstract class ObjectAccessorService { 183 abstract class ObjectAccessorService {
156 /// Return the value of [field] in [object]. 184 /// Return the value of [field] in [object].
157 read(Object object, Symbol field); 185 read(Object object, Symbol field);
158 186
159 /// Update the [value] of [field] in [object]. 187 /// Update the [value] of [field] in [object].
160 void write(Object object, Symbol field, value); 188 void write(Object object, Symbol field, value);
161 189
(...skipping 28 matching lines...) Expand all
190 218
191 219
192 /// A service that converts between [Symbol]s and [String]s. 220 /// A service that converts between [Symbol]s and [String]s.
193 abstract class SymbolConverterService { 221 abstract class SymbolConverterService {
194 /// Returns the name associated with a [symbol]. 222 /// Returns the name associated with a [symbol].
195 String symbolToName(Symbol symbol); 223 String symbolToName(Symbol symbol);
196 224
197 /// Returns the symbol associated with a [name]. 225 /// Returns the symbol associated with a [name].
198 Symbol nameToSymbol(String name); 226 Symbol nameToSymbol(String name);
199 } 227 }
OLDNEW
« no previous file with comments | « pkg/smoke/lib/mirrors.dart ('k') | pkg/smoke/lib/static.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698