@@ -2,18 +2,16 @@ package wrappers
2
2
3
3
import (
4
4
"fmt"
5
- "iter"
6
5
"log/slog"
7
6
"strings"
8
7
9
8
"github.com/gost-dom/code-gen/customrules"
10
9
. "github.com/gost-dom/code-gen/internal"
11
- "github.com/gost-dom/code-gen/packagenames"
12
10
"github.com/gost-dom/code-gen/script-wrappers/configuration"
11
+ . "github.com/gost-dom/code-gen/script-wrappers/model"
13
12
"github.com/gost-dom/code-gen/stdgen"
14
13
g "github.com/gost-dom/generators"
15
14
"github.com/gost-dom/webref/idl"
16
- legacy "github.com/gost-dom/webref/idl/legacy"
17
15
18
16
"github.com/dave/jennifer/jen"
19
17
)
@@ -175,145 +173,6 @@ func createOperation(
175
173
return op
176
174
}
177
175
178
- type ESOperationArgument struct {
179
- Name string
180
- Type string
181
- Optional bool
182
- Variadic bool
183
- IdlType legacy.IdlTypes
184
- ArgumentSpec configuration.ESMethodArgument
185
- Ignore bool
186
- }
187
-
188
- func (a ESOperationArgument ) OptionalInGo () bool {
189
- hasDefault := a .ArgumentSpec .HasDefault
190
- return a .Optional && ! hasDefault
191
- }
192
-
193
- func (a ESOperationArgument ) DefaultValueInGo () (name string , ok bool ) {
194
- ok = a .Optional && a .ArgumentSpec .HasDefault
195
- if defaultValue := a .ArgumentSpec .DefaultValue ; defaultValue != "" {
196
- name = defaultValue
197
- } else {
198
- name = fmt .Sprintf ("default%s" , a .Type )
199
- }
200
- return
201
- }
202
-
203
- type ESOperation struct {
204
- Name string
205
- NotImplemented bool
206
- RetType idl.RetType
207
- HasError bool
208
- CustomImplementation bool
209
- MethodCustomization configuration.ESMethodWrapper
210
- Arguments []ESOperationArgument
211
- }
212
-
213
- func (o ESOperation ) CallbackMethodName () string {
214
- return idl .SanitizeName (o .Name )
215
- }
216
-
217
- func (op ESOperation ) GetHasError () bool {
218
- return op .HasError
219
- }
220
-
221
- func (op ESOperation ) HasResult () bool {
222
- return op .RetType .IsDefined ()
223
- }
224
-
225
- func (o ESOperation ) Encoder () string {
226
- if e := o .MethodCustomization .Encoder ; e != "" {
227
- return e
228
- }
229
- converter := "to"
230
- if o .RetType .Nullable {
231
- converter += "Nullable"
232
- }
233
- converter += idlNameToGoName (o .RetType .TypeName )
234
- return converter
235
- }
236
-
237
- type ESAttribute struct {
238
- Name string
239
- Getter * ESOperation
240
- Setter * ESOperation
241
- }
242
-
243
- type ESConstructorData struct {
244
- Spec * configuration.IdlInterfaceConfiguration
245
- IdlInterface idl.Interface
246
- IdlInterfaceName string
247
- Inheritance string
248
- Operations []ESOperation
249
- Attributes []ESAttribute
250
- Constructor * ESOperation
251
- RunCustomCode bool
252
- }
253
-
254
- // Return the idl mixin interfaces included in this interface AND that has been
255
- // included in the configuration
256
- func (d ESConstructorData ) Includes () []idl.Interface {
257
- var result []idl.Interface
258
- for _ , i := range d .IdlInterface .Includes {
259
- if _ , configured := d .Spec .DomSpec .Interfaces [i .Name ]; configured {
260
- result = append (result , i )
261
- }
262
- }
263
- return result
264
- }
265
-
266
- func (d ESConstructorData ) GetInternalPackage () string {
267
- if d .Name () == "Event" {
268
- return packagenames .Events
269
- }
270
- return packagenames .PackageName (d .Spec .DomSpec .Name )
271
- }
272
-
273
- func (d ESConstructorData ) WrapperFunctionsToInstall () iter.Seq [ESOperation ] {
274
- return func (yield func (ESOperation ) bool ) {
275
- for _ , op := range d .Operations {
276
- if ! op .MethodCustomization .Ignored && ! yield (op ) {
277
- return
278
- }
279
- }
280
- }
281
- }
282
-
283
- func (d ESConstructorData ) AttributesToInstall () iter.Seq [ESAttribute ] {
284
- return func (yield func (ESAttribute ) bool ) {
285
- for _ , a := range d .Attributes {
286
- if ! yield (a ) {
287
- return
288
- }
289
- }
290
- }
291
- }
292
-
293
- func (d ESConstructorData ) WrapperFunctionsToGenerate () iter.Seq [ESOperation ] {
294
- return func (yield func (ESOperation ) bool ) {
295
- for op := range d .WrapperFunctionsToInstall () {
296
- if ! op .MethodCustomization .CustomImplementation && ! yield (op ) {
297
- return
298
- }
299
- }
300
- for _ , a := range d .Attributes {
301
- if a .Getter != nil && ! a .Getter .CustomImplementation {
302
- if ! yield (* a .Getter ) {
303
- return
304
- }
305
- }
306
- if a .Setter != nil && ! a .Setter .CustomImplementation {
307
- if ! yield (* a .Setter ) {
308
- return
309
- }
310
- }
311
- }
312
- }
313
- }
314
-
315
- func (d ESConstructorData ) Name () string { return d .Spec .TypeName }
316
-
317
176
func ReturnOnAnyError (errNames []g.Generator ) g.Generator {
318
177
if len (errNames ) == 0 {
319
178
return g .Noop
0 commit comments