mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[analysis_server] AddExplicitCast
for as
Bug: #49896 Change-Id: Iddbe616db0edadf57ad76637863ad7a29533a77b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260111 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
ecb992586a
commit
0a23e439e9
|
@ -11,6 +11,7 @@ import 'package:analyzer/dart/element/type.dart';
|
|||
import 'package:analyzer/src/dart/ast/extensions.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:analyzer_plugin/utilities/range_factory.dart';
|
||||
|
||||
class AddExplicitCast extends CorrectionProducer {
|
||||
@override
|
||||
|
@ -66,7 +67,12 @@ class AddExplicitCast extends CorrectionProducer {
|
|||
}
|
||||
}
|
||||
if (target is AsExpression) {
|
||||
// TODO(brianwilkerson) Consider updating the right operand.
|
||||
var type = target.type;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addReplacement(range.node(type), (builder) {
|
||||
builder.writeType(toType);
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,15 @@ class A {}
|
|||
class B {}
|
||||
class C {}
|
||||
''');
|
||||
await assertNoFix();
|
||||
await assertHasFix('''
|
||||
f(A a) {
|
||||
C c = a as C;
|
||||
print(c);
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
class C {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_assignment_general() async {
|
||||
|
|
Loading…
Reference in a new issue