Skip to content

Commit

Permalink
Version 2.12.0-214.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'c42c76f5904c29921591cae815c5e7d53fabc2cf' into 'dev'
  • Loading branch information
Dart CI committed Jan 11, 2021
2 parents 28ec4cc + c42c76f commit 7fcbd38
Show file tree
Hide file tree
Showing 446 changed files with 3,646 additions and 2,929 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ vars = {
"http_multi_server_rev" : "e8c8be7f15b4fb50757ff5bf29766721fbe24fe4",
"http_parser_rev": "5dd4d16693242049dfb43b5efa429fedbf932e98",
"http_retry_tag": "0.1.1",
"http_rev": "1617b728fc48f64fb0ed7dc16078c03adcc64179",
"http_rev": "3845753a54624b070828cb3eff7a6c2a4e046cfb",
"http_throttle_tag" : "1.0.2",
"icu_rev" : "79326efe26e5440f530963704c3c0ff965b3a4ac",
"idl_parser_rev": "5fb1ebf49d235b5a70c9f49047e83b0654031eb7",
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/BigIntParsePrint/dart/BigIntParsePrint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const requiredDigits = 11106;

class Benchmark extends BenchmarkBase {
final List<String> strings;
Benchmark(String name, int bits, {bool forInt: false})
Benchmark(String name, int bits, {bool forInt = false})
: strings = generateStrings(bits, forInt),
super(name);

static List<String> generateStrings(int bits, bool forInt) {
List<String> strings = [];
BigInt seed = (BigInt.one << bits) - BigInt.one;
final List<String> strings = [];
final BigInt seed = (BigInt.one << bits) - BigInt.one;
var b = seed;
var restartDelta = BigInt.zero;
var totalLength = 0;
Expand Down Expand Up @@ -130,7 +130,7 @@ class FormatBigIntBenchmark extends Benchmark {
@override
void setup() {
for (String s in strings) {
BigInt b = BigInt.parse(s);
final BigInt b = BigInt.parse(s);
values.add(b - BigInt.one); // We add 'one' back later.
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ class FormatIntBenchmark extends Benchmark {
@override
void setup() {
for (String s in strings) {
int b = int.parse(s);
final int b = int.parse(s);
values.add(b - 4096); // We add this back later.
}
}
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/BigIntParsePrint/dart2/BigIntParsePrint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ const requiredDigits = 11106;

class Benchmark extends BenchmarkBase {
final List<String> strings;
Benchmark(String name, int bits, {bool forInt: false})
Benchmark(String name, int bits, {bool forInt = false})
: strings = generateStrings(bits, forInt),
super(name);

static List<String> generateStrings(int bits, bool forInt) {
List<String> strings = [];
BigInt seed = (BigInt.one << bits) - BigInt.one;
final List<String> strings = [];
final BigInt seed = (BigInt.one << bits) - BigInt.one;
var b = seed;
var restartDelta = BigInt.zero;
var totalLength = 0;
Expand Down Expand Up @@ -132,7 +132,7 @@ class FormatBigIntBenchmark extends Benchmark {
@override
void setup() {
for (String s in strings) {
BigInt b = BigInt.parse(s);
final BigInt b = BigInt.parse(s);
values.add(b - BigInt.one); // We add 'one' back later.
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ class FormatIntBenchmark extends Benchmark {
@override
void setup() {
for (String s in strings) {
int b = int.parse(s);
final int b = int.parse(s);
values.add(b - 4096); // We add this back later.
}
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,24 @@ String demangleMixinApplicationName(String name) {
}
return demangledName;
}

final RegExp templateKey = new RegExp(r'#(\w+)');

/// Replaces occurrences of '#key' in [template], where 'key' is a key in
/// [arguments], with the corresponding values.
String applyArgumentsToTemplate(
String template, Map<String, dynamic> arguments) {
// TODO(johnniwinther): Remove `as dynamic` when unsound null safety is
// no longer supported.
if (arguments as dynamic == null || arguments.isEmpty) {
assert(!template.contains(templateKey),
'Message requires arguments, but none were provided.');
return template;
}
return template.replaceAllMapped(templateKey, (Match match) {
String? key = match.group(1);
Object? value = arguments[key];
assert(value != null, "No value for '$key' found in $arguments");
return value.toString();
});
}
50 changes: 25 additions & 25 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Message _withArgumentsAsciiControlCharacter(int codePoint) {
return new Message(codeAsciiControlCharacter,
message:
"""The control character ${unicode} can only be used in strings and comments.""",
arguments: {'codePoint': codePoint});
arguments: {'unicode': codePoint});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -477,7 +477,7 @@ Message _withArgumentsBuiltInIdentifierAsType(Token token) {
return new Message(codeBuiltInIdentifierAsType,
message:
"""The built-in identifier '${lexeme}' can't be used as a type.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand All @@ -497,7 +497,7 @@ Message _withArgumentsBuiltInIdentifierInDeclaration(Token token) {
String lexeme = token.lexeme;
return new Message(codeBuiltInIdentifierInDeclaration,
message: """Can't use '${lexeme}' as a name here.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -837,7 +837,7 @@ Message _withArgumentsCantUseControlFlowOrSpreadAsConstant(Token token) {
String lexeme = token.lexeme;
return new Message(codeCantUseControlFlowOrSpreadAsConstant,
message: """'${lexeme}' is not supported in constant expressions.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -866,7 +866,7 @@ Message _withArgumentsCantUseDeferredPrefixAsConstant(Token token) {
"""'${lexeme}' can't be used in a constant expression because it's marked as 'deferred' which means it isn't available until loaded.""",
tip: """Try moving the constant from the deferred library, or removing 'deferred' from the import.
""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2419,7 +2419,7 @@ Message _withArgumentsDuplicatedModifier(Token token) {
return new Message(codeDuplicatedModifier,
message: """The modifier '${lexeme}' was already specified.""",
tip: """Try removing all but one occurrence of the modifier.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2735,7 +2735,7 @@ Message _withArgumentsExpectedClassMember(Token token) {
String lexeme = token.lexeme;
return new Message(codeExpectedClassMember,
message: """Expected a class member, but got '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2777,7 +2777,7 @@ Message _withArgumentsExpectedDeclaration(Token token) {
String lexeme = token.lexeme;
return new Message(codeExpectedDeclaration,
message: """Expected a declaration, but got '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2810,7 +2810,7 @@ Message _withArgumentsExpectedEnumBody(Token token) {
message: """Expected a enum body, but got '${lexeme}'.""",
tip:
"""An enum definition must have a body with at least one constant name.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand All @@ -2829,7 +2829,7 @@ Message _withArgumentsExpectedFunctionBody(Token token) {
String lexeme = token.lexeme;
return new Message(codeExpectedFunctionBody,
message: """Expected a function body, but got '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2859,7 +2859,7 @@ Message _withArgumentsExpectedIdentifier(Token token) {
return new Message(codeExpectedIdentifier,
message: """Expected an identifier, but got '${lexeme}'.""",
tip: """Try inserting an identifier before '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2887,7 +2887,7 @@ Message _withArgumentsExpectedIdentifierButGotKeyword(Token token) {
message:
"""'${lexeme}' can't be used as an identifier because it's a keyword.""",
tip: """Try renaming this to be an identifier that isn't a keyword.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2957,7 +2957,7 @@ Message _withArgumentsExpectedString(Token token) {
String lexeme = token.lexeme;
return new Message(codeExpectedString,
message: """Expected a String, but got '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -2995,7 +2995,7 @@ Message _withArgumentsExpectedType(Token token) {
String lexeme = token.lexeme;
return new Message(codeExpectedType,
message: """Expected a type, but got '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -3534,7 +3534,7 @@ Message _withArgumentsExtraneousModifier(Token token) {
return new Message(codeExtraneousModifier,
message: """Can't have modifier '${lexeme}' here.""",
tip: """Try removing '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand All @@ -3556,7 +3556,7 @@ Message _withArgumentsExtraneousModifierInExtension(Token token) {
return new Message(codeExtraneousModifierInExtension,
message: """Can't have modifier '${lexeme}' in an extension.""",
tip: """Try removing '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -5569,7 +5569,7 @@ Message _withArgumentsInvalidOperator(Token token) {
String lexeme = token.lexeme;
return new Message(codeInvalidOperator,
message: """The string '${lexeme}' isn't a user-definable operator.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -6816,7 +6816,7 @@ Message _withArgumentsNoFormals(Token token) {
message: """A function should have formal parameters.""",
tip:
"""Try adding '()' after '${lexeme}', or add 'get' before '${lexeme}' to declare a getter.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -6885,7 +6885,7 @@ Message _withArgumentsNonAsciiIdentifier(String character, int codePoint) {
message:
"""The non-ASCII character '${character}' (${unicode}) can't be used in identifiers, only in strings and comments.""",
tip: """Try using an US-ASCII letter, a digit, '_' (an underscore), or '\$' (a dollar sign).""",
arguments: {'character': character, 'codePoint': codePoint});
arguments: {'character': character, 'unicode': codePoint});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand All @@ -6910,7 +6910,7 @@ Message _withArgumentsNonAsciiWhitespace(int codePoint) {
return new Message(codeNonAsciiWhitespace,
message:
"""The non-ASCII space character ${unicode} can only be used in strings and comments.""",
arguments: {'codePoint': codePoint});
arguments: {'unicode': codePoint});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -7203,7 +7203,7 @@ Message _withArgumentsNotBinaryOperator(Token token) {
String lexeme = token.lexeme;
return new Message(codeNotBinaryOperator,
message: """'${lexeme}' isn't a binary operator.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -9320,7 +9320,7 @@ Message _withArgumentsUnexpectedModifierInNonNnbd(Token token) {
return new Message(codeUnexpectedModifierInNonNnbd,
message:
"""The modifier '${lexeme}' is only available in null safe libraries.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand All @@ -9339,7 +9339,7 @@ Message _withArgumentsUnexpectedToken(Token token) {
String lexeme = token.lexeme;
return new Message(codeUnexpectedToken,
message: """Unexpected token '${lexeme}'.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand All @@ -9360,7 +9360,7 @@ Message _withArgumentsUnmatchedToken(String string, Token token) {
String lexeme = token.lexeme;
return new Message(codeUnmatchedToken,
message: """Can't find '${string}' to match '${lexeme}'.""",
arguments: {'string': string, 'token': token});
arguments: {'string': string, 'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down Expand Up @@ -9429,7 +9429,7 @@ Message _withArgumentsUnsupportedOperator(Token token) {
String lexeme = token.lexeme;
return new Message(codeUnsupportedOperator,
message: """The '${lexeme}' operator is not supported.""",
arguments: {'token': token});
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand Down
28 changes: 28 additions & 0 deletions pkg/_fe_analyzer_shared/test/template_replacement_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:_fe_analyzer_shared/src/messages/codes.dart';

void main() {
test('#a', {'a': 'b'}, 'b');
test('#a #a', {'a': 'b'}, 'b b');
test('#a #b', {'a': 'b', 'b': 'c'}, 'b c');
test('#a #b', {'a': '#b', 'b': 'c'}, '#b c');

test('#a1 #a2', {'a1': 'b', 'a2': 'c'}, 'b c');
test('#a1 #a2', {'a1': '#a2', 'a2': 'a2'}, '#a2 a2');
test('#a1 #a1 #a2 #a2', {'a1': '#a2', 'a2': 'b'}, '#a2 #a2 b b');
}

void test(
String template, Map<String, dynamic>? arguments, String expectedResult) {
expect(expectedResult, applyArgumentsToTemplate(template, arguments!),
'Unexpected result for replacing $arguments in "$template"');
}

void expect(expected, actual, String message) {
if (expected != actual) {
throw '$message: Expected "$expected", actual "$actual".';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
class AddMissingParameter extends MultiCorrectionProducer {
@override
Iterable<CorrectionProducer> get producers sync* {
if (node is! ArgumentList) {
// node is the unmatched argument.
if (node.parent is! ArgumentList) {
return;
}
var context = ExecutableParameters(sessionHelper, node.parent);
var context = ExecutableParameters(sessionHelper, node.parent.parent);
if (context == null) {
return;
}
Expand Down Expand Up @@ -65,7 +66,8 @@ abstract class _AddMissingParameter extends CorrectionProducer {

Future<void> _addParameter(
ChangeBuilder builder, int offset, String prefix, String suffix) async {
ArgumentList argumentList = node;
// node is the unmatched argument.
ArgumentList argumentList = node.parent;
List<Expression> arguments = argumentList.arguments;
var numRequired = context.required.length;
if (numRequired >= arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ConvertToNamedArguments extends CorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
var argumentList = node;
// node is the unmatched argument.
var argumentList = node.parent;
if (argumentList is ArgumentList) {
// Prepare parameters.
List<ParameterElement> parameters;
Expand Down
Loading

0 comments on commit 7fcbd38

Please sign in to comment.