Skip to content

Commit

Permalink
fix(jsii): use base interfaces for 'datatype' property (#265)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr authored Oct 16, 2018
1 parent a7e0566 commit 1c56902
Show file tree
Hide file tree
Showing 12 changed files with 483 additions and 36 deletions.
13 changes: 13 additions & 0 deletions packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,3 +926,16 @@ export class ClassWithPrivateConstructorAndAutomaticProperties implements IInter
private constructor(public readonly readOnlyString: string, public readWriteString: string) {
}
}

export interface IInterfaceWithMethods {
readonly value: string;
doThings(): void;
}

/**
* Even though this interface has only properties, it is disqualified from being a datatype
* because it inherits from an interface that is not a datatype.
*/
export interface IInterfaceThatShouldNotBeADataType extends IInterfaceWithMethods {
readonly otherValue: string;
}
48 changes: 47 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,52 @@
"kind": "interface",
"name": "IFriendlyRandomGenerator"
},
"jsii-calc.IInterfaceThatShouldNotBeADataType": {
"assembly": "jsii-calc",
"docs": {
"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."
},
"fqn": "jsii-calc.IInterfaceThatShouldNotBeADataType",
"interfaces": [
{
"fqn": "jsii-calc.IInterfaceWithMethods"
}
],
"kind": "interface",
"name": "IInterfaceThatShouldNotBeADataType",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "otherValue",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IInterfaceWithMethods": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IInterfaceWithMethods",
"kind": "interface",
"methods": [
{
"abstract": true,
"name": "doThings"
}
],
"name": "IInterfaceWithMethods",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "value",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IInterfaceWithProperties": {
"assembly": "jsii-calc",
"datatype": true,
Expand Down Expand Up @@ -3355,5 +3401,5 @@
}
},
"version": "0.7.7",
"fingerprint": "16f4wL/B1M7rOOzyAzBEtqlOi2GYhDAU5rctonoha5Y="
"fingerprint": "vJH1gHlpRxKo77e0kE+6KATwgsZB0VpBcFEo/9OIG7Q="
}
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,52 @@
"kind": "interface",
"name": "IFriendlyRandomGenerator"
},
"jsii-calc.IInterfaceThatShouldNotBeADataType": {
"assembly": "jsii-calc",
"docs": {
"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."
},
"fqn": "jsii-calc.IInterfaceThatShouldNotBeADataType",
"interfaces": [
{
"fqn": "jsii-calc.IInterfaceWithMethods"
}
],
"kind": "interface",
"name": "IInterfaceThatShouldNotBeADataType",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "otherValue",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IInterfaceWithMethods": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IInterfaceWithMethods",
"kind": "interface",
"methods": [
{
"abstract": true,
"name": "doThings"
}
],
"name": "IInterfaceWithMethods",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "value",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IInterfaceWithProperties": {
"assembly": "jsii-calc",
"datatype": true,
Expand Down Expand Up @@ -3355,5 +3401,5 @@
}
},
"version": "0.7.7",
"fingerprint": "16f4wL/B1M7rOOzyAzBEtqlOi2GYhDAU5rctonoha5Y="
"fingerprint": "vJH1gHlpRxKo77e0kE+6KATwgsZB0VpBcFEo/9OIG7Q="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
/// <summary>
/// Even though this interface has only properties, it is disqualified from being a datatype
/// because it inherits from an interface that is not a datatype.
/// </summary>
[JsiiInterface(typeof(IIInterfaceThatShouldNotBeADataType), "jsii-calc.IInterfaceThatShouldNotBeADataType")]
public interface IIInterfaceThatShouldNotBeADataType : IIInterfaceWithMethods
{
[JsiiProperty("otherValue", "{\"primitive\":\"string\"}")]
string OtherValue
{
get;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
[JsiiInterface(typeof(IIInterfaceWithMethods), "jsii-calc.IInterfaceWithMethods")]
public interface IIInterfaceWithMethods
{
[JsiiProperty("value", "{\"primitive\":\"string\"}")]
string Value
{
get;
}

[JsiiMethod("doThings", null, "[]")]
void DoThings();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
/// <summary>
/// Even though this interface has only properties, it is disqualified from being a datatype
/// because it inherits from an interface that is not a datatype.
/// </summary>
[JsiiTypeProxy(typeof(IIInterfaceThatShouldNotBeADataType), "jsii-calc.IInterfaceThatShouldNotBeADataType")]
internal sealed class IInterfaceThatShouldNotBeADataTypeProxy : DeputyBase, IIInterfaceThatShouldNotBeADataType
{
private IInterfaceThatShouldNotBeADataTypeProxy(ByRefValue reference): base(reference)
{
}

[JsiiProperty("otherValue", "{\"primitive\":\"string\"}")]
public string OtherValue
{
get => GetInstanceProperty<string>();
}

[JsiiProperty("value", "{\"primitive\":\"string\"}")]
public string Value
{
get => GetInstanceProperty<string>();
}

[JsiiMethod("doThings", null, "[]")]
public void DoThings()
{
InvokeInstanceVoidMethod(new object[]{});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
[JsiiTypeProxy(typeof(IIInterfaceWithMethods), "jsii-calc.IInterfaceWithMethods")]
internal sealed class IInterfaceWithMethodsProxy : DeputyBase, IIInterfaceWithMethods
{
private IInterfaceWithMethodsProxy(ByRefValue reference): base(reference)
{
}

[JsiiProperty("value", "{\"primitive\":\"string\"}")]
public string Value
{
get => GetInstanceProperty<string>();
}

[JsiiMethod("doThings", null, "[]")]
public void DoThings()
{
InvokeInstanceVoidMethod(new object[]{});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
case "jsii-calc.GiveMeStructs": return software.amazon.jsii.tests.calculator.GiveMeStructs.class;
case "jsii-calc.IFriendlier": return software.amazon.jsii.tests.calculator.IFriendlier.class;
case "jsii-calc.IFriendlyRandomGenerator": return software.amazon.jsii.tests.calculator.IFriendlyRandomGenerator.class;
case "jsii-calc.IInterfaceThatShouldNotBeADataType": return software.amazon.jsii.tests.calculator.IInterfaceThatShouldNotBeADataType.class;
case "jsii-calc.IInterfaceWithMethods": return software.amazon.jsii.tests.calculator.IInterfaceWithMethods.class;
case "jsii-calc.IInterfaceWithProperties": return software.amazon.jsii.tests.calculator.IInterfaceWithProperties.class;
case "jsii-calc.IInterfaceWithPropertiesExtension": return software.amazon.jsii.tests.calculator.IInterfaceWithPropertiesExtension.class;
case "jsii-calc.IRandomNumberGenerator": return software.amazon.jsii.tests.calculator.IRandomNumberGenerator.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package software.amazon.jsii.tests.calculator;

/**
* Even though this interface has only properties, it is disqualified from being a datatype
* because it inherits from an interface that is not a datatype.
*/
@javax.annotation.Generated(value = "jsii-pacmak")
public interface IInterfaceThatShouldNotBeADataType extends software.amazon.jsii.JsiiSerializable, software.amazon.jsii.tests.calculator.IInterfaceWithMethods {
java.lang.String getOtherValue();

/**
* A proxy class which represents a concrete javascript instance of this type.
*/
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IInterfaceThatShouldNotBeADataType {
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
super(mode);
}

@Override
public java.lang.String getOtherValue() {
return this.jsiiGet("otherValue", java.lang.String.class);
}

@Override
public java.lang.String getValue() {
return this.jsiiGet("value", java.lang.String.class);
}

@Override
public void doThings() {
this.jsiiCall("doThings", Void.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package software.amazon.jsii.tests.calculator;

@javax.annotation.Generated(value = "jsii-pacmak")
public interface IInterfaceWithMethods extends software.amazon.jsii.JsiiSerializable {
java.lang.String getValue();
void doThings();

/**
* A proxy class which represents a concrete javascript instance of this type.
*/
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IInterfaceWithMethods {
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
super(mode);
}

@Override
public java.lang.String getValue() {
return this.jsiiGet("value", java.lang.String.class);
}

@Override
public void doThings() {
this.jsiiCall("doThings", Void.class);
}
}
}
Loading

0 comments on commit 1c56902

Please sign in to comment.