2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.10
6
-
7
5
import 'package:kernel/ast.dart' as ir;
8
6
import 'package:kernel/type_environment.dart' as ir;
9
7
import '../common/names.dart' ;
10
- import 'modular .dart' ;
8
+ import 'modular_migrated .dart' ;
11
9
12
10
class IrAnnotationData {
13
11
final Map <ir.Class , String > _nativeClassNames = {};
@@ -25,13 +23,13 @@ class IrAnnotationData {
25
23
{};
26
24
27
25
// Returns the text from the `@Native(<text>)` annotation of [node], if any.
28
- String getNativeClassName (ir.Class node) => _nativeClassNames[node];
26
+ String ? getNativeClassName (ir.Class node) => _nativeClassNames[node];
29
27
30
28
// Returns `true` if [node] has a native body, as in `method() native;`.
31
29
bool hasNativeBody (ir.Member node) => _nativeMembers.contains (node);
32
30
33
31
// Returns the text from the `@JSName(<text>)` annotation of [node], if any.
34
- String getNativeMemberName (ir.Member node) => _nativeMemberNames[node];
32
+ String ? getNativeMemberName (ir.Member node) => _nativeMemberNames[node];
35
33
36
34
// Returns a list of the text from the `@Creates(<text>)` annotation of
37
35
// [node].
@@ -44,18 +42,18 @@ class IrAnnotationData {
44
42
_returnsAnnotations[node] ?? const [];
45
43
46
44
// Returns the text from the `@JS(<text>)` annotation of [node], if any.
47
- String getJsInteropLibraryName (ir.Library node) =>
45
+ String ? getJsInteropLibraryName (ir.Library node) =>
48
46
_jsInteropLibraryNames[node];
49
47
50
48
// Returns the text from the `@JS(<text>)` annotation of [node], if any.
51
- String getJsInteropClassName (ir.Class node) => _jsInteropClassNames[node];
49
+ String ? getJsInteropClassName (ir.Class node) => _jsInteropClassNames[node];
52
50
53
51
// Returns `true` if [node] is annotated with `@anonymous`.
54
52
bool isAnonymousJsInteropClass (ir.Class node) =>
55
53
_anonymousJsInteropClasses.contains (node);
56
54
57
55
// Returns the text from the `@JS(<text>)` annotation of [node], if any.
58
- String getJsInteropMemberName (ir.Member node) => _jsInteropMemberNames[node];
56
+ String ? getJsInteropMemberName (ir.Member node) => _jsInteropMemberNames[node];
59
57
60
58
// Returns a list of the `@pragma('dart2js:<suffix>')` annotations on [node].
61
59
List <PragmaAnnotationData > getMemberPragmaAnnotationData (ir.Member node) =>
@@ -76,7 +74,7 @@ class IrAnnotationData {
76
74
});
77
75
}
78
76
79
- void forEachJsInteropMember (void Function (ir.Member , String ) f) {
77
+ void forEachJsInteropMember (void Function (ir.Member , String ? ) f) {
80
78
_jsInteropLibraryNames.forEach ((ir.Library library, _) {
81
79
for (ir.Member member in library.members) {
82
80
if (member.isExternal) {
@@ -87,7 +85,7 @@ class IrAnnotationData {
87
85
_jsInteropClassNames.forEach ((ir.Class cls, _) {
88
86
for (ir.Member member in cls.members) {
89
87
if (member is ir.Field ) continue ;
90
- String name = _jsInteropMemberNames[member];
88
+ String ? name = _jsInteropMemberNames[member];
91
89
if (member.isExternal) {
92
90
name ?? = member.name.text;
93
91
}
@@ -131,15 +129,15 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
131
129
void processMember (ir.Member member) {
132
130
ir.StaticTypeContext staticTypeContext = ir.StaticTypeContext (
133
131
member, modularCore.constantEvaluator.typeEnvironment);
134
- List <PragmaAnnotationData > pragmaAnnotations;
135
- List <String > createsAnnotations;
136
- List <String > returnsAnnotations;
132
+ List <PragmaAnnotationData >? pragmaAnnotations;
133
+ List <String >? createsAnnotations;
134
+ List <String >? returnsAnnotations;
137
135
for (ir.Expression annotation in member.annotations) {
138
136
if (annotation is ir.ConstantExpression ) {
139
137
ir.Constant constant = modularCore.constantEvaluator
140
138
.evaluate (staticTypeContext, annotation);
141
139
142
- String jsName = _getJsInteropName (constant);
140
+ String ? jsName = _getJsInteropName (constant);
143
141
if (jsName != null ) {
144
142
data._jsInteropMemberNames[member] = jsName;
145
143
}
@@ -149,28 +147,28 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
149
147
data._nativeMembers.add (member);
150
148
}
151
149
152
- String nativeName = _getNativeMemberName (constant);
150
+ String ? nativeName = _getNativeMemberName (constant);
153
151
if (nativeName != null ) {
154
152
data._nativeMemberNames[member] = nativeName;
155
153
}
156
154
157
- String creates = _getCreatesAnnotation (constant);
155
+ String ? creates = _getCreatesAnnotation (constant);
158
156
if (creates != null ) {
159
157
if (createsAnnotations == null ) {
160
158
data._createsAnnotations[member] = createsAnnotations = [];
161
159
}
162
160
createsAnnotations.add (creates);
163
161
}
164
162
165
- String returns = _getReturnsAnnotation (constant);
163
+ String ? returns = _getReturnsAnnotation (constant);
166
164
if (returns != null ) {
167
165
if (returnsAnnotations == null ) {
168
166
data._returnsAnnotations[member] = returnsAnnotations = [];
169
167
}
170
168
returnsAnnotations.add (returns);
171
169
}
172
170
173
- PragmaAnnotationData pragmaAnnotation = _getPragmaAnnotation (constant);
171
+ PragmaAnnotationData ? pragmaAnnotation = _getPragmaAnnotation (constant);
174
172
if (pragmaAnnotation != null ) {
175
173
if (pragmaAnnotations == null ) {
176
174
data._memberPragmaAnnotations[member] = pragmaAnnotations = [];
@@ -190,7 +188,7 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
190
188
ir.Constant constant = modularCore.constantEvaluator
191
189
.evaluate (staticTypeContext, annotation);
192
190
193
- String jsName = _getJsInteropName (constant);
191
+ String ? jsName = _getJsInteropName (constant);
194
192
if (jsName != null ) {
195
193
data._jsInteropLibraryNames[library] = jsName;
196
194
}
@@ -202,12 +200,12 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
202
200
ir.Constant constant = modularCore.constantEvaluator
203
201
.evaluate (staticTypeContext, annotation);
204
202
205
- String nativeClassName = _getNativeClassName (constant);
203
+ String ? nativeClassName = _getNativeClassName (constant);
206
204
if (nativeClassName != null ) {
207
205
data._nativeClassNames[cls] = nativeClassName;
208
206
}
209
207
210
- String jsName = _getJsInteropName (constant);
208
+ String ? jsName = _getJsInteropName (constant);
211
209
if (jsName != null ) {
212
210
data._jsInteropClassNames[cls] = jsName;
213
211
}
@@ -229,15 +227,15 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
229
227
return data;
230
228
}
231
229
232
- String _getNativeClassName (ir.Constant constant) {
230
+ String ? _getNativeClassName (ir.Constant constant) {
233
231
if (constant is ir.InstanceConstant ) {
234
232
// TODO(johnniwinther): Add an IrCommonElements for these queries; i.e.
235
233
// `commonElements.isNativeAnnotationClass(constant.classNode)`.
236
234
if (constant.classNode.name == 'Native' &&
237
235
constant.classNode.enclosingLibrary.importUri == Uris .dart__js_helper) {
238
236
if (constant.fieldValues.length == 1 ) {
239
237
ir.Constant fieldValue = constant.fieldValues.values.single;
240
- String name;
238
+ String ? name;
241
239
if (fieldValue is ir.StringConstant ) {
242
240
name = fieldValue.value;
243
241
}
@@ -256,7 +254,7 @@ bool _isNativeMember(ir.Constant constant) {
256
254
constant.classNode.enclosingLibrary.importUri == Uris .dart__internal;
257
255
}
258
256
259
- String _getNativeMemberName (ir.Constant constant) {
257
+ String ? _getNativeMemberName (ir.Constant constant) {
260
258
if (constant is ir.InstanceConstant &&
261
259
constant.classNode.name == 'JSName' &&
262
260
constant.classNode.enclosingLibrary.importUri == Uris .dart__js_helper) {
@@ -269,7 +267,7 @@ String _getNativeMemberName(ir.Constant constant) {
269
267
return null ;
270
268
}
271
269
272
- String _getCreatesAnnotation (ir.Constant constant) {
270
+ String ? _getCreatesAnnotation (ir.Constant constant) {
273
271
if (constant is ir.InstanceConstant &&
274
272
constant.classNode.name == 'Creates' &&
275
273
constant.classNode.enclosingLibrary.importUri == Uris .dart__js_helper) {
@@ -282,7 +280,7 @@ String _getCreatesAnnotation(ir.Constant constant) {
282
280
return null ;
283
281
}
284
282
285
- String _getReturnsAnnotation (ir.Constant constant) {
283
+ String ? _getReturnsAnnotation (ir.Constant constant) {
286
284
if (constant is ir.InstanceConstant &&
287
285
constant.classNode.name == 'Returns' &&
288
286
constant.classNode.enclosingLibrary.importUri == Uris .dart__js_helper) {
@@ -295,7 +293,7 @@ String _getReturnsAnnotation(ir.Constant constant) {
295
293
return null ;
296
294
}
297
295
298
- String _getJsInteropName (ir.Constant constant) {
296
+ String ? _getJsInteropName (ir.Constant constant) {
299
297
if (constant is ir.InstanceConstant &&
300
298
constant.classNode.name == 'JS' &&
301
299
(constant.classNode.enclosingLibrary.importUri == Uris .package_js ||
@@ -335,7 +333,7 @@ class PragmaAnnotationData {
335
333
String toString () => 'PragmaAnnotationData($name )' ;
336
334
}
337
335
338
- PragmaAnnotationData _getPragmaAnnotation (ir.Constant constant) {
336
+ PragmaAnnotationData ? _getPragmaAnnotation (ir.Constant constant) {
339
337
if (constant is ! ir.InstanceConstant ) return null ;
340
338
ir.InstanceConstant value = constant;
341
339
ir.Class cls = value.classNode;
@@ -347,8 +345,8 @@ PragmaAnnotationData _getPragmaAnnotation(ir.Constant constant) {
347
345
return const PragmaAnnotationData ('tryInline' );
348
346
}
349
347
} else if (uri == Uris .dart_core && cls.name == 'pragma' ) {
350
- ir.Constant nameValue;
351
- ir.Constant optionsValue;
348
+ ir.Constant ? nameValue;
349
+ ir.Constant ? optionsValue;
352
350
value.fieldValues.forEach ((ir.Reference reference, ir.Constant fieldValue) {
353
351
ir.Field field = reference.asField;
354
352
if (field.name.text == 'name' ) {
@@ -357,8 +355,9 @@ PragmaAnnotationData _getPragmaAnnotation(ir.Constant constant) {
357
355
optionsValue = fieldValue;
358
356
}
359
357
});
360
- if (nameValue is ! ir.StringConstant ) return null ;
361
- ir.StringConstant stringValue = nameValue;
358
+ final nameValueFinal = nameValue;
359
+ if (nameValueFinal is ! ir.StringConstant ) return null ;
360
+ ir.StringConstant stringValue = nameValueFinal;
362
361
String name = stringValue.value;
363
362
String prefix = 'dart2js:' ;
364
363
if (! name.startsWith (prefix)) return null ;
@@ -377,7 +376,7 @@ List<PragmaAnnotationData> computePragmaAnnotationDataFromIr(ir.Member member) {
377
376
ir.Constant constant = constantExpression.constant;
378
377
assert (constant is ! ir.UnevaluatedConstant ,
379
378
"Unexpected unevaluated constant on $member : $metadata " );
380
- PragmaAnnotationData data = _getPragmaAnnotation (constant);
379
+ PragmaAnnotationData ? data = _getPragmaAnnotation (constant);
381
380
if (data != null ) {
382
381
annotations.add (data);
383
382
}
0 commit comments