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

Commit 17c9a00

Browse files
author
Dart CI
committed
Version 2.15.0-22.0.dev
Merge commit 'c9d954efe7c7a71d2bf2c2ca385855b82fbfb379' into 'dev'
2 parents b01ec50 + c9d954e commit 17c9a00

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

pkg/analysis_server/lib/src/services/correction/dart/split_variable_declaration.dart

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:_fe_analyzer_shared/src/scanner/token.dart';
66
import 'package:analysis_server/src/services/correction/assist.dart';
77
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
88
import 'package:analyzer/dart/ast/ast.dart';
9+
import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core.dart';
910
import 'package:analyzer_plugin/utilities/assist/assist.dart';
1011
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
1112
import 'package:analyzer_plugin/utilities/range_factory.dart';
@@ -50,22 +51,34 @@ class SplitVariableDeclaration extends CorrectionProducer {
5051
return;
5152
}
5253

53-
await builder.addDartFileEdit(file, (builder) {
54-
if (variableList.type == null) {
55-
final type = variable.declaredElement!.type;
56-
if (!type.isDynamic && keyword != null) {
57-
builder.addReplacement(range.token(keyword), (builder) {
58-
builder.writeType(type);
59-
});
54+
Future<bool> tryToApplyChange(ChangeBuilder builder) async {
55+
var validChange = true;
56+
await builder.addDartFileEdit(file, (builder) {
57+
if (variableList.type == null) {
58+
final type = variable.declaredElement!.type;
59+
if (!type.isDynamic && keyword != null) {
60+
builder.addReplacement(range.token(keyword), (builder) {
61+
validChange = builder.writeType(type);
62+
});
63+
}
6064
}
61-
}
6265

63-
var indent = utils.getNodePrefix(statement);
64-
var name = variable.name.name;
65-
builder.addSimpleInsertion(variable.name.end, ';' + eol + indent + name);
66-
});
66+
var indent = utils.getNodePrefix(statement);
67+
var name = variable.name.name;
68+
builder.addSimpleInsertion(
69+
variable.name.end, ';' + eol + indent + name);
70+
});
71+
return validChange;
72+
}
73+
74+
if (await tryToApplyChange(_temporaryBuilder(builder))) {
75+
await tryToApplyChange(builder);
76+
}
6777
}
6878

79+
ChangeBuilder _temporaryBuilder(ChangeBuilder builder) =>
80+
ChangeBuilder(workspace: (builder as ChangeBuilderImpl).workspace);
81+
6982
/// Return an instance of this class. Used as a tear-off in `AssistProcessor`.
7083
static SplitVariableDeclaration newInstance() => SplitVariableDeclaration();
7184
}

pkg/analysis_server/test/src/services/correction/assist/split_variable_declaration_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,22 @@ main() {
118118
}
119119
''');
120120
}
121+
122+
Future<void> test_unknownType() async {
123+
addSource('/home/test/lib/a.dart', '''
124+
class A {
125+
_B b => _B();
126+
}
127+
class _B {}
128+
''');
129+
130+
await resolveTestCode('''
131+
import 'package:test/a.dart';
132+
133+
f(A a) {
134+
var x = a.b();
135+
}
136+
''');
137+
await assertNoAssistAt('var ');
138+
}
121139
}

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 15
2929
PATCH 0
30-
PRERELEASE 21
30+
PRERELEASE 22
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)