Skip to content

Commit

Permalink
fix(dotnet): add missing GetInterfaceType in the .NET runtime (#703)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Hamza Assyad authored and RomainMuller committed Aug 16, 2019
1 parent ca44537 commit 56617b1
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 3 deletions.
16 changes: 16 additions & 0 deletions packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1830,3 +1830,19 @@ export class StructPassing {
return inputs.length;
}
}

/**
* We can return arrays of interfaces
* See aws/aws-cdk#2362
*/
export class InterfacesMaker {
public static makeInterfaces(count: number): IDoublable[] {
const output = new Array<IDoublable>();
for (let i = 0; i < count; i++) {
output.push({ doubleValue: i * 2 });
}
return output;
}

private constructor() { }
}
47 changes: 46 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,51 @@
}
]
},
"jsii-calc.InterfacesMaker": {
"assembly": "jsii-calc",
"docs": {
"stability": "experimental",
"summary": "We can return arrays of interfaces See aws/aws-cdk#2362."
},
"fqn": "jsii-calc.InterfacesMaker",
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1838
},
"methods": [
{
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1839
},
"name": "makeInterfaces",
"parameters": [
{
"name": "count",
"type": {
"primitive": "number"
}
}
],
"returns": {
"type": {
"collection": {
"elementtype": {
"fqn": "@scope/jsii-calc-lib.IDoublable"
},
"kind": "array"
}
}
},
"static": true
}
],
"name": "InterfacesMaker"
},
"jsii-calc.JSII417Derived": {
"assembly": "jsii-calc",
"base": "jsii-calc.JSII417PublicBaseOfBase",
Expand Down Expand Up @@ -9361,5 +9406,5 @@
}
},
"version": "0.15.0",
"fingerprint": "s29ilwOj9pcb3e3u8f49bqxkFzU9a52FAr4mHWpRuYA="
"fingerprint": "8Dd+N3LiENMPxOU1iY/Z28bky5f/c49pSvcZ2tg4zCI="
}
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,13 @@ public void CallbacksCorrectlyDeserializeArguments()
}));
}

[Fact(DisplayName = Prefix + nameof(MethodCanReturnArraysOfInterfaces))]
public void MethodCanReturnArraysOfInterfaces()
{
var interfaces = InterfacesMaker.MakeInterfaces(4);
Assert.Equal(4, interfaces.Length);
}

class DataRendererSubclass : DataRenderer
{
[JsiiMethod("renderMap", returnsJson: "{\"type\":{\"primitive\":\"string\"}}", parametersJson: "[{\"name\":\"map\",\"type\":{\"collection\":{\"kind\":\"map\",\"elementtype\":{\"primitive\":\"any\"}}}}]", isOverride: true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public Type GetFrameworkType(TypeReference typeReference, bool isOptional)
{
return MakeNullableIfOptional(enumType);
}

Type interfaceType = GetInterfaceType(typeReference.FullyQualifiedName);
if (interfaceType != null)
{
return interfaceType;
}

throw new ArgumentException("Type reference has a fully qualified name, but is neither a class nor an enum", nameof(typeReference));
}
Expand Down
2 changes: 2 additions & 0 deletions packages/jsii-pacmak/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ target/
node_modules/
.nyc_output/
coverage/

test/expected.*/dotnet/**/obj/Debug
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,51 @@
}
]
},
"jsii-calc.InterfacesMaker": {
"assembly": "jsii-calc",
"docs": {
"stability": "experimental",
"summary": "We can return arrays of interfaces See aws/aws-cdk#2362."
},
"fqn": "jsii-calc.InterfacesMaker",
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1838
},
"methods": [
{
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1839
},
"name": "makeInterfaces",
"parameters": [
{
"name": "count",
"type": {
"primitive": "number"
}
}
],
"returns": {
"type": {
"collection": {
"elementtype": {
"fqn": "@scope/jsii-calc-lib.IDoublable"
},
"kind": "array"
}
}
},
"static": true
}
],
"name": "InterfacesMaker"
},
"jsii-calc.JSII417Derived": {
"assembly": "jsii-calc",
"base": "jsii-calc.JSII417PublicBaseOfBase",
Expand Down Expand Up @@ -9361,5 +9406,5 @@
}
},
"version": "0.15.0",
"fingerprint": "s29ilwOj9pcb3e3u8f49bqxkFzU9a52FAr4mHWpRuYA="
"fingerprint": "8Dd+N3LiENMPxOU1iY/Z28bky5f/c49pSvcZ2tg4zCI="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
/// <summary>We can return arrays of interfaces See aws/aws-cdk#2362.</summary>
/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.InterfacesMaker), fullyQualifiedName: "jsii-calc.InterfacesMaker")]
public class InterfacesMaker : DeputyBase
{
protected InterfacesMaker(ByRefValue reference): base(reference)
{
}

protected InterfacesMaker(DeputyProps props): base(props)
{
}

/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiMethod(name: "makeInterfaces", returnsJson: "{\"type\":{\"collection\":{\"elementtype\":{\"fqn\":\"@scope/jsii-calc-lib.IDoublable\"},\"kind\":\"array\"}}}", parametersJson: "[{\"name\":\"count\",\"type\":{\"primitive\":\"number\"}}]")]
public static Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable[] MakeInterfaces(double count)
{
return InvokeStaticMethod<Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable[]>(typeof(Amazon.JSII.Tests.CalculatorNamespace.InterfacesMaker), new object[]{count});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
case "jsii-calc.InterfaceInNamespaceIncludesClasses.Foo": return software.amazon.jsii.tests.calculator.InterfaceInNamespaceIncludesClasses.Foo.class;
case "jsii-calc.InterfaceInNamespaceIncludesClasses.Hello": return software.amazon.jsii.tests.calculator.InterfaceInNamespaceIncludesClasses.Hello.class;
case "jsii-calc.InterfaceInNamespaceOnlyInterface.Hello": return software.amazon.jsii.tests.calculator.InterfaceInNamespaceOnlyInterface.Hello.class;
case "jsii-calc.InterfacesMaker": return software.amazon.jsii.tests.calculator.InterfacesMaker.class;
case "jsii-calc.JSII417Derived": return software.amazon.jsii.tests.calculator.JSII417Derived.class;
case "jsii-calc.JSII417PublicBaseOfBase": return software.amazon.jsii.tests.calculator.JSII417PublicBaseOfBase.class;
case "jsii-calc.JSObjectLiteralForInterface": return software.amazon.jsii.tests.calculator.JSObjectLiteralForInterface.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package software.amazon.jsii.tests.calculator;

/**
* We can return arrays of interfaces See aws/aws-cdk#2362.
*
* EXPERIMENTAL
*/
@javax.annotation.Generated(value = "jsii-pacmak")
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.InterfacesMaker")
public class InterfacesMaker extends software.amazon.jsii.JsiiObject {

protected InterfacesMaker(final software.amazon.jsii.JsiiObjectRef objRef) {
super(objRef);
}

protected InterfacesMaker(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) {
super(initializationMode);
}

/**
* EXPERIMENTAL
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public static java.util.List<software.amazon.jsii.tests.calculator.lib.IDoublable> makeInterfaces(final java.lang.Number count) {
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") });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,24 @@ def __repr__(self) -> str:



class InterfacesMaker(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.InterfacesMaker"):
"""We can return arrays of interfaces See aws/aws-cdk#2362.
stability
:stability: experimental
"""
@jsii.member(jsii_name="makeInterfaces")
@classmethod
def make_interfaces(cls, count: jsii.Number) -> typing.List[scope.jsii_calc_lib.IDoublable]:
"""
:param count: -
stability
:stability: experimental
"""
return jsii.sinvoke(cls, "makeInterfaces", [count])


class JSII417PublicBaseOfBase(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.JSII417PublicBaseOfBase"):
"""
stability
Expand Down Expand Up @@ -6618,6 +6636,6 @@ def parts(self, value: typing.List[scope.jsii_calc_lib.Value]):
return jsii.set(self, "parts", value)


__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"]
__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"]

publication.publish()
39 changes: 39 additions & 0 deletions packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4131,6 +4131,45 @@ Hello (interface)

.. py:currentmodule:: jsii-calc
InterfacesMaker
^^^^^^^^^^^^^^^

.. py:class:: InterfacesMaker
**Language-specific names:**

.. tabs::

.. code-tab:: c#

using Amazon.JSII.Tests.CalculatorNamespace;

.. code-tab:: java

import software.amazon.jsii.tests.calculator.InterfacesMaker;

.. code-tab:: javascript

const { InterfacesMaker } = require('jsii-calc');

.. code-tab:: typescript

import { InterfacesMaker } from 'jsii-calc';



We can return arrays of interfaces See aws/aws-cdk#2362.




.. py:staticmethod:: makeInterfaces(count) -> @scope/jsii-calc-lib.IDoublable[]
:param count:
:type count: number
:rtype: :py:class:`@scope/jsii-calc-lib.IDoublable`\ []


JSII417Derived
^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions packages/jsii-reflect/test/classes.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ImplementsInterfaceWithInternal
ImplementsInterfaceWithInternalSubclass
ImplementsPrivateInterface
InbetweenClass
InterfacesMaker
JSII417Derived
JSII417PublicBaseOfBase
JSObjectLiteralForInterface
Expand Down
8 changes: 8 additions & 0 deletions packages/jsii-reflect/test/jsii-tree.test.all.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@ assemblies
│ │ ├── <initializer>() initializer (experimental)
│ │ └─┬ bar property (experimental)
│ │ └── type: Optional<string>
│ ├─┬ class InterfacesMaker (experimental)
│ │ └─┬ members
│ │ └─┬ static makeInterfaces(count) method (experimental)
│ │ ├── static
│ │ ├─┬ parameters
│ │ │ └─┬ count
│ │ │ └── type: number
│ │ └── returns: Array<@scope/jsii-calc-lib.IDoublable>
│ ├─┬ class JSII417Derived (experimental)
│ │ ├── base: JSII417PublicBaseOfBase
│ │ └─┬ members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ assemblies
│ │ ├── base: PublicClass
│ │ └── interfaces: IPublicInterface2
│ ├── class Foo
│ ├── class InterfacesMaker
│ ├─┬ class JSII417Derived
│ │ └── base: JSII417PublicBaseOfBase
│ ├── class JSII417PublicBaseOfBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ assemblies
│ │ └─┬ members
│ │ ├── <initializer>() initializer
│ │ └── bar property
│ ├─┬ class InterfacesMaker
│ │ └─┬ members
│ │ └── static makeInterfaces(count) method
│ ├─┬ class JSII417Derived
│ │ └─┬ members
│ │ ├── <initializer>(property) initializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ assemblies
│ ├── class ImplementsPrivateInterface
│ ├── class InbetweenClass
│ ├── class Foo
│ ├── class InterfacesMaker
│ ├── class JSII417Derived
│ ├── class JSII417PublicBaseOfBase
│ ├── class JSObjectLiteralForInterface
Expand Down

0 comments on commit 56617b1

Please sign in to comment.