Skip to content

Commit fa2e2d9

Browse files
author
Jonah Williams
authored
Add checks to constructors and add missing constructor members (flutter#9106)
1 parent 7e1788a commit fa2e2d9

5 files changed

Lines changed: 131 additions & 10 deletions

File tree

lib/stub_ui/lib/src/ui/compositing.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,12 @@ class SceneHost {
875875
/// The scene host takes ownership of the provided export token handle.
876876
SceneHost(dynamic exportTokenHandle);
877877

878+
SceneHost.fromViewHolderToken(
879+
dynamic viewHolderTokenHandle,
880+
void Function() viewConnectedCallback,
881+
void Function() viewDisconnectedCallback,
882+
void Function(bool) viewStateChangedCallback);
883+
878884
/// Releases the resources associated with the child scene host.
879885
///
880886
/// After calling this function, the child scene host cannot be used further.

lib/stub_ui/lib/src/ui/painting.dart

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,8 @@ class Paint {
962962
double get strokeMiterLimit {
963963
return null;
964964
}
965-
set strokeMiterLimit(double value) {
966-
}
965+
966+
set strokeMiterLimit(double value) {}
967967

968968
/// Whether to paint inside shapes, the edges of shapes, or both.
969969
///
@@ -1213,7 +1213,8 @@ abstract class Gradient extends Shader {
12131213
List<Color> colors, [
12141214
List<double> colorStops,
12151215
TileMode tileMode = TileMode.clamp,
1216-
Float64List matrix4, // TODO(yjbanov): Implement this https://github.com/flutter/flutter/issues/32819
1216+
Float64List
1217+
matrix4, // TODO(yjbanov): Implement this https://github.com/flutter/flutter/issues/32819
12171218
]) =>
12181219
_GradientLinear(from, to, colors, colorStops, tileMode);
12191220

@@ -1490,6 +1491,25 @@ class ColorFilter {
14901491
: _color = color,
14911492
_blendMode = blendMode;
14921493

1494+
/// Construct a color filter that transforms a color by a 4x5 matrix. The
1495+
/// matrix is in row-major order and the translation column is specified in
1496+
/// unnormalized, 0...255, space.
1497+
const ColorFilter.matrix(List<double> matrix)
1498+
: _color = null,
1499+
_blendMode = null;
1500+
1501+
/// Construct a color filter that applies the sRGB gamma curve to the RGB
1502+
/// channels.
1503+
const ColorFilter.linearToSrgbGamma()
1504+
: _color = null,
1505+
_blendMode = null;
1506+
1507+
/// Creates a color filter that applies the inverse of the sRGB gamma curve
1508+
/// to the RGB channels.
1509+
const ColorFilter.srgbToLinearGamma()
1510+
: _color = null,
1511+
_blendMode = null;
1512+
14931513
final Color _color;
14941514
final BlendMode _blendMode;
14951515

@@ -1632,6 +1652,14 @@ class ImageFilter {
16321652
ImageFilter.blur({double sigmaX = 0.0, double sigmaY = 0.0}) {
16331653
_initBlur(sigmaX, sigmaY);
16341654
}
1655+
1656+
/// Creates an image filter that applies a matrix transformation.
1657+
///
1658+
/// For example, applying a positive scale matrix (see [Matrix4.diagonal3])
1659+
/// when used with [BackdropFilter] would magnify the background image.
1660+
ImageFilter.matrix(Float64List matrix4,
1661+
{FilterQuality filterQuality = FilterQuality.low}) {}
1662+
16351663
void _initBlur(double sigmaX, double sigmaY) {
16361664
// TODO(b/128318717): Implement me.
16371665
}

lib/stub_ui/lib/src/ui/text.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ class TextStyle {
458458
Paint background,
459459
Paint foreground,
460460
List<Shadow> shadows,
461+
List<FontFeature> fontFeatures,
461462
}) : assert(
462463
color == null || foreground == null,
463464
'Cannot provide both a color and a foreground\n'

lib/stub_ui/lib/src/ui/window.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,9 @@ class PluginUtilities {
11971197
}
11981198
}
11991199

1200-
class ImageShader {}
1200+
class ImageShader {
1201+
ImageShader(Image image, TileMode tmx, TileMode tmy, Float64List matrix4);
1202+
}
12011203

12021204
class IsolateNameServer {
12031205
static SendPort lookupPortByName(String name) {

web_sdk/test/api_conform_test.dart

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,70 @@ void main() {
3939
}
4040
// Next will check that the public methods exposed in each library are
4141
// identical.
42-
final Map<String, MethodDeclaration> uiMethods = <String, MethodDeclaration>{};
43-
final Map<String, MethodDeclaration> webMethods = <String, MethodDeclaration>{};
42+
final Map<String, MethodDeclaration> uiMethods =
43+
<String, MethodDeclaration>{};
44+
final Map<String, MethodDeclaration> webMethods =
45+
<String, MethodDeclaration>{};
46+
final Map<String, ConstructorDeclaration> uiConstructors =
47+
<String, ConstructorDeclaration>{};
48+
final Map<String, ConstructorDeclaration> webConstructors =
49+
<String, ConstructorDeclaration>{};
4450
_collectPublicMethods(uiClass, uiMethods);
4551
_collectPublicMethods(webClass, webMethods);
52+
_collectPublicConstructors(uiClass, uiConstructors);
53+
_collectPublicConstructors(webClass, webConstructors);
54+
55+
for (String name in uiConstructors.keys) {
56+
final ConstructorDeclaration uiConstructor = uiConstructors[name];
57+
final ConstructorDeclaration webConstructor = webConstructors[name];
58+
if (webConstructor == null) {
59+
failed = true;
60+
print(
61+
'Warning: lib/ui/ui.dart $className.$name is missing from lib/stub_ui/ui.dart.',
62+
);
63+
continue;
64+
}
65+
66+
if (uiConstructor.parameters.parameters.length !=
67+
webConstructor.parameters.parameters.length) {
68+
failed = true;
69+
print(
70+
'Warning: lib/ui/ui.dart $className.$name has a different parameter '
71+
'length than in lib/stub_ui/ui.dart.');
72+
}
73+
74+
for (int i = 0;
75+
i < uiConstructor.parameters.parameters.length &&
76+
i < uiConstructor.parameters.parameters.length;
77+
i++) {
78+
// Technically you could re-order named parameters and still be valid,
79+
// but we enforce that they are identical.
80+
for (int i = 0;
81+
i < uiConstructor.parameters.parameters.length &&
82+
i < webConstructor.parameters.parameters.length;
83+
i++) {
84+
final FormalParameter uiParam =
85+
uiConstructor.parameters.parameters[i];
86+
final FormalParameter webParam =
87+
webConstructor.parameters.parameters[i];
88+
if (webParam.identifier.name != uiParam.identifier.name) {
89+
failed = true;
90+
print('Warning: lib/ui/ui.dart $className.$name parameter $i'
91+
' ${uiParam.identifier.name} has a different name in lib/stub_ui/ui.dart.');
92+
}
93+
if (uiParam.isPositional != webParam.isPositional) {
94+
failed = true;
95+
print('Warning: lib/ui/ui.dart $className.$name parameter $i'
96+
'${uiParam.identifier.name} is positional, but not in lib/stub_ui/ui.dart.');
97+
}
98+
if (uiParam.isNamed != webParam.isNamed) {
99+
failed = true;
100+
print('Warning: lib/ui/ui.dart $className.$name parameter $i'
101+
'${uiParam.identifier.name} is named, but not in lib/stub_ui/ui.dart.');
102+
}
103+
}
104+
}
105+
}
46106

47107
for (String methodName in uiMethods.keys) {
48108
final MethodDeclaration uiMethod = uiMethods[methodName];
@@ -57,28 +117,32 @@ void main() {
57117
if (uiMethod.parameters == null || webMethod.parameters == null) {
58118
continue;
59119
}
60-
if (uiMethod.parameters.parameters.length != webMethod.parameters.parameters.length) {
120+
if (uiMethod.parameters.parameters.length !=
121+
webMethod.parameters.parameters.length) {
61122
failed = true;
62123
print(
63124
'Warning: lib/ui/ui.dart $className.$methodName has a different parameter '
64125
'length than in lib/stub_ui/ui.dart.');
65126
}
66127
// Technically you could re-order named parameters and still be valid,
67128
// but we enforce that they are identical.
68-
for (int i = 0; i < uiMethod.parameters.parameters.length && i < webMethod.parameters.parameters.length; i++) {
129+
for (int i = 0;
130+
i < uiMethod.parameters.parameters.length &&
131+
i < webMethod.parameters.parameters.length;
132+
i++) {
69133
final FormalParameter uiParam = uiMethod.parameters.parameters[i];
70134
final FormalParameter webParam = webMethod.parameters.parameters[i];
71135
if (webParam.identifier.name != uiParam.identifier.name) {
72136
failed = true;
73137
print('Warning: lib/ui/ui.dart $className.$methodName parameter $i'
74138
' ${uiParam.identifier.name} has a different name in lib/stub_ui/ui.dart.');
75139
}
76-
if (uiParam.isPositional && !webParam.isPositional) {
140+
if (uiParam.isPositional != webParam.isPositional) {
77141
failed = true;
78142
print('Warning: lib/ui/ui.dart $className.$methodName parameter $i'
79143
'${uiParam.identifier.name} is positional, but not in lib/stub_ui/ui.dart.');
80144
}
81-
if (uiParam.isNamed && !webParam.isNamed) {
145+
if (uiParam.isNamed != webParam.isNamed) {
82146
failed = true;
83147
print('Warning: lib/ui/ui.dart $className.$methodName parameter $i'
84148
'${uiParam.identifier.name} is named, but not in lib/stub_ui/ui.dart.');
@@ -94,6 +158,8 @@ void main() {
94158
exit(0);
95159
}
96160

161+
void _checkParameters() {}
162+
97163
// Collects all public classes defined by the part files of [unit].
98164
void _collectPublicClasses(CompilationUnit unit,
99165
Map<String, ClassDeclaration> destination, String root) {
@@ -121,6 +187,24 @@ void _collectPublicClasses(CompilationUnit unit,
121187
}
122188
}
123189

190+
void _collectPublicConstructors(ClassDeclaration classDeclaration,
191+
Map<String, ConstructorDeclaration> destination) {
192+
for (ClassMember member in classDeclaration.members) {
193+
if (member is! ConstructorDeclaration) {
194+
continue;
195+
}
196+
final ConstructorDeclaration method = member;
197+
if (method?.name?.name == null) {
198+
destination['Unnamed Constructor'] = method;
199+
continue;
200+
}
201+
if (method.name.name.startsWith('_')) {
202+
continue;
203+
}
204+
destination[method.name.name] = method;
205+
}
206+
}
207+
124208
void _collectPublicMethods(ClassDeclaration classDeclaration,
125209
Map<String, MethodDeclaration> destination) {
126210
for (ClassMember member in classDeclaration.members) {

0 commit comments

Comments
 (0)