@@ -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].
98164void _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+
124208void _collectPublicMethods (ClassDeclaration classDeclaration,
125209 Map <String , MethodDeclaration > destination) {
126210 for (ClassMember member in classDeclaration.members) {
0 commit comments