File tree Expand file tree Collapse file tree 5 files changed +35
-11
lines changed
pkg/analysis_server/lib/src/services/correction/dart Expand file tree Collapse file tree 5 files changed +35
-11
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
9
9
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_override_set.dart' ;
10
10
import 'package:analysis_server/src/services/correction/util.dart' ;
11
11
import 'package:analysis_server/src/utilities/flutter.dart' ;
12
+ import 'package:analysis_server/src/utilities/selection.dart' ;
12
13
import 'package:analyzer/dart/analysis/code_style_options.dart' ;
13
14
import 'package:analyzer/dart/analysis/features.dart' ;
14
15
import 'package:analyzer/dart/analysis/results.dart' ;
@@ -164,9 +165,11 @@ class CorrectionProducerContext<T extends ParsedUnitResult> {
164
165
int selectionOffset = - 1 ,
165
166
int selectionLength = 0 ,
166
167
}) {
167
- var selectionEnd = selectionOffset + selectionLength;
168
- var locator = NodeLocator (selectionOffset, selectionEnd);
169
- var node = locator.searchWithin (resolvedResult.unit);
168
+ final selection = resolvedResult.unit.select (
169
+ offset: selectionOffset,
170
+ length: selectionLength,
171
+ );
172
+ var node = selection? .coveringNode;
170
173
node ?? = resolvedResult.unit;
171
174
172
175
final token = _tokenAt (node, selectionOffset) ?? node.beginToken;
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ class AddMissingEnumCaseClauses extends ResolvedCorrectionProducer {
30
30
if (statement is ! SwitchStatement ) {
31
31
return ;
32
32
}
33
+ if (statement.rightParenthesis.isSynthetic) {
34
+ return ;
35
+ }
33
36
34
37
String ? enumName;
35
38
var prefix = '' ;
Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ class ConvertToIfNull extends ResolvedCorrectionProducer {
41
41
defaultExpression = node.elseExpression;
42
42
}
43
43
44
+ if (defaultExpression is SimpleIdentifier &&
45
+ defaultExpression.isSynthetic) {
46
+ return ;
47
+ }
48
+
44
49
var parentheses = defaultExpression.precedence <
45
50
Precedence .forTokenType (TokenType .QUESTION_QUESTION );
46
51
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ class MakeReturnTypeNullable extends ResolvedCorrectionProducer {
24
24
if (node is ! Expression ) {
25
25
return ;
26
26
}
27
+ if (node is SimpleIdentifier && node.isSynthetic) {
28
+ return ;
29
+ }
27
30
28
31
final type = node.staticType;
29
32
if (type == null ) {
Original file line number Diff line number Diff line change @@ -24,14 +24,24 @@ class RemoveEmptyConstructorBody extends ResolvedCorrectionProducer {
24
24
25
25
@override
26
26
Future <void > compute (ChangeBuilder builder) async {
27
- var parent = node.parent;
28
- if (node is Block && parent is BlockFunctionBody ) {
29
- await builder.addDartFileEdit (file, (builder) {
30
- builder.addSimpleReplacement (
31
- utils.getLinesRange (range.node (parent)),
32
- ';' ,
33
- );
34
- });
27
+ final node = this .node;
28
+ if (node is ! Block ) {
29
+ return ;
35
30
}
31
+ if (node.leftBracket.isSynthetic || node.rightBracket.isSynthetic) {
32
+ return ;
33
+ }
34
+
35
+ final blockBody = node.parent;
36
+ if (blockBody is ! BlockFunctionBody ) {
37
+ return ;
38
+ }
39
+
40
+ await builder.addDartFileEdit (file, (builder) {
41
+ builder.addSimpleReplacement (
42
+ utils.getLinesRange (range.node (blockBody)),
43
+ ';' ,
44
+ );
45
+ });
36
46
}
37
47
}
You can’t perform that action at this time.
0 commit comments