Skip to content

Commit

Permalink
Version 2.15.0-22.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'c9d954efe7c7a71d2bf2c2ca385855b82fbfb379' into 'dev'
  • Loading branch information
Dart CI committed Aug 17, 2021
2 parents b01ec50 + c9d954e commit 17c9a00
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:analysis_server/src/services/correction/assist.dart';
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/assist/assist.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
Expand Down Expand Up @@ -50,22 +51,34 @@ class SplitVariableDeclaration extends CorrectionProducer {
return;
}

await builder.addDartFileEdit(file, (builder) {
if (variableList.type == null) {
final type = variable.declaredElement!.type;
if (!type.isDynamic && keyword != null) {
builder.addReplacement(range.token(keyword), (builder) {
builder.writeType(type);
});
Future<bool> tryToApplyChange(ChangeBuilder builder) async {
var validChange = true;
await builder.addDartFileEdit(file, (builder) {
if (variableList.type == null) {
final type = variable.declaredElement!.type;
if (!type.isDynamic && keyword != null) {
builder.addReplacement(range.token(keyword), (builder) {
validChange = builder.writeType(type);
});
}
}
}

var indent = utils.getNodePrefix(statement);
var name = variable.name.name;
builder.addSimpleInsertion(variable.name.end, ';' + eol + indent + name);
});
var indent = utils.getNodePrefix(statement);
var name = variable.name.name;
builder.addSimpleInsertion(
variable.name.end, ';' + eol + indent + name);
});
return validChange;
}

if (await tryToApplyChange(_temporaryBuilder(builder))) {
await tryToApplyChange(builder);
}
}

ChangeBuilder _temporaryBuilder(ChangeBuilder builder) =>
ChangeBuilder(workspace: (builder as ChangeBuilderImpl).workspace);

/// Return an instance of this class. Used as a tear-off in `AssistProcessor`.
static SplitVariableDeclaration newInstance() => SplitVariableDeclaration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,22 @@ main() {
}
''');
}

Future<void> test_unknownType() async {
addSource('/home/test/lib/a.dart', '''
class A {
_B b => _B();
}
class _B {}
''');

await resolveTestCode('''
import 'package:test/a.dart';
f(A a) {
var x = a.b();
}
''');
await assertNoAssistAt('var ');
}
}
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 2
MINOR 15
PATCH 0
PRERELEASE 21
PRERELEASE 22
PRERELEASE_PATCH 0

0 comments on commit 17c9a00

Please sign in to comment.