14
14
` package:json_serializable ` .
15
15
* Removed ` lib/builder.dart ` . Import through ` source_gen.dart ` instead.
16
16
* Removed ` OutputFormatter ` typedef.
17
-
17
+
18
18
* Add ` LibraryReader.allElements ` - a utility to iterate across all ` Element `
19
19
instances contained in Dart library.
20
20
* Add ` LibraryReader.element ` to get back to the ` LibraryElement ` instance.
@@ -29,6 +29,12 @@ findTokenField(DartObject o) {
29
29
}
30
30
```
31
31
32
+ * Add ` throwOnUnresolved ` optional parameter to ` TypeChecker.annotationsOf ` ,
33
+ ` TypeChecker.annotationsOfExact ` , ` TypeChecker.firstAnnotationOf ` , and
34
+ ` TypeChecker.firstAnnotationOfExact ` . Setting this to ` false ` will enable you
35
+ to check for matching annotations with incomplete type information (at your
36
+ own risk).
37
+
32
38
## 0.6.1+1
33
39
34
40
* Tighten constraint on ` source_span ` .
@@ -70,14 +76,14 @@ findTokenField(DartObject o) {
70
76
``` dart
71
77
import 'package:analyzer/dart/element/type.dart';
72
78
import 'package:source_gen/source_gen.dart';
73
-
79
+
74
80
void checkType(DartType dartType) {
75
81
// Checks compared to runtime type `SomeClass`.
76
82
print(const TypeChecker.forRuntime(SomeClass).isExactlyType(dartType));
77
-
83
+
78
84
// Checks compared to a known Url/Symbol:
79
85
const TypeChecker.forUrl('package:foo/foo.dart#SomeClass');
80
-
86
+
81
87
// Checks compared to another resolved `DartType`:
82
88
const TypeChecker.forStatic(anotherDartType);
83
89
}
@@ -86,19 +92,19 @@ findTokenField(DartObject o) {
86
92
* Failing to add a ` library ` directive to a library that is being used as a
87
93
generator target that generates partial files (` part of ` ) is now an explicit
88
94
error that gives a hint on how to name and fix your library:
89
-
95
+
90
96
``` bash
91
97
> Could not find library identifier so a " part of" cannot be built.
92
98
>
93
99
> Consider adding the following to your source file:
94
100
>
95
101
> " library foo.bar;"
96
102
```
97
-
103
+
98
104
In Dart SDK ` >=1.25.0 ` this can be relaxed as ` part of ` can refer to a path.
99
105
To opt-in, ` GeneratorBuilder ` now has a new flag, ` requireLibraryDirective ` .
100
106
Set it to ` false ` , and also set your ` sdk ` constraint appropriately:
101
-
107
+
102
108
``` yaml
103
109
sdk : ' >=1.25.0 <2.0.0'
104
110
` ` `
@@ -107,11 +113,11 @@ findTokenField(DartObject o) {
107
113
high-level APIs, including `findType`, which traverses `export` directives
108
114
for publicly exported types. For example, to find `Generator` from
109
115
`package:source_gen/source_gen.dart` :
110
-
116
+
111
117
` ` ` dart
112
118
void example(LibraryElement pkgSourceGen) {
113
119
var library = new LibraryReader(pkgSourceGen);
114
-
120
+
115
121
// Instead of pkgSourceGen.getType('Generator'), which is null.
116
122
library.findType('Generator');
117
123
}
@@ -120,26 +126,26 @@ findTokenField(DartObject o) {
120
126
* Added `ConstantReader`, a high-level API for reading from constant (static)
121
127
values from Dart source code (usually represented by `DartObject` from the
122
128
`analyzer` package) :
123
-
129
+
124
130
` ` ` dart
125
131
abstract class ConstantReader {
126
132
factory ConstantReader(DartObject object) => ...
127
-
133
+
128
134
// Other methods and properties also exist.
129
-
135
+
130
136
/// Reads[ field] from the constant as another constant value.
131
137
ConstantReader read(String field);
132
-
138
+
133
139
/// Reads [field] from the constant as a boolean.
134
140
///
135
141
/// If the resulting value is ` null`, uses [defaultTo] if defined.
136
142
bool readBool(String field, {bool defaultTo()});
137
-
143
+
138
144
/// Reads [field] from the constant as an int.
139
145
///
140
146
/// If the resulting value is `null`, uses [defaultTo] if defined.
141
147
int readInt(String field, {int defaultTo()});
142
-
148
+
143
149
/// Reads [field] from the constant as a string.
144
150
///
145
151
/// If the resulting value is `null`, uses [defaultTo] if defined.
0 commit comments