22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5+ import '../builder/builder.dart' ;
56import '../builder/class_builder.dart' ;
67import '../builder/declaration_builder.dart' ;
8+ import '../builder/member_builder.dart' ;
9+ import '../builder/name_iterator.dart' ;
710import 'source_library_builder.dart' ;
811
912/// Common interface for builders for a class declarations in source code, such
@@ -19,3 +22,212 @@ abstract class ClassDeclaration
1922 /// either explicitly or implicitly through a no-name default constructor.
2023 bool get hasGenerativeConstructor;
2124}
25+
26+ abstract class ClassDeclarationAugmentationAccess <D extends ClassDeclaration > {
27+ D getOrigin (D classDeclaration);
28+ Iterable <D >? getAugmentations (D classDeclaration);
29+ }
30+
31+ class ClassDeclarationMemberIterator <D extends ClassDeclaration ,
32+ T extends Builder > implements Iterator <T > {
33+ Iterator <T >? _iterator;
34+ Iterator <D >? augmentationBuilders;
35+ final bool includeDuplicates;
36+
37+ factory ClassDeclarationMemberIterator (
38+ ClassDeclarationAugmentationAccess <D > patching, D classBuilder,
39+ {required bool includeDuplicates}) {
40+ return new ClassDeclarationMemberIterator ._(
41+ patching.getOrigin (classBuilder),
42+ patching.getAugmentations (classBuilder)? .iterator,
43+ includeDuplicates: includeDuplicates);
44+ }
45+
46+ ClassDeclarationMemberIterator ._(
47+ D classDeclaration, this .augmentationBuilders,
48+ {required this .includeDuplicates})
49+ : _iterator = classDeclaration.scope.filteredIterator <T >(
50+ parent: classDeclaration,
51+ includeDuplicates: includeDuplicates,
52+ includeAugmentations: false );
53+
54+ @override
55+ bool moveNext () {
56+ if (_iterator != null ) {
57+ if (_iterator! .moveNext ()) {
58+ return true ;
59+ }
60+ }
61+ if (augmentationBuilders != null && augmentationBuilders! .moveNext ()) {
62+ D augmentationClassDeclaration = augmentationBuilders! .current;
63+ _iterator = augmentationClassDeclaration.scope.filteredIterator <T >(
64+ parent: augmentationClassDeclaration,
65+ includeDuplicates: includeDuplicates,
66+ includeAugmentations: false );
67+ }
68+ if (_iterator != null ) {
69+ if (_iterator! .moveNext ()) {
70+ return true ;
71+ }
72+ }
73+ return false ;
74+ }
75+
76+ @override
77+ T get current => _iterator? .current ?? (throw new StateError ('No element' ));
78+ }
79+
80+ class ClassDeclarationMemberNameIterator <D extends ClassDeclaration ,
81+ T extends Builder > implements NameIterator <T > {
82+ NameIterator <T >? _iterator;
83+ Iterator <D >? augmentationBuilders;
84+ final bool includeDuplicates;
85+
86+ factory ClassDeclarationMemberNameIterator (
87+ ClassDeclarationAugmentationAccess <D > patching, D classBuilder,
88+ {required bool includeDuplicates}) {
89+ return new ClassDeclarationMemberNameIterator ._(
90+ patching.getOrigin (classBuilder),
91+ patching.getAugmentations (classBuilder)? .iterator,
92+ includeDuplicates: includeDuplicates);
93+ }
94+
95+ ClassDeclarationMemberNameIterator ._(
96+ D classDeclaration, this .augmentationBuilders,
97+ {required this .includeDuplicates})
98+ : _iterator = classDeclaration.scope.filteredNameIterator <T >(
99+ parent: classDeclaration,
100+ includeDuplicates: includeDuplicates,
101+ includeAugmentations: false );
102+
103+ @override
104+ bool moveNext () {
105+ if (_iterator != null ) {
106+ if (_iterator! .moveNext ()) {
107+ return true ;
108+ }
109+ }
110+ if (augmentationBuilders != null && augmentationBuilders! .moveNext ()) {
111+ D augmentationClassDeclaration = augmentationBuilders! .current;
112+ _iterator = augmentationClassDeclaration.scope.filteredNameIterator <T >(
113+ parent: augmentationClassDeclaration,
114+ includeDuplicates: includeDuplicates,
115+ includeAugmentations: false );
116+ }
117+ if (_iterator != null ) {
118+ if (_iterator! .moveNext ()) {
119+ return true ;
120+ }
121+ }
122+ return false ;
123+ }
124+
125+ @override
126+ T get current => _iterator? .current ?? (throw new StateError ('No element' ));
127+
128+ @override
129+ String get name => _iterator? .name ?? (throw new StateError ('No element' ));
130+ }
131+
132+ class ClassDeclarationConstructorIterator <D extends ClassDeclaration ,
133+ T extends MemberBuilder > implements Iterator <T > {
134+ Iterator <T >? _iterator;
135+ Iterator <D >? augmentationBuilders;
136+ final bool includeDuplicates;
137+
138+ factory ClassDeclarationConstructorIterator (
139+ ClassDeclarationAugmentationAccess <D > patching, D classBuilder,
140+ {required bool includeDuplicates}) {
141+ return new ClassDeclarationConstructorIterator ._(
142+ patching.getOrigin (classBuilder),
143+ patching.getAugmentations (classBuilder)? .iterator,
144+ includeDuplicates: includeDuplicates);
145+ }
146+
147+ ClassDeclarationConstructorIterator ._(
148+ D classDeclaration, this .augmentationBuilders,
149+ {required this .includeDuplicates})
150+ : _iterator = classDeclaration.constructorScope.filteredIterator <T >(
151+ parent: classDeclaration,
152+ includeDuplicates: includeDuplicates,
153+ includeAugmentations: false );
154+
155+ @override
156+ bool moveNext () {
157+ if (_iterator != null ) {
158+ if (_iterator! .moveNext ()) {
159+ return true ;
160+ }
161+ }
162+ if (augmentationBuilders != null && augmentationBuilders! .moveNext ()) {
163+ D augmentationClassDeclaration = augmentationBuilders! .current;
164+ _iterator = augmentationClassDeclaration.constructorScope
165+ .filteredIterator <T >(
166+ parent: augmentationClassDeclaration,
167+ includeDuplicates: includeDuplicates,
168+ includeAugmentations: false );
169+ }
170+ if (_iterator != null ) {
171+ if (_iterator! .moveNext ()) {
172+ return true ;
173+ }
174+ }
175+ return false ;
176+ }
177+
178+ @override
179+ T get current => _iterator? .current ?? (throw new StateError ('No element' ));
180+ }
181+
182+ class ClassDeclarationConstructorNameIterator <D extends ClassDeclaration ,
183+ T extends MemberBuilder > implements NameIterator <T > {
184+ NameIterator <T >? _iterator;
185+ Iterator <D >? augmentationBuilders;
186+ final bool includeDuplicates;
187+
188+ factory ClassDeclarationConstructorNameIterator (
189+ ClassDeclarationAugmentationAccess <D > patching, D classDeclaration,
190+ {required bool includeDuplicates}) {
191+ return new ClassDeclarationConstructorNameIterator ._(
192+ patching.getOrigin (classDeclaration),
193+ patching.getAugmentations (classDeclaration)? .iterator,
194+ includeDuplicates: includeDuplicates);
195+ }
196+
197+ ClassDeclarationConstructorNameIterator ._(
198+ D classBuilder, this .augmentationBuilders,
199+ {required this .includeDuplicates})
200+ : _iterator = classBuilder.constructorScope.filteredNameIterator <T >(
201+ parent: classBuilder,
202+ includeDuplicates: includeDuplicates,
203+ includeAugmentations: false );
204+
205+ @override
206+ bool moveNext () {
207+ if (_iterator != null ) {
208+ if (_iterator! .moveNext ()) {
209+ return true ;
210+ }
211+ }
212+ if (augmentationBuilders != null && augmentationBuilders! .moveNext ()) {
213+ D augmentationClassDeclaration = augmentationBuilders! .current;
214+ _iterator = augmentationClassDeclaration.constructorScope
215+ .filteredNameIterator <T >(
216+ parent: augmentationClassDeclaration,
217+ includeDuplicates: includeDuplicates,
218+ includeAugmentations: false );
219+ }
220+ if (_iterator != null ) {
221+ if (_iterator! .moveNext ()) {
222+ return true ;
223+ }
224+ }
225+ return false ;
226+ }
227+
228+ @override
229+ T get current => _iterator? .current ?? (throw new StateError ('No element' ));
230+
231+ @override
232+ String get name => _iterator? .name ?? (throw new StateError ('No element' ));
233+ }
0 commit comments