Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5c49a9f

Browse files
stereotype441Commit Queue
authored andcommitted
Migration: make NodeBuilder._variables non-nullable
Change-Id: I3bed0b3c788f3933281a1efa0c56025feba62354 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268606 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent d6909d4 commit 5c49a9f

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

pkg/nnbd_migration/lib/src/node_builder.dart

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
3737
PermissiveModeVisitor<DecoratedType>,
3838
CompletenessTracker<DecoratedType> {
3939
/// Constraint variables and decorated types are stored here.
40-
final Variables? _variables;
40+
final Variables _variables;
4141

4242
@override
4343
final Source? source;
@@ -104,7 +104,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
104104
instrumentation?.implicitType(
105105
source, node.exceptionParameter, exceptionType);
106106
}
107-
_variables!.recordDecoratedElementType(
107+
_variables.recordDecoratedElementType(
108108
node.exceptionParameter?.declaredElement, exceptionType);
109109
}
110110
if (node.stackTraceParameter != null) {
@@ -115,7 +115,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
115115
StackTraceTypeOrigin(source, node.stackTraceParameter));
116116
var stackTraceType =
117117
DecoratedType(_typeProvider.stackTraceType, nullabilityNode);
118-
_variables!.recordDecoratedElementType(
118+
_variables.recordDecoratedElementType(
119119
node.stackTraceParameter?.declaredElement, stackTraceType);
120120
instrumentation?.implicitType(
121121
source, node.stackTraceParameter, stackTraceType);
@@ -145,8 +145,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
145145
returnType: decoratedReturnType,
146146
positionalParameters: const [],
147147
namedParameters: {});
148-
_variables!
149-
.recordDecoratedElementType(constructorElement, functionType);
148+
_variables.recordDecoratedElementType(constructorElement, functionType);
150149
}
151150
}
152151
return null;
@@ -167,11 +166,11 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
167166
var functionType = DecoratedType.forImplicitFunction(
168167
_typeProvider, constructorElement.type, _graph.never, _graph, target,
169168
returnType: decoratedReturnType);
170-
_variables!.recordDecoratedElementType(constructorElement, functionType);
169+
_variables.recordDecoratedElementType(constructorElement, functionType);
171170
for (var parameter in constructorElement.parameters) {
172171
var parameterType = DecoratedType.forImplicitType(
173172
_typeProvider, parameter.type, _graph, target);
174-
_variables!.recordDecoratedElementType(parameter, parameterType);
173+
_variables.recordDecoratedElementType(parameter, parameterType);
175174
}
176175
}
177176
return null;
@@ -220,7 +219,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
220219
_typeProvider, declaredElement.type, _graph, target);
221220
instrumentation?.implicitType(source, node, type);
222221
}
223-
_variables!.recordDecoratedElementType(node.declaredElement, type);
222+
_variables.recordDecoratedElementType(node.declaredElement, type);
224223
return type;
225224
}
226225

@@ -234,7 +233,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
234233
} else if (node.declaredElement!.hasRequired) {
235234
return null;
236235
} else if (hint != null && hint.kind == HintCommentKind.required) {
237-
_variables!.recordRequiredHint(source, node, hint);
236+
_variables.recordRequiredHint(source, node, hint);
238237
return null;
239238
}
240239
if (decoratedType == null) {
@@ -249,7 +248,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
249248
DecoratedType? visitEnumDeclaration(EnumDeclaration node) {
250249
node.metadata.accept(this);
251250
var classElement = node.declaredElement!;
252-
_variables!.recordDecoratedElementType(
251+
_variables.recordDecoratedElementType(
253252
classElement, DecoratedType(classElement.thisType, _graph.never));
254253

255254
makeNonNullNode(NullabilityNodeTarget target, [AstNode? forNode]) {
@@ -262,12 +261,12 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
262261
for (var item in node.constants) {
263262
var declaredElement = item.declaredElement!;
264263
var target = NullabilityNodeTarget.element(declaredElement);
265-
_variables!.recordDecoratedElementType(declaredElement,
264+
_variables.recordDecoratedElementType(declaredElement,
266265
DecoratedType(classElement.thisType, makeNonNullNode(target, item)));
267266
}
268267
final valuesGetter = classElement.getGetter('values')!;
269268
var valuesTarget = NullabilityNodeTarget.element(valuesGetter);
270-
_variables!.recordDecoratedElementType(
269+
_variables.recordDecoratedElementType(
271270
valuesGetter,
272271
DecoratedType(valuesGetter.type, makeNonNullNode(valuesTarget),
273272
returnType: DecoratedType(valuesGetter.returnType,
@@ -286,7 +285,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
286285
var type = _pushNullabilityNodeTarget(
287286
NullabilityNodeTarget.text('extended type'),
288287
() => node.extendedType.accept(this));
289-
_variables!.recordDecoratedElementType(node.declaredElement, type);
288+
_variables.recordDecoratedElementType(node.declaredElement, type);
290289
node.members.accept(this);
291290
return null;
292291
}
@@ -386,8 +385,8 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
386385
_positionalParameters = previousPositionalParameters;
387386
_namedParameters = previousNamedParameters;
388387
}
389-
_variables!
390-
.recordDecoratedElementType(functionElement, decoratedFunctionType);
388+
_variables.recordDecoratedElementType(
389+
functionElement, decoratedFunctionType);
391390
return null;
392391
}
393392

@@ -407,7 +406,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
407406
_pushNullabilityNodeTarget(target, () {
408407
decoratedFunctionType = node.functionType!.accept(this);
409408
});
410-
_variables!.recordDecoratedElementType(
409+
_variables.recordDecoratedElementType(
411410
(node.declaredElement as TypeAliasElement).aliasedElement,
412411
decoratedFunctionType);
413412
return null;
@@ -448,11 +447,11 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
448447
// to access it later we won't crash (this could happen due to errors in
449448
// the source code).
450449
if (declaredElement.isGetter) {
451-
_variables!.recordDecoratedElementType(
450+
_variables.recordDecoratedElementType(
452451
declaredElement.variable, decoratedType.returnType);
453452
} else {
454453
var type = decoratedType.positionalParameters![0];
455-
_variables!.recordDecoratedElementType(declaredElement.variable, type,
454+
_variables.recordDecoratedElementType(declaredElement.variable, type,
456455
soft: true);
457456
if (_getAngularAnnotation(node.metadata) == _AngularAnnotation.child) {
458457
_graph.makeNullable(type.node, AngularAnnotationOrigin(source, node));
@@ -520,7 +519,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
520519
if (type.isVoid || type.isDynamic) {
521520
var nullabilityNode = NullabilityNode.forTypeAnnotation(target);
522521
var decoratedType = DecoratedType(type, nullabilityNode);
523-
_variables!.recordDecoratedTypeAnnotation(source, node, decoratedType);
522+
_variables.recordDecoratedTypeAnnotation(source, node, decoratedType);
524523
if (_visitingExternalDeclaration) {
525524
_graph.makeNullableUnion(
526525
nullabilityNode, ExternalDynamicOrigin(source, node));
@@ -608,7 +607,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
608607
positionalParameters: positionalParameters,
609608
namedParameters: namedParameters);
610609
}
611-
_variables!.recordDecoratedTypeAnnotation(source, node, decoratedType);
610+
_variables.recordDecoratedTypeAnnotation(source, node, decoratedType);
612611
_handleNullabilityHint(node, decoratedType);
613612
return decoratedType;
614613
}
@@ -641,10 +640,10 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
641640
() => typeAnnotation?.accept(this));
642641
var hint = getPrefixHint(node.firstTokenAfterCommentAndMetadata);
643642
if (hint != null && hint.kind == HintCommentKind.late_) {
644-
_variables!.recordLateHint(source, node, hint);
643+
_variables.recordLateHint(source, node, hint);
645644
}
646645
if (hint != null && hint.kind == HintCommentKind.lateFinal) {
647-
_variables!.recordLateHint(source, node, hint);
646+
_variables.recordLateHint(source, node, hint);
648647
}
649648
var parent = node.parent;
650649
for (var variable in node.variables) {
@@ -657,7 +656,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
657656
_typeProvider, declaredElement.type, _graph, target);
658657
instrumentation?.implicitType(source, node, type);
659658
}
660-
_variables!.recordDecoratedElementType(declaredElement, type);
659+
_variables.recordDecoratedElementType(declaredElement, type);
661660
variable.initializer?.accept(this);
662661
if (parent is FieldDeclaration) {
663662
var angularAnnotation = _getAngularAnnotation(parent.metadata);
@@ -775,8 +774,8 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
775774
_positionalParameters = previousPositionalParameters;
776775
_namedParameters = previousNamedParameters;
777776
}
778-
_variables!
779-
.recordDecoratedElementType(declaredElement, decoratedFunctionType);
777+
_variables.recordDecoratedElementType(
778+
declaredElement, decoratedFunctionType);
780779
return decoratedFunctionType;
781780
} finally {
782781
_visitingExternalDeclaration = previouslyVisitingExternalDeclaration;
@@ -841,7 +840,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
841840
namedParameters: namedParameters);
842841
_handleNullabilityHint(node, decoratedType);
843842
}
844-
_variables!.recordDecoratedElementType(declaredElement, decoratedType);
843+
_variables.recordDecoratedElementType(declaredElement, decoratedType);
845844
for (var annotation in node.metadata) {
846845
var element = annotation.element;
847846
if (element is ConstructorElement &&
@@ -872,7 +871,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
872871
case HintCommentKind.bang:
873872
_graph.makeNonNullableUnion(decoratedType.node,
874873
NullabilityCommentOrigin(source, node, false));
875-
_variables!.recordNullabilityHint(source, node, hint);
874+
_variables.recordNullabilityHint(source, node, hint);
876875
decoratedType.node.hintActions[HintActionKind.removeNonNullableHint] =
877876
hint.changesToRemove(source!.contents.data);
878877
decoratedType.node.hintActions[HintActionKind.changeToNullableHint] =
@@ -881,7 +880,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
881880
case HintCommentKind.question:
882881
_graph.makeNullableUnion(
883882
decoratedType.node, NullabilityCommentOrigin(source, node, true));
884-
_variables!.recordNullabilityHint(source, node, hint);
883+
_variables.recordNullabilityHint(source, node, hint);
885884
decoratedType.node.hintActions[HintActionKind.removeNullableHint] =
886885
hint.changesToRemove(source!.contents.data);
887886
decoratedType
@@ -935,8 +934,8 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
935934
decoratedSupertypes[class_] = decoratedSupertype;
936935
}
937936
});
938-
_variables!
939-
.recordDecoratedDirectSupertypes(declaredElement, decoratedSupertypes);
937+
_variables.recordDecoratedDirectSupertypes(
938+
declaredElement, decoratedSupertypes);
940939
}
941940

942941
/// Determines whether the given [uri] comes from the Angular package.

pkg/nnbd_migration/lib/src/nullability_migration_impl.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,16 @@ class NullabilityMigrationImpl implements NullabilityMigration {
195195
result.libraryElement.importedLibraries);
196196
_recordTransitiveImportExportOptInStatus(
197197
result.libraryElement.exportedLibraries);
198-
if (_variables == null) {
199-
_variables = Variables(_graph, result.typeProvider,
198+
var variables = _variables;
199+
if (variables == null) {
200+
variables = _variables = Variables(_graph, result.typeProvider,
200201
instrumentation: _instrumentation);
201-
_decoratedClassHierarchy = DecoratedClassHierarchy(_variables, _graph);
202+
_decoratedClassHierarchy = DecoratedClassHierarchy(variables, _graph);
202203
}
203204
var unit = result.unit;
204205
try {
205206
DecoratedTypeParameterBounds.current = _decoratedTypeParameterBounds;
206-
unit.accept(NodeBuilder(_variables, unit.declaredElement!.source,
207+
unit.accept(NodeBuilder(variables, unit.declaredElement!.source,
207208
_permissive! ? listener : null, _graph, result.typeProvider,
208209
instrumentation: _instrumentation));
209210
} finally {

0 commit comments

Comments
 (0)