diff --git a/analysis_options.yaml b/analysis_options.yaml index 1eeb5c8f9e6a6..5f355bb4e8335 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -31,7 +31,7 @@ linter: - avoid_bool_literals_in_conditional_expressions # - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023 # - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023 - - avoid_classes_with_only_static_members + # - avoid_classes_with_only_static_members # we do this commonly - avoid_double_and_int_checks - avoid_dynamic_calls - avoid_empty_else diff --git a/lib/ui/isolate_name_server.dart b/lib/ui/isolate_name_server.dart index c220b4ed8fb69..4b1a64300d897 100644 --- a/lib/ui/isolate_name_server.dart +++ b/lib/ui/isolate_name_server.dart @@ -19,11 +19,7 @@ part of dart.ui; /// communication or multiple-message communication is necessary, it is /// recommended to establish a separate communication channel in that first /// message (e.g. by passing a dedicated [SendPort]). -class IsolateNameServer { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - IsolateNameServer._(); - +abstract final class IsolateNameServer { /// Looks up the [SendPort] associated with a given name. /// /// Returns null if the name does not exist. To register the name in the first diff --git a/lib/ui/natives.dart b/lib/ui/natives.dart index d06f133d0dc9e..ed32d16668b12 100644 --- a/lib/ui/natives.dart +++ b/lib/ui/natives.dart @@ -6,11 +6,7 @@ part of dart.ui; // ignore_for_file: avoid_classes_with_only_static_members /// Helper functions for Dart Plugin Registrants. -class DartPluginRegistrant { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - DartPluginRegistrant._(); - +abstract final class DartPluginRegistrant { static bool _wasInitialized = false; /// Makes sure the that the Dart Plugin Registrant has been called for this diff --git a/lib/ui/plugins.dart b/lib/ui/plugins.dart index ac38e1c05f65b..b517530c6f19c 100644 --- a/lib/ui/plugins.dart +++ b/lib/ui/plugins.dart @@ -39,11 +39,7 @@ class CallbackHandle { /// /// * [IsolateNameServer], which provides utilities for dealing with /// [Isolate]s. -class PluginUtilities { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - PluginUtilities._(); - +abstract final class PluginUtilities { static final Map _forwardCache = {}; static final Map _backwardCache = diff --git a/lib/web_ui/lib/src/engine/html/path/path_utils.dart b/lib/web_ui/lib/src/engine/html/path/path_utils.dart index 0f7dacda7c715..8c77c3e4ef1f0 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_utils.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_utils.dart @@ -26,11 +26,7 @@ class SPathVerb { static const int kClose = 5; // 0 points } -abstract class SPath { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - SPath._(); - +abstract final class SPath { static const int kMoveVerb = SPathVerb.kMove; static const int kLineVerb = SPathVerb.kLine; static const int kQuadVerb = SPathVerb.kQuad; diff --git a/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart b/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart index b2dd353abcf8d..bd9a5d78b6a8a 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart @@ -10,11 +10,7 @@ import '../../browser_detection.dart'; import 'shader_builder.dart'; /// Provides common shaders used for gradients and drawVertices APIs. -abstract class VertexShaders { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - VertexShaders._(); - +abstract final class VertexShaders { static final Uint16List vertexIndicesForRect = Uint16List.fromList([0, 1, 2, 2, 3, 0]); @@ -73,11 +69,7 @@ abstract class VertexShaders { } } -abstract class FragmentShaders { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - FragmentShaders._(); - +abstract final class FragmentShaders { static String writeTextureFragmentShader( bool isWebGl2, ui.TileMode? tileModeX, ui.TileMode? tileModeY) { final ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); diff --git a/lib/web_ui/lib/src/engine/text/word_breaker.dart b/lib/web_ui/lib/src/engine/text/word_breaker.dart index 1e4fd51920006..a3e46c81a2ab6 100644 --- a/lib/web_ui/lib/src/engine/text/word_breaker.dart +++ b/lib/web_ui/lib/src/engine/text/word_breaker.dart @@ -15,11 +15,7 @@ class _FindBreakDirection { } /// [WordBreaker] exposes static methods to identify word boundaries. -abstract class WordBreaker { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - WordBreaker._(); - +abstract final class WordBreaker { /// It starts from [index] and tries to find the next word boundary in [text]. static int nextBreakIndex(String text, int index) => _findBreakIndex(_FindBreakDirection.forward, text, index); diff --git a/lib/web_ui/lib/window.dart b/lib/web_ui/lib/window.dart index 8493ec1888b53..b53592964dd99 100644 --- a/lib/web_ui/lib/window.dart +++ b/lib/web_ui/lib/window.dart @@ -173,11 +173,7 @@ class CallbackHandle { } // TODO(dit): see https://github.com/flutter/flutter/issues/33615. -class PluginUtilities { - // This class is only a namespace, and should not be instantiated or - // extended directly. - factory PluginUtilities._() => throw UnsupportedError('Namespace'); - +abstract final class PluginUtilities { static CallbackHandle? getCallbackHandle(Function callback) { throw UnimplementedError(); } @@ -187,11 +183,7 @@ class PluginUtilities { } } -class IsolateNameServer { - // This class is only a namespace, and should not be instantiated or - // extended directly. - factory IsolateNameServer._() => throw UnsupportedError('Namespace'); - +abstract final class IsolateNameServer { static dynamic lookupPortByName(String name) { throw UnimplementedError(); } diff --git a/lib/web_ui/pubspec.yaml b/lib/web_ui/pubspec.yaml index 95e1aaad4bacb..75cf412b50400 100644 --- a/lib/web_ui/pubspec.yaml +++ b/lib/web_ui/pubspec.yaml @@ -18,7 +18,6 @@ dependencies: path: ../../third_party/web_test_fonts dev_dependencies: - analyzer: 5.2.0 archive: 3.1.2 args: any async: any diff --git a/tools/api_check/lib/apicheck.dart b/tools/api_check/lib/apicheck.dart index 7aafdb6d02239..6e6ecb93be692 100644 --- a/tools/api_check/lib/apicheck.dart +++ b/tools/api_check/lib/apicheck.dart @@ -12,7 +12,6 @@ import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart'; import 'package:analyzer/dart/analysis/utilities.dart'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:pub_semver/pub_semver.dart'; /// Returns all indexed fields in [className]. /// @@ -163,10 +162,7 @@ List _getBlockStartingWith({ /// Apply a visitor to all compilation units in the dart:ui library. void visitUIUnits(String flutterRoot, AstVisitor visitor) { final String uiRoot = '$flutterRoot/lib/ui'; - final FeatureSet analyzerFeatures = FeatureSet.fromEnableFlags2( - sdkLanguageVersion: Version.parse('2.17.0'), - flags: ['non-nullable'], - ); + final FeatureSet analyzerFeatures = FeatureSet.latestLanguageVersion(); final ParseStringResult uiResult = parseFile(path: '$uiRoot/ui.dart', featureSet: analyzerFeatures); for (final PartDirective part in uiResult.unit.directives.whereType()) { final String partPath = part.uri.stringValue!; diff --git a/web_sdk/pubspec.yaml b/web_sdk/pubspec.yaml index 6222f1371364a..448654dfad4ed 100644 --- a/web_sdk/pubspec.yaml +++ b/web_sdk/pubspec.yaml @@ -9,5 +9,6 @@ dependencies: path: 1.8.2 dev_dependencies: - analyzer: 4.3.1 + analyzer: 5.7.1 test: 1.22.1 + pub_semver: 2.1.3 diff --git a/web_sdk/test/api_conform_test.dart b/web_sdk/test/api_conform_test.dart index db5ffb8587ed7..21d14dce0524c 100644 --- a/web_sdk/test/api_conform_test.dart +++ b/web_sdk/test/api_conform_test.dart @@ -10,6 +10,7 @@ import 'package:analyzer/dart/analysis/features.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/utilities.dart'; import 'package:analyzer/dart/ast/ast.dart'; +import 'package:pub_semver/pub_semver.dart'; // Ignore members defined on Object. const Set _kObjectMembers = { @@ -19,7 +20,10 @@ const Set _kObjectMembers = { }; CompilationUnit _parseAndCheckDart(String path) { - final FeatureSet analyzerFeatures = FeatureSet.latestLanguageVersion(); + final FeatureSet analyzerFeatures = FeatureSet.fromEnableFlags2( + flags: ['class-modifiers', 'sealed-class', 'records', 'patterns'], + sdkLanguageVersion: Version.parse('3.0.0-0'), + ); if (!analyzerFeatures.isEnabled(Feature.non_nullable)) { throw Exception('non-nullable feature is disabled.'); } @@ -120,20 +124,20 @@ void main() { uiConstructor.parameters.parameters[i]; final FormalParameter webParam = webConstructor.parameters.parameters[i]; - if (webParam.identifier!.name != uiParam.identifier!.name) { + if (webParam.name!.lexeme != uiParam.name!.lexeme) { failed = true; print('Warning: lib/ui/ui.dart $className.$name parameter $i' - ' ${uiParam.identifier!.name} has a different name in lib/web_ui/ui.dart.'); + ' ${uiParam.name!.lexeme} has a different name in lib/web_ui/ui.dart.'); } if (uiParam.isPositional != webParam.isPositional) { failed = true; print('Warning: lib/ui/ui.dart $className.$name parameter $i' - '${uiParam.identifier!.name} is positional, but not in lib/web_ui/ui.dart.'); + '${uiParam.name!.lexeme} is positional, but not in lib/web_ui/ui.dart.'); } if (uiParam.isNamed != webParam.isNamed) { failed = true; print('Warning: lib/ui/ui.dart $className.$name parameter $i' - '${uiParam.identifier!.name} is named, but not in lib/web_ui/ui.dart.'); + '${uiParam.name!.lexeme} is named, but not in lib/web_ui/ui.dart.'); } } } @@ -170,20 +174,20 @@ void main() { i++) { final FormalParameter uiParam = uiMethod.parameters!.parameters[i]; final FormalParameter webParam = webMethod.parameters!.parameters[i]; - if (webParam.identifier!.name != uiParam.identifier!.name) { + if (webParam.name!.lexeme != uiParam.name!.lexeme) { failed = true; print('Warning: lib/ui/ui.dart $className.$methodName parameter $i' - ' ${uiParam.identifier!.name} has a different name in lib/web_ui/ui.dart.'); + ' ${uiParam.name!.lexeme} has a different name in lib/web_ui/ui.dart.'); } if (uiParam.isPositional != webParam.isPositional) { failed = true; print('Warning: lib/ui/ui.dart $className.$methodName parameter $i' - '${uiParam.identifier!.name} is positional, but not in lib/web_ui/ui.dart.'); + '${uiParam.name!.lexeme} is positional, but not in lib/web_ui/ui.dart.'); } if (uiParam.isNamed != webParam.isNamed) { failed = true; print('Warning: lib/ui/ui.dart $className.$methodName parameter $i' - '${uiParam.identifier!.name} is named, but not in lib/web_ui/ui.dart.'); + '${uiParam.name!.lexeme} is named, but not in lib/web_ui/ui.dart.'); } // check nullability if (uiParam is SimpleFormalParameter && @@ -193,7 +197,7 @@ void main() { if (isUiNullable != isWebNullable) { failed = true; print('Warning: lib/ui/ui.dart $className.$methodName parameter $i ' - '${uiParam.identifier} has a different nullability than in lib/web_ui/ui.dart.'); + '${uiParam.name} has a different nullability than in lib/web_ui/ui.dart.'); } } } @@ -247,28 +251,28 @@ void main() { final SimpleFormalParameter webParam = (webTypeDef.type as GenericFunctionType).parameters.parameters[i] as SimpleFormalParameter; - if (webParam.identifier == null) { + if (webParam.name == null) { failed = true; print('Warning: lib/web_ui/ui.dart $typeDefName parameter $i should have name.'); } - if (uiParam.identifier == null) { + if (uiParam.name == null) { failed = true; print('Warning: lib/ui/ui.dart $typeDefName parameter $i should have name.'); } - if (webParam.identifier?.name != uiParam.identifier?.name) { + if (webParam.name?.lexeme != uiParam.name?.lexeme) { failed = true; print('Warning: lib/ui/ui.dart $typeDefName parameter $i ' - '${uiParam.identifier!.name} has a different name in lib/web_ui/ui.dart.'); + '${uiParam.name!.lexeme} has a different name in lib/web_ui/ui.dart.'); } if (uiParam.isPositional != webParam.isPositional) { failed = true; print('Warning: lib/ui/ui.dart $typeDefName parameter $i ' - '${uiParam.identifier!.name} is positional, but not in lib/web_ui/ui.dart.'); + '${uiParam.name!.lexeme} is positional, but not in lib/web_ui/ui.dart.'); } if (uiParam.isNamed != webParam.isNamed) { failed = true; print('Warning: lib/ui/ui.dart $typeDefName parameter $i ' - '${uiParam.identifier!.name} is named, but not in lib/web_ui/ui.dart.'); + '${uiParam.name!.lexeme}} is named, but not in lib/web_ui/ui.dart.'); } final bool isUiNullable = uiParam.type?.question != null; @@ -276,7 +280,7 @@ void main() { if (isUiNullable != isWebNullable) { failed = true; print('Warning: lib/ui/ui.dart $typeDefName parameter $i ' - '${uiParam.identifier} has a different nullability than in lib/web_ui/ui.dart.'); + '${uiParam.name} has a different nullability than in lib/web_ui/ui.dart.'); } } @@ -315,10 +319,10 @@ void _collectPublicClasses(CompilationUnit unit, continue; } final ClassDeclaration classDeclaration = member; - if (classDeclaration.name.name.startsWith('_')) { + if (classDeclaration.name.lexeme.startsWith('_')) { continue; } - destination[classDeclaration.name.name] = classDeclaration; + destination[classDeclaration.name.lexeme] = classDeclaration; } } } @@ -329,7 +333,7 @@ void _collectPublicConstructors(ClassDeclaration classDeclaration, if (member is! ConstructorDeclaration) { continue; } - final String? methodName = member.name?.name; + final String? methodName = member.name?.lexeme; if (methodName == null) { destination['Unnamed Constructor'] = member; continue; @@ -347,10 +351,10 @@ void _collectPublicMethods(ClassDeclaration classDeclaration, if (member is! MethodDeclaration) { continue; } - if (member.name.name.startsWith('_')) { + if (member.name.lexeme.startsWith('_')) { continue; } - destination[member.name.name] = member; + destination[member.name.lexeme] = member; } } @@ -369,10 +373,10 @@ void _collectPublicTypeDefs(CompilationUnit unit, continue; } final GenericTypeAlias typeDeclaration = member; - if (typeDeclaration.name.name.startsWith('_')) { + if (typeDeclaration.name.lexeme.startsWith('_')) { continue; } - destination[typeDeclaration.name.name] = typeDeclaration; + destination[typeDeclaration.name.lexeme] = typeDeclaration; } } } diff --git a/web_sdk/web_test_utils/pubspec.yaml b/web_sdk/web_test_utils/pubspec.yaml index c9b8530271a9a..2879b821cc479 100644 --- a/web_sdk/web_test_utils/pubspec.yaml +++ b/web_sdk/web_test_utils/pubspec.yaml @@ -5,7 +5,7 @@ environment: sdk: '>=3.0.0-0 <4.0.0' dependencies: - collection: 1.15.0 + collection: 1.17.0 crypto: 3.0.1 image: 3.0.1 js: 0.6.4