From 3154bb0d378b55cfd123f0ccabb350fe20a58435 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 15 Jan 2019 18:55:10 +0000 Subject: [PATCH] Stop using external deprecated members in front_end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3fa03de568f72bfc3adb46efcfa2b61b781c706b Reviewed-on: https://dart-review.googlesource.com/c/89020 Commit-Queue: Samuel Rawlins Reviewed-by: Sigmund Cherem Reviewed-by: Peter von der Ahé --- pkg/compiler/lib/src/dart2js.dart | 2 +- pkg/front_end/analysis_options.yaml | 3 --- .../src/api_prototype/terminal_color_support.dart | 2 +- pkg/front_end/lib/src/fasta/colors.dart | 2 +- pkg/front_end/lib/src/fasta/crash.dart | 2 +- pkg/front_end/test/fasta/parser/type_info_test.dart | 12 ++++++------ .../type_inference/interface_resolver_test.dart | 4 ++-- pkg/front_end/test/memory_file_system_test.dart | 6 +++--- pkg/front_end/test/scanner_replacement_test.dart | 2 +- pkg/front_end/test/scanner_test.dart | 2 +- pkg/front_end/test/standard_file_system_test.dart | 6 +++--- pkg/front_end/test/token_test.dart | 8 ++++---- pkg/front_end/tool/_fasta/command_line.dart | 5 +++-- pkg/front_end/tool/_fasta/log_collector.dart | 12 ++++++------ .../tool/_fasta/resolve_input_uri_test.dart | 5 +++-- pkg/front_end/tool/perf.dart | 2 +- tests/compiler/dart2js/helpers/memory_compiler.dart | 4 +--- tools/patch_sdk.dart | 6 +++++- 18 files changed, 43 insertions(+), 42 deletions(-) diff --git a/pkg/compiler/lib/src/dart2js.dart b/pkg/compiler/lib/src/dart2js.dart index dbfe8902933..50b8aeb3e15 100644 --- a/pkg/compiler/lib/src/dart2js.dart +++ b/pkg/compiler/lib/src/dart2js.dart @@ -658,7 +658,7 @@ void writeString(Uri uri, String text) { if (uri.scheme != 'file') { fail('Unhandled scheme ${uri.scheme}.'); } - var file = new File(uri.toFilePath()).openSync(mode: FileMode.WRITE); + var file = new File(uri.toFilePath()).openSync(mode: FileMode.write); file.writeStringSync(text); file.closeSync(); } diff --git a/pkg/front_end/analysis_options.yaml b/pkg/front_end/analysis_options.yaml index ae13d06bc8d..0fb6ccc365c 100644 --- a/pkg/front_end/analysis_options.yaml +++ b/pkg/front_end/analysis_options.yaml @@ -9,8 +9,5 @@ analyzer: # Allow having TODOs in the code todo: ignore - # Allow cross-package deprecated calls - # TODO(srawlins): clean these up and remove this "ignore." - deprecated_member_use: ignore # Allow deprecated calls from within the same package deprecated_member_use_from_same_package: ignore diff --git a/pkg/front_end/lib/src/api_prototype/terminal_color_support.dart b/pkg/front_end/lib/src/api_prototype/terminal_color_support.dart index 4d866f35f5c..e0e3ebc2a7f 100644 --- a/pkg/front_end/lib/src/api_prototype/terminal_color_support.dart +++ b/pkg/front_end/lib/src/api_prototype/terminal_color_support.dart @@ -87,7 +87,7 @@ bool _computeEnableColors() { } String numberOfColors = lines[0]; - if (int.parse(numberOfColors, onError: (_) => -1) < 8) { + if (int.tryParse(numberOfColors) ?? -1 < 8) { if (debug) { print("Not enabling colors, less than 8 colors supported: " "${jsonEncode(numberOfColors)}."); diff --git a/pkg/front_end/lib/src/fasta/colors.dart b/pkg/front_end/lib/src/fasta/colors.dart index 65b2e79e3ac..edde5bbee46 100644 --- a/pkg/front_end/lib/src/fasta/colors.dart +++ b/pkg/front_end/lib/src/fasta/colors.dart @@ -174,7 +174,7 @@ bool computeEnableColors(CompilerContext context) { } String numberOfColors = lines[0]; - if (int.parse(numberOfColors, onError: (_) => -1) < 8) { + if (int.tryParse(numberOfColors) ?? -1 < 8) { if (context.options.verbose) { print("Not enabling colors, less than 8 colors supported: " "${jsonEncode(numberOfColors)}."); diff --git a/pkg/front_end/lib/src/fasta/crash.dart b/pkg/front_end/lib/src/fasta/crash.dart index f4745d55b38..8498da95ca5 100644 --- a/pkg/front_end/lib/src/fasta/crash.dart +++ b/pkg/front_end/lib/src/fasta/crash.dart @@ -93,7 +93,7 @@ Future reportCrash(error, StackTrace trace, int port = request?.connectionInfo?.remotePort; await note(" to $host:$port"); await request - ..headers.contentType = ContentType.JSON + ..headers.contentType = ContentType.json ..write(json); await request.close(); await note("."); diff --git a/pkg/front_end/test/fasta/parser/type_info_test.dart b/pkg/front_end/test/fasta/parser/type_info_test.dart index 2f13cfe3dce..eced64d8983 100644 --- a/pkg/front_end/test/fasta/parser/type_info_test.dart +++ b/pkg/front_end/test/fasta/parser/type_info_test.dart @@ -140,7 +140,7 @@ class NoTypeInfoTest { final TypeInfoListener listener = new TypeInfoListener(); expect(noType.ensureTypeNotVoid(start, new Parser(listener)), - new isInstanceOf()); + const TypeMatcher()); expect(listener.calls, [ 'handleIdentifier typeReference', 'handleNoTypeArguments ;', @@ -154,7 +154,7 @@ class NoTypeInfoTest { final TypeInfoListener listener = new TypeInfoListener(); expect(noType.ensureTypeOrVoid(start, new Parser(listener)), - new isInstanceOf()); + const TypeMatcher()); expect(listener.calls, [ 'handleIdentifier typeReference', 'handleNoTypeArguments ;', @@ -2478,7 +2478,7 @@ void expectNestedInfo(expectedInfo, String source) { } void expectNestedComplexInfo(String source) { - expectNestedInfo(const isInstanceOf(), source); + expectNestedInfo(const TypeMatcher(), source); } TypeInfo compute(expectedInfo, String source, Token start, bool required, @@ -2502,7 +2502,7 @@ ComplexTypeInfo computeComplex( List expectedErrors) { int expectedGtGtAndNullEndCount = countGtGtAndNullEnd(start); ComplexTypeInfo typeInfo = compute( - const isInstanceOf(), source, start, required, + const TypeMatcher(), source, start, required, inDeclaration: inDeclaration); expect(typeInfo.start, start.next, reason: source); expect(typeInfo.couldBeExpression, couldBeExpression); @@ -2530,7 +2530,7 @@ void expectComplexTypeArg(String source, Token start = scan(source); int expectedGtGtAndNullEndCount = countGtGtAndNullEnd(start); ComplexTypeParamOrArgInfo typeVarInfo = computeVar( - const isInstanceOf(), + const TypeMatcher(), source, start, inDeclaration); @@ -2564,7 +2564,7 @@ void expectComplexTypeParam(String source, Token start = scan(source); int expectedGtGtAndNullEndCount = countGtGtAndNullEnd(start); ComplexTypeParamOrArgInfo typeVarInfo = computeVar( - const isInstanceOf(), + const TypeMatcher(), source, start, inDeclaration); diff --git a/pkg/front_end/test/fasta/type_inference/interface_resolver_test.dart b/pkg/front_end/test/fasta/type_inference/interface_resolver_test.dart index d34cb0103db..0b6ee37ed84 100644 --- a/pkg/front_end/test/fasta/type_inference/interface_resolver_test.dart +++ b/pkg/front_end/test/fasta/type_inference/interface_resolver_test.dart @@ -220,7 +220,7 @@ class InterfaceResolverTest { var field = makeField(); var class_ = makeClass(fields: [field]); var candidate = getCandidate(class_, false); - expect(candidate, new isInstanceOf()); + expect(candidate, const TypeMatcher()); expect(candidate.parent, same(class_)); expect(candidate.name, field.name); expect(candidate.kind, ProcedureKind.Getter); @@ -233,7 +233,7 @@ class InterfaceResolverTest { var field = makeField(); var class_ = makeClass(fields: [field]); var candidate = getCandidate(class_, true); - expect(candidate, new isInstanceOf()); + expect(candidate, const TypeMatcher()); expect(candidate.parent, same(class_)); expect(candidate.name, field.name); expect(candidate.kind, ProcedureKind.Setter); diff --git a/pkg/front_end/test/memory_file_system_test.dart b/pkg/front_end/test/memory_file_system_test.dart index 366d2a1cba0..c62dbc337ae 100644 --- a/pkg/front_end/test/memory_file_system_test.dart +++ b/pkg/front_end/test/memory_file_system_test.dart @@ -25,8 +25,8 @@ main() { }); } -const Matcher _throwsFileSystemException = - const Throws(const isInstanceOf()); +final Matcher _throwsFileSystemException = + throwsA(const TypeMatcher()); @reflectiveTest class FileTest extends _BaseTestNative { @@ -233,7 +233,7 @@ abstract class MemoryFileSystemTestMixin implements _BaseTest { ]) { if (!uri.path.startsWith('/')) { expect(() => fileSystem.entityForUri(uri), - throwsA(new isInstanceOf())); + throwsA(const TypeMatcher())); } } } diff --git a/pkg/front_end/test/scanner_replacement_test.dart b/pkg/front_end/test/scanner_replacement_test.dart index a9f0b70b900..aa227f1bde9 100644 --- a/pkg/front_end/test/scanner_replacement_test.dart +++ b/pkg/front_end/test/scanner_replacement_test.dart @@ -242,7 +242,7 @@ class ScannerTest_Replacement extends ScannerTestBase { token = token.next; } } - var isNotErrorToken = isNot(new isInstanceOf()); + var isNotErrorToken = isNot(const TypeMatcher()); while (!token.isEof) { if (errorsFirst) expect(token, isNotErrorToken); previous = token; diff --git a/pkg/front_end/test/scanner_test.dart b/pkg/front_end/test/scanner_test.dart index 936ad38046a..67a212bb4ad 100644 --- a/pkg/front_end/test/scanner_test.dart +++ b/pkg/front_end/test/scanner_test.dart @@ -113,7 +113,7 @@ abstract class ScannerTestBase { if (lessThan is BeginToken) { expect(lessThan.endToken, greaterThan); } - expect(greaterThan, isNot(new isInstanceOf())); + expect(greaterThan, isNot(const TypeMatcher())); } void test_async_star() { diff --git a/pkg/front_end/test/standard_file_system_test.dart b/pkg/front_end/test/standard_file_system_test.dart index bd67f3bd889..5644c98f8ad 100644 --- a/pkg/front_end/test/standard_file_system_test.dart +++ b/pkg/front_end/test/standard_file_system_test.dart @@ -25,8 +25,8 @@ main() { }); } -const Matcher _throwsFileSystemException = - const Throws(const isInstanceOf()); +final Matcher _throwsFileSystemException = + throwsA(const TypeMatcher()); @reflectiveTest class DirectoryTest extends _BaseTest { @@ -197,7 +197,7 @@ class StandardFileSystemTest extends _BaseTest { ]) { if (!uri.path.startsWith('/')) { expect(() => StandardFileSystem.instance.entityForUri(uri), - throwsA(new isInstanceOf())); + throwsA(const TypeMatcher())); } } } diff --git a/pkg/front_end/test/token_test.dart b/pkg/front_end/test/token_test.dart index 4b39e62ee8b..686c789fcd3 100644 --- a/pkg/front_end/test/token_test.dart +++ b/pkg/front_end/test/token_test.dart @@ -46,22 +46,22 @@ class Foo { Token comment = nextComment(); expect(comment.lexeme, contains('Single line dartdoc comment')); expect(comment.type, TokenType.SINGLE_LINE_COMMENT); - expect(comment, new isInstanceOf()); + expect(comment, const TypeMatcher()); comment = nextComment(); expect(comment.lexeme, contains('Multi-line dartdoc comment')); expect(comment.type, TokenType.MULTI_LINE_COMMENT); - expect(comment, new isInstanceOf()); + expect(comment, const TypeMatcher()); comment = nextComment(); expect(comment.lexeme, contains('Single line comment')); expect(comment.type, TokenType.SINGLE_LINE_COMMENT); - expect(comment, new isInstanceOf()); + expect(comment, const TypeMatcher()); comment = nextComment(); expect(comment.lexeme, contains('Multi-line comment')); expect(comment.type, TokenType.MULTI_LINE_COMMENT); - expect(comment, new isInstanceOf()); + expect(comment, const TypeMatcher()); } void test_isSynthetic() { diff --git a/pkg/front_end/tool/_fasta/command_line.dart b/pkg/front_end/tool/_fasta/command_line.dart index d4ccb3abd4d..e4c2dff3375 100644 --- a/pkg/front_end/tool/_fasta/command_line.dart +++ b/pkg/front_end/tool/_fasta/command_line.dart @@ -182,10 +182,11 @@ class ParsedArguments { } var parsedValue; if (valueSpecification == int) { - parsedValue = int.parse(value, onError: (_) { + parsedValue = int.tryParse(value); + if (parsedValue == null) { return throw new CommandLineProblem.deprecated( "Value for '$argument', '$value', isn't an int."); - }); + } } else if (valueSpecification == bool) { if (value == null || value == "true" || value == "yes") { parsedValue = true; diff --git a/pkg/front_end/tool/_fasta/log_collector.dart b/pkg/front_end/tool/_fasta/log_collector.dart index 5f3e184819e..f95564cbaa3 100644 --- a/pkg/front_end/tool/_fasta/log_collector.dart +++ b/pkg/front_end/tool/_fasta/log_collector.dart @@ -38,14 +38,14 @@ collectLog(DateTime time, HttpRequest request) async { } on FormatException catch (e) { print(e); return badRequest( - request, HttpStatus.BAD_REQUEST, "Malformed JSON data: ${e.message}."); + request, HttpStatus.badRequest, "Malformed JSON data: ${e.message}."); } if (data is! Map) { return badRequest( - request, HttpStatus.BAD_REQUEST, "Malformed JSON data: not a map."); + request, HttpStatus.badRequest, "Malformed JSON data: not a map."); } if (data["type"] != "crash") { - return badRequest(request, HttpStatus.BAD_REQUEST, + return badRequest(request, HttpStatus.badRequest, "Malformed JSON data: type should be 'crash'."); } request.response.close(); @@ -92,16 +92,16 @@ main(List arguments) async { throw "Unexpected arguments: ${arguments.join(' ')}."; } int port = uri.hasPort ? uri.port : 0; - var host = uri.host.isEmpty ? InternetAddress.LOOPBACK_IP_V4 : uri.host; + var host = uri.host.isEmpty ? InternetAddress.loopbackIPv4 : uri.host; HttpServer server = await HttpServer.bind(host, port); print("Listening on http://${server.address.host}:${server.port}/"); await for (HttpRequest request in server) { if (request.method != "POST") { - badRequest(request, HttpStatus.METHOD_NOT_ALLOWED, "Not allowed."); + badRequest(request, HttpStatus.methodNotAllowed, "Not allowed."); continue; } if (request.uri.path != "/") { - badRequest(request, HttpStatus.NOT_FOUND, "Not found."); + badRequest(request, HttpStatus.notFound, "Not found."); continue; } collectLog(new DateTime.now(), request); diff --git a/pkg/front_end/tool/_fasta/resolve_input_uri_test.dart b/pkg/front_end/tool/_fasta/resolve_input_uri_test.dart index d644f92e496..9e499dbc6cc 100644 --- a/pkg/front_end/tool/_fasta/resolve_input_uri_test.dart +++ b/pkg/front_end/tool/_fasta/resolve_input_uri_test.dart @@ -22,8 +22,9 @@ main() { expect(resolveInputUri('c:/foo').scheme, 'file'); if (Platform.isWindows) { /// : is an invalid path character in windows. - expect(() => resolveInputUri('test:foo').scheme, throws); - expect(() => resolveInputUri('org-dartlang-foo:bar').scheme, throws); + expect(() => resolveInputUri('test:foo').scheme, throwsFormatException); + expect(() => resolveInputUri('org-dartlang-foo:bar').scheme, + throwsFormatException); } else { expect(resolveInputUri('test:foo').scheme, 'file'); expect(resolveInputUri('org-dartlang-foo:bar').scheme, 'file'); diff --git a/pkg/front_end/tool/perf.dart b/pkg/front_end/tool/perf.dart index 582d65a9751..553ffc6862e 100644 --- a/pkg/front_end/tool/perf.dart +++ b/pkg/front_end/tool/perf.dart @@ -22,13 +22,13 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/file_system/physical_file_system.dart' show PhysicalResourceProvider; -import 'package:analyzer/source/package_map_resolver.dart'; import 'package:analyzer/src/context/builder.dart'; import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; import 'package:analyzer/src/file_system/file_system.dart'; import 'package:analyzer/src/generated/parser.dart'; import 'package:analyzer/src/generated/source.dart'; import 'package:analyzer/src/generated/source_io.dart'; +import 'package:analyzer/src/source/package_map_resolver.dart'; import 'package:front_end/src/fasta/scanner.dart'; import 'package:front_end/src/scanner/token.dart'; import 'package:package_config/discovery.dart'; diff --git a/tests/compiler/dart2js/helpers/memory_compiler.dart b/tests/compiler/dart2js/helpers/memory_compiler.dart index 60626609c16..ce4eda75472 100644 --- a/tests/compiler/dart2js/helpers/memory_compiler.dart +++ b/tests/compiler/dart2js/helpers/memory_compiler.dart @@ -114,9 +114,7 @@ CompilerImpl compilerFor( Uri platformBinaries = computePlatformBinariesLocation(); if (packageRoot == null && packageConfig == null) { - if (Platform.packageRoot != null) { - packageRoot = Uri.base.resolve(Platform.packageRoot); - } else if (Platform.packageConfig != null) { + if (Platform.packageConfig != null) { packageConfig = Uri.base.resolve(Platform.packageConfig); } else { // The tests are run with the base directory as the SDK root diff --git a/tools/patch_sdk.dart b/tools/patch_sdk.dart index 458ee6be177..b0ef7d761d3 100644 --- a/tools/patch_sdk.dart +++ b/tools/patch_sdk.dart @@ -12,7 +12,11 @@ import 'dart:async'; import 'dart:math' as math; import 'dart:convert' show jsonEncode; -import 'package:analyzer/analyzer.dart'; +// ignore: deprecated_member_use +import 'package:analyzer/analyzer.dart' + show parseCompilationUnit, parseDirectives; +import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/src/generated/sdk.dart'; import 'package:compiler/src/kernel/dart2js_target.dart' show Dart2jsTarget; import 'package:path/path.dart' as path;