Skip to content

Commit 857c323

Browse files
author
Tony Sansone
committed
Reset path-base for excerpts
1 parent 89ba313 commit 857c323

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/content/language/constructors.md

+19-17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Constructors create instances of classes.
2222
* To instantiate any instance variables,
2323
[initialize formal parameters](#parameter-initialization).
2424

25+
<?code-excerpt path-base="misc/lib/language_tour/classes"?>
26+
2527
<?code-excerpt replace="/ *\/\/\s+ignore_for_file:[^\n]+\n//g; /(^|\n) *\/\/\s+ignore:[^\n]+\n/$1/g; /(\n[^\n]+) *\/\/\s+ignore:[^\n]+\n/$1\n/g; / *\/\/\s+ignore:[^\n]+//g; /([A-Z]\w*)\d\b/$1/g"?>
2628

2729
## Types of constructors
@@ -36,7 +38,7 @@ no-argument constructor in the superclass.
3638

3739
To instantiate a class, use the generative constructor.
3840

39-
<?code-excerpt "misc/lib/language_tour/classes/point_alt.dart (idiomatic-constructor)" plaster="none"?>
41+
<?code-excerpt "point_alt.dart (idiomatic-constructor)" plaster="none"?>
4042
```dart
4143
class Point {
4244
double x = 0;
@@ -52,7 +54,7 @@ class Point {
5254
Use a named constructor to implement multiple constructors for a class
5355
or to provide extra clarity:
5456

55-
<?code-excerpt "misc/lib/language_tour/classes/point.dart (named-constructor)" replace="/Point\.\S*/[!$&!]/g" plaster="none"?>
57+
<?code-excerpt "point.dart (named-constructor)" replace="/Point\.\S*/[!$&!]/g" plaster="none"?>
5658
```dart
5759
const double xOrigin = 0;
5860
const double yOrigin = 0;
@@ -93,7 +95,7 @@ In the following example,
9395
the constructor for the `Employee` class calls the named constructor
9496
for its superclass, `Person`. Click **Run** to execute the code.
9597

96-
<?code-excerpt "misc/lib/language_tour/classes/employee.dart (super)" plaster="none"?>
98+
<?code-excerpt "employee.dart (super)" plaster="none"?>
9799
```dart:run-dartpad:height-450px:ga_id-non_default_superclass_constructor
98100
class Person {
99101
String? firstName;
@@ -125,7 +127,7 @@ As Dart evaluates the arguments to the superclass constructor *before*
125127
invoking the constructor, an argument can be an expression like a
126128
function call.
127129

128-
<?code-excerpt "misc/lib/language_tour/classes/employee.dart (method-then-constructor)"?>
130+
<?code-excerpt "employee.dart (method-then-constructor)"?>
129131
```dart
130132
class Employee extends Person {
131133
Employee() : super.fromJson(fetchDefaultData());
@@ -173,7 +175,7 @@ you must manually pass in all super constructor parameters.
173175
If the super-constructor invocation includes positional arguments,
174176
super-initializer parameters can't be positional.
175177

176-
<?code-excerpt "misc/lib/language_tour/classes/super_initializer_parameters.dart (positional)" plaster="none"?>
178+
<?code-excerpt "super_initializer_parameters.dart (positional)" plaster="none"?>
177179
```dart
178180
class Vector2d {
179181
final double x;
@@ -209,7 +211,7 @@ between named super parameters (`super.y` in the next example)
209211
and named arguments to the super constructor invocation
210212
(`super.named(x: 0)`).
211213

212-
<?code-excerpt "misc/lib/language_tour/classes/super_initializer_parameters.dart (named)" plaster="none"?>
214+
<?code-excerpt "super_initializer_parameters.dart (named)" plaster="none"?>
213215
```dart
214216
class Vector2d {
215217
// ...
@@ -235,7 +237,7 @@ empty, with the constructor call
235237
(using `this` instead of the class name)
236238
appearing after a colon (:).
237239

238-
<?code-excerpt "misc/lib/language_tour/classes/point_redirecting.dart"?>
240+
<?code-excerpt "point_redirecting.dart"?>
239241
```dart
240242
class Point {
241243
double x, y;
@@ -254,7 +256,7 @@ If your class produces objects that never change, you can make these
254256
objects compile-time constants. To do this, define a `const` constructor
255257
and make sure that all instance variables are `final`.
256258

257-
<?code-excerpt "misc/lib/language_tour/classes/immutable_point.dart"?>
259+
<?code-excerpt "immutable_point.dart"?>
258260
```dart
259261
class ImmutablePoint {
260262
static const ImmutablePoint origin = ImmutablePoint(0, 0);
@@ -296,7 +298,7 @@ In the following example includes two factory constructors.
296298
* The `Logger.fromJson` factory constructor initializes a final variable
297299
from a JSON object.
298300

299-
<?code-excerpt "misc/lib/language_tour/classes/logger.dart (constructors)"?>
301+
<?code-excerpt "logger.dart (constructors)"?>
300302
```dart
301303
class Logger {
302304
final String name;
@@ -328,7 +330,7 @@ Factory constructors can't access to `this`.
328330

329331
Invoke a factory constructor just like you would any other constructor:
330332

331-
<?code-excerpt "misc/lib/language_tour/classes/logger.dart (logger)"?>
333+
<?code-excerpt "logger.dart (logger)"?>
332334
```dart
333335
var logger = Logger('UI');
334336
logger.log('Button clicked');
@@ -345,7 +347,7 @@ Dart can initialize parameters in a constructor in three ways.
345347

346348
Initialize the constructor parameters when you declare variables.
347349

348-
<?code-excerpt "misc/lib/language_tour/classes/point_alt.dart (initialize-declaration)" plaster="none"?>
350+
<?code-excerpt "point_alt.dart (initialize-declaration)" plaster="none"?>
349351
```dart
350352
class PointA {
351353
[!double x = 1.0;!]
@@ -385,7 +387,7 @@ Initializing formal parameters also allow you to initialize
385387
non-nullable or `final` instance variables.
386388
Both of these types of variables require initialization or a default value.
387389

388-
<?code-excerpt "misc/lib/language_tour/classes/point_alt.dart (initialize-formal)" plaster="none"?>
390+
<?code-excerpt "point_alt.dart (initialize-formal)" plaster="none"?>
389391
```dart
390392
class PointB {
391393
final double x;
@@ -408,7 +410,7 @@ class PointB {
408410

409411
This also works with named variables.
410412

411-
<?code-excerpt "misc/lib/language_tour/classes/point_alt.dart (initialize-named)" plaster="none"?>
413+
<?code-excerpt "point_alt.dart (initialize-named)" plaster="none"?>
412414
```dart
413415
class PointC {
414416
double x; // must be set in constructor
@@ -438,7 +440,7 @@ You can then pass the computed values to a normal constructor.
438440

439441
The constructor parameters could be set as nullable and not be initialized.
440442

441-
<?code-excerpt "misc/lib/language_tour/classes/point_alt.dart (initialize-null)" plaster="none"?>
443+
<?code-excerpt "point_alt.dart (initialize-null)" plaster="none"?>
442444
```dart
443445
class PointD {
444446
[!double? x;!] // null if not set in constructor
@@ -459,7 +461,7 @@ class PointD {
459461
Before the constructor body runs, you can initialize instance variables.
460462
Separate initializers with commas.
461463

462-
<?code-excerpt "misc/lib/language_tour/classes/point_alt.dart (initializer-list)"?>
464+
<?code-excerpt "point_alt.dart (initializer-list)"?>
463465
```dart
464466
// Initializer list sets instance variables before
465467
// the constructor body runs.
@@ -477,7 +479,7 @@ The right-hand side of an initializer list can't access `this`.
477479
To validate inputs during development,
478480
use `assert` in the initializer list.
479481

480-
<?code-excerpt "misc/lib/language_tour/classes/point_alt.dart (initializer-list-with-assert)" replace="/assert\(.*?\)/[!$&!]/g"?>
482+
<?code-excerpt "point_alt.dart (initializer-list-with-assert)" replace="/assert\(.*?\)/[!$&!]/g"?>
481483
```dart
482484
Point.withAssert(this.x, this.y) : [!assert(x >= 0)!] {
483485
print('In Point.withAssert(): ($x, $y)');
@@ -489,7 +491,7 @@ Initializer lists help set up `final` fields.
489491
The following example initializes three `final` fields in an initializer list.
490492
To execute the code, click **Run**.
491493

492-
<?code-excerpt "misc/lib/language_tour/classes/point_with_distance_field.dart"?>
494+
<?code-excerpt "point_with_distance_field.dart"?>
493495
```dart:run-dartpad:height-340px:ga_id-initializer_list
494496
import 'dart:math';
495497

0 commit comments

Comments
 (0)