@@ -277,6 +277,7 @@ interface BaseMethodOpts {
277
277
278
278
interface BaseMethodEmitOpts {
279
279
renderAbstract ?: boolean ;
280
+ forceEmitBody ?: boolean ;
280
281
}
281
282
282
283
abstract class BaseMethod implements PythonBase {
@@ -285,10 +286,11 @@ abstract class BaseMethod implements PythonBase {
285
286
public readonly abstract : boolean ;
286
287
287
288
protected readonly abstract implicitParameter : string ;
288
- protected readonly jsiiMethod ? : string ;
289
+ protected readonly jsiiMethod : string ;
289
290
protected readonly decorator ?: string ;
290
291
protected readonly classAsFirstParameter : boolean = false ;
291
292
protected readonly returnFromJSIIMethod : boolean = true ;
293
+ protected readonly shouldEmitBody : boolean = true ;
292
294
293
295
private readonly jsName ?: string ;
294
296
private readonly parameters : spec . Parameter [ ] ;
@@ -313,7 +315,7 @@ abstract class BaseMethod implements PythonBase {
313
315
}
314
316
315
317
public emit ( code : CodeMaker , resolver : TypeResolver , opts ?: BaseMethodEmitOpts ) {
316
- const { renderAbstract = true } = opts || { } ;
318
+ const { renderAbstract = true , forceEmitBody = false } = opts || { } ;
317
319
318
320
let returnType : string ;
319
321
if ( this . returns !== undefined ) {
@@ -420,12 +422,12 @@ abstract class BaseMethod implements PythonBase {
420
422
}
421
423
422
424
code . openBlock ( `def ${ this . name } (${ pythonParams . join ( ", " ) } ) -> ${ returnType } ` ) ;
423
- this . emitBody ( code , resolver , renderAbstract ) ;
425
+ this . emitBody ( code , resolver , renderAbstract , forceEmitBody ) ;
424
426
code . closeBlock ( ) ;
425
427
}
426
428
427
- private emitBody ( code : CodeMaker , resolver : TypeResolver , renderAbstract : boolean ) {
428
- if ( this . jsiiMethod === undefined || ( renderAbstract && this . abstract ) ) {
429
+ private emitBody ( code : CodeMaker , resolver : TypeResolver , renderAbstract : boolean , forceEmitBody : boolean ) {
430
+ if ( ( ! this . shouldEmitBody && ! forceEmitBody ) || ( renderAbstract && this . abstract ) ) {
429
431
code . line ( "..." ) ;
430
432
} else {
431
433
if ( this . liftedProp !== undefined ) {
@@ -498,6 +500,7 @@ interface BasePropertyOpts {
498
500
499
501
interface BasePropertyEmitOpts {
500
502
renderAbstract ?: boolean ;
503
+ forceEmitBody ?: boolean ;
501
504
}
502
505
503
506
abstract class BaseProperty implements PythonBase {
@@ -507,8 +510,9 @@ abstract class BaseProperty implements PythonBase {
507
510
508
511
protected readonly abstract decorator : string ;
509
512
protected readonly abstract implicitParameter : string ;
510
- protected readonly jsiiGetMethod ?: string ;
511
- protected readonly jsiiSetMethod ?: string ;
513
+ protected readonly jsiiGetMethod : string ;
514
+ protected readonly jsiiSetMethod : string ;
515
+ protected readonly shouldEmitBody : boolean = true ;
512
516
513
517
private readonly jsName : string ;
514
518
private readonly type : spec . TypeReference ;
@@ -528,7 +532,7 @@ abstract class BaseProperty implements PythonBase {
528
532
}
529
533
530
534
public emit ( code : CodeMaker , resolver : TypeResolver , opts ?: BasePropertyEmitOpts ) {
531
- const { renderAbstract = true } = opts || { } ;
535
+ const { renderAbstract = true , forceEmitBody = false } = opts || { } ;
532
536
const pythonType = resolver . resolve ( this . type , { forwardReferences : false } ) ;
533
537
534
538
code . line ( `@${ this . decorator } ` ) ;
@@ -537,7 +541,7 @@ abstract class BaseProperty implements PythonBase {
537
541
code . line ( "@abc.abstractmethod" ) ;
538
542
}
539
543
code . openBlock ( `def ${ this . name } (${ this . implicitParameter } ) -> ${ pythonType } ` ) ;
540
- if ( this . jsiiGetMethod !== undefined && ( ! renderAbstract || ! this . abstract ) ) {
544
+ if ( ( this . shouldEmitBody || forceEmitBody ) && ( ! renderAbstract || ! this . abstract ) ) {
541
545
code . line ( `return jsii.${ this . jsiiGetMethod } (${ this . implicitParameter } , "${ this . jsName } ")` ) ;
542
546
} else {
543
547
code . line ( "..." ) ;
@@ -550,7 +554,7 @@ abstract class BaseProperty implements PythonBase {
550
554
code . line ( "@abc.abstractmethod" ) ;
551
555
}
552
556
code . openBlock ( `def ${ this . name } (${ this . implicitParameter } , value: ${ pythonType } )` ) ;
553
- if ( this . jsiiSetMethod !== undefined && ( ! renderAbstract || ! this . abstract ) ) {
557
+ if ( ( this . shouldEmitBody || forceEmitBody ) && ( ! renderAbstract || ! this . abstract ) ) {
554
558
code . line ( `return jsii.${ this . jsiiSetMethod } (${ this . implicitParameter } , "${ this . jsName } ", value)` ) ;
555
559
} else {
556
560
code . line ( "..." ) ;
@@ -562,6 +566,29 @@ abstract class BaseProperty implements PythonBase {
562
566
563
567
class Interface extends BasePythonClassType {
564
568
569
+ public emit ( code : CodeMaker , resolver : TypeResolver ) {
570
+ code . line ( `@jsii.interface(jsii_type="${ this . fqn } ")` ) ;
571
+
572
+ // First we do our normal class logic for emitting our members.
573
+ super . emit ( code , resolver ) ;
574
+
575
+ // Then, we have to emit a Proxy class which implements our proxy interface.
576
+ resolver = this . fqn ? resolver . bind ( this . fqn ) : resolver ;
577
+ const proxyBases : string [ ] = this . bases . map ( b => `jsii.proxy_for(${ resolver . resolve ( b ) } )` ) ;
578
+ code . openBlock ( `class ${ this . getProxyClassName ( ) } (${ proxyBases . join ( ", " ) } )` ) ;
579
+ code . line ( `__jsii_type__ = "${ this . fqn } "` ) ;
580
+
581
+ if ( this . members . length > 0 ) {
582
+ for ( const member of this . members ) {
583
+ member . emit ( code , resolver , { forceEmitBody : true } ) ;
584
+ }
585
+ } else {
586
+ code . line ( "pass" ) ;
587
+ }
588
+
589
+ code . closeBlock ( ) ;
590
+ }
591
+
565
592
protected getClassParams ( resolver : TypeResolver ) : string [ ] {
566
593
const params : string [ ] = this . bases . map ( b => resolver . resolve ( b ) ) ;
567
594
@@ -570,15 +597,31 @@ class Interface extends BasePythonClassType {
570
597
return params ;
571
598
}
572
599
600
+ protected emitPreamble ( code : CodeMaker , _resolver : TypeResolver ) {
601
+ code . line ( "@staticmethod" ) ;
602
+ code . openBlock ( "def __jsii_proxy_class__()" ) ;
603
+ code . line ( `return ${ this . getProxyClassName ( ) } ` ) ;
604
+ code . closeBlock ( ) ;
605
+ }
606
+
607
+ private getProxyClassName ( ) : string {
608
+ return `_${ this . name } Proxy` ;
609
+ }
610
+
573
611
}
574
612
575
613
class InterfaceMethod extends BaseMethod {
576
614
protected readonly implicitParameter : string = "self" ;
615
+ protected readonly jsiiMethod : string = "invoke" ;
616
+ protected readonly shouldEmitBody : boolean = false ;
577
617
}
578
618
579
619
class InterfaceProperty extends BaseProperty {
580
620
protected readonly decorator : string = "property" ;
581
621
protected readonly implicitParameter : string = "self" ;
622
+ protected readonly jsiiGetMethod : string = "get" ;
623
+ protected readonly jsiiSetMethod : string = "set" ;
624
+ protected readonly shouldEmitBody : boolean = false ;
582
625
}
583
626
584
627
class TypedDict extends BasePythonClassType {
0 commit comments