| Index: src/site/docs/dart-up-and-running/contents/ch03.html
|
| diff --git a/src/site/docs/dart-up-and-running/contents/ch03.html b/src/site/docs/dart-up-and-running/contents/ch03.html
|
| index 27dbf4ac490e853915a6f7f1ed6d8c8a24ccfc8f..29eb493a6e55f12e7c999c42322a41ec7a4b76be 100644
|
| --- a/src/site/docs/dart-up-and-running/contents/ch03.html
|
| +++ b/src/site/docs/dart-up-and-running/contents/ch03.html
|
| @@ -87,7 +87,9 @@ assert(codeUnitList[0] == 78);</pre></div><div class="sect3"><div class="titlepa
|
| assert('structured web apps'.toUpperCase() == 'STRUCTURED WEB APPS');
|
|
|
| // Convert to lowercase.
|
| -assert('STRUCTURED WEB APPS'.toLowerCase() == 'structured web apps');</pre></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="ch03-trimming-and-empty-strings"></a>Trimming and empty strings</h4></div></div></div><p>Remove all leading and trailing white space with
|
| +assert('STRUCTURED WEB APPS'.toLowerCase() == 'structured web apps');</pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>These methods don't work for every language. For example, the
|
| + Turkish alphabet's dotless <span class="emphasis"><em>I</em></span> is converted
|
| + incorrectly.</p></div></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="ch03-trimming-and-empty-strings"></a>Trimming and empty strings</h4></div></div></div><p>Remove all leading and trailing white space with
|
| <code class="literal">trim()</code>. To check whether a string is empty (length
|
| is zero), use <code class="literal">isEmpty</code>.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em><em><span class="remark">ch03/string-tests.dart
|
| @@ -1426,38 +1428,31 @@ main() {
|
| }</pre></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="ch03-utf-other"></a>Other Functionality</h3></div></div></div><p>The UTF library can decode and encode UTF-16 and UTF-32 bytes. The
|
| library can also convert directly to and from Unicode code points and
|
| UTF8-encoded bytes. For details, see the <a class="ulink" href="http://api.dartlang.org/utf.html" target="_top">API docs for the UTF
|
| - library.</a></p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ch03-mirrors"></a>dart:mirrors - Reflection</h2></div></div></div><p>The mirrors library provides basic reflection abilities to Dart. Use mirrors
|
| - to query the structure of your program, and to dynamically invoke functions or
|
| - methods at runtime.</p><p>Mirrors can give you information about objects and classes inside the
|
| - current isolate, as well as in other (possibly remote) isolates. Therefore,
|
| - the mirrors library often has two versions of each method:
|
| - synchronous (for working inside the current isolate) and asynchronous
|
| - (for working with another isolate).
|
| - This section covers mirrors only as they apply to the
|
| - current isolate.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p> Mirrors can also work on static source code.
|
| - For example, the dartdoc tool
|
| - (which generates HTML docs from Dart source code)
|
| - uses source-code mirrors.
|
| - </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="ch03-mirrors-symbols"></a>Symbols</h3></div></div></div><p>The mirror system represents the names of Dart declarations
|
| - (classes, fields, and so on) by instances of the class
|
| - <a class="ulink" href="http://api.dartlang.org/dart_core/Symbol.html" target="_top">Symbol</a>.
|
| - Symbols help compilers like dart2js produce efficient output,
|
| - even when minified.</p><p>When you know the name of the symbol ahead of time,
|
| - use Symbol's const constructor.
|
| - This way, repeated uses of the same symbol can use the same
|
| - canonicalized instance.
|
| - If the name of the symbol is determined dynamically at runtime,
|
| - use the factory constructor.</p><pre class="screen"><em><span class="remark">lang-dart
|
| + library.</a></p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ch03-mirrors"></a>dart:mirrors - Reflection</h2></div></div></div><p>The mirrors library provides basic reflection abilities to Dart. Use
|
| + mirrors to query the structure of your program, and to dynamically invoke
|
| + functions or methods at runtime.</p><p>Mirrors can give you information about objects and classes inside
|
| + the current isolate, as well as in other (possibly remote) isolates.
|
| + Therefore, the mirrors library often has two versions of each method:
|
| + synchronous (for working inside the current isolate) and asynchronous (for
|
| + working with another isolate). This section covers mirrors only as they
|
| + apply to the current isolate.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Mirrors can also work on static source code. For example, the
|
| + dartdoc tool (which generates HTML docs from Dart source code) uses
|
| + source-code mirrors.</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="ch03-mirrors-symbols"></a>Symbols</h3></div></div></div><p>The mirror system represents the names of Dart declarations
|
| + (classes, fields, and so on) by instances of the class <a class="ulink" href="http://api.dartlang.org/dart_core/Symbol.html" target="_top">Symbol</a>.
|
| + Symbols help compilers like dart2js produce efficient output, even when
|
| + minified.</p><p>When you know the name of the symbol ahead of time, use Symbol's
|
| + const constructor. This way, repeated uses of the same symbol can use
|
| + the same canonicalized instance. If the name of the symbol is determined
|
| + dynamically at runtime, use the factory constructor.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>// If the symbol name is known at compile time.
|
| const className = const Symbol('MyClass');
|
|
|
| // If the symbol name is dynamically determined.
|
| var userInput = askUserForNameOfFunction();
|
| -var functionName = new Symbol(userInput);</pre><p>During minification, a compiler might replace a Symbol name
|
| - with a different (often smaller) name.
|
| - To convert from a symbol back to a string, use
|
| - <code class="literal">MirrorSystem.getName()</code>. This function returns
|
| - the correct name, even if the code was minified.</p><pre class="screen"><em><span class="remark">lang-dart
|
| +var functionName = new Symbol(userInput);</pre><p>During minification, a compiler might replace a Symbol name with a
|
| + different (often smaller) name. To convert from a symbol back to a
|
| + string, use <code class="literal">MirrorSystem.getName()</code>. This function
|
| + returns the correct name, even if the code was minified.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>import 'dart:mirrors';
|
|
|
| main() {
|
| @@ -1465,7 +1460,8 @@ main() {
|
|
|
| assert('MyClass' == MirrorSystem.getName(name));
|
| }</pre></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="ch03-mirrors-introspection"></a>Introspection</h3></div></div></div><p>Use mirrors to introspect the running program's structure. You can
|
| - inspect classes, libraries, instances, and more.</p><p>The examples in this section use the following Person class:</p><pre class="screen"><em><span class="remark">lang-dart
|
| + inspect classes, libraries, instances, and more.</p><p>The examples in this section use the following Person
|
| + class:</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>class Person {
|
| String firstName;
|
| String lastName;
|
| @@ -1478,19 +1474,18 @@ main() {
|
| void greet(String other) {
|
| print('Hello there, $other!');
|
| }
|
| -}</pre><p>To begin, you
|
| - need to <span class="emphasis"><em>reflect</em></span> on a class or object to
|
| - get its <span class="emphasis"><em>mirror</em></span>.</p><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="ch03-mirrors-class-inspect"></a>Class Mirrors</h4></div></div></div><p>Reflect on a Type to get its ClassMirror.</p><pre class="screen"><em><span class="remark">lang-dart
|
| +}</pre><p>To begin, you need to <span class="emphasis"><em>reflect</em></span> on a class or
|
| + object to get its <span class="emphasis"><em>mirror</em></span>.</p><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="ch03-mirrors-class-inspect"></a>Class Mirrors</h4></div></div></div><p>Reflect on a Type to get its ClassMirror.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>ClassMirror mirror = reflectClass(Person);
|
|
|
| -assert('Person' == MirrorSystem.getName(mirror.simpleName));</pre><p>You can also call <code class="literal">runtimeType</code>
|
| - to get a Type from an instance.</p><pre class="screen"><em><span class="remark">lang-dart
|
| +assert('Person' == MirrorSystem.getName(mirror.simpleName));</pre><p>You can also call <code class="literal">runtimeType</code> to get a Type
|
| + from an instance.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>var bob = new Person('Bob', 'Smith', 33);
|
| ClassMirror mirror = reflectClass(bob.runtimeType);
|
|
|
| -assert('Person' == MirrorSystem.getName(mirror.simpleName));</pre><p>Once you have a ClassMirror, you can get a class's
|
| - constructors, fields, and more. Here is an example of listing
|
| - the constructors of a class.</p><pre class="screen"><em><span class="remark">lang-dart
|
| +assert('Person' == MirrorSystem.getName(mirror.simpleName));</pre><p>Once you have a ClassMirror, you can get a class's constructors,
|
| + fields, and more. Here is an example of listing the constructors of a
|
| + class.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>showConstructors(ClassMirror mirror) {
|
| Map<Symbol, MethodMirror> constructors = mirror.constructors;
|
|
|
| @@ -1498,7 +1493,7 @@ assert('Person' == MirrorSystem.getName(mirror.simpleName));</pre><p>Once you ha
|
| print('The constructor $s has ${m.parameters.length} parameters.');
|
| });
|
| }</pre><p>Here is an example of listing all of the fields declared by a
|
| - class.</p><pre class="screen"><em><span class="remark">lang-dart
|
| + class.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>showFields(ClassMirror mirror) {
|
| Map<Symbol, VariableMirror> fields = mirror.variables;
|
|
|
| @@ -1510,26 +1505,20 @@ assert('Person' == MirrorSystem.getName(mirror.simpleName));</pre><p>Once you ha
|
| print('The field $s is $privateStatus and $finalStatus and is annotated '
|
| 'as $typeAnnotation');
|
| });
|
| -}</pre><p>For a full list of methods,
|
| - consult the <a class="ulink" href="http://api.dartlang.org/dart_mirrors/ClassMirror.html" target="_top">API docs
|
| - for ClassMirror</a>.</p></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="ch03-mirrors-instance-inspect"></a>Instance Mirrors</h4></div></div></div><p>Reflect on an object to get an InstanceMirror.</p><pre class="screen"><em><span class="remark">lang-dart
|
| +}</pre><p>For a full list of methods, consult the <a class="ulink" href="http://api.dartlang.org/dart_mirrors/ClassMirror.html" target="_top">API docs
|
| + for ClassMirror</a>.</p></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="ch03-mirrors-instance-inspect"></a>Instance Mirrors</h4></div></div></div><p>Reflect on an object to get an InstanceMirror.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em>reflectOnInstance() {
|
| var p = new Person('Bob', 'Smith', int);
|
| InstanceMirror mirror = reflect(p);
|
| }</pre><p>If you have an InstanceMirror and you want to get the object
|
| - that it reflects, use <code class="literal">reflectee</code>.
|
| - This works only if the current isolate knows about the type
|
| - of the reflectee. Remember, mirrors work across isolates, and one
|
| - isolate might contain a class that is not in the current
|
| - isolate.</p><pre class="screen"><em><span class="remark">lang-dart
|
| + that it reflects, use <code class="literal">reflectee</code>. This works only if
|
| + the current isolate knows about the type of the reflectee. Remember,
|
| + mirrors work across isolates, and one isolate might contain a class
|
| + that is not in the current isolate.</p><pre class="screen"><em><span class="remark">lang-dart
|
| </span></em> var person = mirror.reflectee;
|
| - assert(identical(p, person));</pre><p>Once you have an InstanceMirror, you can invoke methods and
|
| - call getters and setters.
|
| - For a full list of methods,
|
| - consult the <a class="ulink" href="http://api.dartlang.org/dart_mirrors/InstanceMirror.html" target="_top">API docs
|
| - for InstanceMirror</a>.</p></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="ch03-mirrors-invocation"></a>Invocation</h3></div></div></div><p>
|
| - {To be written}
|
| - </p><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp17910288"></a>get and set fields</h4></div></div></div></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp17911056"></a>invoke</h4></div></div></div></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp17911824"></a>delegate</h4></div></div></div></div></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ch03-summary"></a>Summary</h2></div></div></div><p>This chapter introduced you to the most commonly used functionality
|
| + assert(identical(p, person));</pre><p>Once you have an InstanceMirror, you can invoke methods and call
|
| + getters and setters. For a full list of methods, consult the <a class="ulink" href="http://api.dartlang.org/dart_mirrors/InstanceMirror.html" target="_top">API
|
| + docs for InstanceMirror</a>.</p></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="ch03-mirrors-invocation"></a>Invocation</h3></div></div></div><p>{PENDING: To be written}</p><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp17920016"></a>get and set fields</h4></div></div></div></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp17920784"></a>invoke</h4></div></div></div></div><div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp17921552"></a>delegate</h4></div></div></div></div></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ch03-summary"></a>Summary</h2></div></div></div><p>This chapter introduced you to the most commonly used functionality
|
| in many of Dart’s built-in libraries. It didn’t cover all the built-in
|
| libraries, however. Other libraries you might want to look into include
|
| <a class="ulink" href="http://api.dartlang.org/dart_collection.html" target="_top">dart:collection,</a>
|
|
|