Skip to content

Commit 1c56902

Browse files
authored
fix(jsii): use base interfaces for 'datatype' property (#265)
If an interface inherits from a non-datatype interface, it should no longer be classified as a datatype interface itself. Making this change requires that information about the base classes has already been determined, so I introduced an ordering mechanism for 'deferred's. Fixes #264.
1 parent a7e0566 commit 1c56902

File tree

12 files changed

+483
-36
lines changed

12 files changed

+483
-36
lines changed

packages/jsii-calc/lib/compliance.ts

+13
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,16 @@ export class ClassWithPrivateConstructorAndAutomaticProperties implements IInter
926926
private constructor(public readonly readOnlyString: string, public readWriteString: string) {
927927
}
928928
}
929+
930+
export interface IInterfaceWithMethods {
931+
readonly value: string;
932+
doThings(): void;
933+
}
934+
935+
/**
936+
* Even though this interface has only properties, it is disqualified from being a datatype
937+
* because it inherits from an interface that is not a datatype.
938+
*/
939+
export interface IInterfaceThatShouldNotBeADataType extends IInterfaceWithMethods {
940+
readonly otherValue: string;
941+
}

packages/jsii-calc/test/assembly.jsii

+47-1
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,52 @@
14521452
"kind": "interface",
14531453
"name": "IFriendlyRandomGenerator"
14541454
},
1455+
"jsii-calc.IInterfaceThatShouldNotBeADataType": {
1456+
"assembly": "jsii-calc",
1457+
"docs": {
1458+
"comment": "Even though this interface has only properties, it is disqualified from being a datatype\nbecause it inherits from an interface that is not a datatype."
1459+
},
1460+
"fqn": "jsii-calc.IInterfaceThatShouldNotBeADataType",
1461+
"interfaces": [
1462+
{
1463+
"fqn": "jsii-calc.IInterfaceWithMethods"
1464+
}
1465+
],
1466+
"kind": "interface",
1467+
"name": "IInterfaceThatShouldNotBeADataType",
1468+
"properties": [
1469+
{
1470+
"abstract": true,
1471+
"immutable": true,
1472+
"name": "otherValue",
1473+
"type": {
1474+
"primitive": "string"
1475+
}
1476+
}
1477+
]
1478+
},
1479+
"jsii-calc.IInterfaceWithMethods": {
1480+
"assembly": "jsii-calc",
1481+
"fqn": "jsii-calc.IInterfaceWithMethods",
1482+
"kind": "interface",
1483+
"methods": [
1484+
{
1485+
"abstract": true,
1486+
"name": "doThings"
1487+
}
1488+
],
1489+
"name": "IInterfaceWithMethods",
1490+
"properties": [
1491+
{
1492+
"abstract": true,
1493+
"immutable": true,
1494+
"name": "value",
1495+
"type": {
1496+
"primitive": "string"
1497+
}
1498+
}
1499+
]
1500+
},
14551501
"jsii-calc.IInterfaceWithProperties": {
14561502
"assembly": "jsii-calc",
14571503
"datatype": true,
@@ -3355,5 +3401,5 @@
33553401
}
33563402
},
33573403
"version": "0.7.7",
3358-
"fingerprint": "16f4wL/B1M7rOOzyAzBEtqlOi2GYhDAU5rctonoha5Y="
3404+
"fingerprint": "vJH1gHlpRxKo77e0kE+6KATwgsZB0VpBcFEo/9OIG7Q="
33593405
}

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

+47-1
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,52 @@
14521452
"kind": "interface",
14531453
"name": "IFriendlyRandomGenerator"
14541454
},
1455+
"jsii-calc.IInterfaceThatShouldNotBeADataType": {
1456+
"assembly": "jsii-calc",
1457+
"docs": {
1458+
"comment": "Even though this interface has only properties, it is disqualified from being a datatype\nbecause it inherits from an interface that is not a datatype."
1459+
},
1460+
"fqn": "jsii-calc.IInterfaceThatShouldNotBeADataType",
1461+
"interfaces": [
1462+
{
1463+
"fqn": "jsii-calc.IInterfaceWithMethods"
1464+
}
1465+
],
1466+
"kind": "interface",
1467+
"name": "IInterfaceThatShouldNotBeADataType",
1468+
"properties": [
1469+
{
1470+
"abstract": true,
1471+
"immutable": true,
1472+
"name": "otherValue",
1473+
"type": {
1474+
"primitive": "string"
1475+
}
1476+
}
1477+
]
1478+
},
1479+
"jsii-calc.IInterfaceWithMethods": {
1480+
"assembly": "jsii-calc",
1481+
"fqn": "jsii-calc.IInterfaceWithMethods",
1482+
"kind": "interface",
1483+
"methods": [
1484+
{
1485+
"abstract": true,
1486+
"name": "doThings"
1487+
}
1488+
],
1489+
"name": "IInterfaceWithMethods",
1490+
"properties": [
1491+
{
1492+
"abstract": true,
1493+
"immutable": true,
1494+
"name": "value",
1495+
"type": {
1496+
"primitive": "string"
1497+
}
1498+
}
1499+
]
1500+
},
14551501
"jsii-calc.IInterfaceWithProperties": {
14561502
"assembly": "jsii-calc",
14571503
"datatype": true,
@@ -3355,5 +3401,5 @@
33553401
}
33563402
},
33573403
"version": "0.7.7",
3358-
"fingerprint": "16f4wL/B1M7rOOzyAzBEtqlOi2GYhDAU5rctonoha5Y="
3404+
"fingerprint": "vJH1gHlpRxKo77e0kE+6KATwgsZB0VpBcFEo/9OIG7Q="
33593405
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
/// <summary>
6+
/// Even though this interface has only properties, it is disqualified from being a datatype
7+
/// because it inherits from an interface that is not a datatype.
8+
/// </summary>
9+
[JsiiInterface(typeof(IIInterfaceThatShouldNotBeADataType), "jsii-calc.IInterfaceThatShouldNotBeADataType")]
10+
public interface IIInterfaceThatShouldNotBeADataType : IIInterfaceWithMethods
11+
{
12+
[JsiiProperty("otherValue", "{\"primitive\":\"string\"}")]
13+
string OtherValue
14+
{
15+
get;
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiInterface(typeof(IIInterfaceWithMethods), "jsii-calc.IInterfaceWithMethods")]
6+
public interface IIInterfaceWithMethods
7+
{
8+
[JsiiProperty("value", "{\"primitive\":\"string\"}")]
9+
string Value
10+
{
11+
get;
12+
}
13+
14+
[JsiiMethod("doThings", null, "[]")]
15+
void DoThings();
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
/// <summary>
6+
/// Even though this interface has only properties, it is disqualified from being a datatype
7+
/// because it inherits from an interface that is not a datatype.
8+
/// </summary>
9+
[JsiiTypeProxy(typeof(IIInterfaceThatShouldNotBeADataType), "jsii-calc.IInterfaceThatShouldNotBeADataType")]
10+
internal sealed class IInterfaceThatShouldNotBeADataTypeProxy : DeputyBase, IIInterfaceThatShouldNotBeADataType
11+
{
12+
private IInterfaceThatShouldNotBeADataTypeProxy(ByRefValue reference): base(reference)
13+
{
14+
}
15+
16+
[JsiiProperty("otherValue", "{\"primitive\":\"string\"}")]
17+
public string OtherValue
18+
{
19+
get => GetInstanceProperty<string>();
20+
}
21+
22+
[JsiiProperty("value", "{\"primitive\":\"string\"}")]
23+
public string Value
24+
{
25+
get => GetInstanceProperty<string>();
26+
}
27+
28+
[JsiiMethod("doThings", null, "[]")]
29+
public void DoThings()
30+
{
31+
InvokeInstanceVoidMethod(new object[]{});
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiTypeProxy(typeof(IIInterfaceWithMethods), "jsii-calc.IInterfaceWithMethods")]
6+
internal sealed class IInterfaceWithMethodsProxy : DeputyBase, IIInterfaceWithMethods
7+
{
8+
private IInterfaceWithMethodsProxy(ByRefValue reference): base(reference)
9+
{
10+
}
11+
12+
[JsiiProperty("value", "{\"primitive\":\"string\"}")]
13+
public string Value
14+
{
15+
get => GetInstanceProperty<string>();
16+
}
17+
18+
[JsiiMethod("doThings", null, "[]")]
19+
public void DoThings()
20+
{
21+
InvokeInstanceVoidMethod(new object[]{});
22+
}
23+
}
24+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
4040
case "jsii-calc.GiveMeStructs": return software.amazon.jsii.tests.calculator.GiveMeStructs.class;
4141
case "jsii-calc.IFriendlier": return software.amazon.jsii.tests.calculator.IFriendlier.class;
4242
case "jsii-calc.IFriendlyRandomGenerator": return software.amazon.jsii.tests.calculator.IFriendlyRandomGenerator.class;
43+
case "jsii-calc.IInterfaceThatShouldNotBeADataType": return software.amazon.jsii.tests.calculator.IInterfaceThatShouldNotBeADataType.class;
44+
case "jsii-calc.IInterfaceWithMethods": return software.amazon.jsii.tests.calculator.IInterfaceWithMethods.class;
4345
case "jsii-calc.IInterfaceWithProperties": return software.amazon.jsii.tests.calculator.IInterfaceWithProperties.class;
4446
case "jsii-calc.IInterfaceWithPropertiesExtension": return software.amazon.jsii.tests.calculator.IInterfaceWithPropertiesExtension.class;
4547
case "jsii-calc.IRandomNumberGenerator": return software.amazon.jsii.tests.calculator.IRandomNumberGenerator.class;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package software.amazon.jsii.tests.calculator;
2+
3+
/**
4+
* Even though this interface has only properties, it is disqualified from being a datatype
5+
* because it inherits from an interface that is not a datatype.
6+
*/
7+
@javax.annotation.Generated(value = "jsii-pacmak")
8+
public interface IInterfaceThatShouldNotBeADataType extends software.amazon.jsii.JsiiSerializable, software.amazon.jsii.tests.calculator.IInterfaceWithMethods {
9+
java.lang.String getOtherValue();
10+
11+
/**
12+
* A proxy class which represents a concrete javascript instance of this type.
13+
*/
14+
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IInterfaceThatShouldNotBeADataType {
15+
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
16+
super(mode);
17+
}
18+
19+
@Override
20+
public java.lang.String getOtherValue() {
21+
return this.jsiiGet("otherValue", java.lang.String.class);
22+
}
23+
24+
@Override
25+
public java.lang.String getValue() {
26+
return this.jsiiGet("value", java.lang.String.class);
27+
}
28+
29+
@Override
30+
public void doThings() {
31+
this.jsiiCall("doThings", Void.class);
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package software.amazon.jsii.tests.calculator;
2+
3+
@javax.annotation.Generated(value = "jsii-pacmak")
4+
public interface IInterfaceWithMethods extends software.amazon.jsii.JsiiSerializable {
5+
java.lang.String getValue();
6+
void doThings();
7+
8+
/**
9+
* A proxy class which represents a concrete javascript instance of this type.
10+
*/
11+
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IInterfaceWithMethods {
12+
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
13+
super(mode);
14+
}
15+
16+
@Override
17+
public java.lang.String getValue() {
18+
return this.jsiiGet("value", java.lang.String.class);
19+
}
20+
21+
@Override
22+
public void doThings() {
23+
this.jsiiCall("doThings", Void.class);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)