Better loop for ADD_TYPE_ANNOTATION

Fixes #47015

Change-Id: I3b3c6e88e601c5da9bc60936f08007bdea52375d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211444
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Ahmed Ashour 2021-08-27 00:42:16 +00:00 committed by commit-bot@chromium.org
parent 5c582f82f0
commit 47b7fd4b75
2 changed files with 7 additions and 9 deletions

View file

@ -142,11 +142,9 @@ class AddTypeAnnotation extends CorrectionProducer {
return;
}
// Ensure that there is a single type.
if (variables.length > 1) {
for (var v in variables) {
if (v != variable && _typeForVariable(v) != type) {
return;
}
for (var i = 1; i < variables.length; i++) {
if (_typeForVariable(variables[i]) != type) {
return;
}
}
if ((type is! InterfaceType || type.isDartCoreNull) &&

View file

@ -54,8 +54,8 @@ class CreateMissingOverrides extends CorrectionProducer {
await builder.addDartFileEdit(file, (builder) {
final syntheticLeftBracket = targetClass.leftBracket.isSynthetic;
if (syntheticLeftBracket) {
var previousToLeftBracket = targetClass.leftBracket.previous;
builder.addSimpleInsertion(previousToLeftBracket!.end, ' {');
var previousToLeftBracket = targetClass.leftBracket.previous!;
builder.addSimpleInsertion(previousToLeftBracket.end, ' {');
}
builder.addInsertion(location.offset, (builder) {
@ -109,8 +109,8 @@ class CreateMissingOverrides extends CorrectionProducer {
builder.write(location.suffix);
if (targetClass.rightBracket.isSynthetic) {
var next = targetClass.rightBracket.next;
if (next!.type != TokenType.CLOSE_CURLY_BRACKET) {
var next = targetClass.rightBracket.next!;
if (next.type != TokenType.CLOSE_CURLY_BRACKET) {
if (!syntheticLeftBracket) {
builder.write(eol);
}