@@ -151,10 +151,6 @@ Class printContext(PrintContext c) {
151151List <Spec > printContextExtension (PrintContext c) {
152152 final context = c.context;
153153
154- if (context.config.disableCopyWithGeneration) {
155- return [];
156- }
157-
158154 final properties = c.context.properties;
159155
160156 final whenMethod = _printWhen (
@@ -168,26 +164,29 @@ List<Spec> printContextExtension(PrintContext c) {
168164 context.typenameProperty,
169165 context.possibleTypes,
170166 );
171-
167+ final methods = [
168+ if (! context.config.disableCopyWithGeneration)
169+ _printCopyWithMethod (
170+ c.namePrinter.printClassName (context.path),
171+ c,
172+ ),
173+ if (whenMethod != null ) whenMethod,
174+ if (maybeWhenMethod != null ) maybeWhenMethod,
175+ ];
172176 return [
173- Extension (
174- (b) => b
175- ..name = c.namePrinter.printClassExtensionName (context.path)
176- ..on = refer (c.namePrinter.printClassName (context.path))
177- ..methods = ListBuilder ([
178- _printCopyWithMethod (
179- c.namePrinter.printClassName (context.path),
180- c,
181- ),
182- if (whenMethod != null ) whenMethod,
183- if (maybeWhenMethod != null ) maybeWhenMethod,
184- ]),
185- ),
186- ...printCopyWithClasses (
187- c,
188- c.namePrinter.printClassName (context.path),
189- properties,
190- ),
177+ if (methods.isNotEmpty)
178+ Extension (
179+ (b) => b
180+ ..name = c.namePrinter.printClassExtensionName (context.path)
181+ ..on = refer (c.namePrinter.printClassName (context.path))
182+ ..methods = ListBuilder (methods),
183+ ),
184+ if (! context.config.disableCopyWithGeneration)
185+ ...printCopyWithClasses (
186+ c,
187+ c.namePrinter.printClassName (context.path),
188+ properties,
189+ ),
191190 ];
192191}
193192
0 commit comments