Skip to content

Commit 4373c30

Browse files
authored
[pigeon] correct usage of extended generics in generator methods (#8910)
This update is necessary for an impending linter change. Corrects improper usage of generics in the options for generators
1 parent e3d259d commit 4373c30

File tree

9 files changed

+37
-36
lines changed

9 files changed

+37
-36
lines changed

packages/pigeon/lib/src/cpp/cpp_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class CppOptions {
9898
/// Options that control how C++ code will be generated.
9999
///
100100
/// For internal use only.
101-
class InternalCppOptions extends PigeonInternalOptions {
101+
class InternalCppOptions extends InternalOptions {
102102
/// Creates a [InternalCppOptions] object.
103103
const InternalCppOptions({
104104
required this.headerIncludePath,

packages/pigeon/lib/src/dart/dart_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class DartOptions {
8787
}
8888

8989
/// Options that control how Dart code will be generated.
90-
class InternalDartOptions extends PigeonInternalOptions {
90+
class InternalDartOptions extends InternalOptions {
9191
/// Constructor for InternalDartOptions.
9292
const InternalDartOptions({
9393
this.copyrightHeader,

packages/pigeon/lib/src/generator.dart

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ import 'ast.dart';
66
import 'generator_tools.dart';
77

88
/// The internal options used by the generator.
9-
abstract class PigeonInternalOptions {
9+
abstract class InternalOptions {
1010
/// Constructor.
11-
const PigeonInternalOptions();
11+
const InternalOptions();
1212
}
1313

1414
/// An abstract base class of generators.
1515
///
1616
/// This provides the structure that is common across generators for different languages.
17-
abstract class Generator<PigeonInternalOptions> {
17+
abstract class Generator<T extends InternalOptions> {
1818
/// Constructor.
1919
const Generator();
2020

2121
/// Generates files for specified language with specified [generatorOptions]
2222
void generate(
23-
PigeonInternalOptions generatorOptions,
23+
T generatorOptions,
2424
Root root,
2525
StringSink sink, {
2626
required String dartPackageName,
2727
});
2828
}
2929

3030
/// An abstract base class that enforces code generation across platforms.
31-
abstract class StructuredGenerator<PigeonInternalOptions>
32-
extends Generator<PigeonInternalOptions> {
31+
abstract class StructuredGenerator<T extends InternalOptions>
32+
extends Generator<T> {
3333
/// Constructor.
3434
const StructuredGenerator();
3535

3636
@override
3737
void generate(
38-
PigeonInternalOptions generatorOptions,
38+
T generatorOptions,
3939
Root root,
4040
StringSink sink, {
4141
required String dartPackageName,
@@ -126,15 +126,15 @@ abstract class StructuredGenerator<PigeonInternalOptions>
126126

127127
/// Adds specified headers to [indent].
128128
void writeFilePrologue(
129-
PigeonInternalOptions generatorOptions,
129+
T generatorOptions,
130130
Root root,
131131
Indent indent, {
132132
required String dartPackageName,
133133
});
134134

135135
/// Writes specified imports to [indent].
136136
void writeFileImports(
137-
PigeonInternalOptions generatorOptions,
137+
T generatorOptions,
138138
Root root,
139139
Indent indent, {
140140
required String dartPackageName,
@@ -144,7 +144,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
144144
///
145145
/// This method is not required, and does not need to be overridden.
146146
void writeOpenNamespace(
147-
PigeonInternalOptions generatorOptions,
147+
T generatorOptions,
148148
Root root,
149149
Indent indent, {
150150
required String dartPackageName,
@@ -154,7 +154,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
154154
///
155155
/// This method is not required, and does not need to be overridden.
156156
void writeCloseNamespace(
157-
PigeonInternalOptions generatorOptions,
157+
T generatorOptions,
158158
Root root,
159159
Indent indent, {
160160
required String dartPackageName,
@@ -164,7 +164,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
164164
///
165165
/// This method is not required, and does not need to be overridden.
166166
void writeGeneralUtilities(
167-
PigeonInternalOptions generatorOptions,
167+
T generatorOptions,
168168
Root root,
169169
Indent indent, {
170170
required String dartPackageName,
@@ -174,7 +174,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
174174
///
175175
/// Can be overridden to add extra code before/after enums.
176176
void writeEnums(
177-
PigeonInternalOptions generatorOptions,
177+
T generatorOptions,
178178
Root root,
179179
Indent indent, {
180180
required String dartPackageName,
@@ -192,7 +192,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
192192

193193
/// Writes a single Enum to [indent]. This is needed in most generators.
194194
void writeEnum(
195-
PigeonInternalOptions generatorOptions,
195+
T generatorOptions,
196196
Root root,
197197
Indent indent,
198198
Enum anEnum, {
@@ -203,7 +203,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
203203
///
204204
/// Can be overridden to add extra code before/after apis.
205205
void writeDataClasses(
206-
PigeonInternalOptions generatorOptions,
206+
T generatorOptions,
207207
Root root,
208208
Indent indent, {
209209
required String dartPackageName,
@@ -221,15 +221,15 @@ abstract class StructuredGenerator<PigeonInternalOptions>
221221

222222
/// Writes the custom codec to [indent].
223223
void writeGeneralCodec(
224-
PigeonInternalOptions generatorOptions,
224+
T generatorOptions,
225225
Root root,
226226
Indent indent, {
227227
required String dartPackageName,
228228
});
229229

230230
/// Writes a single data class to [indent].
231231
void writeDataClass(
232-
PigeonInternalOptions generatorOptions,
232+
T generatorOptions,
233233
Root root,
234234
Indent indent,
235235
Class classDefinition, {
@@ -238,7 +238,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
238238

239239
/// Writes a single class encode method to [indent].
240240
void writeClassEncode(
241-
PigeonInternalOptions generatorOptions,
241+
T generatorOptions,
242242
Root root,
243243
Indent indent,
244244
Class classDefinition, {
@@ -247,7 +247,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
247247

248248
/// Writes a single class decode method to [indent].
249249
void writeClassDecode(
250-
PigeonInternalOptions generatorOptions,
250+
T generatorOptions,
251251
Root root,
252252
Indent indent,
253253
Class classDefinition, {
@@ -256,7 +256,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
256256

257257
/// Writes a single class decode method to [indent].
258258
void writeClassEquality(
259-
PigeonInternalOptions generatorOptions,
259+
T generatorOptions,
260260
Root root,
261261
Indent indent,
262262
Class classDefinition, {
@@ -267,7 +267,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
267267
///
268268
/// Can be overridden to add extra code before/after classes.
269269
void writeApis(
270-
PigeonInternalOptions generatorOptions,
270+
T generatorOptions,
271271
Root root,
272272
Indent indent, {
273273
required String dartPackageName,
@@ -312,7 +312,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
312312

313313
/// Writes a single Flutter Api to [indent].
314314
void writeFlutterApi(
315-
PigeonInternalOptions generatorOptions,
315+
T generatorOptions,
316316
Root root,
317317
Indent indent,
318318
AstFlutterApi api, {
@@ -321,7 +321,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
321321

322322
/// Writes a single Host Api to [indent].
323323
void writeHostApi(
324-
PigeonInternalOptions generatorOptions,
324+
T generatorOptions,
325325
Root root,
326326
Indent indent,
327327
AstHostApi api, {
@@ -330,7 +330,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
330330

331331
/// Writes the implementation of an `InstanceManager` to [indent].
332332
void writeInstanceManager(
333-
PigeonInternalOptions generatorOptions,
333+
T generatorOptions,
334334
Root root,
335335
Indent indent, {
336336
required String dartPackageName,
@@ -339,7 +339,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
339339
/// Writes the implementation of the API for the `InstanceManager` to
340340
/// [indent].
341341
void writeInstanceManagerApi(
342-
PigeonInternalOptions generatorOptions,
342+
T generatorOptions,
343343
Root root,
344344
Indent indent, {
345345
required String dartPackageName,
@@ -356,14 +356,14 @@ abstract class StructuredGenerator<PigeonInternalOptions>
356356
/// needs to create its own codec (it has methods/fields/constructor that use
357357
/// a data class) it should extend this codec and not `StandardMessageCodec`.
358358
void writeProxyApiBaseCodec(
359-
PigeonInternalOptions generatorOptions,
359+
T generatorOptions,
360360
Root root,
361361
Indent indent,
362362
) {}
363363

364364
/// Writes a single Proxy Api to [indent].
365365
void writeProxyApi(
366-
PigeonInternalOptions generatorOptions,
366+
T generatorOptions,
367367
Root root,
368368
Indent indent,
369369
AstProxyApi api, {
@@ -372,7 +372,7 @@ abstract class StructuredGenerator<PigeonInternalOptions>
372372

373373
/// Writes a single event channel Api to [indent].
374374
void writeEventChannelApi(
375-
PigeonInternalOptions generatorOptions,
375+
T generatorOptions,
376376
Root root,
377377
Indent indent,
378378
AstEventChannelApi api, {

packages/pigeon/lib/src/generator_tools.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'dart:mirrors';
1010
import 'package:yaml/yaml.dart' as yaml;
1111

1212
import 'ast.dart';
13+
import 'generator.dart';
1314

1415
/// The current version of pigeon.
1516
///
@@ -794,7 +795,7 @@ enum FileType {
794795
/// Options for [Generator]s that have multiple output file types.
795796
///
796797
/// Specifies which file to write as well as wraps all language options.
797-
class OutputFileOptions<T> {
798+
class OutputFileOptions<T extends InternalOptions> extends InternalOptions {
798799
/// Constructor.
799800
OutputFileOptions({required this.fileType, required this.languageOptions});
800801

packages/pigeon/lib/src/gobject/gobject_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class GObjectOptions {
7474
}
7575

7676
/// Options that control how GObject code will be generated.
77-
class InternalGObjectOptions extends PigeonInternalOptions {
77+
class InternalGObjectOptions extends InternalOptions {
7878
/// Creates a [InternalGObjectOptions] object
7979
const InternalGObjectOptions({
8080
required this.headerIncludePath,

packages/pigeon/lib/src/java/java_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class JavaOptions {
9090
}
9191

9292
/// Options that control how Java code will be generated.
93-
class InternalJavaOptions extends PigeonInternalOptions {
93+
class InternalJavaOptions extends InternalOptions {
9494
/// Creates a [InternalJavaOptions] object
9595
const InternalJavaOptions({
9696
required this.javaOut,

packages/pigeon/lib/src/kotlin/kotlin_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class KotlinOptions {
9999
}
100100

101101
///
102-
class InternalKotlinOptions extends PigeonInternalOptions {
102+
class InternalKotlinOptions extends InternalOptions {
103103
/// Creates a [InternalKotlinOptions] object
104104
const InternalKotlinOptions({
105105
this.package,

packages/pigeon/lib/src/objc/objc_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ObjcOptions {
9393
}
9494

9595
/// Options that control how Objective-C code will be generated.
96-
class InternalObjcOptions extends PigeonInternalOptions {
96+
class InternalObjcOptions extends InternalOptions {
9797
/// Parametric constructor for InternalObjcOptions.
9898
const InternalObjcOptions({
9999
required this.headerIncludePath,

packages/pigeon/lib/src/swift/swift_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class SwiftOptions {
7979
}
8080

8181
/// Options that control how Swift code will be generated.
82-
class InternalSwiftOptions extends PigeonInternalOptions {
82+
class InternalSwiftOptions extends InternalOptions {
8383
/// Creates a [InternalSwiftOptions] object
8484
const InternalSwiftOptions({
8585
this.copyrightHeader,

0 commit comments

Comments
 (0)