Skip to content

Commit 56617b1

Browse files
Hamza AssyadRomainMuller
authored andcommitted
fix(dotnet): add missing GetInterfaceType in the .NET runtime (#703)
Add support for return type being array of interfaces. Tested with the customer code. https://docs.aws.amazon.com/cdk/api/latest/dotnet/api/Amazon.CDK.AWS.EC2.Vpc.html#Amazon_CDK_AWS_EC2_Vpc_PrivateSubnets This was not supported by the runtime, as it only allowed for classes and enums: ``` public virtual IISubnet[] PrivateSubnets { get; } ``` Fixes aws/aws-cdk#2362
1 parent ca44537 commit 56617b1

File tree

16 files changed

+253
-3
lines changed

16 files changed

+253
-3
lines changed

packages/jsii-calc/lib/compliance.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,3 +1830,19 @@ export class StructPassing {
18301830
return inputs.length;
18311831
}
18321832
}
1833+
1834+
/**
1835+
* We can return arrays of interfaces
1836+
* See aws/aws-cdk#2362
1837+
*/
1838+
export class InterfacesMaker {
1839+
public static makeInterfaces(count: number): IDoublable[] {
1840+
const output = new Array<IDoublable>();
1841+
for (let i = 0; i < count; i++) {
1842+
output.push({ doubleValue: i * 2 });
1843+
}
1844+
return output;
1845+
}
1846+
1847+
private constructor() { }
1848+
}

packages/jsii-calc/test/assembly.jsii

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,51 @@
47754775
}
47764776
]
47774777
},
4778+
"jsii-calc.InterfacesMaker": {
4779+
"assembly": "jsii-calc",
4780+
"docs": {
4781+
"stability": "experimental",
4782+
"summary": "We can return arrays of interfaces See aws/aws-cdk#2362."
4783+
},
4784+
"fqn": "jsii-calc.InterfacesMaker",
4785+
"kind": "class",
4786+
"locationInModule": {
4787+
"filename": "lib/compliance.ts",
4788+
"line": 1838
4789+
},
4790+
"methods": [
4791+
{
4792+
"docs": {
4793+
"stability": "experimental"
4794+
},
4795+
"locationInModule": {
4796+
"filename": "lib/compliance.ts",
4797+
"line": 1839
4798+
},
4799+
"name": "makeInterfaces",
4800+
"parameters": [
4801+
{
4802+
"name": "count",
4803+
"type": {
4804+
"primitive": "number"
4805+
}
4806+
}
4807+
],
4808+
"returns": {
4809+
"type": {
4810+
"collection": {
4811+
"elementtype": {
4812+
"fqn": "@scope/jsii-calc-lib.IDoublable"
4813+
},
4814+
"kind": "array"
4815+
}
4816+
}
4817+
},
4818+
"static": true
4819+
}
4820+
],
4821+
"name": "InterfacesMaker"
4822+
},
47784823
"jsii-calc.JSII417Derived": {
47794824
"assembly": "jsii-calc",
47804825
"base": "jsii-calc.JSII417PublicBaseOfBase",
@@ -9361,5 +9406,5 @@
93619406
}
93629407
},
93639408
"version": "0.15.0",
9364-
"fingerprint": "s29ilwOj9pcb3e3u8f49bqxkFzU9a52FAr4mHWpRuYA="
9409+
"fingerprint": "8Dd+N3LiENMPxOU1iY/Z28bky5f/c49pSvcZ2tg4zCI="
93659410
}

packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,13 @@ public void CallbacksCorrectlyDeserializeArguments()
979979
}));
980980
}
981981

982+
[Fact(DisplayName = Prefix + nameof(MethodCanReturnArraysOfInterfaces))]
983+
public void MethodCanReturnArraysOfInterfaces()
984+
{
985+
var interfaces = InterfacesMaker.MakeInterfaces(4);
986+
Assert.Equal(4, interfaces.Length);
987+
}
988+
982989
class DataRendererSubclass : DataRenderer
983990
{
984991
[JsiiMethod("renderMap", returnsJson: "{\"type\":{\"primitive\":\"string\"}}", parametersJson: "[{\"name\":\"map\",\"type\":{\"collection\":{\"kind\":\"map\",\"elementtype\":{\"primitive\":\"any\"}}}}]", isOverride: true)]

packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Services/TypeCache.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public Type GetFrameworkType(TypeReference typeReference, bool isOptional)
6969
{
7070
return MakeNullableIfOptional(enumType);
7171
}
72+
73+
Type interfaceType = GetInterfaceType(typeReference.FullyQualifiedName);
74+
if (interfaceType != null)
75+
{
76+
return interfaceType;
77+
}
7278

7379
throw new ArgumentException("Type reference has a fully qualified name, but is neither a class nor an enum", nameof(typeReference));
7480
}

packages/jsii-pacmak/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ target/
99
node_modules/
1010
.nyc_output/
1111
coverage/
12+
13+
test/expected.*/dotnet/**/obj/Debug

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,51 @@
47754775
}
47764776
]
47774777
},
4778+
"jsii-calc.InterfacesMaker": {
4779+
"assembly": "jsii-calc",
4780+
"docs": {
4781+
"stability": "experimental",
4782+
"summary": "We can return arrays of interfaces See aws/aws-cdk#2362."
4783+
},
4784+
"fqn": "jsii-calc.InterfacesMaker",
4785+
"kind": "class",
4786+
"locationInModule": {
4787+
"filename": "lib/compliance.ts",
4788+
"line": 1838
4789+
},
4790+
"methods": [
4791+
{
4792+
"docs": {
4793+
"stability": "experimental"
4794+
},
4795+
"locationInModule": {
4796+
"filename": "lib/compliance.ts",
4797+
"line": 1839
4798+
},
4799+
"name": "makeInterfaces",
4800+
"parameters": [
4801+
{
4802+
"name": "count",
4803+
"type": {
4804+
"primitive": "number"
4805+
}
4806+
}
4807+
],
4808+
"returns": {
4809+
"type": {
4810+
"collection": {
4811+
"elementtype": {
4812+
"fqn": "@scope/jsii-calc-lib.IDoublable"
4813+
},
4814+
"kind": "array"
4815+
}
4816+
}
4817+
},
4818+
"static": true
4819+
}
4820+
],
4821+
"name": "InterfacesMaker"
4822+
},
47784823
"jsii-calc.JSII417Derived": {
47794824
"assembly": "jsii-calc",
47804825
"base": "jsii-calc.JSII417PublicBaseOfBase",
@@ -9361,5 +9406,5 @@
93619406
}
93629407
},
93639408
"version": "0.15.0",
9364-
"fingerprint": "s29ilwOj9pcb3e3u8f49bqxkFzU9a52FAr4mHWpRuYA="
9409+
"fingerprint": "8Dd+N3LiENMPxOU1iY/Z28bky5f/c49pSvcZ2tg4zCI="
93659410
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
/// <summary>We can return arrays of interfaces See aws/aws-cdk#2362.</summary>
6+
/// <remarks>
7+
/// stability: Experimental
8+
/// </remarks>
9+
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.InterfacesMaker), fullyQualifiedName: "jsii-calc.InterfacesMaker")]
10+
public class InterfacesMaker : DeputyBase
11+
{
12+
protected InterfacesMaker(ByRefValue reference): base(reference)
13+
{
14+
}
15+
16+
protected InterfacesMaker(DeputyProps props): base(props)
17+
{
18+
}
19+
20+
/// <remarks>
21+
/// stability: Experimental
22+
/// </remarks>
23+
[JsiiMethod(name: "makeInterfaces", returnsJson: "{\"type\":{\"collection\":{\"elementtype\":{\"fqn\":\"@scope/jsii-calc-lib.IDoublable\"},\"kind\":\"array\"}}}", parametersJson: "[{\"name\":\"count\",\"type\":{\"primitive\":\"number\"}}]")]
24+
public static Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable[] MakeInterfaces(double count)
25+
{
26+
return InvokeStaticMethod<Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable[]>(typeof(Amazon.JSII.Tests.CalculatorNamespace.InterfacesMaker), new object[]{count});
27+
}
28+
}
29+
}

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
@@ -101,6 +101,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
101101
case "jsii-calc.InterfaceInNamespaceIncludesClasses.Foo": return software.amazon.jsii.tests.calculator.InterfaceInNamespaceIncludesClasses.Foo.class;
102102
case "jsii-calc.InterfaceInNamespaceIncludesClasses.Hello": return software.amazon.jsii.tests.calculator.InterfaceInNamespaceIncludesClasses.Hello.class;
103103
case "jsii-calc.InterfaceInNamespaceOnlyInterface.Hello": return software.amazon.jsii.tests.calculator.InterfaceInNamespaceOnlyInterface.Hello.class;
104+
case "jsii-calc.InterfacesMaker": return software.amazon.jsii.tests.calculator.InterfacesMaker.class;
104105
case "jsii-calc.JSII417Derived": return software.amazon.jsii.tests.calculator.JSII417Derived.class;
105106
case "jsii-calc.JSII417PublicBaseOfBase": return software.amazon.jsii.tests.calculator.JSII417PublicBaseOfBase.class;
106107
case "jsii-calc.JSObjectLiteralForInterface": return software.amazon.jsii.tests.calculator.JSObjectLiteralForInterface.class;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package software.amazon.jsii.tests.calculator;
2+
3+
/**
4+
* We can return arrays of interfaces See aws/aws-cdk#2362.
5+
*
6+
* EXPERIMENTAL
7+
*/
8+
@javax.annotation.Generated(value = "jsii-pacmak")
9+
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
10+
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.InterfacesMaker")
11+
public class InterfacesMaker extends software.amazon.jsii.JsiiObject {
12+
13+
protected InterfacesMaker(final software.amazon.jsii.JsiiObjectRef objRef) {
14+
super(objRef);
15+
}
16+
17+
protected InterfacesMaker(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) {
18+
super(initializationMode);
19+
}
20+
21+
/**
22+
* EXPERIMENTAL
23+
*/
24+
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
25+
public static java.util.List<software.amazon.jsii.tests.calculator.lib.IDoublable> makeInterfaces(final java.lang.Number count) {
26+
return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.jsii.tests.calculator.InterfacesMaker.class, "makeInterfaces", java.util.List.class, new Object[] { java.util.Objects.requireNonNull(count, "count is required") });
27+
}
28+
}

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
@@ -3505,6 +3505,24 @@ def __repr__(self) -> str:
35053505

35063506

35073507

3508+
class InterfacesMaker(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.InterfacesMaker"):
3509+
"""We can return arrays of interfaces See aws/aws-cdk#2362.
3510+
3511+
stability
3512+
:stability: experimental
3513+
"""
3514+
@jsii.member(jsii_name="makeInterfaces")
3515+
@classmethod
3516+
def make_interfaces(cls, count: jsii.Number) -> typing.List[scope.jsii_calc_lib.IDoublable]:
3517+
"""
3518+
:param count: -
3519+
3520+
stability
3521+
:stability: experimental
3522+
"""
3523+
return jsii.sinvoke(cls, "makeInterfaces", [count])
3524+
3525+
35083526
class JSII417PublicBaseOfBase(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.JSII417PublicBaseOfBase"):
35093527
"""
35103528
stability
@@ -6618,6 +6636,6 @@ def parts(self, value: typing.List[scope.jsii_calc_lib.Value]):
66186636
return jsii.set(self, "parts", value)
66196637

66206638

6621-
__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithJavaReservedWords", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DataRenderer", "DefaultedConstructorArgument", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DiamondInheritanceBaseLevelStruct", "DiamondInheritanceFirstMidLevelStruct", "DiamondInheritanceSecondMidLevelStruct", "DiamondInheritanceTopLevelStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SecondLevelStruct", "SingleInstanceTwoTypes", "SingletonInt", "SingletonIntEnum", "SingletonString", "SingletonStringEnum", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "StructPassing", "StructWithJavaReservedWords", "Sum", "SyncVirtualMethods", "Thrower", "TopLevelStruct", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "WithPrivatePropertyInConstructor", "__jsii_assembly__", "composition"]
6639+
__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithJavaReservedWords", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DataRenderer", "DefaultedConstructorArgument", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DiamondInheritanceBaseLevelStruct", "DiamondInheritanceFirstMidLevelStruct", "DiamondInheritanceSecondMidLevelStruct", "DiamondInheritanceTopLevelStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "InterfacesMaker", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SecondLevelStruct", "SingleInstanceTwoTypes", "SingletonInt", "SingletonIntEnum", "SingletonString", "SingletonStringEnum", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "StructPassing", "StructWithJavaReservedWords", "Sum", "SyncVirtualMethods", "Thrower", "TopLevelStruct", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "WithPrivatePropertyInConstructor", "__jsii_assembly__", "composition"]
66226640

66236641
publication.publish()

0 commit comments

Comments
 (0)