From 56505e0575a0052ca2042e87831a1cdc6b925066 Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Fri, 20 Mar 2026 09:09:46 -0700 Subject: [PATCH] Stop using `Match.group`. The `Match.operator[]` does the same thing and is generally recommended (and shorter). (I want to deprecate `group` and `groups`) Tested: Refactoring. CoreLibraryReviewExempt: Calling equivalent function. Change-Id: I4c758968ae622fe16b7322be1b29b05b91e7fcd9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489021 Reviewed-by: Paul Berry Reviewed-by: Brian Wilkerson Reviewed-by: Martin Kustermann Commit-Queue: Lasse Nielsen --- .../lib/src/base/errors.dart | 2 +- .../lib/src/messages/codes.dart | 2 +- pkg/_fe_analyzer_shared/test/mini_ast.dart | 2 +- .../lib/src/lsp/completion_utils.dart | 4 +- pkg/analysis_server/lib/src/lsp/dartdoc.dart | 5 +- pkg/analysis_server/lib/src/lsp/mapping.dart | 4 +- .../completion/dart/fuzzy_filter_sort.dart | 2 +- .../statement/statement_completion.dart | 2 +- .../dart/replace_with_named_constant.dart | 2 +- .../completion/dart/text_expectations.dart | 4 +- .../test/stress/utilities/git.dart | 4 +- .../tool/log_player/normalize.dart | 2 +- .../tool/lsp_spec/codegen_dart.dart | 4 +- .../tool/lsp_spec/meta_model_cleaner.dart | 6 +- .../src/dartdoc/dartdoc_directive_info.dart | 4 +- .../src/test_utilities/test_code_format.dart | 2 +- .../test_utilities/test_library_builder.dart | 2 +- pkg/analyzer/lib/src/workspace/blaze.dart | 2 +- .../resolution/node_text_expectations.dart | 4 +- .../lib/src/inferrer/type_graph_dump.dart | 2 +- .../test/helpers/compiler_helper.dart | 5 +- .../sourcemaps/helpers/output_structure.dart | 14 ++--- .../test/sourcemaps/minified_names_test.dart | 8 +-- .../tools/translate_dart2js_stacktrace.dart | 4 +- .../bin/src/library_size_split.dart | 4 +- pkg/dart2js_tools/lib/src/name_decoder.dart | 12 ++-- pkg/dartdev/lib/src/commands/install.dart | 8 +-- pkg/dartdev/lib/src/native_assets_macos.dart | 2 +- pkg/dartdev/lib/src/unified_analytics.dart | 2 +- pkg/dartdev/test/commands/devtools_test.dart | 2 +- .../test/commands/language_server_test.dart | 2 +- pkg/dartdev/test/commands/run_test.dart | 2 +- pkg/dartdev/test/commands/test_test.dart | 2 +- pkg/dds/lib/src/dap/adapters/dart.dart | 4 +- pkg/dds/lib/src/dap/isolate_manager.dart | 4 +- pkg/dds/lib/src/dap/utils.dart | 6 +- pkg/dds/lib/src/dap/variables.dart | 4 +- pkg/dds/test/dap/integration/debug_test.dart | 2 +- .../test/dap/integration/test_support.dart | 2 +- ...evtools_server_path_strategy_dds_test.dart | 4 +- .../devtools_server_path_strategy_test.dart | 2 +- pkg/dev_compiler/lib/src/command/command.dart | 2 +- .../test/pid_file_discovery_test.dart | 2 +- pkg/front_end/presubmit_helper.dart | 2 +- pkg/front_end/test/binary_md_dill_reader.dart | 2 +- ...inary_md_vm_tags_and_version_git_test.dart | 8 +-- pkg/front_end/test/hot_reload_e2e_test.dart | 2 +- pkg/front_end/test/utils/kernel_chain.dart | 2 +- pkg/front_end/tool/benchmarker.dart | 4 +- pkg/observatory/bin/observatory.dart | 2 +- .../lib/src/debugger/debugger_location.dart | 38 ++++++------ .../lib/src/stepping_helper.dart | 4 +- pkg/vm/test/incremental_compiler_test.dart | 10 ++-- .../test/overdue_timer_detection_test.dart | 2 +- .../tool/common/generate_common.dart | 2 +- .../tests/vm/dart/isolates/reload_utils.dart | 4 +- ...dwarf_stack_traces_flag_deferred_test.dart | 4 +- .../use_dwarf_stack_traces_flag_helper.dart | 6 +- .../tests/vm/dart/use_macho_options_test.dart | 6 +- .../dart/v8_snapshot_profile_writer_test.dart | 10 ++-- .../js_dev_runtime/private/regexp_helper.dart | 2 +- .../js_dev_runtime/private/string_helper.dart | 18 +++--- .../js_runtime/lib/regexp_helper.dart | 8 +-- .../js_runtime/lib/string_helper.dart | 19 +++--- sdk/lib/_internal/vm/lib/regexp_patch.dart | 12 ++-- sdk/lib/_internal/vm/lib/string_patch.dart | 11 ++-- sdk/lib/_internal/wasm/lib/regexp_helper.dart | 10 ++-- sdk/lib/_internal/wasm/lib/string_helper.dart | 13 +++-- sdk/lib/core/pattern.dart | 10 ++-- sdk/lib/svg/dart2js/svg_dart2js.dart | 2 +- tests/corelib/reg_exp_all_matches_test.dart | 30 +++++----- tests/corelib/reg_exp_group_test.dart | 6 +- tests/corelib/reg_exp_groups_test.dart | 4 ++ .../regexp/ecma-regex-examples_test.dart | 2 +- .../extended-characters-match_test.dart | 19 +++--- tests/corelib/regexp/global_test.dart | 30 +++++----- tests/corelib/regexp/indexof_test.dart | 2 +- tests/corelib/regexp/lastindex_test.dart | 10 ++-- tests/corelib/regexp/named_captures_test.dart | 2 +- tests/corelib/regexp/no-extensions_test.dart | 58 +++++++++---------- tests/corelib/regexp/non-bmp_test.dart | 24 ++------ .../regexp/non-capturing-groups_test.dart | 6 +- tests/corelib/regexp/parentheses_test.dart | 2 +- tests/corelib/regexp/pcre-test-4_test.dart | 2 +- tests/corelib/regexp/standalones_test.dart | 20 +++---- .../corelib/regexp/unicode-handling_test.dart | 6 +- tests/corelib/regexp/v8_regexp_utils.dart | 6 +- tests/language/reg_exp/reg_exp4_test.dart | 4 +- tests/language/reg_exp/reg_exp_test.dart | 6 +- tests/standalone/dwarf_stack_trace_test.dart | 2 +- tests/standalone/io/platform_test.dart | 12 ++-- tests/web/native/error_safeToString_test.dart | 2 +- tests/web/wasm/source_map_simple_lib.dart | 4 +- .../wasm/source_map_unminification_test.dart | 2 +- third_party/pkg/dap/tool/codegen.dart | 3 +- tools/package_deps/bin/package_deps.dart | 6 +- tools/rev_sdk_deps.dart | 2 +- 97 files changed, 313 insertions(+), 332 deletions(-) diff --git a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart index 6f67fd14ce0..0730045233c 100644 --- a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart +++ b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart @@ -320,7 +320,7 @@ abstract class DiagnosticCode { if (correctionMessage != null) correctionMessage, ]) { for (RegExpMatch match in _positionalArgumentRegExp.allMatches(s)) { - result = max(result, int.parse(match.group(1)!) + 1); + result = max(result, int.parse(match[1]!) + 1); } } return result; diff --git a/pkg/_fe_analyzer_shared/lib/src/messages/codes.dart b/pkg/_fe_analyzer_shared/lib/src/messages/codes.dart index d8ac4da5bd2..77fa9a01939 100644 --- a/pkg/_fe_analyzer_shared/lib/src/messages/codes.dart +++ b/pkg/_fe_analyzer_shared/lib/src/messages/codes.dart @@ -459,7 +459,7 @@ String applyArgumentsToTemplate( return template; } return template.replaceAllMapped(templateKey, (Match match) { - String? key = match.group(1); + String? key = match[1]; Object? value = arguments[key]; assert(value != null, "No value for '$key' found in $arguments"); return value.toString(); diff --git a/pkg/_fe_analyzer_shared/test/mini_ast.dart b/pkg/_fe_analyzer_shared/test/mini_ast.dart index 6fa8a6b9316..f7f4af4358c 100644 --- a/pkg/_fe_analyzer_shared/test/mini_ast.dart +++ b/pkg/_fe_analyzer_shared/test/mini_ast.dart @@ -144,7 +144,7 @@ String computeLocation() { '_locationRegExp failed to match $stackLine in $callStack', ); } - return match.group(0)!; + return match[0]!; } Statement continue_([Label? target]) => diff --git a/pkg/analysis_server/lib/src/lsp/completion_utils.dart b/pkg/analysis_server/lib/src/lsp/completion_utils.dart index d47c6fcbbfc..bf86313cfde 100644 --- a/pkg/analysis_server/lib/src/lsp/completion_utils.dart +++ b/pkg/analysis_server/lib/src/lsp/completion_utils.dart @@ -370,7 +370,7 @@ lsp.CompletionItem? toLspCompletionItem( if (labelMatch != null) { cleanedDoc = null; labelDetails = ( - detail: labelMatch.group(1)!, + detail: labelMatch[1]!, truncatedParams: labelDetails.truncatedParams, truncatedSignature: labelDetails.truncatedSignature, autoImportUri: labelDetails.autoImportUri, @@ -634,7 +634,7 @@ CompletionDetail _getCompletionDetail( if (returnType == null && element.kind == ElementKind.SETTER && parameters != null) { - returnType = completionSetterTypePattern.firstMatch(parameters)?.group(1); + returnType = completionSetterTypePattern.firstMatch(parameters)?[1]; parameters = null; } } else if (suggestion is FunctionCall) { diff --git a/pkg/analysis_server/lib/src/lsp/dartdoc.dart b/pkg/analysis_server/lib/src/lsp/dartdoc.dart index a1c5190de23..fbc5f194ad6 100644 --- a/pkg/analysis_server/lib/src/lsp/dartdoc.dart +++ b/pkg/analysis_server/lib/src/lsp/dartdoc.dart @@ -17,10 +17,7 @@ String? cleanDartdoc(String? doc) { // Remove any code block section names like ```dart preamble that Flutter // docs contain. - doc = doc.replaceAllMapped( - _dartdocCodeBlockSections, - (match) => match.group(1)!, - ); + doc = doc.replaceAllMapped(_dartdocCodeBlockSections, (match) => match[1]!); return doc; } diff --git a/pkg/analysis_server/lib/src/lsp/mapping.dart b/pkg/analysis_server/lib/src/lsp/mapping.dart index 0ebd9656f2c..fdf9ff86a48 100644 --- a/pkg/analysis_server/lib/src/lsp/mapping.dart +++ b/pkg/analysis_server/lib/src/lsp/mapping.dart @@ -568,7 +568,7 @@ CompletionDetail getCompletionDetail( if (returnType == null && element?.kind == server.ElementKind.SETTER && parameters != null) { - returnType = completionSetterTypePattern.firstMatch(parameters)?.group(1); + returnType = completionSetterTypePattern.firstMatch(parameters)?[1]; parameters = null; } @@ -1275,7 +1275,7 @@ lsp.CompletionItem toCompletionItem( if (labelMatch != null) { cleanedDoc = null; labelDetails = ( - detail: labelMatch.group(1)!, + detail: labelMatch[1]!, truncatedParams: labelDetails.truncatedParams, truncatedSignature: labelDetails.truncatedSignature, autoImportUri: labelDetails.autoImportUri, diff --git a/pkg/analysis_server/lib/src/services/completion/dart/fuzzy_filter_sort.dart b/pkg/analysis_server/lib/src/services/completion/dart/fuzzy_filter_sort.dart index 2653afb3058..194883467d9 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/fuzzy_filter_sort.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/fuzzy_filter_sort.dart @@ -25,7 +25,7 @@ List fuzzyFilterSort({ if (suggestion.kind == CompletionSuggestionKind.KEYWORD || suggestion.kind == CompletionSuggestionKind.NAMED_ARGUMENT) { - var identifier = _identifierPattern.matchAsPrefix(textToMatch)?.group(1); + var identifier = _identifierPattern.matchAsPrefix(textToMatch)?[1]; if (identifier == null) { return -1; } diff --git a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart index c3195e4749a..d19f8da164a 100644 --- a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart +++ b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart @@ -650,7 +650,7 @@ class StatementCompletionProcessor { // emptyCondition, emptyInitializersEmptyCondition replacementLength = match.end - match.start; sb = SourceBuilder(file, forParts.leftSeparator.offset); - sb.append('; ${match.group(1) ?? ''}; )'); + sb.append('; ${match[1] ?? ''}; )'); var suffix = text.substring(match.end); if (suffix.trim().isNotEmpty) { sb.append(' '); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_named_constant.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_named_constant.dart index 91398a87f63..1c7c4382cb0 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_named_constant.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_named_constant.dart @@ -45,6 +45,6 @@ class ReplaceWithNamedConstant extends ResolvedCorrectionProducer { if (match == null) { return null; } - return match.group(1); + return match[1]; } } diff --git a/pkg/analysis_server/test/services/completion/dart/text_expectations.dart b/pkg/analysis_server/test/services/completion/dart/text_expectations.dart index 1b26522cfcc..e59e92ff7f5 100644 --- a/pkg/analysis_server/test/services/completion/dart/text_expectations.dart +++ b/pkg/analysis_server/test/services/completion/dart/text_expectations.dart @@ -69,8 +69,8 @@ class TextExpectationsCollector { fail('Cannot parse: $invocationTraceLine'); } - var path = Uri.parse(locationMatch.group(1)!).toFilePath(); - var line = int.parse(locationMatch.group(2)!); + var path = Uri.parse(locationMatch[1]!).toFilePath(); + var line = int.parse(locationMatch[2]!); var file = _getFile(path); var invocation = file.findInvocation(invocationLine: line); diff --git a/pkg/analysis_server/test/stress/utilities/git.dart b/pkg/analysis_server/test/stress/utilities/git.dart index ef3a45bd30f..c64dd3e6551 100644 --- a/pkg/analysis_server/test/stress/utilities/git.dart +++ b/pkg/analysis_server/test/stress/utilities/git.dart @@ -43,8 +43,8 @@ class BlobDiff { var currentHunk = hunks.isEmpty ? null : hunks.last; if (line.startsWith('@@')) { var match = hunkHeaderRegExp.matchAsPrefix(line)!; - var srcLine = int.parse(match.group(1)!); - var dstLine = int.parse(match.group(2)!); + var srcLine = int.parse(match[1]!); + var dstLine = int.parse(match[2]!); hunks.add(DiffHunk(srcLine, dstLine)); } else if (currentHunk != null && line.startsWith('+')) { currentHunk.addLines.add(line.substring(1)); diff --git a/pkg/analysis_server/tool/log_player/normalize.dart b/pkg/analysis_server/tool/log_player/normalize.dart index eaeae542a92..074bdc15126 100644 --- a/pkg/analysis_server/tool/log_player/normalize.dart +++ b/pkg/analysis_server/tool/log_player/normalize.dart @@ -72,7 +72,7 @@ Future main(List args) async { print('found ${absFileMatches.length} absolute file paths remaining:'); } for (var match in absFileMatches.take(5)) { - print('- ${match.group(0)}'); + print('- ${match[0]}'); } } diff --git a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart index 89b66210a0e..c0671eb4d5b 100644 --- a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart +++ b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart @@ -309,8 +309,8 @@ String _memberNameForType(TypeBase type) { String _rewriteCommentReference(String comment) { var commentReferencePattern = RegExp(r'\[([\w ]+)\]\(#(\w+)\)'); return comment.replaceAllMapped(commentReferencePattern, (m) { - var description = m.group(1); - var reference = m.group(2); + var description = m[1]; + var reference = m[2]; if (description == reference) { return '[$reference]'; } else { diff --git a/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart b/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart index d0d3cd581a7..8f3d17353c7 100644 --- a/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart +++ b/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart @@ -114,18 +114,18 @@ class LspMetaModelCleaner { // spaces. text = text.replaceAllMapped( _sourceCommentWrappingNewlinesPattern, - (match) => match.group(0)!.replaceAll('\n', ' '), + (match) => match[0]!.replaceAll('\n', ' '), ); // Replace any references to other types with a format that's valid for // Dart. text = text.replaceAllMapped( _sourceCommentDocumentLinksPattern, - (match) => '[${match.group(1)!}]', + (match) => '[${match[1]!}]', ); text = text.replaceAllMapped( _sourceCommentReferencesPattern, - (match) => '[${match.group(1)!}]', + (match) => '[${match[1]!}]', ); // Replace any references to Thenable/Promise to Future. diff --git a/pkg/analyzer/lib/src/dartdoc/dartdoc_directive_info.dart b/pkg/analyzer/lib/src/dartdoc/dartdoc_directive_info.dart index 14a4a0b79ab..56bfb954bf3 100644 --- a/pkg/analyzer/lib/src/dartdoc/dartdoc_directive_info.dart +++ b/pkg/analyzer/lib/src/dartdoc/dartdoc_directive_info.dart @@ -129,7 +129,7 @@ class DartdocDirectiveInfo { } else { var match = macroRegExp.firstMatch(line); if (match != null) { - var name = match.group(1)!; + var name = match[1]!; var value = templateMap[name]; if (value != null) { lines[i] = value; @@ -139,7 +139,7 @@ class DartdocDirectiveInfo { match = videoRegExp.firstMatch(line); if (match != null) { - var uri = match.group(2); + var uri = match[2]; if (uri != null && uri.isNotEmpty) { String label = uri; if (label.startsWith('https://')) { diff --git a/pkg/analyzer/lib/src/test_utilities/test_code_format.dart b/pkg/analyzer/lib/src/test_utilities/test_code_format.dart index b876c8ad9ac..557e12c1e95 100644 --- a/pkg/analyzer/lib/src/test_utilities/test_code_format.dart +++ b/pkg/analyzer/lib/src/test_utilities/test_code_format.dart @@ -87,7 +87,7 @@ class TestCode { var rangeEndOffsets = {}; late int start; - int scannedNumber() => int.parse(scanner.lastMatch!.group(1)!); + int scannedNumber() => int.parse(scanner.lastMatch![1]!); void recordPosition(int number) { if (positionOffsets.containsKey(number)) { diff --git a/pkg/analyzer/lib/src/test_utilities/test_library_builder.dart b/pkg/analyzer/lib/src/test_utilities/test_library_builder.dart index 4401b29eb40..86a8878bb24 100644 --- a/pkg/analyzer/lib/src/test_utilities/test_library_builder.dart +++ b/pkg/analyzer/lib/src/test_utilities/test_library_builder.dart @@ -532,7 +532,7 @@ class _TokenStream { int _index = 0; factory _TokenStream.fromString(String input) { - var tokens = _tokenizer.allMatches(input).map((m) => m.group(0)!).toList(); + var tokens = _tokenizer.allMatches(input).map((m) => m[0]!).toList(); return _TokenStream._(tokens); } diff --git a/pkg/analyzer/lib/src/workspace/blaze.dart b/pkg/analyzer/lib/src/workspace/blaze.dart index 7bfce614960..7e57d59131b 100644 --- a/pkg/analyzer/lib/src/workspace/blaze.dart +++ b/pkg/analyzer/lib/src/workspace/blaze.dart @@ -580,7 +580,7 @@ class BlazeWorkspace extends Workspace var pattern = RegExp(r'(^|\s+)_version\s*=\s*"(\d+\.\d+)"'); for (var match in pattern.allMatches(content)) { - return Version.parse('${match.group(2)}.0'); + return Version.parse('${match[2]}.0'); } return null; diff --git a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart index e7359d502e1..8057431945d 100644 --- a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart +++ b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart @@ -267,8 +267,8 @@ class NodeTextExpectationsCollector { fail('Cannot parse: $invocationTraceLine'); } - var path = Uri.parse(locationMatch.group(1)!).toFilePath(); - var line = int.parse(locationMatch.group(2)!); + var path = Uri.parse(locationMatch[1]!).toFilePath(); + var line = int.parse(locationMatch[2]!); var file = _getFile(path); var invocation = file.findInvocation(invocationLine: line); diff --git a/pkg/compiler/lib/src/inferrer/type_graph_dump.dart b/pkg/compiler/lib/src/inferrer/type_graph_dump.dart index fc638cdd870..1b8d0924c71 100644 --- a/pkg/compiler/lib/src/inferrer/type_graph_dump.dart +++ b/pkg/compiler/lib/src/inferrer/type_graph_dump.dart @@ -207,7 +207,7 @@ class _GraphGenerator extends TypeInformationVisitor { /// Escapes characters in [text] so it can be used as part of a label. String escapeLabel(String text) { - return text.replaceAllMapped(escapeRegexp, (m) => '\\${m.group(0)}'); + return text.replaceAllMapped(escapeRegexp, (m) => '\\${m[0]}'); } /// Creates an edge from [src] to [dst]. diff --git a/pkg/compiler/test/helpers/compiler_helper.dart b/pkg/compiler/test/helpers/compiler_helper.dart index a532c4473a6..7ec52085843 100644 --- a/pkg/compiler/test/helpers/compiler_helper.dart +++ b/pkg/compiler/test/helpers/compiler_helper.dart @@ -238,9 +238,8 @@ checkerForAbsentPresent(String test) { Expect.fail("No 'absent:' or 'present:' directives in '$test'"); } for (Match match in matches) { - String? directive = match.group(1); - Pattern pattern = match.groups([2, 3, 4]).where((s) => s != null).single!; - if (match.group(4) != null) pattern = RegExp(pattern as String); + String? directive = match[1]; + Pattern pattern = match[2] ?? match[3] ?? RegExp(match[4]!); if (directive == 'present') { Expect.isTrue( generated.contains(pattern), diff --git a/pkg/compiler/test/sourcemaps/helpers/output_structure.dart b/pkg/compiler/test/sourcemaps/helpers/output_structure.dart index e0eac84b570..d61090db53b 100644 --- a/pkg/compiler/test/sourcemaps/helpers/output_structure.dart +++ b/pkg/compiler/test/sourcemaps/helpers/output_structure.dart @@ -384,15 +384,15 @@ class LibraryBlock extends AbstractEntity { BasicEntity? next; Match? matchFunction = TOP_LEVEL_FUNCTION.firstMatch(line); if (matchFunction != null) { - next = TopLevelFunction(matchFunction.group(1)!, index); + next = TopLevelFunction(matchFunction[1]!, index); } else { Match? matchClass = TOP_LEVEL_CLASS.firstMatch(line); if (matchClass != null) { - next = LibraryClass(matchClass.group(1)!, index); + next = LibraryClass(matchClass[1]!, index); } else { Match? matchValue = TOP_LEVEL_VALUE.firstMatch(line); if (matchValue != null) { - next = TopLevelValue(matchValue.group(1)!, index); + next = TopLevelValue(matchValue[1]!, index); } } } @@ -511,7 +511,7 @@ class LibraryClass extends BasicEntity { BasicEntity? next; Match? match = MEMBER_FUNCTION.firstMatch(line); if (match != null) { - next = MemberFunction(match.group(1)!, index); + next = MemberFunction(match[1]!, index); } else { match = STATICS.firstMatch(line); if (match != null) { @@ -519,11 +519,11 @@ class LibraryClass extends BasicEntity { } else { match = MEMBER_OBJECT.firstMatch(line); if (match != null) { - next = MemberObject(match.group(1)!, index); + next = MemberObject(match[1]!, index); } else { match = MEMBER_VALUE.firstMatch(line); if (match != null) { - next = MemberValue(match.group(1)!, index); + next = MemberValue(match[1]!, index); } } } @@ -595,7 +595,7 @@ class Statics extends BasicEntity { BasicEntity? next; Match? matchFunction = STATIC_FUNCTION.firstMatch(line); if (matchFunction != null) { - next = MemberFunction(matchFunction.group(1)!, index); + next = MemberFunction(matchFunction[1]!, index); } if (next != null) { if (current != null) { diff --git a/pkg/compiler/test/sourcemaps/minified_names_test.dart b/pkg/compiler/test/sourcemaps/minified_names_test.dart index 3372117a7d7..d4c3c92306c 100644 --- a/pkg/compiler/test/sourcemaps/minified_names_test.dart +++ b/pkg/compiler/test/sourcemaps/minified_names_test.dart @@ -70,10 +70,10 @@ RegExp _nameMatcher = RegExp("// Expected deobfuscated name: (.*)\n"); Future runTest(String code) async { var patternMatch = _patternMatcher.firstMatch(code); Expect.isNotNull(patternMatch, "Could not find the error pattern."); - var pattern = RegExp(patternMatch!.group(1)!); + var pattern = RegExp(patternMatch![1]!); var kindMatch = _kindMatcher.firstMatch(code); Expect.isNotNull(kindMatch, "Could not find the expected minified kind."); - var kind = kindMatch!.group(1)!; + var kind = kindMatch![1]!; // TODO(sigmund): add support for "other" when we encode symbol information // directly for each field and local variable. @@ -85,7 +85,7 @@ Future runTest(String code) async { var nameMatch = _nameMatcher.firstMatch(code); Expect.isNotNull(nameMatch, "Could not find the expected deobfuscated name."); - var expectedName = nameMatch!.group(1)!; + var expectedName = nameMatch![1]!; var test = MinifiedNameTest(pattern, kind, expectedName, code); print('expectations: ${pattern.pattern} $kind $expectedName'); await checkExpectation(test, false); @@ -114,7 +114,7 @@ checkExpectation(MinifiedNameTest test, bool minified) async { 'Error didn\'t match the test pattern' '\nerror: $error\npattern:${test.pattern}', ); - var name = match!.group(1)!; + var name = match![1]!; print(' obfuscated-name: $name'); Expect.isNotNull(name, 'Error didn\'t contain a name\nerror: $error'); diff --git a/pkg/compiler/test/sourcemaps/tools/translate_dart2js_stacktrace.dart b/pkg/compiler/test/sourcemaps/tools/translate_dart2js_stacktrace.dart index 62813ef7a8f..2facfbada36 100644 --- a/pkg/compiler/test/sourcemaps/tools/translate_dart2js_stacktrace.dart +++ b/pkg/compiler/test/sourcemaps/tools/translate_dart2js_stacktrace.dart @@ -68,8 +68,8 @@ main(List arguments) async { continue; } Match m = ms.first; - int l = int.parse(m.group(1)!); - int c = int.parse(m.group(2)!); + int l = int.parse(m[1]!); + int c = int.parse(m[2]!); SourceMapSpan? span = sourceMap.spanFor(l, c); if (span == null) { if (options['inline']) { diff --git a/pkg/dart2js_info/bin/src/library_size_split.dart b/pkg/dart2js_info/bin/src/library_size_split.dart index 7cff6f8bbce..1e70f9ffb78 100644 --- a/pkg/dart2js_info/bin/src/library_size_split.dart +++ b/pkg/dart2js_info/bin/src/library_size_split.dart @@ -115,8 +115,8 @@ class LibrarySizeCommand extends Command with PrintUsageException { final match = group.matcher.firstMatch('${lib.uri}'); if (match != null) { var name = group.name; - if (name == null && match.groupCount > 0) name = match.group(1); - name ??= match.group(0); + if (name == null && match.groupCount > 0) name = match[1]; + name ??= match[0]; sizes.putIfAbsent(name, () => _SizeEntry(name, group.cluster)); sizes[name].size += lib.size; } diff --git a/pkg/dart2js_tools/lib/src/name_decoder.dart b/pkg/dart2js_tools/lib/src/name_decoder.dart index 66c606bb7f3..d5f802bb139 100644 --- a/pkg/dart2js_tools/lib/src/name_decoder.dart +++ b/pkg/dart2js_tools/lib/src/name_decoder.dart @@ -85,7 +85,7 @@ class MinifiedNameDecoder extends ErrorMapDecoder { StackTraceLine? line, TargetEntry? entry, ) { - var minifiedName = match.group(1); + var minifiedName = match[1]; return mapping!.globalNames[minifiedName]; } } @@ -101,7 +101,7 @@ class CannotReadPropertyDecoder extends ErrorMapDecoder { StackTraceLine? line, TargetEntry? entry, ) { - var minifiedName = match.group(1); + var minifiedName = match[1]; var name = mapping!.instanceNames[minifiedName]; if (name == null) return null; return "Cannot read property '$name' of"; @@ -176,8 +176,8 @@ class NoSuchMethodDecoder1 extends NoSuchMethodDecoderBase { StackTraceLine? line, TargetEntry? entry, ) { - var minifiedName = match.group(1); - var suffix = match.group(2) ?? ''; + var minifiedName = match[1]; + var suffix = match[2] ?? ''; var name = _translateMinifiedName(mapping!, minifiedName); if (name == null) return null; return "NoSuchMethodError: method not found: $name$suffix"; @@ -197,7 +197,7 @@ class NoSuchMethodDecoder2 extends NoSuchMethodDecoderBase { StackTraceLine? line, TargetEntry? entry, ) { - var minifiedName = match.group(1); + var minifiedName = match[1]; var name = _translateMinifiedName(mapping!, minifiedName); if (name == null) return null; return "NoSuchMethodError: method not found: $name"; @@ -215,7 +215,7 @@ class UnhandledNotAFunctionError extends ErrorMapDecoder { StackTraceLine? line, TargetEntry? entry, ) { - var minifiedName = match.group(1); + var minifiedName = match[1]; var name = mapping!.instanceNames[minifiedName]; if (name == null) return null; return "Error: $name is not a function"; diff --git a/pkg/dartdev/lib/src/commands/install.dart b/pkg/dartdev/lib/src/commands/install.dart index a75fd07c890..721cc3368b8 100644 --- a/pkg/dartdev/lib/src/commands/install.dart +++ b/pkg/dartdev/lib/src/commands/install.dart @@ -764,10 +764,10 @@ class GitSshUrl { } return GitSshUrl( - user: match.group(1)!, - host: match.group(2)!, - owner: match.group(3)!, - repository: match.group(4)!, + user: match[1]!, + host: match[2]!, + owner: match[3]!, + repository: match[4]!, fullUrl: url, ); } diff --git a/pkg/dartdev/lib/src/native_assets_macos.dart b/pkg/dartdev/lib/src/native_assets_macos.dart index a81c4c17822..95857a77708 100644 --- a/pkg/dartdev/lib/src/native_assets_macos.dart +++ b/pkg/dartdev/lib/src/native_assets_macos.dart @@ -135,7 +135,7 @@ Map> parseOtoolArchitectureSections(String output) { 'Expected a single architecture section in otool output: $output', ); } - final String? architectureString = architectureHeader.group(2); + final String? architectureString = architectureHeader[2]; if (architectureString != null) { currentArchitecture = outputArchitectures[architectureString]; if (currentArchitecture == null) { diff --git a/pkg/dartdev/lib/src/unified_analytics.dart b/pkg/dartdev/lib/src/unified_analytics.dart index ce6b40c8a2e..14251be1bc1 100644 --- a/pkg/dartdev/lib/src/unified_analytics.dart +++ b/pkg/dartdev/lib/src/unified_analytics.dart @@ -79,7 +79,7 @@ String sanitizeStacktrace(dynamic st, {bool shorten = true}) { iter = iter.toList().reversed; for (var match in iter) { - var replacement = match.group(1)!; + var replacement = match[1]!; str = str.substring(0, match.start) + replacement + str.substring(match.end); } diff --git a/pkg/dartdev/test/commands/devtools_test.dart b/pkg/dartdev/test/commands/devtools_test.dart index 335445571b0..f49443f961d 100644 --- a/pkg/dartdev/test/commands/devtools_test.dart +++ b/pkg/dartdev/test/commands/devtools_test.dart @@ -241,7 +241,7 @@ Future main() async { if (event.contains(dartVMServiceRegExp)) { await sub.cancel(); serviceUriCompleter.complete( - dartVMServiceRegExp.firstMatch(event)!.group(1), + dartVMServiceRegExp.firstMatch(event)![1], ); } }); diff --git a/pkg/dartdev/test/commands/language_server_test.dart b/pkg/dartdev/test/commands/language_server_test.dart index 142a8b95e3f..ca4c065b7b6 100644 --- a/pkg/dartdev/test/commands/language_server_test.dart +++ b/pkg/dartdev/test/commands/language_server_test.dart @@ -176,7 +176,7 @@ Future _readLspMessage(Stream> stream) { final headers = parts[0]; final body = parts[1]; final length = int.parse( - contentLengthRegExp.firstMatch(headers)!.group(1)!, + contentLengthRegExp.firstMatch(headers)![1]!, ); // Check if we're already had the full payload. if (body.length >= length) { diff --git a/pkg/dartdev/test/commands/run_test.dart b/pkg/dartdev/test/commands/run_test.dart index e7e459db972..800bbb4bd13 100644 --- a/pkg/dartdev/test/commands/run_test.dart +++ b/pkg/dartdev/test/commands/run_test.dart @@ -534,7 +534,7 @@ void main(List args) => print("$b $args"); ); void onData(event) { if (event.contains('The Dart VM service is listening on')) { - final vmServicePort = int.parse(regexp.firstMatch(event)!.group(1)!); + final vmServicePort = int.parse(regexp.firstMatch(event)![1]!); expect(server.port != vmServicePort, isTrue); p.kill(); } diff --git a/pkg/dartdev/test/commands/test_test.dart b/pkg/dartdev/test/commands/test_test.dart index 0dbf5f57eb8..3be60dad69a 100644 --- a/pkg/dartdev/test/commands/test_test.dart +++ b/pkg/dartdev/test/commands/test_test.dart @@ -217,7 +217,7 @@ void main() { if (line.contains(vmServiceUriRegExp)) { await sub.cancel(); final httpUri = Uri.parse( - vmServiceUriRegExp.firstMatch(line)!.group(0)!, + vmServiceUriRegExp.firstMatch(line)![0]!, ); completer.complete( httpUri.replace(scheme: 'ws', path: '${httpUri.path}ws'), diff --git a/pkg/dds/lib/src/dap/adapters/dart.dart b/pkg/dds/lib/src/dap/adapters/dart.dart index 2886f56ca95..a5cd18a5ffe 100644 --- a/pkg/dds/lib/src/dap/adapters/dart.dart +++ b/pkg/dds/lib/src/dap/adapters/dart.dart @@ -1212,7 +1212,7 @@ abstract class DartDebugAdapter '${match.group(1)}\${') + (match) => '${match[1]}\${') // Remove any backslashes the user added to "escape" braces. .replaceAll(r'\\{', '{'); return _evaluateAndPrintErrors(thread, expression, 'log message'); diff --git a/pkg/dds/lib/src/dap/utils.dart b/pkg/dds/lib/src/dap/utils.dart index 1d8c554aeac..7f466beefe4 100644 --- a/pkg/dds/lib/src/dap/utils.dart +++ b/pkg/dds/lib/src/dap/utils.dart @@ -100,9 +100,9 @@ StackFrameLocation? _parseStackFrame(String input) { final match = _stackFrameLocationPattern.firstMatch(input); if (match == null) return null; - final uriMatch = match.group(1); - final lineMatch = match.group(2); - final colMatch = match.group(3); + final uriMatch = match[1]; + final lineMatch = match[2]; + final colMatch = match[3]; var uri = uriMatch != null ? Uri.tryParse(uriMatch) : null; final line = lineMatch != null ? int.tryParse(lineMatch) : null; diff --git a/pkg/dds/lib/src/dap/variables.dart b/pkg/dds/lib/src/dap/variables.dart index 62446478635..b5b2c316013 100644 --- a/pkg/dds/lib/src/dap/variables.dart +++ b/pkg/dds/lib/src/dap/variables.dart @@ -142,8 +142,8 @@ class EvaluationExpression { /// format a value should be presented in. factory EvaluationExpression.parse(String expression) { final match = _expressionWithFormatSpecifierRegex.firstMatch(expression); - expression = match?.group(1) ?? expression; - final formatSpecifiers = match?.group(2)?.split(',').toSet() ?? const {}; + expression = match?[1] ?? expression; + final formatSpecifiers = match?[2]?.split(',').toSet() ?? const {}; final format = formatSpecifiers.isEmpty ? null : VariableFormat( diff --git a/pkg/dds/test/dap/integration/debug_test.dart b/pkg/dds/test/dap/integration/debug_test.dart index b8969b5f3bb..0ebb650eb0e 100644 --- a/pkg/dds/test/dap/integration/debug_test.dart +++ b/pkg/dds/test/dap/integration/debug_test.dart @@ -792,5 +792,5 @@ Uri _extractVmServiceUri(OutputEventBody vmConnectionBanner) { // TODO(dantup): Change this to use the dart.debuggerUris custom event // if implemented (which VS Code also needs). final match = dapVmServiceBannerPattern.firstMatch(vmConnectionBanner.output); - return Uri.parse(match!.group(1)!); + return Uri.parse(match![1]!); } diff --git a/pkg/dds/test/dap/integration/test_support.dart b/pkg/dds/test/dap/integration/test_support.dart index 7c0c450bbdf..ebdbd596298 100644 --- a/pkg/dds/test/dap/integration/test_support.dart +++ b/pkg/dds/test/dap/integration/test_support.dart @@ -123,7 +123,7 @@ Future waitForStdoutVmServiceBanner(Process process) { (line) { final match = vmServiceBannerPattern.firstMatch(line); if (match != null) { - vmServiceUriCompleter.complete(Uri.parse(match.group(1)!)); + vmServiceUriCompleter.complete(Uri.parse(match[1]!)); vmServiceBannerSub.cancel(); } }, diff --git a/pkg/dds/test/devtools_server/devtools_server_path_strategy_dds_test.dart b/pkg/dds/test/devtools_server/devtools_server_path_strategy_dds_test.dart index 2b61572de11..40909bc2e18 100644 --- a/pkg/dds/test/devtools_server/devtools_server_path_strategy_dds_test.dart +++ b/pkg/dds/test/devtools_server/devtools_server_path_strategy_dds_test.dart @@ -42,7 +42,7 @@ void main() { (String line) { final match = devToolsBannerRegex.firstMatch(line); if (match != null) { - completer.complete(match.group(1)!); + completer.complete(match[1]!); } }, onDone: () { @@ -98,7 +98,7 @@ void main() { // Extract the base href so if the test failures, we get a simpler error // than just the entire content. - final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)!.group(1); + final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)![1]; expect(actualBaseHref, htmlEscape.convert(expectedBaseHref)); }, timeout: const Timeout.factor(10)); } diff --git a/pkg/dds/test/devtools_server/devtools_server_path_strategy_test.dart b/pkg/dds/test/devtools_server/devtools_server_path_strategy_test.dart index a2bff8938b9..c321fd4f412 100644 --- a/pkg/dds/test/devtools_server/devtools_server_path_strategy_test.dart +++ b/pkg/dds/test/devtools_server/devtools_server_path_strategy_test.dart @@ -85,7 +85,7 @@ void main() { // Extract the base href so if the test failures, we get a simpler error // than just the entire content. - final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)!.group(1); + final actualBaseHref = baseHrefRegex.firstMatch(bodyContent)![1]; expect(actualBaseHref, htmlEscape.convert(expectedBaseHref)); }, timeout: const Timeout.factor(10)); } diff --git a/pkg/dev_compiler/lib/src/command/command.dart b/pkg/dev_compiler/lib/src/command/command.dart index f1ae810cebe..4dd9d7903d9 100644 --- a/pkg/dev_compiler/lib/src/command/command.dart +++ b/pkg/dev_compiler/lib/src/command/command.dart @@ -1186,7 +1186,7 @@ Map placeSourceMap( // The source location is part of a different package. var match = _crossPackageLib.matchAsPrefix(relativeUriPath); if (match != null) { - var crossPackageName = match.group(1); + var crossPackageName = match[1]; return relativeUriPath.replaceFirst( '../../$crossPackageName/lib/', '../$crossPackageName/', diff --git a/pkg/dtd_impl/test/pid_file_discovery_test.dart b/pkg/dtd_impl/test/pid_file_discovery_test.dart index a815101318b..469a473a07a 100644 --- a/pkg/dtd_impl/test/pid_file_discovery_test.dart +++ b/pkg/dtd_impl/test/pid_file_discovery_test.dart @@ -46,7 +46,7 @@ void main() { if (line.startsWith('The Dart Tooling Daemon is listening on')) { final match = uriRegex.firstMatch(line); if (match != null) { - uri = match.group(1); + uri = match[1]; } } else if (line.startsWith('Trusted Client Secret')) { break; // We have both the URI (printed first) and the secret. diff --git a/pkg/front_end/presubmit_helper.dart b/pkg/front_end/presubmit_helper.dart index ffe84a84b25..1b9a2ded350 100644 --- a/pkg/front_end/presubmit_helper.dart +++ b/pkg/front_end/presubmit_helper.dart @@ -210,7 +210,7 @@ MessagesWork? _createMessagesTestWork(List changedFiles) { List filters = []; for (String file in changedFiles) { if (_messagesYamlPathRegExp.matchAsPrefix(file) case var match?) { - filters.add('messages/${match.group(1)}/...'); + filters.add('messages/${match[1]}/...'); } } diff --git a/pkg/front_end/test/binary_md_dill_reader.dart b/pkg/front_end/test/binary_md_dill_reader.dart index 647f4fa774d..e275d5c3301 100644 --- a/pkg/front_end/test/binary_md_dill_reader.dart +++ b/pkg/front_end/test/binary_md_dill_reader.dart @@ -204,7 +204,7 @@ class BinaryMdDillReader { String? nameExtends = null; Match? extendsMatch = (new RegExp("extends (.+)[ \{]")).firstMatch(name); if (extendsMatch != null) { - nameExtends = extendsMatch.group(1); + nameExtends = extendsMatch[1]; } name = _getType(name); if (name.contains("<")) { diff --git a/pkg/front_end/test/binary_md_vm_tags_and_version_git_test.dart b/pkg/front_end/test/binary_md_vm_tags_and_version_git_test.dart index 739023790dc..f25120b4513 100644 --- a/pkg/front_end/test/binary_md_vm_tags_and_version_git_test.dart +++ b/pkg/front_end/test/binary_md_vm_tags_and_version_git_test.dart @@ -52,13 +52,13 @@ Future main() async { while (true) { RegExpMatch? match = tagParser.firstMatch(line); if (match != null) { - int value = int.parse(match.group(2)!); + int value = int.parse(match[2]!); int end = value + 1; - if (uses8Tags(match.group(1)!)) { + if (uses8Tags(match[1]!)) { end = value + 8; } for (int j = value; j < end; j++) { - vmTagToName[j] = match.group(1)!; + vmTagToName[j] = match[1]!; } } if (!vmTagLines[i].trim().endsWith(r"\")) { @@ -71,7 +71,7 @@ Future main() async { while (true) { RegExpMatch? match = constantTagParser.firstMatch(line); if (match != null) { - vmConstantTagToName[int.parse(match.group(2)!)] = match.group(1)!; + vmConstantTagToName[int.parse(match[2]!)] = match[1]!; } if (vmTagLines[i].trim().startsWith("}")) { break; diff --git a/pkg/front_end/test/hot_reload_e2e_test.dart b/pkg/front_end/test/hot_reload_e2e_test.dart index 67e055aae7e..cfd50a35e8c 100644 --- a/pkg/front_end/test/hot_reload_e2e_test.dart +++ b/pkg/front_end/test/hot_reload_e2e_test.dart @@ -84,7 +84,7 @@ abstract class TestCase { var portLine = await lines[0]; Expect.isTrue(dartVMServicePortRegExp.hasMatch(portLine)); var match = dartVMServicePortRegExp.firstMatch(portLine); - return int.parse(match!.group(1)!); + return int.parse(match![1]!); } /// Request vm to resume execution diff --git a/pkg/front_end/test/utils/kernel_chain.dart b/pkg/front_end/test/utils/kernel_chain.dart index 6434980e31e..c4021d07b93 100644 --- a/pkg/front_end/test/utils/kernel_chain.dart +++ b/pkg/front_end/test/utils/kernel_chain.dart @@ -259,7 +259,7 @@ class ErrorCommentChecker "'$plainTextProblem' with '$extractLineRegExp'"; } for (RegExpMatch match in matches) { - String lineString = match.group(0)!; + String lineString = match[0]!; notYetSeen.remove(lineString); if (expectNoProblemOn.contains(lineString)) { failures.add( diff --git a/pkg/front_end/tool/benchmarker.dart b/pkg/front_end/tool/benchmarker.dart index 499ac4579e9..7f96d9dacdd 100644 --- a/pkg/front_end/tool/benchmarker.dart +++ b/pkg/front_end/tool/benchmarker.dart @@ -466,8 +466,8 @@ Map _benchmark( line = line.substring(0, pos); } for (RegExpMatch match in _extractPerfNumbers.allMatches(line)) { - String stringValue = match.group(1)!.trim(); - String caption = match.group(2)!.trim(); + String stringValue = match[1]!.trim(); + String caption = match[2]!.trim(); stringValue = stringValue.replaceAll(",", ""); num value; if (stringValue.contains(".")) { diff --git a/pkg/observatory/bin/observatory.dart b/pkg/observatory/bin/observatory.dart index ae72ee2aab5..b972e1f6d8e 100644 --- a/pkg/observatory/bin/observatory.dart +++ b/pkg/observatory/bin/observatory.dart @@ -92,7 +92,7 @@ ${result.stderr} final uriRegExp = RegExp('Serving `web` on (http://.*)'); final sub = process.stdout.transform(utf8.decoder).listen((e) { if (uriRegExp.hasMatch(e)) { - uriCompleter.complete(uriRegExp.firstMatch(e)!.group(1)); + uriCompleter.complete(uriRegExp.firstMatch(e)![1]); } }); diff --git a/pkg/observatory/lib/src/debugger/debugger_location.dart b/pkg/observatory/lib/src/debugger/debugger_location.dart index 7c7da887a67..57661cf4533 100644 --- a/pkg/observatory/lib/src/debugger/debugger_location.dart +++ b/pkg/observatory/lib/src/debugger/debugger_location.dart @@ -79,16 +79,16 @@ class DebuggerLocation { Match match, { bool package = false, }) async { - var scriptName = match.group(1); + var scriptName = match[1]; if (package) { scriptName = "package:$scriptName"; } if (scriptName != null) { scriptName = scriptName.substring(0, scriptName.length - 1); } - var lineStr = match.group(2); + var lineStr = match[2]; assert(lineStr != null); - var colStr = match.group(3); + var colStr = match[3]; if (colStr != null) { colStr = colStr.substring(1); } @@ -245,8 +245,8 @@ class DebuggerLocation { Match match, ) { Isolate isolate = debugger.isolate; - var base = match.group(1)!; - var qualifier = match.group(2); + var base = match[1]!; + var qualifier = match[2]; return _lookupClass(isolate, base).then((classes) { var functions = []; @@ -269,7 +269,7 @@ class DebuggerLocation { for (var function in cls.functions) { if (function.kind == M.FunctionKind.constructor) { // Constructor names are class-qualified. - if (match.group(0) == function.name) { + if (match[0] == function.name) { functions.add(function); } } else { @@ -281,15 +281,13 @@ class DebuggerLocation { } } if (functions.length == 0) { - return new DebuggerLocation.error( - "Function '${match.group(0)}' not found", - ); + return new DebuggerLocation.error("Function '${match[0]}' not found"); } else if (functions.length == 1) { return new DebuggerLocation.func(functions[0]); } else { // TODO(turnidge): Allow the user to disambiguate. return new DebuggerLocation.error( - "Function '${match.group(0)}' is ambiguous", + "Function '${match[0]}' is ambiguous", ); } }); @@ -327,8 +325,8 @@ class DebuggerLocation { Match match, ) { Isolate isolate = debugger.isolate; - var base = match.group(1) ?? ''; - var qualifier = match.group(2); + var base = match[1] ?? ''; + var qualifier = match[2]; if (qualifier == null) { return _lookupClass(isolate, base, allowPrefix: true).then((classes) { @@ -353,11 +351,11 @@ class DebuggerLocation { for (var cls in classes) { for (var function in cls.functions) { if (function.kind == M.FunctionKind.constructor) { - if (function.name!.startsWith(match.group(0)!)) { + if (function.name!.startsWith(match[0]!)) { completions.add(function.name!); } } else { - if (function.qualifiedName!.startsWith(match.group(0)!)) { + if (function.qualifiedName!.startsWith(match[0]!)) { completions.add(function.qualifiedName!); } } @@ -382,7 +380,7 @@ class DebuggerLocation { var lineStr; var lineStrComplete = false; var colStr; - if (_startsWithDigit(match.group(1)!)) { + if (_startsWithDigit(match[1]!)) { // CASE 1: We have matched a prefix of (lineStr:)(colStr) var frame = await _currentFrame(debugger); if (frame == null) { @@ -390,21 +388,21 @@ class DebuggerLocation { } scriptName = frame.location!.script.name; scriptNameComplete = true; - lineStr = match.group(1) ?? ''; + lineStr = match[1] ?? ''; if (lineStr.endsWith(':')) { lineStr = lineStr.substring(0, lineStr.length - 1); lineStrComplete = true; } - colStr = match.group(2) ?? ''; + colStr = match[2] ?? ''; } else { // CASE 2: We have matched a prefix of (scriptName:)(lineStr)(:colStr) - scriptName = match.group(1) ?? ''; + scriptName = match[1] ?? ''; if (scriptName.endsWith(':')) { scriptName = scriptName.substring(0, scriptName.length - 1); scriptNameComplete = true; } - lineStr = match.group(2) ?? ''; - colStr = match.group(3) ?? ''; + lineStr = match[2] ?? ''; + colStr = match[3] ?? ''; if (colStr.startsWith(':')) { lineStrComplete = true; colStr = colStr.substring(1); diff --git a/pkg/sourcemap_testing/lib/src/stepping_helper.dart b/pkg/sourcemap_testing/lib/src/stepping_helper.dart index 60748037ba1..f78f1ea90e9 100644 --- a/pkg/sourcemap_testing/lib/src/stepping_helper.dart +++ b/pkg/sourcemap_testing/lib/src/stepping_helper.dart @@ -369,8 +369,8 @@ List<_DartStackTraceDataEntry> _extractStackTrace( continue; } Match m = ms.first; - int l = int.parse(m.group(1)!); - int c = int.parse(m.group(2)!); + int l = int.parse(m[1]!); + int c = int.parse(m[2]!); SourceMapSpan? span = _getColumnOrPredecessor(sourceMap, l, c); if (span?.start == null) { result.add( diff --git a/pkg/vm/test/incremental_compiler_test.dart b/pkg/vm/test/incremental_compiler_test.dart index 7a3fb4b631a..0c7c5b45857 100644 --- a/pkg/vm/test/incremental_compiler_test.dart +++ b/pkg/vm/test/incremental_compiler_test.dart @@ -563,7 +563,7 @@ main() { if (s.startsWith(kDartVMServiceListening)) { expect(dartVMServicePortRegExp.hasMatch(s), isTrue); final match = dartVMServicePortRegExp.firstMatch(s)!; - port = int.parse(match.group(1)!); + port = int.parse(match[1]!); await collectAndCheckCoverageData(port, true); if (!portLineCompleter.isCompleted) { portLineCompleter.complete("done"); @@ -673,7 +673,7 @@ main() { if (s.startsWith(kDartVMServiceListening)) { expect(dartVMServicePortRegExp.hasMatch(s), isTrue); final match = dartVMServicePortRegExp.firstMatch(s)!; - port = int.parse(match.group(1)!); + port = int.parse(match[1]!); await collectAndCheckCoverageData( port, true, @@ -958,7 +958,7 @@ main() { if (s.startsWith(kDartVMServiceListening)) { expect(dartVMServicePortRegExp.hasMatch(s), isTrue); final match = dartVMServicePortRegExp.firstMatch(s)!; - port = int.parse(match.group(1)!); + port = int.parse(match[1]!); Set hits1 = await collectAndCheckCoverageData( port, true, @@ -1063,7 +1063,7 @@ main() { ); expect(dartVMServicePortRegExp.hasMatch(portLine), isTrue); final match = dartVMServicePortRegExp.firstMatch(portLine)!; - final port = int.parse(match.group(1)!); + final port = int.parse(match[1]!); var remoteVm = new RemoteVm(port); await remoteVm.resume(); @@ -1491,7 +1491,7 @@ main() { if (s.startsWith(kDartVMServiceListening)) { expect(dartVMServicePortRegExp.hasMatch(s), isTrue); final match = dartVMServicePortRegExp.firstMatch(s)!; - port = int.parse(match.group(1)!); + port = int.parse(match[1]!); RemoteVm remoteVm = new RemoteVm(port); // Wait for the script to have loaded. diff --git a/pkg/vm_service/test/overdue_timer_detection_test.dart b/pkg/vm_service/test/overdue_timer_detection_test.dart index 21d40fc0ae7..e3d716a07ff 100644 --- a/pkg/vm_service/test/overdue_timer_detection_test.dart +++ b/pkg/vm_service/test/overdue_timer_detection_test.dart @@ -41,7 +41,7 @@ final tests = [ r'A timer should have fired (\d+) ms ago, but just fired now.', ); final millisecondsOverdueAsString = - detailsRegex.firstMatch(event.details!)!.group(1)!; + detailsRegex.firstMatch(event.details!)![1]!; expect( int.parse(millisecondsOverdueAsString), greaterThanOrEqualTo(100), diff --git a/pkg/vm_service/tool/common/generate_common.dart b/pkg/vm_service/tool/common/generate_common.dart index ca95e30a934..323b3bc00a9 100644 --- a/pkg/vm_service/tool/common/generate_common.dart +++ b/pkg/vm_service/tool/common/generate_common.dart @@ -25,6 +25,6 @@ mixin ApiParseUtil { if (match == null) throw 'Unable to locate service protocol version'; // Append a `.0`. - return Version.parse('${match.group(0)}.0'); + return Version.parse('${match[0]}.0'); } } diff --git a/runtime/tests/vm/dart/isolates/reload_utils.dart b/runtime/tests/vm/dart/isolates/reload_utils.dart index 8fce85e7912..2847590addb 100644 --- a/runtime/tests/vm/dart/isolates/reload_utils.dart +++ b/runtime/tests/vm/dart/isolates/reload_utils.dart @@ -57,9 +57,9 @@ List generateReloadVersions(String fileContent) { final line = lines[i]; final m = includeIn.firstMatch(line); if (m != null) { - final annotation = int.parse(m.group(1) as String); + final annotation = int.parse(m[1] as String); reloadAnnotation[i] = annotation; - reloadPlusAnnotation[i] = m.group(2) == '+'; + reloadPlusAnnotation[i] = m[2] == '+'; } else { // No annotation means include always. reloadPlusAnnotation[i] = true; diff --git a/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_deferred_test.dart b/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_deferred_test.dart index 298665b9fbb..cd60e900c96 100644 --- a/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_deferred_test.dart +++ b/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_deferred_test.dart @@ -539,11 +539,11 @@ Map> parseUsingAddressRegExp( for (final line in lines) { var match = re.firstMatch(line); if (match != null) { - final address = int.parse(match.group(1)!, radix: 16); + final address = int.parse(match[1]!, radix: 16); var unitId = rootLoadingUnitId; match = _unitRE.firstMatch(line); if (match != null) { - unitId = int.parse(match.group(1)!); + unitId = int.parse(match[1]!); } result[unitId] ??= []; result[unitId]!.add(address); diff --git a/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_helper.dart b/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_helper.dart index 35f5ea1591c..f8159487358 100644 --- a/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_helper.dart +++ b/runtime/tests/vm/dart/use_dwarf_stack_traces_flag_helper.dart @@ -391,7 +391,7 @@ String buildId(Iterable lines) { for (final line in lines) { final match = _buildIdRE.firstMatch(line); if (match != null) { - return match.group(1)!; + return match[1]!; } } return ''; @@ -409,7 +409,7 @@ Iterable removeColumns(Iterable lines) sync* { for (final line in lines) { final match = _columnsRE.firstMatch(line); if (match != null) { - yield line.replaceRange(match.start, match.end, '(${match.group(1)!})'); + yield line.replaceRange(match.start, match.end, '(${match[1]!})'); } else { yield line; } @@ -420,7 +420,7 @@ Iterable parseUsingAddressRegExp(RegExp re, Iterable lines) sync* { for (final line in lines) { final match = re.firstMatch(line); if (match != null) { - yield int.parse(match.group(1)!, radix: 16); + yield int.parse(match[1]!, radix: 16); } } } diff --git a/runtime/tests/vm/dart/use_macho_options_test.dart b/runtime/tests/vm/dart/use_macho_options_test.dart index f9f764dd4ff..a334a769928 100644 --- a/runtime/tests/vm/dart/use_macho_options_test.dart +++ b/runtime/tests/vm/dart/use_macho_options_test.dart @@ -244,13 +244,13 @@ void checkDebugMaps(List testCases) { for (int i = 0; i < expected.length; i++) { final expectedLine = expected[i]; final isSymbol = _symbolLineRegExp.hasMatch(expectedLine); - final expectedTriple = _tripleLineRegExp.firstMatch(expectedLine)?.group(1); + final expectedTriple = _tripleLineRegExp.firstMatch(expectedLine)?[1]; final expectedTimestampMatch = _timestampLineRegExp.firstMatch( expectedLine, ); if (expectedTimestampMatch != null) { - final expectedTimestamp = int.tryParse(expectedTimestampMatch.group(1)!); + final expectedTimestamp = int.tryParse(expectedTimestampMatch[1]!); // The timestamp (value of the N_OSO symbol) in our snapshots is always 0. Expect.equals(0, expectedTimestamp); } @@ -265,7 +265,7 @@ void checkDebugMaps(List testCases) { for (final c in got) { final gotLine = c[i]; if (expectedTriple != null) { - final gotTriple = _tripleLineRegExp.firstMatch(gotLine)?.group(1); + final gotTriple = _tripleLineRegExp.firstMatch(gotLine)?[1]; Expect.equals(expectedTriple, gotTriple); } else if (isSymbol) { Expect.isTrue(_symbolLineRegExp.hasMatch(gotLine)); diff --git a/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart b/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart index 79dbd7567e3..e1ddae63dc4 100644 --- a/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart +++ b/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart @@ -343,9 +343,7 @@ testMacros() async { .transform(LineSplitter())) { Match? match = matchComplete(fieldEntry, line); if (match != null) { - fields - .putIfAbsent(match.group(1)!, () => Set()) - .add(match.group(2)!); + fields.putIfAbsent(match[1]!, () => Set()).add(match[2]!); } } @@ -370,7 +368,7 @@ testMacros() async { .transform(LineSplitter())) { Match? match = matchComplete(classStart, line); if (match != null) { - currentClass = match.group(1); + currentClass = match[1]; continue; } @@ -387,9 +385,9 @@ testMacros() async { print("$currentClass is missing entirely."); continue; } - if (!fields[currentClass]!.contains(match.group(2)!)) { + if (!fields[currentClass]!.contains(match[2]!)) { hasMissingFields = true; - print("$currentClass is missing ${match.group(2)!}."); + print("$currentClass is missing ${match[2]!}."); } } } diff --git a/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart b/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart index cc5e67e71fc..5dd646402d2 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/regexp_helper.dart @@ -156,7 +156,7 @@ class JSSyntaxRegExp implements RegExp { String? stringMatch(String string) { var match = firstMatch(string); - if (match != null) return match.group(0); + if (match != null) return match[0]; return null; } diff --git a/sdk/lib/_internal/js_dev_runtime/private/string_helper.dart b/sdk/lib/_internal/js_dev_runtime/private/string_helper.dart index f8a759a6ac2..bd71baa50e8 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/string_helper.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/string_helper.dart @@ -28,20 +28,22 @@ class StringMatch implements Match { const StringMatch(int this.start, String this.input, String this.pattern); int get end => start + pattern.length; - String operator [](int g) => group(g); - int get groupCount => 0; - String group(int group_) { - if (group_ != 0) { - throw RangeError.value(group_); + String operator [](int group) { + if (group != 0) { + throw RangeError.value(group); } return pattern; } - List groups(List groups_) { + int get groupCount => 0; + + String group(int group) => this[group]; + + List groups(List groupIndices) { List result = []; - for (int g in groups_) { - result.add(group(g)); + for (int g in groupIndices) { + result.add(this[g]); } return result; } diff --git a/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart b/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart index 3ddd0080038..32d0e918e08 100644 --- a/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart +++ b/sdk/lib/_internal/js_runtime/lib/regexp_helper.dart @@ -163,7 +163,7 @@ class JSSyntaxRegExp implements RegExp { String? stringMatch(String string) { var match = firstMatch(string); - if (match != null) return match.group(0); + if (match != null) return match[0]; return null; } @@ -237,16 +237,16 @@ class _MatchImplementation implements RegExpMatch { // The JS below changes the static type to avoid an implicit cast. // TODO(sra): Find a nicer way to do this, e.g. unsafeCast. - String? group(int index) => JS('String|Null', '#', _match[index]); + String? group(int index) => this[index]; - String? operator [](int index) => group(index); + String? operator [](int index) => JS('String|Null', '#', _match[index]); int get groupCount => _match.length - 1; List groups(List groups) { List out = []; for (int i in groups) { - out.add(group(i)); + out.add(this[i]); } return out; } diff --git a/sdk/lib/_internal/js_runtime/lib/string_helper.dart b/sdk/lib/_internal/js_runtime/lib/string_helper.dart index 94e09138725..dd089f231fe 100644 --- a/sdk/lib/_internal/js_runtime/lib/string_helper.dart +++ b/sdk/lib/_internal/js_runtime/lib/string_helper.dart @@ -42,20 +42,21 @@ class StringMatch implements Match { const StringMatch(int this.start, String this.input, String this.pattern); int get end => start + pattern.length; - String operator [](int g) => group(g); - int get groupCount => 0; - - String group(int group_) { - if (group_ != 0) { - throw RangeError.value(group_); + String operator [](int group) { + if (group != 0) { + throw RangeError.value(group); } return pattern; } - List groups(List groups_) { + int get groupCount => 0; + + String group(int group) => this[group]; + + List groups(List groupIndices) { List result = []; - for (int g in groups_) { - result.add(group(g)); + for (int g in groupIndices) { + result.add(this[g]); } return result; } diff --git a/sdk/lib/_internal/vm/lib/regexp_patch.dart b/sdk/lib/_internal/vm/lib/regexp_patch.dart index 728cf80dd95..f0a788b8105 100644 --- a/sdk/lib/_internal/vm/lib/regexp_patch.dart +++ b/sdk/lib/_internal/vm/lib/regexp_patch.dart @@ -94,6 +94,10 @@ class _RegExpMatch implements RegExpMatch { } String? group(int groupIdx) { + return this[groupIdx]; + } + + String? operator [](int groupIdx) { if (groupIdx < 0 || groupIdx > _regexp._groupCount) { throw RangeError.value(groupIdx); } @@ -106,14 +110,10 @@ class _RegExpMatch implements RegExpMatch { return input._substringUnchecked(startIndex, endIndex); } - String? operator [](int groupIdx) { - return this.group(groupIdx); - } - List groups(List groupsSpec) { var groupsList = List.filled(groupsSpec.length, null); for (int i = 0; i < groupsSpec.length; i++) { - groupsList[i] = group(groupsSpec[i]); + groupsList[i] = this[groupsSpec[i]]; } return groupsList; } @@ -131,7 +131,7 @@ class _RegExpMatch implements RegExpMatch { var groupIndex = nameList[i + 1] as int; if (name == groupName) { if (_start(groupIndex) >= 0) { - return group(groupIndex); + return this[groupIndex]; } // Keeping looking for a duplicated name. exists = true; diff --git a/sdk/lib/_internal/vm/lib/string_patch.dart b/sdk/lib/_internal/vm/lib/string_patch.dart index a9d34e7e3e4..358ce5f7b9e 100644 --- a/sdk/lib/_internal/vm/lib/string_patch.dart +++ b/sdk/lib/_internal/vm/lib/string_patch.dart @@ -1406,20 +1406,21 @@ final class _StringMatch implements Match { const _StringMatch(this.start, this.input, this.pattern); int get end => start + pattern.length; - String operator [](int g) => group(g); - int get groupCount => 0; - - String group(int group) { + String operator [](int group) { if (group != 0) { throw RangeError.value(group); } return pattern; } + int get groupCount => 0; + + String group(int group) => this[group]; + List groups(List groups) { List result = []; for (int g in groups) { - result.add(group(g)); + result.add(this[g]); } return result; } diff --git a/sdk/lib/_internal/wasm/lib/regexp_helper.dart b/sdk/lib/_internal/wasm/lib/regexp_helper.dart index b9d4b7a7db5..b247b9c31da 100644 --- a/sdk/lib/_internal/wasm/lib/regexp_helper.dart +++ b/sdk/lib/_internal/wasm/lib/regexp_helper.dart @@ -147,7 +147,7 @@ class JSSyntaxRegExp implements RegExp { String? stringMatch(String string) { var match = firstMatch(string); - if (match != null) return match.group(0); + if (match != null) return match[0]; return null; } @@ -199,20 +199,20 @@ class _MatchImplementation implements RegExpMatch { int get end => (start + (_match[0].toString()).length); - String? group(int index) { + String? group(int index) => this[index]; + + String? operator [](int index) { // index < 0 || index >= _match.length IndexErrorUtils.checkIndex(index, _match.length); return _match[index]?.toString(); } - String? operator [](int index) => group(index); - int get groupCount => _match.length - 1; List groups(List groups) { List out = []; for (int i in groups) { - out.add(group(i)); + out.add(this[i]); } return out; } diff --git a/sdk/lib/_internal/wasm/lib/string_helper.dart b/sdk/lib/_internal/wasm/lib/string_helper.dart index 552ed7ce9ce..d65a1b0b55b 100644 --- a/sdk/lib/_internal/wasm/lib/string_helper.dart +++ b/sdk/lib/_internal/wasm/lib/string_helper.dart @@ -11,18 +11,19 @@ class StringMatch implements Match { const StringMatch(this.start, this.input, this.pattern); int get end => start + pattern.length; - String operator [](int g) => group(g); - int get groupCount => 0; - - String group(int group) { - IndexErrorUtils.checkIndex(group, 1); + String operator [](int g) { + IndexErrorUtils.checkIndex(g, 1); return pattern; } + int get groupCount => 0; + + String group(int group) => this[group]; + List groups(List groups) { List result = []; for (int g in groups) { - result.add(group(g)); + result.add(this[g]); } return result; } diff --git a/sdk/lib/core/pattern.dart b/sdk/lib/core/pattern.dart index 4e61b6d87d3..53cffab399b 100644 --- a/sdk/lib/core/pattern.dart +++ b/sdk/lib/core/pattern.dart @@ -100,11 +100,11 @@ abstract interface class Match { /// final string = '[00:13.37] This is a chat message.'; /// final regExp = RegExp(r'^\[\s*(\d+):(\d+)\.(\d+)\]\s*(.*)$'); /// final match = regExp.firstMatch(string)!; - /// final message = jsonEncode(match[0]!); // '[00:13.37] This is a chat message.' - /// final hours = jsonEncode(match[1]!); // '00' - /// final minutes = jsonEncode(match[2]!); // '13' - /// final seconds = jsonEncode(match[3]!); // '37' - /// final text = jsonEncode(match[4]!); // 'This is a chat message.' + /// final message = jsonEncode(match.group(0)!); // '[00:13.37] This is a chat message.' + /// final hours = jsonEncode(match.group(1)!); // '00' + /// final minutes = jsonEncode(match.group(2)!); // '13' + /// final seconds = jsonEncode(match.group(3)!); // '37' + /// final text = jsonEncode(match.group(4)!); // 'This is a chat message.' /// ``` String? group(int group); diff --git a/sdk/lib/svg/dart2js/svg_dart2js.dart b/sdk/lib/svg/dart2js/svg_dart2js.dart index f76e2e55dcd..32580d4ee2e 100644 --- a/sdk/lib/svg/dart2js/svg_dart2js.dart +++ b/sdk/lib/svg/dart2js/svg_dart2js.dart @@ -2677,7 +2677,7 @@ class SvgElement extends Element implements GlobalEventHandlers, NoncedElement { final match = _START_TAG_REGEXP.firstMatch(svg); Element parentElement; - if (match != null && match.group(1)!.toLowerCase() == 'svg') { + if (match != null && match[1]!.toLowerCase() == 'svg') { parentElement = document.body!; } else { parentElement = new SvgSvgElement(); diff --git a/tests/corelib/reg_exp_all_matches_test.dart b/tests/corelib/reg_exp_all_matches_test.dart index bf59fc85871..21f4ccc4e48 100644 --- a/tests/corelib/reg_exp_all_matches_test.dart +++ b/tests/corelib/reg_exp_all_matches_test.dart @@ -17,9 +17,9 @@ class RegExpAllMatchesTest { Expect.isNull(it.current); } Expect.isTrue(it.moveNext()); - Expect.equals('foo', it.current.group(0)); + Expect.equals('foo', it.current[0]); Expect.isTrue(it.moveNext()); - Expect.equals('foo', it.current.group(0)); + Expect.equals('foo', it.current[0]); Expect.isFalse(it.moveNext()); // Run two iterators over the same results. @@ -27,12 +27,12 @@ class RegExpAllMatchesTest { Iterator it2 = matches.iterator; Expect.isTrue(it.moveNext()); Expect.isTrue(it2.moveNext()); - Expect.equals('foo', it.current.group(0)); - Expect.equals('foo', it2.current.group(0)); + Expect.equals('foo', it.current[0]); + Expect.equals('foo', it2.current[0]); Expect.isTrue(it.moveNext()); Expect.isTrue(it2.moveNext()); - Expect.equals('foo', it.current.group(0)); - Expect.equals('foo', it2.current.group(0)); + Expect.equals('foo', it.current[0]); + Expect.equals('foo', it2.current[0]); Expect.equals(false, it.moveNext()); Expect.equals(false, it2.moveNext()); } @@ -41,14 +41,14 @@ class RegExpAllMatchesTest { var matches = new RegExp("foo").allMatches("foo foo"); var strbuf = new StringBuffer(); matches.forEach((Match m) { - strbuf.write(m.group(0)); + strbuf.write(m[0]); }); Expect.equals("foofoo", strbuf.toString()); } static testMap() { var matches = new RegExp("foo?").allMatches("foo fo foo fo"); - var mapped = matches.map((Match m) => "${m.group(0)}bar"); + var mapped = matches.map((Match m) => "${m[0]}bar"); Expect.equals(4, mapped.length); var strbuf = new StringBuffer(); for (String s in mapped) { @@ -60,12 +60,12 @@ class RegExpAllMatchesTest { static testFilter() { var matches = new RegExp("foo?").allMatches("foo fo foo fo"); var filtered = matches.where((Match m) { - return m.group(0) == 'foo'; + return m[0] == 'foo'; }); Expect.equals(2, filtered.length); var strbuf = new StringBuffer(); for (Match m in filtered) { - strbuf.write(m.group(0)); + strbuf.write(m[0]); } Expect.equals("foofoo", strbuf.toString()); } @@ -75,13 +75,13 @@ class RegExpAllMatchesTest { Expect.equals( true, matches.every((Match m) { - return m.group(0)!.startsWith("fo"); + return m[0]!.startsWith("fo"); }), ); Expect.equals( false, matches.every((Match m) { - return m.group(0)!.startsWith("foo"); + return m[0]!.startsWith("foo"); }), ); } @@ -91,19 +91,19 @@ class RegExpAllMatchesTest { Expect.equals( true, matches.any((Match m) { - return m.group(0)!.startsWith("fo"); + return m[0]!.startsWith("fo"); }), ); Expect.equals( true, matches.any((Match m) { - return m.group(0)!.startsWith("foo"); + return m[0]!.startsWith("foo"); }), ); Expect.equals( false, matches.any((Match m) { - return m.group(0)!.startsWith("fooo"); + return m[0]!.startsWith("fooo"); }), ); } diff --git a/tests/corelib/reg_exp_group_test.dart b/tests/corelib/reg_exp_group_test.dart index 463e7e18b7a..e244639b562 100644 --- a/tests/corelib/reg_exp_group_test.dart +++ b/tests/corelib/reg_exp_group_test.dart @@ -9,9 +9,9 @@ import "package:expect/expect.dart"; class RegExpGroupTest { static testMain() { var match = new RegExp("(a(b)((c|de)+))").firstMatch("abcde")!; - Expect.equals('abcde', match.group(0)); - Expect.equals('abcde', match.group(1)); - Expect.equals('b', match.group(2)); + Expect.equals('abcde', match[0]); + Expect.equals('abcde', match[1]); + Expect.equals('b', match[2]); Expect.equals('cde', match[3]); Expect.equals('de', match[4]); } diff --git a/tests/corelib/reg_exp_groups_test.dart b/tests/corelib/reg_exp_groups_test.dart index 97b15d85329..2a24b361890 100644 --- a/tests/corelib/reg_exp_groups_test.dart +++ b/tests/corelib/reg_exp_groups_test.dart @@ -11,9 +11,13 @@ class RegExpGroupsTest { var match = new RegExp("(a(b)((c|de)+))").firstMatch("abcde")!; var groups = match.groups([0, 4, 2, 3]); Expect.equals('abcde', groups[0]); + Expect.equals('abcde', match.group(0)); Expect.equals('de', groups[1]); + Expect.equals('de', match.group(4)); Expect.equals('b', groups[2]); + Expect.equals('b', match.group(2)); Expect.equals('cde', groups[3]); + Expect.equals('cde', match.group(3)); } } diff --git a/tests/corelib/regexp/ecma-regex-examples_test.dart b/tests/corelib/regexp/ecma-regex-examples_test.dart index 9e045f8385a..a4234443eff 100644 --- a/tests/corelib/regexp/ecma-regex-examples_test.dart +++ b/tests/corelib/regexp/ecma-regex-examples_test.dart @@ -55,7 +55,7 @@ void main() { var regex06 = new RegExp(r"^(a+)\1*,\1+$"); Expect.equals( - "aaaaaaaaaa,aaaaaaaaaaaaaaa".replaceAllMapped(regex06, (m) => m.group(1)!), + "aaaaaaaaaa,aaaaaaaaaaaaaaa".replaceAllMapped(regex06, (m) => m[1]!), "aaaaa", ); diff --git a/tests/corelib/regexp/extended-characters-match_test.dart b/tests/corelib/regexp/extended-characters-match_test.dart index 0c28e8a2245..885a087cab2 100644 --- a/tests/corelib/regexp/extended-characters-match_test.dart +++ b/tests/corelib/regexp/extended-characters-match_test.dart @@ -33,18 +33,15 @@ void main() { shouldBeNull((new RegExp("[\u0100-\u0101]")).firstMatch("a")); shouldBeNull((new RegExp("[\u0100]")).firstMatch("a")); shouldBeNull((new RegExp("\u0100")).firstMatch("a")); - assertEquals((new RegExp("[\u0061]")).firstMatch("a")!.group(0), "a"); - assertEquals((new RegExp("[\u0100-\u0101a]")).firstMatch("a")!.group(0), "a"); - assertEquals((new RegExp("[\u0100a]")).firstMatch("a")!.group(0), "a"); - assertEquals((new RegExp("\u0061")).firstMatch("a")!.group(0), "a"); - assertEquals((new RegExp("[a-\u0100]")).firstMatch("a")!.group(0), "a"); + assertEquals((new RegExp("[\u0061]")).firstMatch("a")![0], "a"); + assertEquals((new RegExp("[\u0100-\u0101a]")).firstMatch("a")![0], "a"); + assertEquals((new RegExp("[\u0100a]")).firstMatch("a")![0], "a"); + assertEquals((new RegExp("\u0061")).firstMatch("a")![0], "a"); + assertEquals((new RegExp("[a-\u0100]")).firstMatch("a")![0], "a"); + assertEquals((new RegExp("[\u0100]")).firstMatch("\u0100")![0], "\u0100"); assertEquals( - (new RegExp("[\u0100]")).firstMatch("\u0100")!.group(0), + (new RegExp("[\u0100-\u0101]")).firstMatch("\u0100")![0], "\u0100", ); - assertEquals( - (new RegExp("[\u0100-\u0101]")).firstMatch("\u0100")!.group(0), - "\u0100", - ); - assertEquals((new RegExp("\u0100")).firstMatch("\u0100")!.group(0), "\u0100"); + assertEquals((new RegExp("\u0100")).firstMatch("\u0100")![0], "\u0100"); } diff --git a/tests/corelib/regexp/global_test.dart b/tests/corelib/regexp/global_test.dart index c855456565b..1d1a6098ab7 100644 --- a/tests/corelib/regexp/global_test.dart +++ b/tests/corelib/regexp/global_test.dart @@ -43,7 +43,7 @@ void main() { str = "It was a pleasure to burn."; str = str.replaceAllMapped( new RegExp(r"(?=(\w+))\b"), - (Match m) => m.group(1)!.length.toString(), + (Match m) => m[1]!.length.toString(), ); assertEquals("2It 3was 1a 8pleasure 2to 4burn.", str); @@ -52,9 +52,9 @@ void main() { str = str.replaceAllMapped( new RegExp(r"(not?)|(do)|(try)", caseSensitive: false), (m) { - if (m.group(1) != null) return "-"; - if (m.group(2) != null) return "+"; - if (m.group(3) != null) return "="; + if (m[1] != null) return "-"; + if (m[2] != null) return "+"; + if (m[3] != null) return "="; throw 'Unexpected match $m'; }, ); @@ -63,9 +63,9 @@ void main() { // Test multiple alternate captures. str = "FOUR LEGS GOOD, TWO LEGS BAD!"; str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) LEGS (GOOD|BAD)"), (m) { - if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD"); - if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD"); - return (m.group(0)!.length - 10).toString(); + if (m[1] == "FOUR") assertTrue(m[2] == "GOOD"); + if (m[1] == "TWO") assertTrue(m[2] == "BAD"); + return (m[0]!.length - 10).toString(); }); assertEquals("4, 2!", str); @@ -84,7 +84,7 @@ void main() { str = "It was a pleasure to \u70e7."; str = str.replaceAllMapped( new RegExp(r"(?=(\w+))\b"), - (m) => "${m.group(1)!.length}", + (m) => "${m[1]!.length}", ); assertEquals("2It 3was 1a 8pleasure 2to \u70e7.", str); @@ -93,9 +93,9 @@ void main() { str = str.replaceAllMapped( new RegExp(r"(not?)|(d\u26aa)|(try)", caseSensitive: false), (m) { - if (m.group(1) != null) return "-"; - if (m.group(2) != null) return "+"; - if (m.group(3) != null) return "="; + if (m[1] != null) return "-"; + if (m[2] != null) return "+"; + if (m[3] != null) return "="; throw 'Unexpected match $m'; }, ); @@ -104,9 +104,9 @@ void main() { // Test multiple alternate captures. str = "FOUR \u817f GOOD, TWO \u817f BAD!"; str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) \u817f (GOOD|BAD)"), (m) { - if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD"); - if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD"); - return (m.group(0)!.length - 7).toString(); + if (m[1] == "FOUR") assertTrue(m[2] == "GOOD"); + if (m[1] == "TWO") assertTrue(m[2] == "BAD"); + return (m[0]!.length - 7).toString(); }); assertEquals("4, 2!", str); @@ -120,7 +120,7 @@ void main() { str = "up up up up"; str = str.replaceAllMapped( new RegExp(r"\b(?=u(p))"), - (m) => "${m.group(1)!.length}", + (m) => "${m[1]!.length}", ); assertEquals("1up 1up 1up 1up", str); diff --git a/tests/corelib/regexp/indexof_test.dart b/tests/corelib/regexp/indexof_test.dart index d49285cee49..af9a02081c4 100644 --- a/tests/corelib/regexp/indexof_test.dart +++ b/tests/corelib/regexp/indexof_test.dart @@ -43,7 +43,7 @@ void main() { var length = matches[idx][1]; var expected = str.substring(from, from + length); var name = "$str[$from..${from + length}]"; - assertEquals(expected, result[idx].group(0), name); + assertEquals(expected, result[idx][0], name); } } else { assertTrue(result.isEmpty); diff --git a/tests/corelib/regexp/lastindex_test.dart b/tests/corelib/regexp/lastindex_test.dart index a50eaba7812..4b24594548c 100644 --- a/tests/corelib/regexp/lastindex_test.dart +++ b/tests/corelib/regexp/lastindex_test.dart @@ -32,13 +32,15 @@ void main() { var re = new RegExp(r"[^\s$]+"); var accumulate = ""; var match; - for (var match in re.allMatches(" abcdefg")) - accumulate += match.group(0)! + "; "; + for (var match in re.allMatches(" abcdefg")) { + accumulate += match[0]! + "; "; + } assertEquals(accumulate, "abcdefg; "); re = new RegExp(r"\d"); accumulate = ""; - for (var match in re.allMatches("123456789")) - accumulate += match.group(0)! + "; "; + for (var match in re.allMatches("123456789")) { + accumulate += match[0]! + "; "; + } assertEquals(accumulate, "1; 2; 3; 4; 5; 6; 7; 8; 9; "); } diff --git a/tests/corelib/regexp/named_captures_test.dart b/tests/corelib/regexp/named_captures_test.dart index 104aa0d5e8f..5771ba3d1d8 100644 --- a/tests/corelib/regexp/named_captures_test.dart +++ b/tests/corelib/regexp/named_captures_test.dart @@ -93,7 +93,7 @@ void main() { assertTrue(m1 != null); assertEquals(m1!.groupCount, m2.groupCount); for (int i = 0; i < m1.groupCount; i++) { - assertEquals(m1.group(i), m2.group(i)); + assertEquals(m1[i], m2[i]); } } } diff --git a/tests/corelib/regexp/no-extensions_test.dart b/tests/corelib/regexp/no-extensions_test.dart index f1a357734a3..6c0369f7789 100644 --- a/tests/corelib/regexp/no-extensions_test.dart +++ b/tests/corelib/regexp/no-extensions_test.dart @@ -33,70 +33,64 @@ void main() { ); shouldBeNull(new RegExp(r"\\x{41}").firstMatch("yA1")); - assertEquals(new RegExp(r"[\x{41}]").firstMatch("yA1")!.group(0), "1"); - assertEquals(new RegExp(r"\x1g").firstMatch("x1g")!.group(0), "x1g"); - assertEquals(new RegExp(r"[\x1g]").firstMatch("x")!.group(0), "x"); - assertEquals(new RegExp(r"[\x1g]").firstMatch("1")!.group(0), "1"); + assertEquals(new RegExp(r"[\x{41}]").firstMatch("yA1")![0], "1"); + assertEquals(new RegExp(r"\x1g").firstMatch("x1g")![0], "x1g"); + assertEquals(new RegExp(r"[\x1g]").firstMatch("x")![0], "x"); + assertEquals(new RegExp(r"[\x1g]").firstMatch("1")![0], "1"); assertEquals( new RegExp( r"\2147483648", - ).firstMatch(new String.fromCharCode(140) + "7483648")!.group(0), + ).firstMatch(new String.fromCharCode(140) + "7483648")![0], new String.fromCharCode(140) + "7483648", ); assertEquals( - new RegExp(r"\4294967296").firstMatch("\"94967296")!.group(0), + new RegExp(r"\4294967296").firstMatch("\"94967296")![0], "\"94967296", ); assertEquals( - new RegExp(r"\8589934592").firstMatch("\8589934592")!.group(0), + new RegExp(r"\8589934592").firstMatch("\8589934592")![0], "\8589934592", ); assertEquals( - "\nAbc\n".replaceAllMapped(new RegExp(r"(\n)[^\n]+$"), (m) => m.group(1)!), + "\nAbc\n".replaceAllMapped(new RegExp(r"(\n)[^\n]+$"), (m) => m[1]!), "\nAbc\n", ); shouldBeNull(new RegExp(r"x$").firstMatch("x\n")); assertThrows(() => new RegExp(r"x++")); shouldBeNull(new RegExp(r"[]]").firstMatch("]")); - assertEquals(new RegExp(r"\060").firstMatch("y01")!.group(0), "0"); - assertEquals(new RegExp(r"[\060]").firstMatch("y01")!.group(0), "0"); - assertEquals(new RegExp(r"\606").firstMatch("y06")!.group(0), "06"); - assertEquals(new RegExp(r"[\606]").firstMatch("y06")!.group(0), "0"); - assertEquals(new RegExp(r"[\606]").firstMatch("y6")!.group(0), "6"); - assertEquals(new RegExp(r"\101").firstMatch("yA1")!.group(0), "A"); - assertEquals(new RegExp(r"[\101]").firstMatch("yA1")!.group(0), "A"); - assertEquals(new RegExp(r"\1011").firstMatch("yA1")!.group(0), "A1"); - assertEquals(new RegExp(r"[\1011]").firstMatch("yA1")!.group(0), "A"); - assertEquals(new RegExp(r"[\1011]").firstMatch("y1")!.group(0), "1"); + assertEquals(new RegExp(r"\060").firstMatch("y01")![0], "0"); + assertEquals(new RegExp(r"[\060]").firstMatch("y01")![0], "0"); + assertEquals(new RegExp(r"\606").firstMatch("y06")![0], "06"); + assertEquals(new RegExp(r"[\606]").firstMatch("y06")![0], "0"); + assertEquals(new RegExp(r"[\606]").firstMatch("y6")![0], "6"); + assertEquals(new RegExp(r"\101").firstMatch("yA1")![0], "A"); + assertEquals(new RegExp(r"[\101]").firstMatch("yA1")![0], "A"); + assertEquals(new RegExp(r"\1011").firstMatch("yA1")![0], "A1"); + assertEquals(new RegExp(r"[\1011]").firstMatch("yA1")![0], "A"); + assertEquals(new RegExp(r"[\1011]").firstMatch("y1")![0], "1"); assertEquals( - new RegExp( - r"\10q", - ).firstMatch("y" + new String.fromCharCode(8) + "q")!.group(0), + new RegExp(r"\10q").firstMatch("y" + new String.fromCharCode(8) + "q")![0], new String.fromCharCode(8) + "q", ); assertEquals( new RegExp( r"[\10q]", - ).firstMatch("y" + new String.fromCharCode(8) + "q")!.group(0), + ).firstMatch("y" + new String.fromCharCode(8) + "q")![0], new String.fromCharCode(8), ); assertEquals( - new RegExp( - r"\1q", - ).firstMatch("y" + new String.fromCharCode(1) + "q")!.group(0), + new RegExp(r"\1q").firstMatch("y" + new String.fromCharCode(1) + "q")![0], new String.fromCharCode(1) + "q", ); assertEquals( - new RegExp( - r"[\1q]", - ).firstMatch("y" + new String.fromCharCode(1) + "q")!.group(0), + new RegExp(r"[\1q]").firstMatch("y" + new String.fromCharCode(1) + "q")![0], new String.fromCharCode(1), ); - assertEquals(new RegExp(r"[\1q]").firstMatch("yq")!.group(0), "q"); - assertEquals(new RegExp(r"\8q").firstMatch("\8q")!.group(0), "\8q"); - assertEquals(new RegExp(r"[\8q]").firstMatch("y8q")!.group(0), "8"); - assertEquals(new RegExp(r"[\8q]").firstMatch("yq")!.group(0), "q"); + assertEquals(new RegExp(r"[\1q]").firstMatch("yq")![0], "q"); + assertEquals(new RegExp(r"\8q").firstMatch("\8q")![0], "\8q"); + assertEquals(new RegExp(r"[\8q]").firstMatch("y8q")![0], "8"); + assertEquals(new RegExp(r"[\8q]").firstMatch("yq")![0], "q"); shouldBe(new RegExp(r"(x)\1q").firstMatch("xxq"), ["xxq", "x"]); shouldBe(new RegExp(r"(x)[\1q]").firstMatch("xxq"), ["xq", "x"]); shouldBe( diff --git a/tests/corelib/regexp/non-bmp_test.dart b/tests/corelib/regexp/non-bmp_test.dart index 2fb9d701e27..70ae39bacf8 100644 --- a/tests/corelib/regexp/non-bmp_test.dart +++ b/tests/corelib/regexp/non-bmp_test.dart @@ -36,28 +36,16 @@ void main() { var surrogatePair = new String.fromCharCode(0xD800) + new String.fromCharCode(0xDC00); - assertEquals(new RegExp(r".").firstMatch(surrogatePair)!.group(0)!.length, 1); - assertEquals( - new RegExp(r"\D").firstMatch(surrogatePair)!.group(0)!.length, - 1, - ); - assertEquals( - new RegExp(r"\S").firstMatch(surrogatePair)!.group(0)!.length, - 1, - ); - assertEquals( - new RegExp(r"\W").firstMatch(surrogatePair)!.group(0)!.length, - 1, - ); - assertEquals( - new RegExp(r"[^x]").firstMatch(surrogatePair)!.group(0)!.length, - 1, - ); + assertEquals(new RegExp(r".").firstMatch(surrogatePair)![0]!.length, 1); + assertEquals(new RegExp(r"\D").firstMatch(surrogatePair)![0]!.length, 1); + assertEquals(new RegExp(r"\S").firstMatch(surrogatePair)![0]!.length, 1); + assertEquals(new RegExp(r"\W").firstMatch(surrogatePair)![0]!.length, 1); + assertEquals(new RegExp(r"[^x]").firstMatch(surrogatePair)![0]!.length, 1); assertEquals( new RegExp( r".{1,2}", - ).firstMatch("!!" + new String.fromCharCode(0xA1))!.group(0)!.length, + ).firstMatch("!!" + new String.fromCharCode(0xA1))![0]!.length, 2, ); shouldBeNull(new RegExp(r".").firstMatch("")); diff --git a/tests/corelib/regexp/non-capturing-groups_test.dart b/tests/corelib/regexp/non-capturing-groups_test.dart index b54b359f58f..24989a28c3d 100644 --- a/tests/corelib/regexp/non-capturing-groups_test.dart +++ b/tests/corelib/regexp/non-capturing-groups_test.dart @@ -42,15 +42,15 @@ void main() { assertEquals("y".indexOf(new RegExp(r"(x)?\1y")), 0); assertEquals("y".replaceAll(new RegExp(r"(x)?\1y"), "z"), "z"); assertEquals( - "y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m.group(1) ?? "null"), + "y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m[1] ?? "null"), "null", ); assertEquals( - "y".replaceAllMapped(new RegExp(r"(x)?\1y"), (m) => m.group(1) ?? "null"), + "y".replaceAllMapped(new RegExp(r"(x)?\1y"), (m) => m[1] ?? "null"), "null", ); assertEquals( - "y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m.group(1) ?? "null"), + "y".replaceAllMapped(new RegExp(r"(x)?y"), (m) => m[1] ?? "null"), "null", ); } diff --git a/tests/corelib/regexp/parentheses_test.dart b/tests/corelib/regexp/parentheses_test.dart index a1998faca96..92188451a86 100644 --- a/tests/corelib/regexp/parentheses_test.dart +++ b/tests/corelib/regexp/parentheses_test.dart @@ -394,7 +394,7 @@ void main() { Expect.listEquals( regexp59 .allMatches('Y aaa X Match1 Y aaa Y Match2 Z') - .map((m) => m.group(0)) + .map((m) => m[0]) .toList(), ['X Match1 Y', 'Y Match2 Z'], ); diff --git a/tests/corelib/regexp/pcre-test-4_test.dart b/tests/corelib/regexp/pcre-test-4_test.dart index 287cdb7d079..67ed1a00ba9 100644 --- a/tests/corelib/regexp/pcre-test-4_test.dart +++ b/tests/corelib/regexp/pcre-test-4_test.dart @@ -850,7 +850,7 @@ void main() { input1 = "\u0100aY\u0256Z"; results = ["\u0100", "Y\u0256Z"]; Expect.listEquals( - regexGlobal0.allMatches(input1).map((m) => m.group(0)).toList(), + regexGlobal0.allMatches(input1).map((m) => m[0]).toList(), results, ); diff --git a/tests/corelib/regexp/standalones_test.dart b/tests/corelib/regexp/standalones_test.dart index fe2b4bdf2ec..ceefe3b9c5b 100644 --- a/tests/corelib/regexp/standalones_test.dart +++ b/tests/corelib/regexp/standalones_test.dart @@ -40,45 +40,45 @@ void main() { var pattern = new RegExp(r"^\d", multiLine: true); var resultList = pattern.allMatches(string).toList(); assertEquals(2, resultList.length, "1"); - assertEquals('7', resultList[0].group(0), "2"); - assertEquals('3', resultList[1].group(0), "3"); + assertEquals('7', resultList[0][0], "2"); + assertEquals('3', resultList[1][0], "3"); pattern = new RegExp(r"\d$", multiLine: true); resultList = pattern.allMatches(string).toList(); assertEquals(2, resultList.length, "4"); - assertEquals('9', resultList[0].group(0), "5"); - assertEquals('5', resultList[1].group(0), "6"); + assertEquals('9', resultList[0][0], "5"); + assertEquals('5', resultList[1][0], "6"); string = 'aaa\n789\r\nccc\r\nddd'; pattern = new RegExp(r"^\d", multiLine: true); resultList = pattern.allMatches(string).toList(); assertEquals(1, resultList.length, "7"); - assertEquals('7', resultList[0].group(0), "8"); + assertEquals('7', resultList[0][0], "8"); pattern = new RegExp(r"\d$", multiLine: true); resultList = pattern.allMatches(string).toList(); assertEquals(1, resultList.length, "9"); - assertEquals('9', resultList[0].group(0), "10"); + assertEquals('9', resultList[0][0], "10"); // Tests from ecma_3/RegExp/regress-72964.js pattern = new RegExp(r"[\S]+"); string = '\u00BF\u00CD\u00BB\u00A7'; var resultMatch = pattern.firstMatch(string)!; assertEquals(1, resultMatch.groupCount + 1, "11"); - assertEquals(string, resultMatch.group(0), "12"); + assertEquals(string, resultMatch[0], "12"); string = '\u00BF\u00CD \u00BB\u00A7'; resultMatch = pattern.firstMatch(string)!; assertEquals(1, resultMatch.groupCount + 1, "13"); - assertEquals('\u00BF\u00CD', resultMatch.group(0), "14"); + assertEquals('\u00BF\u00CD', resultMatch[0], "14"); string = '\u4e00\uac00\u4e03\u4e00'; resultMatch = pattern.firstMatch(string)!; assertEquals(1, resultMatch.groupCount + 1, "15"); - assertEquals(string, resultMatch.group(0), "16"); + assertEquals(string, resultMatch[0], "16"); string = '\u4e00\uac00 \u4e03\u4e00'; resultMatch = pattern.firstMatch(string)!; assertEquals(1, resultMatch.groupCount + 1, "17"); - assertEquals('\u4e00\uac00', resultMatch.group(0), "18"); + assertEquals('\u4e00\uac00', resultMatch[0], "18"); } diff --git a/tests/corelib/regexp/unicode-handling_test.dart b/tests/corelib/regexp/unicode-handling_test.dart index de764dc59cc..5dc1353e825 100644 --- a/tests/corelib/regexp/unicode-handling_test.dart +++ b/tests/corelib/regexp/unicode-handling_test.dart @@ -53,7 +53,7 @@ void main() { var b = I3.firstMatch(a); if (b != null) { - a = b.group(2); + a = b[2]; } return Gn(a); @@ -66,12 +66,12 @@ void main() { var sample = "sample bm\u2820p cm\\u2820p"; var inlineRe = new RegExp(r".m\u2820p"); - assertEquals(inlineRe.firstMatch(sample)!.group(0), 'bm\u2820p'); + assertEquals(inlineRe.firstMatch(sample)![0], 'bm\u2820p'); // Test handling of \u007c "|" var bsample = "sample bm\u007cp cm\\u007cp"; var binlineRe = new RegExp(r".m\u007cp"); - assertEquals(binlineRe.firstMatch(bsample)!.group(0), 'bm|p'); + assertEquals(binlineRe.firstMatch(bsample)![0], 'bm|p'); } diff --git a/tests/corelib/regexp/v8_regexp_utils.dart b/tests/corelib/regexp/v8_regexp_utils.dart index 3b7afff726b..7fa4f03655c 100644 --- a/tests/corelib/regexp/v8_regexp_utils.dart +++ b/tests/corelib/regexp/v8_regexp_utils.dart @@ -33,7 +33,7 @@ void assertNull(actual, [num? testid = null]) { void assertToStringEquals(str, match, num? testid) { var actual = []; for (int i = 0; i <= match.groupCount; i++) { - var g = match.group(i); + var g = match[i]; actual.add((g == null) ? "" : g); } Expect.equals(str, actual.join(","), "Test $testid"); @@ -57,13 +57,13 @@ void shouldBe(actual, expected, [String message = '']) { } else { Expect.equals(expected.length, actual.groupCount + 1); for (int i = 0; i <= actual.groupCount; i++) { - Expect.equals(expected[i], actual.group(i), message); + Expect.equals(expected[i], actual[i], message); } } } Match? firstMatch(String str, RegExp pattern) => pattern.firstMatch(str); List allStringMatches(String str, RegExp pattern) => - pattern.allMatches(str).map((Match m) => m.group(0)).toList(); + pattern.allMatches(str).map((Match m) => m[0]).toList(); void description(str) {} diff --git a/tests/language/reg_exp/reg_exp4_test.dart b/tests/language/reg_exp/reg_exp4_test.dart index 208f1bd71c5..cda4f471bc0 100644 --- a/tests/language/reg_exp/reg_exp4_test.dart +++ b/tests/language/reg_exp/reg_exp4_test.dart @@ -12,8 +12,8 @@ class RegEx2Test { print("got match"); int groupCount = match.groupCount; print("groupCount is $groupCount"); - print("group 0 is ${match.group(0)}"); - print("group 1 is ${match.group(1)}"); + print("group 0 is ${match[0]}"); + print("group 1 is ${match[1]}"); } else { print("match not round"); } diff --git a/tests/language/reg_exp/reg_exp_test.dart b/tests/language/reg_exp/reg_exp_test.dart index 1419cb7b192..90e76689588 100644 --- a/tests/language/reg_exp/reg_exp_test.dart +++ b/tests/language/reg_exp/reg_exp_test.dart @@ -10,9 +10,9 @@ void main() { String str = "Parse my string"; List matches = exp.allMatches(str).toList(); Expect.equals(3, matches.length); - Expect.equals("Parse", matches[0].group(0)); - Expect.equals("my", matches[1].group(0)); - Expect.equals("string", matches[2].group(0)); + Expect.equals("Parse", matches[0][0]); + Expect.equals("my", matches[1][0]); + Expect.equals("string", matches[2][0]); // Check that allMatches progresses correctly for empty matches, and that // it includes the empty match at the end position. diff --git a/tests/standalone/dwarf_stack_trace_test.dart b/tests/standalone/dwarf_stack_trace_test.dart index 9aa834d2859..2fff03c55b7 100644 --- a/tests/standalone/dwarf_stack_trace_test.dart +++ b/tests/standalone/dwarf_stack_trace_test.dart @@ -284,7 +284,7 @@ Iterable parseUsingAddressRegExp(RegExp re, Iterable lines) sync* { for (final line in lines) { final match = re.firstMatch(line); if (match == null) continue; - final s = match.group(1); + final s = match[1]; if (s == null) continue; yield int.parse(s, radix: 16); } diff --git a/tests/standalone/io/platform_test.dart b/tests/standalone/io/platform_test.dart index 08904d15c04..1eba6431cce 100644 --- a/tests/standalone/io/platform_test.dart +++ b/tests/standalone/io/platform_test.dart @@ -105,19 +105,19 @@ testVersion() { if (match == null) { throw new FormatException(); } - var major = int.parse(match.group(1)!); + var major = int.parse(match[1]!); // Major version. Expect.isTrue(major == 1 || major == 2 || major == 3); // Minor version. - Expect.isTrue(int.parse(match.group(2)!) >= 0); + Expect.isTrue(int.parse(match[2]!) >= 0); // Patch version. - Expect.isTrue(int.parse(match.group(3)!) >= 0); + Expect.isTrue(int.parse(match[3]!) >= 0); // Dev - if (match.group(4) != null) { + if (match[4] != null) { // Dev prerelease minor version - Expect.isTrue(int.parse(match.group(5)!) >= 0); + Expect.isTrue(int.parse(match[5]!) >= 0); // Dev prerelease patch version - Expect.isTrue(int.parse(match.group(6)!) >= 0); + Expect.isTrue(int.parse(match[6]!) >= 0); } } diff --git a/tests/web/native/error_safeToString_test.dart b/tests/web/native/error_safeToString_test.dart index e0299541933..06d06ed6f38 100644 --- a/tests/web/native/error_safeToString_test.dart +++ b/tests/web/native/error_safeToString_test.dart @@ -81,7 +81,7 @@ void setup() { expectTypeName(expectedName, s) { var m = new RegExp(r"Instance of '(.*)'").firstMatch(s); Expect.isNotNull(m); - var name = m!.group(1); + var name = m![1]; Expect.isTrue( expectedName == name || name!.length <= 3 || name!.startsWith('minified:'), "Is '$expectedName' or minified: '$name'", diff --git a/tests/web/wasm/source_map_simple_lib.dart b/tests/web/wasm/source_map_simple_lib.dart index 56dcac2f8cb..ba5ee1aab39 100644 --- a/tests/web/wasm/source_map_simple_lib.dart +++ b/tests/web/wasm/source_map_simple_lib.dart @@ -127,7 +127,7 @@ List<(String?, int?, int?, String?)?> parseStack( if (hexOffsetMatch == null) { throw 'Unable to parse hex offset in frame "$line"'; } - final hexOffsetStr = hexOffsetMatch.group(1)!; // includes '0x' + final hexOffsetStr = hexOffsetMatch[1]!; // includes '0x' final offset = int.tryParse(hexOffsetStr); if (offset == null) { throw 'Unable to parse hex number in frame "$line"'; @@ -136,7 +136,7 @@ List<(String?, int?, int?, String?)?> parseStack( if (moduleIdMatch == null) { throw 'Unable to parse module name in frame "$line"'; } - final moduleIdString = moduleIdMatch.group(1)!; + final moduleIdString = moduleIdMatch[1]!; final moduleId = isMinified ? parseMinifiedModule(moduleIdString) : int.parse(moduleIdString.replaceAll('module', '')); diff --git a/tests/web/wasm/source_map_unminification_test.dart b/tests/web/wasm/source_map_unminification_test.dart index 8370285f46b..b5619026f53 100644 --- a/tests/web/wasm/source_map_unminification_test.dart +++ b/tests/web/wasm/source_map_unminification_test.dart @@ -53,5 +53,5 @@ final RegExp classRegexp = RegExp(r'minified:(Class\d+)'); String unminify(String input, Dart2jsMapping mapping) => input.replaceAllMapped( classRegexp, - (match) => mapping.globalNames[match.group(1)!]!, + (match) => mapping.globalNames[match[1]!]!, ); diff --git a/third_party/pkg/dap/tool/codegen.dart b/third_party/pkg/dap/tool/codegen.dart index 816a61f6f2b..96b4628119b 100644 --- a/third_party/pkg/dap/tool/codegen.dart +++ b/third_party/pkg/dap/tool/codegen.dart @@ -38,8 +38,7 @@ class CodeGenerator { name .replaceAll(RegExp(r'^_+'), '') // Also replace any other underscores to make camelCase - .replaceAllMapped( - RegExp(r'_(.)'), (m) => m.group(1)!.toUpperCase()); + .replaceAllMapped(RegExp(r'_(.)'), (m) => m[1]!.toUpperCase()); } /// Re-wraps [lines] at [maxLength] to help keep comments for indented code diff --git a/tools/package_deps/bin/package_deps.dart b/tools/package_deps/bin/package_deps.dart index 61860cd1b99..f0ea51a2ca2 100644 --- a/tools/package_deps/bin/package_deps.dart +++ b/tools/package_deps/bin/package_deps.dart @@ -388,13 +388,13 @@ class Package implements Comparable { var match = importRegex1.firstMatch(line); if (match != null) { - results.add(match.group(2)!); + results.add(match[2]!); continue; } match = importRegex2.firstMatch(line); if (match != null) { - results.add(match.group(2)!); + results.add(match[2]!); continue; } } @@ -444,7 +444,7 @@ class SdkDeps { var pkgDep = pkgRegExp.firstMatch(line); if (pkgDep != null) { - pkgs.add(pkgDep.group(1)!); + pkgs.add(pkgDep[1]!); } } diff --git a/tools/rev_sdk_deps.dart b/tools/rev_sdk_deps.dart index fa0790c7922..5f288d03e60 100644 --- a/tools/rev_sdk_deps.dart +++ b/tools/rev_sdk_deps.dart @@ -157,7 +157,7 @@ Set calculatePinnedDeps() { return depsFile .readAsLinesSync() .where((line) => packageRevision.hasMatch(line) && line.contains('", #')) - .map((line) => packageRevision.firstMatch(line)!.group(1)!) + .map((line) => packageRevision.firstMatch(line)![1]!) .toSet(); }