Skip to content

Commit dfc8f1b

Browse files
committed
Merge branch 'master' into pub
2 parents d2b4f8c + 1027b7f commit dfc8f1b

36 files changed

+3215
-10
lines changed

.tools/cpex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ cp example/bin/sealed/nullsafe/data/simple/common.dart sealed_annotations/exampl
1414
cp example/bin/sealed/nullsafe/data/simple/common.sealed.dart sealed_annotations/example/
1515
cp example/bin/sealed/nullsafe/data/generic/result_complex.dart sealed_annotations/example/
1616
cp example/bin/sealed/nullsafe/data/generic/result_complex.sealed.dart sealed_annotations/example/
17+
cp example/bin/sealed/nullsafe/data/simple/hierarchy.dart sealed_annotations/example/
18+
cp example/bin/sealed/nullsafe/data/simple/hierarchy.sealed.dart sealed_annotations/example/
19+
cp example/bin/sealed/nullsafe/data/generic/result_hierarchy.dart sealed_annotations/example/
20+
cp example/bin/sealed/nullsafe/data/generic/result_hierarchy.sealed.dart sealed_annotations/example/
1721

1822
cp example/bin/sealed/nullsafe/data/simple/weather.dart sealed_generators/example/
1923
cp example/bin/sealed/nullsafe/data/simple/weather.sealed.dart sealed_generators/example/
@@ -27,5 +31,9 @@ cp example/bin/sealed/nullsafe/data/simple/common.dart sealed_generators/example
2731
cp example/bin/sealed/nullsafe/data/simple/common.sealed.dart sealed_generators/example/
2832
cp example/bin/sealed/nullsafe/data/generic/result_complex.dart sealed_generators/example/
2933
cp example/bin/sealed/nullsafe/data/generic/result_complex.sealed.dart sealed_generators/example/
34+
cp example/bin/sealed/nullsafe/data/simple/hierarchy.dart sealed_generators/example/
35+
cp example/bin/sealed/nullsafe/data/simple/hierarchy.sealed.dart sealed_generators/example/
36+
cp example/bin/sealed/nullsafe/data/generic/result_hierarchy.dart sealed_generators/example/
37+
cp example/bin/sealed/nullsafe/data/generic/result_hierarchy.sealed.dart sealed_generators/example/
3038

3139
echo DONE

.tools/cpex.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ copy example\bin\sealed\nullsafe\data\simple\common.dart sealed_annotations\exam
1414
copy example\bin\sealed\nullsafe\data\simple\common.sealed.dart sealed_annotations\example\
1515
copy example\bin\sealed\nullsafe\data\generic\result_complex.dart sealed_annotations\example\
1616
copy example\bin\sealed\nullsafe\data\generic\result_complex.sealed.dart sealed_annotations\example\
17+
copy example\bin\sealed\nullsafe\data\simple\hierarchy.dart sealed_annotations\example\
18+
copy example\bin\sealed\nullsafe\data\simple\hierarchy.sealed.dart sealed_annotations\example\
19+
copy example\bin\sealed\nullsafe\data\generic\result_hierarchy.dart sealed_annotations\example\
20+
copy example\bin\sealed\nullsafe\data\generic\result_hierarchy.sealed.dart sealed_annotations\example\
1721

1822
copy example\bin\sealed\nullsafe\data\simple\weather.dart sealed_generators\example\
1923
copy example\bin\sealed\nullsafe\data\simple\weather.sealed.dart sealed_generators\example\
@@ -27,5 +31,9 @@ copy example\bin\sealed\nullsafe\data\simple\common.dart sealed_generators\examp
2731
copy example\bin\sealed\nullsafe\data\simple\common.sealed.dart sealed_generators\example\
2832
copy example\bin\sealed\nullsafe\data\generic\result_complex.dart sealed_generators\example\
2933
copy example\bin\sealed\nullsafe\data\generic\result_complex.sealed.dart sealed_generators\example\
34+
copy example\bin\sealed\nullsafe\data\simple\hierarchy.dart sealed_generators\example\
35+
copy example\bin\sealed\nullsafe\data\simple\hierarchy.sealed.dart sealed_generators\example\
36+
copy example\bin\sealed\nullsafe\data\generic\result_hierarchy.dart sealed_generators\example\
37+
copy example\bin\sealed\nullsafe\data\generic\result_hierarchy.sealed.dart sealed_generators\example\
3038

3139
echo DONE

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.12.0
2+
3+
- Added hierarchy feature to use sealed classes directly in sealed hierarchies
4+
15
## 1.11.0
26

37
- Added whenOrNull and mapOrNull methods (#12)

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,52 @@ abstract class _WeatherInfo {
321321
}
322322
```
323323

324+
### Hierarchy Feature
325+
326+
If Sealed classes are in the same file you can reference them directly using their manifest class name. This is to
327+
avoid `@WithType` annotation and better refactoring capability.
328+
329+
```dart
330+
@Sealed()
331+
abstract class _Apple {
332+
void eat();
333+
}
334+
335+
@Sealed()
336+
abstract class _Banana {
337+
void eat();
338+
}
339+
340+
@Sealed()
341+
abstract class _Basket {
342+
void friends(_Apple? apple, _Banana? banana);
343+
344+
// or equivalently
345+
// void friends(@WithType('Apple?') apple, @WithType('Banana?') banana);
346+
}
347+
```
348+
349+
And for generic case:
350+
351+
```dart
352+
@Sealed()
353+
abstract class _Result<D extends num> {
354+
void success(D data);
355+
356+
void error(Object exception);
357+
}
358+
359+
@Sealed()
360+
abstract class _Basket {
361+
void hold(_Result<int> x);
362+
363+
// or equivalently:
364+
// void hold(@WithType('Result<int>') x);
365+
}
366+
```
367+
368+
`@WithType` annotation will override hierarchy feature if present.
369+
324370
## Common Fields
325371

326372
Sometimes you need some fields to be present in all of your sealed classes. For example consider making a sealed class

example/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.12.0
2+
3+
- Added hierarchy feature to use sealed classes directly in sealed hierarchies
4+
15
## 1.11.0
26

37
- Added whenOrNull and mapOrNull methods (#12)

example/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,52 @@ abstract class _WeatherInfo {
321321
}
322322
```
323323

324+
### Hierarchy Feature
325+
326+
If Sealed classes are in the same file you can reference them directly using their manifest class name. This is to
327+
avoid `@WithType` annotation and better refactoring capability.
328+
329+
```dart
330+
@Sealed()
331+
abstract class _Apple {
332+
void eat();
333+
}
334+
335+
@Sealed()
336+
abstract class _Banana {
337+
void eat();
338+
}
339+
340+
@Sealed()
341+
abstract class _Basket {
342+
void friends(_Apple? apple, _Banana? banana);
343+
344+
// or equivalently
345+
// void friends(@WithType('Apple?') apple, @WithType('Banana?') banana);
346+
}
347+
```
348+
349+
And for generic case:
350+
351+
```dart
352+
@Sealed()
353+
abstract class _Result<D extends num> {
354+
void success(D data);
355+
356+
void error(Object exception);
357+
}
358+
359+
@Sealed()
360+
abstract class _Basket {
361+
void hold(_Result<int> x);
362+
363+
// or equivalently:
364+
// void hold(@WithType('Result<int>') x);
365+
}
366+
```
367+
368+
`@WithType` annotation will override hierarchy feature if present.
369+
324370
## Common Fields
325371

326372
Sometimes you need some fields to be present in all of your sealed classes. For example consider making a sealed class
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:sealed_annotations/sealed_annotations.dart';
2+
3+
part 'result_hierarchy.sealed.dart';
4+
5+
@Sealed()
6+
abstract class _Result<D extends num> {
7+
void success(D data);
8+
9+
void error(Object exception);
10+
}
11+
12+
@Sealed()
13+
abstract class _Basket {
14+
void hold(
15+
_Result<int> x,
16+
_Result<double>? y,
17+
);
18+
}

0 commit comments

Comments
 (0)