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

Commit 6b7e44a

Browse files
author
Dart CI
committed
Version 2.19.0-444.0.dev
Merge f28b2d7 into dev
2 parents 88473a3 + f28b2d7 commit 6b7e44a

File tree

446 files changed

+4393
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

446 files changed

+4393
-255
lines changed

CHANGELOG.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,15 @@
171171

172172
#### Analyzer
173173

174-
- add static enforcement of new `mustBeOverridden` annotation
175-
- add quick fixes for diagnostics:
176-
`abstract_field_initializer`,
177-
`ambiguous_extension_member_access`,
178-
`argument_type_not_assignable`,
179-
`assert_in_redirecting_constructor`,
180-
`combinators_ordering`,
181-
`default_value_on_required_parameter`,
182-
`initializing_formal_for_non_existent_field`,
183-
`missing_default_value_for_parameter_positional`,
184-
`super_formal_parameter_without_associated_named`,
185-
`undefined_identifier`
186-
- add new hints: `cast_from_null_always_fails`, `duplicate_export`
174+
- add static enforcement of new `mustBeOverridden` annotation, and quick fixes
175+
- add quick fixes for many diagnostics including compile-time errors, hints, and
176+
lints. There are now quick fixes for over 300 diagnostic codes. These lint
177+
rules have new fixes: `combinators_ordering`, `dangling_library_doc_comments`,
178+
`implicit_call_tearoffs`, `library_annotations`, and
179+
`unnecessary_library_directive`.
180+
- add new hints: `body_might_complete_normally_catch_error`,
181+
`cast_from_null_always_fails`, `cast_from_nullable_always_fails`,
182+
`deprecated_colon_for_default_value`, and `duplicate_export`
187183
- remove hint: `invalid_override_different_default_values`
188184

189185
#### Linter

pkg/_fe_analyzer_shared/lib/src/parser/forwarding_listener.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,11 @@ class ForwardingListener implements Listener {
19941994
keyword, equals, semicolon);
19951995
}
19961996

1997+
@override
1998+
void handlePatternAssignment(Token equals) {
1999+
listener?.handlePatternAssignment(equals);
2000+
}
2001+
19972002
@override
19982003
void logEvent(String name) {
19992004
listener?.logEvent(name);

pkg/_fe_analyzer_shared/lib/src/parser/listener.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,4 +2139,13 @@ class Listener implements UnescapeErrorListener {
21392139
Token keyword, Token equals, Token semicolon) {
21402140
logEvent('PatternVariableDeclarationStatement');
21412141
}
2142+
2143+
/// Called after the parser has processed a pattern assignment consisting of
2144+
/// `PATTERN EQUALS EXPRESSION`.
2145+
///
2146+
/// PATTERN may only be one of the patterns accepted by the `outerPattern`
2147+
/// grammar rule defined in the patterns spec.
2148+
void handlePatternAssignment(Token equals) {
2149+
logEvent("PatternAssignment");
2150+
}
21422151
}

pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5466,10 +5466,14 @@ class Parser {
54665466
listener.handleIdentifier(token, IdentifierContext.expression);
54675467
}
54685468
} else {
5469-
token = optional('throw', token.next!)
5470-
? parseThrowExpression(token, /* allowCascades = */ true)
5471-
: parsePrecedenceExpression(
5472-
token, ASSIGNMENT_PRECEDENCE, /* allowCascades = */ true);
5469+
if (allowPatterns && looksLikeOuterPatternEquals(token)) {
5470+
token = parsePatternAssignment(token);
5471+
} else {
5472+
token = optional('throw', token.next!)
5473+
? parseThrowExpression(token, /* allowCascades = */ true)
5474+
: parsePrecedenceExpression(
5475+
token, ASSIGNMENT_PRECEDENCE, /* allowCascades = */ true);
5476+
}
54735477
}
54745478
expressionDepth--;
54755479
return token;
@@ -9796,7 +9800,8 @@ class Parser {
97969800
if (next.isIdentifier) {
97979801
return skipObjectPatternRest(next);
97989802
} else {
9799-
throw new UnimplementedError('TODO(paulberry)');
9803+
// IDENTIFIER `.` NON-IDENTIFIER (not a pattern)
9804+
return null;
98009805
}
98019806
}
98029807
TypeParamOrArgInfo typeParamOrArg = computeTypeParamOrArg(token);
@@ -9847,6 +9852,17 @@ class Parser {
98479852
return semicolon;
98489853
}
98499854

9855+
/// patternAssignment ::= outerPattern '=' expression
9856+
Token parsePatternAssignment(Token token) {
9857+
token = parsePattern(token, isRefutableContext: false);
9858+
Token equals = token.next!;
9859+
// Caller should have assured that the pattern was followed by an `=`.
9860+
assert(optional('=', equals));
9861+
token = parseExpression(equals);
9862+
listener.handlePatternAssignment(equals);
9863+
return token;
9864+
}
9865+
98509866
/// switchExpression ::= 'switch' '(' expression ')' '{'
98519867
/// switchExpressionCase ( ',' switchExpressionCase )*
98529868
/// ','? '}'

pkg/analysis_server/lib/src/computer/computer_highlights.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
905905
void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
906906
computer._addRegion_token(
907907
node.requiredKeyword, HighlightRegionType.KEYWORD);
908+
computer._addRegion_token(
909+
node.name, HighlightRegionType.PARAMETER_DECLARATION);
908910
super.visitFunctionTypedFormalParameter(node);
909911
}
910912

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
1111
import 'package:analyzer_plugin/utilities/range_factory.dart';
1212

1313
class AddExplicitCall extends CorrectionProducer {
14+
@override
15+
bool get canBeAppliedInBulk => true;
16+
17+
@override
18+
bool get canBeAppliedToFile => true;
19+
1420
@override
1521
FixKind get fixKind => DartFixKind.ADD_EXPLICIT_CALL;
1622

23+
@override
24+
FixKind get multiFixKind => DartFixKind.ADD_EXPLICIT_CALL_MULTI;
25+
1726
@override
1827
Future<void> compute(ChangeBuilder builder) async {
1928
AstNode? current = node;
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
6+
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
7+
import 'package:analysis_server/src/services/correction/fix.dart';
8+
import 'package:analyzer/dart/analysis/features.dart';
9+
import 'package:analyzer/dart/ast/ast.dart';
10+
import 'package:analyzer/source/line_info.dart';
11+
import 'package:analyzer/source/source_range.dart';
12+
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
13+
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
14+
import 'package:analyzer_plugin/utilities/range_factory.dart';
15+
import 'package:collection/collection.dart';
16+
17+
class MoveDocCommentToLibraryDirective extends CorrectionProducer {
18+
@override
19+
FixKind get fixKind => DartFixKind.MOVE_DOC_COMMENT_TO_LIBRARY_DIRECTIVE;
20+
21+
@override
22+
Future<void> compute(ChangeBuilder builder) async {
23+
var comment = node.thisOrAncestorOfType<Comment>();
24+
if (comment == null) {
25+
return;
26+
}
27+
var compilationUnit = comment.root;
28+
if (compilationUnit is! CompilationUnit) {
29+
return;
30+
}
31+
32+
var firstDirective = compilationUnit.directives.firstOrNull;
33+
if (firstDirective is LibraryDirective) {
34+
await _moveToExistingLibraryDirective(builder, comment, firstDirective);
35+
} else if (libraryElement.featureSet.isEnabled(Feature.unnamedLibraries)) {
36+
await _moveToNewLibraryDirective(builder, comment, compilationUnit);
37+
}
38+
39+
// If the library doesn't support unnamed libraries, then we cannot add
40+
// a new library directive; we don't know what to name it.
41+
}
42+
43+
Future<void> _moveToExistingLibraryDirective(ChangeBuilder builder,
44+
Comment comment, LibraryDirective libraryDirective) async {
45+
// Just move the annotation to the existing library directive.
46+
var commentRange = utils.getLinesRange(range.node(comment));
47+
await builder.addDartFileEdit(file, (builder) {
48+
builder.addDeletion(commentRange);
49+
var commentText = utils.getRangeText(commentRange);
50+
builder.addSimpleInsertion(
51+
libraryDirective.firstTokenAfterCommentAndMetadata.offset,
52+
commentText);
53+
});
54+
}
55+
56+
Future<void> _moveToNewLibraryDirective(ChangeBuilder builder,
57+
Comment comment, CompilationUnit compilationUnit) async {
58+
var commentRange = _rangeOfFirstBlock(comment, compilationUnit.lineInfo);
59+
60+
// Create a new, unnamed library directive, and move the comment to just
61+
// above the directive.
62+
var token = compilationUnit.beginToken;
63+
64+
if (token.type == TokenType.SCRIPT_TAG) {
65+
// TODO(srawlins): Handle this case.
66+
return;
67+
}
68+
69+
if (token.precedingComments == comment.beginToken) {
70+
// Do not "move" the comment. Just slip a library directive below it.
71+
await builder.addDartFileEdit(file, (builder) {
72+
builder.addSimpleInsertion(commentRange.end, 'library;$eol');
73+
});
74+
return;
75+
}
76+
77+
int insertionOffset;
78+
String prefix;
79+
Token? commentOnFirstToken = token.precedingComments;
80+
if (commentOnFirstToken != null) {
81+
while (commentOnFirstToken!.next != null) {
82+
commentOnFirstToken = commentOnFirstToken.next!;
83+
84+
if (commentOnFirstToken == comment.beginToken) {
85+
// Do not "move" the comment. Just slip a library directive below it.
86+
await builder.addDartFileEdit(file, (builder) {
87+
builder.addSimpleInsertion(commentRange.end, 'library;$eol$eol');
88+
});
89+
return;
90+
}
91+
}
92+
// `token` is now the last of the leading comments (perhaps a Copyight
93+
// notice, a Dart language version, etc.)
94+
insertionOffset = commentOnFirstToken.end;
95+
prefix = '$eol$eol';
96+
} else {
97+
insertionOffset = 0;
98+
prefix = '';
99+
}
100+
101+
await builder.addDartFileEdit(file, (builder) {
102+
builder.addDeletion(commentRange);
103+
var commentText = utils.getRangeText(commentRange);
104+
builder.addSimpleInsertion(
105+
insertionOffset, '$prefix${commentText}library;$eol$eol');
106+
});
107+
}
108+
109+
/// The range of the first "block" in [comment].
110+
///
111+
/// A [Comment] can contain blank lines (even an end-of-line comment, and an
112+
/// end-of-line doc comment). But for the purpose of this fix, we interpret
113+
/// only the first "block" or "paragraph" of text as what was intented to be
114+
/// the library comment.
115+
SourceRange _rangeOfFirstBlock(Comment comment, LineInfo lineInfo) {
116+
for (var token in comment.tokens) {
117+
var next = token.next;
118+
if (next != null &&
119+
lineInfo.getLocation(next.offset).lineNumber >
120+
lineInfo.getLocation(token.end).lineNumber + 1) {
121+
// There is a blank line. Interpret this as two separate doc comments.
122+
return utils.getLinesRange(range.startEnd(comment.tokens.first, token));
123+
}
124+
}
125+
return utils.getLinesRange(range.node(comment));
126+
}
127+
}

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ LintCode.control_flow_in_finally:
18191819
LintCode.curly_braces_in_flow_control_structures:
18201820
status: hasFix
18211821
LintCode.dangling_library_doc_comments:
1822-
status: needsEvaluation
1822+
status: hasFix
18231823
LintCode.depend_on_referenced_packages:
18241824
status: needsFix
18251825
LintCode.deprecated_consistency:

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ class DartFixKind {
143143
DartFixKindPriority.DEFAULT,
144144
'Add explicit .call tearoff',
145145
);
146+
static const ADD_EXPLICIT_CALL_MULTI = FixKind(
147+
'dart.fix.add.explicitCall.multi',
148+
DartFixKindPriority.IN_FILE,
149+
'Add explicit .call to implicit tearoffs in file',
150+
);
146151
static const ADD_EXPLICIT_CAST = FixKind(
147152
'dart.fix.add.explicitCast',
148153
DartFixKindPriority.DEFAULT,
@@ -852,6 +857,11 @@ class DartFixKind {
852857
DartFixKindPriority.DEFAULT,
853858
"Move this annotation to a library directive",
854859
);
860+
static const MOVE_DOC_COMMENT_TO_LIBRARY_DIRECTIVE = FixKind(
861+
'dart.fix.moveDocCommentToLibraryDirective',
862+
DartFixKindPriority.DEFAULT,
863+
"Move this doc comment to a library directive",
864+
);
855865
static const ORGANIZE_IMPORTS = FixKind(
856866
'dart.fix.organize.imports',
857867
DartFixKindPriority.DEFAULT,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import 'package:analysis_server/src/services/correction/dart/make_return_type_nu
107107
import 'package:analysis_server/src/services/correction/dart/make_variable_not_final.dart';
108108
import 'package:analysis_server/src/services/correction/dart/make_variable_nullable.dart';
109109
import 'package:analysis_server/src/services/correction/dart/move_annotation_to_library_directive.dart';
110+
import 'package:analysis_server/src/services/correction/dart/move_doc_comment_to_library_directive.dart';
110111
import 'package:analysis_server/src/services/correction/dart/move_type_arguments_to_class.dart';
111112
import 'package:analysis_server/src/services/correction/dart/organize_imports.dart';
112113
import 'package:analysis_server/src/services/correction/dart/qualify_reference.dart';
@@ -461,6 +462,9 @@ class FixProcessor extends BaseProcessor {
461462
LintNames.curly_braces_in_flow_control_structures: [
462463
UseCurlyBraces.new,
463464
],
465+
LintNames.dangling_library_doc_comments: [
466+
MoveDocCommentToLibraryDirective.new,
467+
],
464468
LintNames.diagnostic_describe_all_properties: [
465469
AddDiagnosticPropertyReference.new,
466470
],

pkg/analysis_server/lib/src/services/linter/lint_names.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class LintNames {
5353
static const String combinators_ordering = 'combinators_ordering';
5454
static const String curly_braces_in_flow_control_structures =
5555
'curly_braces_in_flow_control_structures';
56+
static const String dangling_library_doc_comments =
57+
'dangling_library_doc_comments';
5658
static const String diagnostic_describe_all_properties =
5759
'diagnostic_describe_all_properties';
5860
static const String directives_ordering = 'directives_ordering';

0 commit comments

Comments
 (0)