|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | | -import 'package:kernel/ast.dart'; |
6 | | - |
7 | 5 | import '../base/problems.dart'; |
8 | | -import '../base/scope.dart'; |
9 | 6 | import '../builder/builder.dart'; |
10 | 7 | import '../builder/constructor_reference_builder.dart'; |
11 | 8 | import '../builder/declaration_builders.dart'; |
12 | | -import '../builder/function_builder.dart'; |
13 | 9 | import '../builder/member_builder.dart'; |
14 | 10 | import '../builder/name_iterator.dart'; |
15 | | -import '../builder/type_builder.dart'; |
16 | | -import '../codes/cfe_codes.dart'; |
17 | | -import '../dill/dill_member_builder.dart'; |
18 | | -import '../type_inference/type_schema.dart'; |
19 | 11 | import 'source_factory_builder.dart'; |
20 | 12 | import 'source_library_builder.dart'; |
21 | 13 |
|
@@ -106,112 +98,8 @@ mixin ClassDeclarationMixin implements ClassDeclaration { |
106 | 98 | unexpected("$fileUri", "${declaration.declarationBuilder!.fileUri}", |
107 | 99 | fileOffset, fileUri); |
108 | 100 | } |
109 | | - if (declaration is SourceFactoryBuilder && |
110 | | - declaration.redirectionTarget != null) { |
111 | | - // Compute the immediate redirection target, not the effective. |
112 | | - |
113 | | - ConstructorReferenceBuilder redirectionTarget = |
114 | | - declaration.redirectionTarget!; |
115 | | - List<TypeBuilder>? typeArguments = redirectionTarget.typeArguments; |
116 | | - Builder? target = redirectionTarget.target; |
117 | | - if (typeArguments != null && target is MemberBuilder) { |
118 | | - TypeName redirectionTargetName = redirectionTarget.typeName; |
119 | | - if (redirectionTargetName.qualifier == null) { |
120 | | - // Do nothing. This is the case of an identifier followed by |
121 | | - // type arguments, such as the following: |
122 | | - // B<T> |
123 | | - // B<T>.named |
124 | | - } else { |
125 | | - if (target.name.isEmpty) { |
126 | | - // Do nothing. This is the case of a qualified |
127 | | - // non-constructor prefix (for example, with a library |
128 | | - // qualifier) followed by type arguments, such as the |
129 | | - // following: |
130 | | - // lib.B<T> |
131 | | - } else if (target.name != redirectionTargetName.name) { |
132 | | - // Do nothing. This is the case of a qualified |
133 | | - // non-constructor prefix followed by type arguments followed |
134 | | - // by a constructor name, such as the following: |
135 | | - // lib.B<T>.named |
136 | | - } else { |
137 | | - // TODO(cstefantsova,johnniwinther): Handle this in case in |
138 | | - // ConstructorReferenceBuilder.resolveIn and unify with other |
139 | | - // cases of handling of type arguments after constructor |
140 | | - // names. |
141 | | - addProblem( |
142 | | - messageConstructorWithTypeArguments, |
143 | | - redirectionTargetName.nameOffset, |
144 | | - redirectionTargetName.nameLength); |
145 | | - } |
146 | | - } |
147 | | - } |
148 | | - |
149 | | - Builder? targetBuilder = redirectionTarget.target; |
150 | | - Member? targetNode; |
151 | | - if (targetBuilder is FunctionBuilder) { |
152 | | - targetNode = targetBuilder.invokeTarget!; |
153 | | - } else if (targetBuilder is DillMemberBuilder) { |
154 | | - targetNode = targetBuilder.invokeTarget!; |
155 | | - } else if (targetBuilder is AmbiguousBuilder) { |
156 | | - libraryBuilder.addProblemForRedirectingFactory( |
157 | | - declaration, |
158 | | - templateDuplicatedDeclarationUse |
159 | | - .withArguments(redirectionTarget.fullNameForErrors), |
160 | | - redirectionTarget.charOffset, |
161 | | - noLength, |
162 | | - redirectionTarget.fileUri); |
163 | | - } else { |
164 | | - libraryBuilder.addProblemForRedirectingFactory( |
165 | | - declaration, |
166 | | - templateRedirectionTargetNotFound |
167 | | - .withArguments(redirectionTarget.fullNameForErrors), |
168 | | - redirectionTarget.charOffset, |
169 | | - noLength, |
170 | | - redirectionTarget.fileUri); |
171 | | - } |
172 | | - if (targetNode != null && |
173 | | - targetNode is Constructor && |
174 | | - targetNode.enclosingClass.isAbstract) { |
175 | | - libraryBuilder.addProblemForRedirectingFactory( |
176 | | - declaration, |
177 | | - templateAbstractRedirectedClassInstantiation |
178 | | - .withArguments(redirectionTarget.fullNameForErrors), |
179 | | - redirectionTarget.charOffset, |
180 | | - noLength, |
181 | | - redirectionTarget.fileUri); |
182 | | - targetNode = null; |
183 | | - } |
184 | | - if (targetNode != null && |
185 | | - targetNode is Constructor && |
186 | | - targetNode.enclosingClass.isEnum) { |
187 | | - libraryBuilder.addProblemForRedirectingFactory( |
188 | | - declaration, |
189 | | - messageEnumFactoryRedirectsToConstructor, |
190 | | - redirectionTarget.charOffset, |
191 | | - noLength, |
192 | | - redirectionTarget.fileUri); |
193 | | - targetNode = null; |
194 | | - } |
195 | | - if (targetNode != null) { |
196 | | - List<DartType>? typeArguments = |
197 | | - declaration.redirectionTypeArguments; |
198 | | - if (typeArguments == null) { |
199 | | - int typeArgumentCount; |
200 | | - if (targetBuilder!.isExtensionTypeMember) { |
201 | | - ExtensionTypeDeclarationBuilder |
202 | | - extensionTypeDeclarationBuilder = |
203 | | - targetBuilder.parent as ExtensionTypeDeclarationBuilder; |
204 | | - typeArgumentCount = |
205 | | - extensionTypeDeclarationBuilder.typeParametersCount; |
206 | | - } else { |
207 | | - typeArgumentCount = |
208 | | - targetNode.enclosingClass!.typeParameters.length; |
209 | | - } |
210 | | - typeArguments = new List<DartType>.filled( |
211 | | - typeArgumentCount, const UnknownType()); |
212 | | - } |
213 | | - declaration.setRedirectingFactoryBody(targetNode, typeArguments); |
214 | | - } |
| 101 | + if (declaration is SourceFactoryBuilder) { |
| 102 | + declaration.resolveRedirectingFactory(this); |
215 | 103 | } |
216 | 104 | } |
217 | 105 | } |
|
0 commit comments