Skip to content

Commit 4ecf28c

Browse files
authored
feat(jsii): support multiple class declaration sites (#348)
Classes can have members added to them in multiple declarations. Combine all sites into a single class model.
1 parent aafd405 commit 4ecf28c

File tree

21 files changed

+1415
-9649
lines changed

21 files changed

+1415
-9649
lines changed

package-lock.json

Lines changed: 0 additions & 7667 deletions
This file was deleted.

packages/codemaker/package-lock.json

Lines changed: 207 additions & 661 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jsii-calc/lib/compliance.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,18 @@ export class JsiiAgent {
12341234
}
12351235
};
12361236

1237+
// To support module augmentation classes must support multiple declaration sites
1238+
// (the tail of which must be interfaces)
1239+
export class AugmentableClass {
1240+
public methodOne(): void {
1241+
console.log('methodOne');
1242+
}
1243+
}
1244+
1245+
export interface AugmentableClass {
1246+
methodTwo(): void;
1247+
}
1248+
12371249
// Ensure the JSII kernel tags instances with the "most appropriate" FQN type label, so that runtimes are able to
12381250
// correctly choose the implementation proxy that should be used. Failure to do so could cause situations where userland
12391251
// needs to up-cast an instance to an incompatible type, which certain runtimes (such as Java) will prevent.

packages/jsii-calc/test/assembly.jsii

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,23 @@
735735
],
736736
"name": "AsyncVirtualMethods"
737737
},
738+
"jsii-calc.AugmentableClass": {
739+
"assembly": "jsii-calc",
740+
"fqn": "jsii-calc.AugmentableClass",
741+
"initializer": {
742+
"initializer": true
743+
},
744+
"kind": "class",
745+
"methods": [
746+
{
747+
"name": "methodOne"
748+
},
749+
{
750+
"name": "methodTwo"
751+
}
752+
],
753+
"name": "AugmentableClass"
754+
},
738755
"jsii-calc.BinaryOperation": {
739756
"abstract": true,
740757
"assembly": "jsii-calc",
@@ -3825,5 +3842,5 @@
38253842
}
38263843
},
38273844
"version": "0.7.13",
3828-
"fingerprint": "WNp0Sw1d2+3FaQD0Fn01K4wYQi7Ms3w+NQatOylD1kM="
3845+
"fingerprint": "aAWhjTLeZrF20RGP+ziDi3xp7D9syctn1izqVdgXi7E="
38293846
}

packages/jsii-pacmak/package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,23 @@
735735
],
736736
"name": "AsyncVirtualMethods"
737737
},
738+
"jsii-calc.AugmentableClass": {
739+
"assembly": "jsii-calc",
740+
"fqn": "jsii-calc.AugmentableClass",
741+
"initializer": {
742+
"initializer": true
743+
},
744+
"kind": "class",
745+
"methods": [
746+
{
747+
"name": "methodOne"
748+
},
749+
{
750+
"name": "methodTwo"
751+
}
752+
],
753+
"name": "AugmentableClass"
754+
},
738755
"jsii-calc.BinaryOperation": {
739756
"abstract": true,
740757
"assembly": "jsii-calc",
@@ -3825,5 +3842,5 @@
38253842
}
38263843
},
38273844
"version": "0.7.13",
3828-
"fingerprint": "WNp0Sw1d2+3FaQD0Fn01K4wYQi7Ms3w+NQatOylD1kM="
3845+
"fingerprint": "aAWhjTLeZrF20RGP+ziDi3xp7D9syctn1izqVdgXi7E="
38293846
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiClass(typeof(AugmentableClass), "jsii-calc.AugmentableClass", "[]")]
6+
public class AugmentableClass : DeputyBase
7+
{
8+
public AugmentableClass(): base(new DeputyProps(new object[]{}))
9+
{
10+
}
11+
12+
protected AugmentableClass(ByRefValue reference): base(reference)
13+
{
14+
}
15+
16+
protected AugmentableClass(DeputyProps props): base(props)
17+
{
18+
}
19+
20+
[JsiiMethod("methodOne", null, "[]")]
21+
public virtual void MethodOne()
22+
{
23+
InvokeInstanceVoidMethod(new object[]{});
24+
}
25+
26+
[JsiiMethod("methodTwo", null, "[]")]
27+
public virtual void MethodTwo()
28+
{
29+
InvokeInstanceVoidMethod(new object[]{});
30+
}
31+
}
32+
}

packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
2626
case "jsii-calc.AllTypesEnum": return software.amazon.jsii.tests.calculator.AllTypesEnum.class;
2727
case "jsii-calc.AllowedMethodNames": return software.amazon.jsii.tests.calculator.AllowedMethodNames.class;
2828
case "jsii-calc.AsyncVirtualMethods": return software.amazon.jsii.tests.calculator.AsyncVirtualMethods.class;
29+
case "jsii-calc.AugmentableClass": return software.amazon.jsii.tests.calculator.AugmentableClass.class;
2930
case "jsii-calc.BinaryOperation": return software.amazon.jsii.tests.calculator.BinaryOperation.class;
3031
case "jsii-calc.Calculator": return software.amazon.jsii.tests.calculator.Calculator.class;
3132
case "jsii-calc.CalculatorProps": return software.amazon.jsii.tests.calculator.CalculatorProps.class;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package software.amazon.jsii.tests.calculator;
2+
3+
@javax.annotation.Generated(value = "jsii-pacmak")
4+
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.AugmentableClass")
5+
public class AugmentableClass extends software.amazon.jsii.JsiiObject {
6+
protected AugmentableClass(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
7+
super(mode);
8+
}
9+
public AugmentableClass() {
10+
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii);
11+
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this);
12+
}
13+
14+
public void methodOne() {
15+
this.jsiiCall("methodOne", Void.class);
16+
}
17+
18+
public void methodTwo() {
19+
this.jsiiCall("methodTwo", Void.class);
20+
}
21+
}

packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,42 @@ AsyncVirtualMethods
673673
:rtype: number
674674

675675

676+
AugmentableClass
677+
^^^^^^^^^^^^^^^^
678+
679+
.. py:class:: AugmentableClass()
680+
681+
**Language-specific names:**
682+
683+
.. tabs::
684+
685+
.. code-tab:: c#
686+
687+
using Amazon.JSII.Tests.CalculatorNamespace;
688+
689+
.. code-tab:: java
690+
691+
import software.amazon.jsii.tests.calculator.AugmentableClass;
692+
693+
.. code-tab:: javascript
694+
695+
const { AugmentableClass } = require('jsii-calc');
696+
697+
.. code-tab:: typescript
698+
699+
import { AugmentableClass } from 'jsii-calc';
700+
701+
702+
703+
704+
.. py:method:: methodOne()
705+
706+
707+
708+
.. py:method:: methodTwo()
709+
710+
711+
676712
BinaryOperation
677713
^^^^^^^^^^^^^^^
678714

0 commit comments

Comments
 (0)