replace some ._() constructors with class modifiers (flutter/engine#40328)
replace some ._() constructors with class modifiers
This commit is contained in:
committed by
GitHub
parent
be4da063e8
commit
1986d84d6e
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Function, CallbackHandle?> _forwardCache =
|
||||
<Function, CallbackHandle?>{};
|
||||
static final Map<CallbackHandle, Function?> _backwardCache =
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(<int>[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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<String> _getBlockStartingWith({
|
||||
/// Apply a visitor to all compilation units in the dart:ui library.
|
||||
void visitUIUnits(String flutterRoot, AstVisitor<void> visitor) {
|
||||
final String uiRoot = '$flutterRoot/lib/ui';
|
||||
final FeatureSet analyzerFeatures = FeatureSet.fromEnableFlags2(
|
||||
sdkLanguageVersion: Version.parse('2.17.0'),
|
||||
flags: <String>['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<PartDirective>()) {
|
||||
final String partPath = part.uri.stringValue!;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<String> _kObjectMembers = <String>{
|
||||
@@ -19,7 +20,10 @@ const Set<String> _kObjectMembers = <String>{
|
||||
};
|
||||
|
||||
CompilationUnit _parseAndCheckDart(String path) {
|
||||
final FeatureSet analyzerFeatures = FeatureSet.latestLanguageVersion();
|
||||
final FeatureSet analyzerFeatures = FeatureSet.fromEnableFlags2(
|
||||
flags: <String>['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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user