3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'package:kernel/ast.dart' ;
6
- import 'package:kernel/class_hierarchy.dart' ;
7
-
8
- import '../fasta_codes.dart'
9
- show templateInternalProblemNotFoundIn, templateTypeArgumentMismatch;
10
- import '../problems.dart' ;
11
6
import '../scope.dart' ;
12
7
import '../source/source_library_builder.dart' ;
13
8
import 'builder.dart' ;
9
+ import 'builder_mixins.dart' ;
14
10
import 'declaration_builder.dart' ;
15
- import 'field_builder.dart' ;
16
11
import 'library_builder.dart' ;
17
- import 'member_builder.dart' ;
18
12
import 'metadata_builder.dart' ;
19
- import 'nullability_builder.dart' ;
20
13
import 'type_builder.dart' ;
21
14
import 'type_variable_builder.dart' ;
22
15
@@ -50,54 +43,12 @@ abstract class ExtensionBuilder implements DeclarationBuilder {
50
43
}
51
44
52
45
abstract class ExtensionBuilderImpl extends DeclarationBuilderImpl
46
+ with DeclarationBuilderMixin
53
47
implements ExtensionBuilder {
54
48
ExtensionBuilderImpl (List <MetadataBuilder >? metadata, int modifiers,
55
49
String name, LibraryBuilder parent, int charOffset, Scope scope)
56
50
: super (metadata, modifiers, name, parent, charOffset, scope);
57
51
58
- /// Lookup a static member of this declaration.
59
- @override
60
- Builder ? findStaticBuilder (
61
- String name, int charOffset, Uri fileUri, LibraryBuilder accessingLibrary,
62
- {bool isSetter = false }) {
63
- if (accessingLibrary.nameOriginBuilder.origin !=
64
- libraryBuilder.nameOriginBuilder.origin &&
65
- name.startsWith ("_" )) {
66
- return null ;
67
- }
68
- Builder ? declaration = isSetter
69
- ? scope.lookupSetter (name, charOffset, fileUri, isInstanceScope: false )
70
- : scope.lookup (name, charOffset, fileUri, isInstanceScope: false );
71
- // TODO(johnniwinther): Handle patched extensions.
72
- return declaration;
73
- }
74
-
75
- @override
76
- DartType buildAliasedType (
77
- LibraryBuilder library,
78
- NullabilityBuilder nullabilityBuilder,
79
- List <TypeBuilder >? arguments,
80
- TypeUse typeUse,
81
- Uri fileUri,
82
- int charOffset,
83
- ClassHierarchyBase ? hierarchy,
84
- {required bool hasExplicitTypeArguments}) {
85
- if (library is SourceLibraryBuilder &&
86
- library.libraryFeatures.extensionTypes.isEnabled) {
87
- return buildAliasedTypeWithBuiltArguments (
88
- library,
89
- nullabilityBuilder.build (library),
90
- _buildAliasedTypeArguments (library, arguments, hierarchy),
91
- typeUse,
92
- fileUri,
93
- charOffset,
94
- hasExplicitTypeArguments: hasExplicitTypeArguments);
95
- } else {
96
- throw new UnsupportedError ("ExtensionBuilder.buildType is not supported"
97
- "in library '${library .importUri }'." );
98
- }
99
- }
100
-
101
52
@override
102
53
DartType buildAliasedTypeWithBuiltArguments (
103
54
LibraryBuilder library,
@@ -117,109 +68,9 @@ abstract class ExtensionBuilderImpl extends DeclarationBuilderImpl
117
68
}
118
69
}
119
70
120
- @override
121
- int get typeVariablesCount => typeParameters? .length ?? 0 ;
122
-
123
- List <DartType > _buildAliasedTypeArguments (LibraryBuilder library,
124
- List <TypeBuilder >? arguments, ClassHierarchyBase ? hierarchy) {
125
- if (arguments == null && typeParameters == null ) {
126
- return < DartType > [];
127
- }
128
-
129
- if (arguments == null && typeParameters != null ) {
130
- List <DartType > result =
131
- new List <DartType >.generate (typeParameters! .length, (int i) {
132
- return typeParameters! [i].defaultType! .buildAliased (
133
- library, TypeUse .defaultTypeAsTypeArgument, hierarchy);
134
- }, growable: true );
135
- if (library is SourceLibraryBuilder ) {
136
- library.inferredTypes.addAll (result);
137
- }
138
- return result;
139
- }
140
-
141
- if (arguments != null && arguments.length != typeVariablesCount) {
142
- // That should be caught and reported as a compile-time error earlier.
143
- return unhandled (
144
- templateTypeArgumentMismatch
145
- .withArguments (typeVariablesCount)
146
- .problemMessage,
147
- "buildTypeArguments" ,
148
- - 1 ,
149
- null );
150
- }
151
-
152
- assert (arguments! .length == typeVariablesCount);
153
- List <DartType > result =
154
- new List <DartType >.generate (arguments! .length, (int i) {
155
- return arguments[i]
156
- .buildAliased (library, TypeUse .typeArgument, hierarchy);
157
- }, growable: true );
158
- return result;
159
- }
160
-
161
- @override
162
- void forEach (void f (String name, Builder builder)) {
163
- scope
164
- .filteredNameIterator (
165
- includeDuplicates: false , includeAugmentations: false )
166
- .forEach (f);
167
- }
168
-
169
71
@override
170
72
bool get isExtension => true ;
171
73
172
- @override
173
- InterfaceType ? get thisType => null ;
174
-
175
- @override
176
- Builder ? lookupLocalMember (String name,
177
- {bool setter = false , bool required = false }) {
178
- // TODO(johnniwinther): Support patching on extensions.
179
- Builder ? builder = scope.lookupLocalMember (name, setter: setter);
180
- if (required && builder == null ) {
181
- internalProblem (
182
- templateInternalProblemNotFoundIn.withArguments (
183
- name, fullNameForErrors),
184
- - 1 ,
185
- null );
186
- }
187
- return builder;
188
- }
189
-
190
- @override
191
- Builder ? lookupLocalMemberByName (Name name,
192
- {bool setter = false , bool required = false }) {
193
- Builder ? builder =
194
- lookupLocalMember (name.text, setter: setter, required : required );
195
- if (builder == null && setter) {
196
- // When looking up setters, we include assignable fields.
197
- builder = lookupLocalMember (name.text, setter: false , required : required );
198
- if (builder is ! FieldBuilder || ! builder.isAssignable) {
199
- builder = null ;
200
- }
201
- }
202
- if (builder != null ) {
203
- if (name.isPrivate && libraryBuilder.library != name.library) {
204
- builder = null ;
205
- } else if (builder is FieldBuilder &&
206
- ! builder.isStatic &&
207
- ! builder.isExternal) {
208
- // Non-external extension instance fields are invalid.
209
- builder = null ;
210
- } else if (builder.isDuplicate) {
211
- // Duplicates are not visible in the instance scope.
212
- builder = null ;
213
- } else if (builder is MemberBuilder && builder.isConflictingSetter) {
214
- // Conflicting setters are not visible in the instance scope.
215
- // TODO(johnniwinther): Should we return an [AmbiguousBuilder] here and
216
- // above?
217
- builder = null ;
218
- }
219
- }
220
- return builder;
221
- }
222
-
223
74
@override
224
75
String get debugName => "ExtensionBuilder" ;
225
76
}
0 commit comments