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

Side by Side Diff: sdk/lib/mirrors/mirrors.dart

Issue 1122983002: Improve documentation for MirrorsUsed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | « no previous file | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // For the purposes of the mirrors library, we adopt a naming 5 // For the purposes of the mirrors library, we adopt a naming
6 // convention with respect to getters and setters. Specifically, for 6 // convention with respect to getters and setters. Specifically, for
7 // some variable or field... 7 // some variable or field...
8 // 8 //
9 // var myField; 9 // var myField;
10 // 10 //
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 * 1189 *
1190 * The following text is non-normative: 1190 * The following text is non-normative:
1191 * 1191 *
1192 * In some scenarios, for example, when minifying Dart code, or when generating 1192 * In some scenarios, for example, when minifying Dart code, or when generating
1193 * JavaScript code from a Dart program, the size and performance of the output 1193 * JavaScript code from a Dart program, the size and performance of the output
1194 * can suffer from use of reflection. In those cases, telling the compiler 1194 * can suffer from use of reflection. In those cases, telling the compiler
1195 * what is used, can have a significant impact. 1195 * what is used, can have a significant impact.
1196 * 1196 *
1197 * Example usage: 1197 * Example usage:
1198 * 1198 *
1199 * @MirrorsUsed(symbols: 'foo', override: '*') 1199 * @MirrorsUsed(symbols: 'foo')
1200 * import 'dart:mirrors'; 1200 * import 'dart:mirrors';
1201 * 1201 *
1202 * class Foo { 1202 * class Foo {
1203 * noSuchMethod(Invocation invocation) { 1203 * noSuchMethod(Invocation invocation) {
1204 * print(MirrorSystem.getName(invocation.memberName)); 1204 * print(MirrorSystem.getName(invocation.memberName));
1205 * } 1205 * }
1206 * } 1206 * }
1207 * 1207 *
1208 * main() { 1208 * main() {
1209 * new Foo().foo(); // Prints "foo". 1209 * new Foo().foo(); // Prints "foo".
1210 * new Foo().bar(); // Might print an arbitrary (mangled) name, "bar". 1210 * new Foo().bar(); // Might print an arbitrary (mangled) name, "bar".
1211 * } 1211 * }
1212 *
1213 * For a detailed description of the parameters to the [MirrorsUsed] constructor
1214 * see the comments for the respective fields [symbols]. [targets] and
Kathy Walrath 2015/05/05 19:24:57 delete "the respective fields " . -> ,
herhut 2015/05/06 14:24:16 Done.
1215 * [metaTargets].
Kathy Walrath 2015/05/05 19:24:57 what about [override]?
herhut 2015/05/06 14:24:17 Good catch, thanks!
1216 *
1217 * An import of `dart:mirrors` may have multiple [MirrorsUsed] annotations. This
1218 * is particularly helpful to specify overrides for specific libraries. For
1219 * example
Kathy Walrath 2015/05/05 19:24:57 example -> example:
herhut 2015/05/06 14:24:15 Done.
1220 *
1221 * @MirrorsUsed(targets: 'foo.Bar', override: 'foo')
1222 * @MirrorsUsed(targets: 'Bar')
1223 * import 'dart:mirrors';
1224 *
1225 * will ensure that the target `Bar` from the current library and from library
1226 * `foo` is available for reflection. See also [override].
1212 */ 1227 */
1213 // TODO(ahe): Remove ", override: '*'" when it isn't necessary anymore.
1214 class MirrorsUsed { 1228 class MirrorsUsed {
1215 // Note: the fields of this class are untyped. This is because the most 1229 // Note: the fields of this class are untyped. This is because the most
1216 // convenient way to specify to specify symbols today is using a single 1230 // convenient way to specify symbols today is using a single string. In
1217 // string. In some cases, a const list of classes might be convenient. Some 1231 // some cases, a const list of classes might be convenient. Some
1218 // might prefer to use a const list of symbols. 1232 // might prefer to use a const list of symbols.
1219 1233
1220 /** 1234 /**
1221 * The list of strings passed to new [Symbol], and symbols that might be 1235 * The list of strings passed to new [Symbol], and symbols that might be
1222 * passed to [MirrorSystem.getName]. 1236 * passed to [MirrorSystem.getName].
1223 * 1237 *
1224 * Combined with the names of [targets], [metaTargets] and their members, 1238 * Combined with the names of [targets], [metaTargets] and their members,
1225 * this forms the complete list of strings passed to new [Symbol], and 1239 * this forms the complete list of strings passed to new [Symbol], and
1226 * symbols that might be passed to [MirrorSystem.getName] by the library to 1240 * symbols that might be passed to [MirrorSystem.getName] by the library to
1227 * which this metadata applies. 1241 * which this metadata applies.
1228 * 1242 *
1229 * The following text is non-normative: 1243 * The following text is non-normative:
1230 * 1244 *
1245 * Dart2js currently supports the below formats to specify symbols:
Kathy Walrath 2015/05/05 19:24:58 below -> following
herhut 2015/05/06 14:24:16 Done.
1246 *
1247 * * A [List] of [String] constants representing symbol names, e.g.,
Kathy Walrath 2015/05/05 19:24:57 A -> A constant ? (it must be a const List, right?
herhut 2015/05/06 14:24:16 Done.
1248 * `const ['foo', 'bar']`.
1249 * * A single [String] constant whose value is a comma separated list of
Kathy Walrath 2015/05/05 19:24:58 comma separated -> comma-separated
Lasse Reichstein Nielsen 2015/05/06 07:41:21 comma + whitespace separated apparently? Are multi
herhut 2015/05/06 14:24:16 Done.
herhut 2015/05/06 14:24:16 This is meant to be a documentation, not a formal
1250 * symbol names, e.g., `"foo, bar"`.
1251 *
1231 * Specifying this option turns off the following warnings emitted by 1252 * Specifying this option turns off the following warnings emitted by
Kathy Walrath 2015/05/05 19:24:57 this option -> the `symbols` field
herhut 2015/05/06 14:24:17 Done.
1232 * dart2js: 1253 * dart2js:
1233 * 1254 *
1234 * * Using "MirrorSystem.getName" may result in larger output. 1255 * * Using "MirrorSystem.getName" may result in larger output.
1235 * * Using "new #{name}" may result in larger output. 1256 * * Using "new #{name}" may result in larger output.
1236 * 1257 *
1237 * Use symbols = "*" to turn off the warnings mentioned above.
1238 *
1239 * For example, if using [noSuchMethod] to interact with a database, extract 1258 * For example, if using [noSuchMethod] to interact with a database, extract
Kathy Walrath 2015/05/05 19:24:57 using -> you're using
herhut 2015/05/06 14:24:16 Done.
1240 * all the possible column names and include them in this list. Similarly, 1259 * all the possible column names and include them in this list. Similarly,
1241 * if using [noSuchMethod] to interact with another language (JavaScript, for 1260 * if using [noSuchMethod] to interact with another language (JavaScript, for
Kathy Walrath 2015/05/05 19:24:58 using -> you're using
herhut 2015/05/06 14:24:17 Done.
1242 * example) extract all the identifiers from API used and include them in 1261 * example) extract all the identifiers from API used and include them in
Kathy Walrath 2015/05/05 19:24:57 API -> the API you use
herhut 2015/05/06 14:24:15 Done.
1243 * this list. 1262 * this list.
1263 *
1264 * Note that specifying a symbol only ensures that the symbol will be
1265 * available under that name at runtime. It does not mark targets with
1266 * that name as available for reflection. See [targets] and [metaTargets]
1267 * for that purpose.
1244 */ 1268 */
1245 final symbols; 1269 final symbols;
1246 1270
1247 /** 1271 /**
1248 * A list of reflective targets. 1272 * A list of reflective targets.
1249 * 1273 *
1250 * Combined with [metaTargets], this provides the complete list of reflective 1274 * Combined with [metaTargets], this provides the complete list of reflective
1251 * targets used by the library to which this metadata applies. 1275 * targets used by the library to which this metadata applies.
Lasse Reichstein Nielsen 2015/05/06 07:41:21 What kinds of declarations can be targets. It's s
herhut 2015/05/06 14:24:16 It is not stated here because it is not formally d
1252 * 1276 *
1253 * The following text is non-normative: 1277 * The following text is non-normative:
1254 * 1278 *
1279 * Dart2js currently supports the below formats to specify targets:
Kathy Walrath 2015/05/05 19:24:58 Same comments as above: below -> following [List]
herhut 2015/05/06 14:24:16 Done.
1280 *
1281 * * A [List] containing [String] constants representing (qualified)
1282 * names of targets and Dart types.
1283 * * A single [String] constant whose value is a comma separated list of
1284 * (qualified) names.
1285 * * A single Dart type.
1286 *
1287 * A (qualified) name is resolved to a target as follows:
1288 *
1289 * 1. If the qualified name matches a library name, the matching library is
Lasse Reichstein Nielsen 2015/05/06 07:41:20 "matches" meaning? I guess equals-after-canonicali
herhut 2015/05/06 14:24:17 ...not a spec.
1290 * the target.
1291 * 2. Else, find the longest prefix of the name such that the prefix ends
1292 * with a `.` and is a library name.
Lasse Reichstein Nielsen 2015/05/06 07:41:21 ends with -> ends just before (Otherwise the prefi
herhut 2015/05/06 14:24:16 Done.
1293 * 3. Use that library as current scope. If no matching prefix was found, use
1294 * the current library, i.e., the library where the [MirrorsUsed]
1295 * annotation was placed.
1296 * 4. Split the remaining suffix into a list of [String] using `.` as a
Lasse Reichstein Nielsen 2015/05/06 07:41:20 Split the remaining suffix (the entire name in cas
herhut 2015/05/06 14:24:16 Done.
1297 * separator.
1298 * 5. Select all targets in the current scope whose name matches a [String]
Lasse Reichstein Nielsen 2015/05/06 07:41:21 "matches" means? Equals for non-setters or equals-
herhut 2015/05/06 14:24:16 without the = for setters. Again this is not a spe
1299 * from the list.
Lasse Reichstein Nielsen 2015/05/06 07:41:20 Step 5 looks wrong. Not saying it's not what's hap
herhut 2015/05/06 14:24:16 This is how it is and I added an example to highli
1300 *
Kathy Walrath 2015/05/05 19:24:58 A brief example would be nice here.
herhut 2015/05/06 14:24:16 Added.
Kathy Walrath 2015/05/06 20:54:25 That helps. Thanks!
1301 * Note that everything within a target also is available for reflection.
1302 * So, if a library is specified as target, all classes in that library
1303 * become targets for reflection. Likewise, if a class is a target, all
1304 * its methods and fields become targets for reflection.
1305 *
1255 * For now, there is no formal description of what a reflective target is. 1306 * For now, there is no formal description of what a reflective target is.
1256 * Informally, it is a list of things that are expected to have fully 1307 * Informally, a target is a library, a class, a method or a field.
1257 * functional mirrors. 1308 *
1258 */ 1309 */
1259 final targets; 1310 final targets;
1260 1311
1261 /** 1312 /**
1262 * A list of classes that when used as metadata indicates a reflective 1313 * A list of classes that when used as metadata indicates a reflective
1263 * target. 1314 * target. See also [targets].
1264 * 1315 *
1265 * See [targets]. 1316 * The following text is non-normative:
Lasse Reichstein Nielsen 2015/05/06 07:41:20 What does that mean? Where it the normative defini
herhut 2015/05/06 14:24:17 There is none.
1317 *
1318 * The format for specifying the list of classes is the same as used for
1319 * specifying [targets]. However, as a library cannot be used as a metadata
1320 * annotation in Dart, adding a library to the list of [metaTargets] has no
1321 * effect. In particular, adding a library to [metaTargets] does not make
1322 * the library's classes a valid metadata annotation to enable reflection.
Lasse Reichstein Nielsen 2015/05/06 07:41:21 a valid metadata annotation -> valid metadata anno
herhut 2015/05/06 14:24:17 Done.
1323 *
1324 * If a class specified in [metaTargets] is used as metadata annotation
Lasse Reichstein Nielsen 2015/05/06 07:41:21 If an instance of a class ...
herhut 2015/05/06 14:24:17 Done.
1325 * on a class, field or method, that class, field or method is added to
Lasse Reichstein Nielsen 2015/05/06 07:41:21 But not library?
herhut 2015/05/06 14:24:16 Good catch, thanks!
1326 * the set of targets for reflection.
1327 *
1328 * Example usage:
1329 *
1330 * library example;
1331 * @MirrorsUsed(metaTargets: "example.Reflectable")
1332 * import "dart:mirrors";
1333 *
1334 * class Reflectable {
1335 * const Reflectable();
1336 * }
1337 *
1338 * class Foo {
1339 * @Reflectable()
1340 * reflectableMethod() { ... }
1341 *
1342 * nonReflectableMethod() { ... }
1343 * }
1344 *
1345 * In the above example. `reflectableMethod` is marked as reflectable by
1346 * using the `Reflectable` class, which in turn is specified in the
1347 * [metaTargets] annotation.
1348 *
1349 * The method `nonReflectableMethod` lacks a metadata annotation and thus
1350 * will not be reflectable at runtime.
1266 */ 1351 */
1267 final metaTargets; 1352 final metaTargets;
1268 1353
1269 /** 1354 /**
1270 * A list of library names or "*". 1355 * A list of library names or "*".
1271 * 1356 *
1272 * When used as metadata on an import of "dart:mirrors", this metadata does 1357 * When used as metadata on an import of "dart:mirrors", this metadata does
1273 * not apply to the library in which the annotation is used, but instead 1358 * not apply to the library in which the annotation is used, but instead
1274 * applies to the other libraries (all libraries if "*" is used). 1359 * applies to the other libraries (all libraries if "*" is used). In
Lasse Reichstein Nielsen 2015/05/06 07:41:21 So it *does* apply to itself if "*" is used? And i
herhut 2015/05/06 14:24:17 I had to rewrite the entire section after looking
1360 * particular, if the other library has a metadata annotation of its own,
1361 * it will be shadowed by the override.
Lasse Reichstein Nielsen 2015/05/06 07:41:21 The word "shadow" suggests an ordering where the o
Lasse Reichstein Nielsen 2015/05/06 07:41:21 What if you specify yourself without using "*"? l
herhut 2015/05/06 14:24:16 Removed.
herhut 2015/05/06 14:24:17 Removed.
1362 *
1363 * If two libraries have mutual overrides, they will shadow each other and
1364 * an empty annotation will be assumed.
Lasse Reichstein Nielsen 2015/05/06 07:41:21 That's not what "shadow each other" means (if it m
herhut 2015/05/06 14:24:16 Removed.
1365 *
1366 * The following text is non-normative:
Lasse Reichstein Nielsen 2015/05/06 07:41:21 Where is the normative text then?
herhut 2015/05/06 14:24:16 Does not exist.
1367 *
1368 * While the annotation will apply to the given target libraries, the
1369 * [symbols], [targets] and [metaTargets] are still evaluated in the
1370 * scope of the annotation. Thus, to select a target from library `foo`,
1371 * a qualified name has to be used or, if the target is visible in the
1372 * current scope, its type may be referenced.
1373 *
1374 * For example
Kathy Walrath 2015/05/05 19:24:57 -> For example, the following code marks all targe
herhut 2015/05/06 14:24:16 Done.
1375 *
1376 * @MirrorsUsed(metaTargets: "foo.Reflectable", override: "foo")
1377 *
1378 * will mark all targets in the library `foo` as reflectable that have
1379 * a metadata annotation using the `Reflectable` class from the same library.
1380 * However,
Kathy Walrath 2015/05/05 19:24:58 Delete previous two lines (moved, actually). Chang
herhut 2015/05/06 14:24:17 Done.
1381 *
1382 * @MirrorsUsed(metaTargets: "Reflectable", override: "foo")
1383 *
1384 * would require the use of the `Reflectable` class from the current
Kathy Walrath 2015/05/05 19:24:58 Delete these 2 lines (move up above, actually).
herhut 2015/05/06 14:24:16 Done.
1385 * library, instead.
1275 */ 1386 */
Lasse Reichstein Nielsen 2015/05/06 07:41:21 So, if I get this right: Override specifies a set
herhut 2015/05/06 14:24:16 Removed.
1276 final override; 1387 final override;
1277 1388
1389 /**
1390 * See the documentation for [MirrorsUsed.symbols], [MirrorsUsed.targets],
1391 * [MirrorsUsed.metaTargets] and [MirrorsUsed.override] for documentation
1392 * of the parameters.
1393 */
1278 const MirrorsUsed( 1394 const MirrorsUsed(
1279 {this.symbols, this.targets, this.metaTargets, this.override}); 1395 {this.symbols, this.targets, this.metaTargets, this.override});
1280 } 1396 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698