Skip to content

Commit b03511b

Browse files
author
Elad Ben-Israel
authored
fix(jsii): consider interfaces from erased base classes (#491)
When a base class is erased, we now treat it's "implementation" clauses as if they were part of the original class (similar to how we merge declarations for methods/properties). Fixes #487
1 parent 6bbf743 commit b03511b

File tree

17 files changed

+251
-15
lines changed

17 files changed

+251
-15
lines changed

packages/jsii-calc/lib/erasures.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ interface IJSII417PrivateBase extends IJSII417PublicBaseOfBase {
3737
export interface IJSII417Derived extends IJSII417PrivateBase {
3838
baz(): void;
3939
}
40+
41+
//
42+
// Interfaces should be copied from erased classes to public classes
43+
// https://github.com/awslabs/jsii/issues/487
44+
//
45+
// tslint:disable-next-line:no-empty-interface
46+
export interface IJsii487External { }
47+
class Jsii487Internal implements IJsii487External { }
48+
export class Jsii487Derived extends Jsii487Internal { }

packages/jsii-calc/test/assembly.jsii

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,16 @@
30353035
}
30363036
]
30373037
},
3038+
"jsii-calc.IJsii487External": {
3039+
"assembly": "jsii-calc",
3040+
"fqn": "jsii-calc.IJsii487External",
3041+
"kind": "interface",
3042+
"locationInModule": {
3043+
"filename": "lib/erasures.ts",
3044+
"line": 46
3045+
},
3046+
"name": "IJsii487External"
3047+
},
30383048
"jsii-calc.IMutableObjectLiteral": {
30393049
"assembly": "jsii-calc",
30403050
"fqn": "jsii-calc.IMutableObjectLiteral",
@@ -4038,6 +4048,20 @@
40384048
}
40394049
]
40404050
},
4051+
"jsii-calc.Jsii487Derived": {
4052+
"assembly": "jsii-calc",
4053+
"fqn": "jsii-calc.Jsii487Derived",
4054+
"initializer": {},
4055+
"interfaces": [
4056+
"jsii-calc.IJsii487External"
4057+
],
4058+
"kind": "class",
4059+
"locationInModule": {
4060+
"filename": "lib/erasures.ts",
4061+
"line": 48
4062+
},
4063+
"name": "Jsii487Derived"
4064+
},
40414065
"jsii-calc.JsiiAgent": {
40424066
"assembly": "jsii-calc",
40434067
"docs": {
@@ -6744,5 +6768,5 @@
67446768
}
67456769
},
67466770
"version": "0.10.3",
6747-
"fingerprint": "HkyspjelXmNd6gQibMCkuk+WfsM6Q9e3uZLl2ee3kbY="
6771+
"fingerprint": "CSE0eCLDxK7s+qnmR58ZJo0mcEROi4f8Sxlx2pHaBDs="
67486772
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,16 @@
30353035
}
30363036
]
30373037
},
3038+
"jsii-calc.IJsii487External": {
3039+
"assembly": "jsii-calc",
3040+
"fqn": "jsii-calc.IJsii487External",
3041+
"kind": "interface",
3042+
"locationInModule": {
3043+
"filename": "lib/erasures.ts",
3044+
"line": 46
3045+
},
3046+
"name": "IJsii487External"
3047+
},
30383048
"jsii-calc.IMutableObjectLiteral": {
30393049
"assembly": "jsii-calc",
30403050
"fqn": "jsii-calc.IMutableObjectLiteral",
@@ -4038,6 +4048,20 @@
40384048
}
40394049
]
40404050
},
4051+
"jsii-calc.Jsii487Derived": {
4052+
"assembly": "jsii-calc",
4053+
"fqn": "jsii-calc.Jsii487Derived",
4054+
"initializer": {},
4055+
"interfaces": [
4056+
"jsii-calc.IJsii487External"
4057+
],
4058+
"kind": "class",
4059+
"locationInModule": {
4060+
"filename": "lib/erasures.ts",
4061+
"line": 48
4062+
},
4063+
"name": "Jsii487Derived"
4064+
},
40414065
"jsii-calc.JsiiAgent": {
40424066
"assembly": "jsii-calc",
40434067
"docs": {
@@ -6744,5 +6768,5 @@
67446768
}
67456769
},
67466770
"version": "0.10.3",
6747-
"fingerprint": "HkyspjelXmNd6gQibMCkuk+WfsM6Q9e3uZLl2ee3kbY="
6771+
"fingerprint": "CSE0eCLDxK7s+qnmR58ZJo0mcEROi4f8Sxlx2pHaBDs="
67486772
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiInterface(nativeType: typeof(IIJsii487External), fullyQualifiedName: "jsii-calc.IJsii487External")]
6+
public interface IIJsii487External
7+
{
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiTypeProxy(nativeType: typeof(IIJsii487External), fullyQualifiedName: "jsii-calc.IJsii487External")]
6+
internal sealed class IJsii487ExternalProxy : DeputyBase, IIJsii487External
7+
{
8+
private IJsii487ExternalProxy(ByRefValue reference): base(reference)
9+
{
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiClass(nativeType: typeof(Jsii487Derived), fullyQualifiedName: "jsii-calc.Jsii487Derived")]
6+
public class Jsii487Derived : DeputyBase, IIJsii487External
7+
{
8+
public Jsii487Derived(): base(new DeputyProps(new object[]{}))
9+
{
10+
}
11+
12+
protected Jsii487Derived(ByRefValue reference): base(reference)
13+
{
14+
}
15+
16+
protected Jsii487Derived(DeputyProps props): base(props)
17+
{
18+
}
19+
}
20+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
6767
case "jsii-calc.IInterfaceWithPropertiesExtension": return software.amazon.jsii.tests.calculator.IInterfaceWithPropertiesExtension.class;
6868
case "jsii-calc.IJSII417Derived": return software.amazon.jsii.tests.calculator.IJSII417Derived.class;
6969
case "jsii-calc.IJSII417PublicBaseOfBase": return software.amazon.jsii.tests.calculator.IJSII417PublicBaseOfBase.class;
70+
case "jsii-calc.IJsii487External": return software.amazon.jsii.tests.calculator.IJsii487External.class;
7071
case "jsii-calc.IMutableObjectLiteral": return software.amazon.jsii.tests.calculator.IMutableObjectLiteral.class;
7172
case "jsii-calc.INonInternalInterface": return software.amazon.jsii.tests.calculator.INonInternalInterface.class;
7273
case "jsii-calc.IPrivatelyImplemented": return software.amazon.jsii.tests.calculator.IPrivatelyImplemented.class;
@@ -89,6 +90,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
8990
case "jsii-calc.JSObjectLiteralToNative": return software.amazon.jsii.tests.calculator.JSObjectLiteralToNative.class;
9091
case "jsii-calc.JSObjectLiteralToNativeClass": return software.amazon.jsii.tests.calculator.JSObjectLiteralToNativeClass.class;
9192
case "jsii-calc.JavaReservedWords": return software.amazon.jsii.tests.calculator.JavaReservedWords.class;
93+
case "jsii-calc.Jsii487Derived": return software.amazon.jsii.tests.calculator.Jsii487Derived.class;
9294
case "jsii-calc.JsiiAgent": return software.amazon.jsii.tests.calculator.JsiiAgent.class;
9395
case "jsii-calc.LoadBalancedFargateServiceProps": return software.amazon.jsii.tests.calculator.LoadBalancedFargateServiceProps.class;
9496
case "jsii-calc.Multiply": return software.amazon.jsii.tests.calculator.Multiply.class;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package software.amazon.jsii.tests.calculator;
2+
3+
@javax.annotation.Generated(value = "jsii-pacmak")
4+
public interface IJsii487External extends software.amazon.jsii.JsiiSerializable {
5+
6+
/**
7+
* A proxy class which represents a concrete javascript instance of this type.
8+
*/
9+
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IJsii487External {
10+
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
11+
super(mode);
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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.Jsii487Derived")
5+
public class Jsii487Derived extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IJsii487External {
6+
protected Jsii487Derived(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
7+
super(mode);
8+
}
9+
public Jsii487Derived() {
10+
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii);
11+
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this);
12+
}
13+
}

packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,18 @@ def baz(self) -> None:
12741274
return jsii.invoke(self, "baz", [])
12751275

12761276

1277+
@jsii.interface(jsii_type="jsii-calc.IJsii487External")
1278+
class IJsii487External(jsii.compat.Protocol):
1279+
@staticmethod
1280+
def __jsii_proxy_class__():
1281+
return _IJsii487ExternalProxy
1282+
1283+
pass
1284+
1285+
class _IJsii487ExternalProxy():
1286+
__jsii_type__ = "jsii-calc.IJsii487External"
1287+
pass
1288+
12771289
@jsii.interface(jsii_type="jsii-calc.IMutableObjectLiteral")
12781290
class IMutableObjectLiteral(jsii.compat.Protocol):
12791291
@staticmethod
@@ -1955,6 +1967,12 @@ def while_(self, value: str):
19551967
return jsii.set(self, "while", value)
19561968

19571969

1970+
@jsii.implements(IJsii487External)
1971+
class Jsii487Derived(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.Jsii487Derived"):
1972+
def __init__(self) -> None:
1973+
jsii.create(Jsii487Derived, self, [])
1974+
1975+
19581976
class JsiiAgent(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.JsiiAgent"):
19591977
"""Host runtime version should be set via JSII_AGENT."""
19601978
def __init__(self) -> None:
@@ -3272,6 +3290,6 @@ def parts(self, value: typing.List[scope.jsii_calc_lib.Value]):
32723290
return jsii.set(self, "parts", value)
32733291

32743292

3275-
__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "__jsii_assembly__", "composition"]
3293+
__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "__jsii_assembly__", "composition"]
32763294

32773295
publication.publish()

0 commit comments

Comments
 (0)