From 4e70209f2b1707383babdcb9510318eccfd02683 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 6 Aug 2018 11:38:06 +0300 Subject: [PATCH] fix: "Malformed enum value" when using @scoped packages (#139) Fixes #138 The code that validated the format of jsii enum values was too rigid and didn't allow "/" in type names. When using a package from an npm scope, the enum value will look like this `@scope/foo.EnumType/MemberName`. Also, add a verification that the enum member exists in the enum and fail otherwise. Required fix in kernel, java and dotnet runtimes. --- packages/jsii-calc-lib/lib/index.ts | 9 ++++ packages/jsii-calc-lib/test/assembly.jsii | 20 ++++++++- packages/jsii-calc/lib/index.ts | 17 ++++++- packages/jsii-calc/test/assembly.jsii | 44 ++++++++++++++++++- .../Amazon.JSII.Runtime/Deputy/EnumValue.cs | 8 ++-- .../ComplianceTests.cs | 11 +++++ .../amazon/jsii/testing/ComplianceTest.java | 12 +++++ .../java/software/amazon/jsii/JsiiEngine.java | 8 ++-- packages/jsii-kernel/lib/kernel.ts | 15 +++++-- packages/jsii-kernel/test/test.kernel.ts | 23 ++++++++++ packages/jsii-pacmak/bin/jsii-pacmak.ts | 2 + packages/jsii-pacmak/test/diff-test.sh | 2 +- .../Amazon.JSII.Tests.Calculator.Lib/.jsii | 20 ++++++++- .../EnumFromScopedModule.cs | 17 +++++++ .../calculator/lib/EnumFromScopedModule.java | 10 +++++ .../sphinx/_scope_jsii-calc-lib.rst | 10 +++++ .../dotnet/Amazon.JSII.Tests.Calculator/.jsii | 44 ++++++++++++++++++- .../ReferenceEnumFromScopedPackage.cs | 41 +++++++++++++++++ .../ReferenceEnumFromScopedPackage.java | 28 ++++++++++++ .../expected.jsii-calc/sphinx/jsii-calc.rst | 25 +++++++++++ 20 files changed, 348 insertions(+), 18 deletions(-) create mode 100644 packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/EnumFromScopedModule.cs create mode 100644 packages/jsii-pacmak/test/expected.jsii-calc-lib/java/src/main/java/software/amazon/jsii/tests/calculator/lib/EnumFromScopedModule.java create mode 100644 packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/ReferenceEnumFromScopedPackage.cs create mode 100644 packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ReferenceEnumFromScopedPackage.java diff --git a/packages/jsii-calc-lib/lib/index.ts b/packages/jsii-calc-lib/lib/index.ts index 155ff8e590..e7d0a1a801 100644 --- a/packages/jsii-calc-lib/lib/index.ts +++ b/packages/jsii-calc-lib/lib/index.ts @@ -82,3 +82,12 @@ export interface StructWithOnlyOptionals { optional2?: number optional3?: boolean } + +/** + * Check that enums from @scoped packages can be references. + * See awslabs/jsii#138 + */ +export enum EnumFromScopedModule { + Value1, + Value2 +} diff --git a/packages/jsii-calc-lib/test/assembly.jsii b/packages/jsii-calc-lib/test/assembly.jsii index e879b8763b..48fd9e5788 100644 --- a/packages/jsii-calc-lib/test/assembly.jsii +++ b/packages/jsii-calc-lib/test/assembly.jsii @@ -1,5 +1,5 @@ { - "fingerprint": "GbVnxjsdaq598NCRdOJ8entjQRwThRmFgdeLNaQbIZY=", + "fingerprint": "yzHGjyI4/53o87fPNjR/Nz/4G58kg5jVoKtgwdqaEU8=", "author": { "name": "Amazon Web Services", "organization": true, @@ -73,6 +73,24 @@ } }, "types": { + "@scope/jsii-calc-lib.EnumFromScopedModule": { + "assembly": "@scope/jsii-calc-lib", + "docs": { + "comment": "Check that enums from @scoped packages can be references.\nSee awslabs/jsii#138" + }, + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule", + "kind": "enum", + "members": [ + { + "name": "Value1" + }, + { + "name": "Value2" + } + ], + "name": "EnumFromScopedModule", + "namespace": "@scope/jsii-calc-lib" + }, "@scope/jsii-calc-lib.IFriendly": { "assembly": "@scope/jsii-calc-lib", "docs": { diff --git a/packages/jsii-calc/lib/index.ts b/packages/jsii-calc/lib/index.ts index 220b5bac6b..d97c496e91 100644 --- a/packages/jsii-calc/lib/index.ts +++ b/packages/jsii-calc/lib/index.ts @@ -1,5 +1,5 @@ // tslint:disable -import { Operation, Value, Number, IFriendly, MyFirstStruct, StructWithOnlyOptionals } from '@scope/jsii-calc-lib' +import { Operation, Value, Number, IFriendly, MyFirstStruct, StructWithOnlyOptionals, EnumFromScopedModule } from '@scope/jsii-calc-lib' import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; @@ -1101,4 +1101,19 @@ export class UseCalcBase { export interface ImplictBaseOfBase extends base.BaseProps { goo: Date; +} + +/** + * See awslabs/jsii#138 + */ +export class ReferenceEnumFromScopedPackage { + public foo?: EnumFromScopedModule = EnumFromScopedModule.Value2; + + public loadFoo(): EnumFromScopedModule | undefined { + return this.foo; + } + + public saveFoo(value: EnumFromScopedModule) { + this.foo = value; + } } \ No newline at end of file diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index e772ea90dd..053e97e215 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -1,5 +1,5 @@ { - "fingerprint": "ZR90w/OQ/vVxm0Cg1sicOKwbZxbGK43MXqj2ksUyCrk=", + "fingerprint": "ENUxKESaYuaH8SRuMSsikJscFgsj+E8Ey1WvHIsNsZg=", "author": { "name": "Amazon Web Services", "organization": true, @@ -1919,6 +1919,48 @@ } ] }, + "jsii-calc.ReferenceEnumFromScopedPackage": { + "assembly": "jsii-calc", + "docs": { + "comment": "See awslabs/jsii#138" + }, + "fqn": "jsii-calc.ReferenceEnumFromScopedPackage", + "initializer": { + "initializer": true + }, + "kind": "class", + "methods": [ + { + "name": "loadFoo", + "returns": { + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule", + "optional": true + } + }, + { + "name": "saveFoo", + "parameters": [ + { + "name": "value", + "type": { + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule" + } + } + ] + } + ], + "name": "ReferenceEnumFromScopedPackage", + "namespace": "jsii-calc", + "properties": [ + { + "name": "foo", + "type": { + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule", + "optional": true + } + } + ] + }, "jsii-calc.ReturnsNumber": { "assembly": "jsii-calc", "fqn": "jsii-calc.ReturnsNumber", diff --git a/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/EnumValue.cs b/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/EnumValue.cs index 723835aca8..b5dadefad4 100644 --- a/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/EnumValue.cs +++ b/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/EnumValue.cs @@ -11,14 +11,14 @@ public EnumValue(string value) { Value = value ?? throw new ArgumentNullException(nameof(value)); - string[] valueTokens = value.Split('/'); - if (valueTokens.Length != 2) + int sep = value.LastIndexOf('/'); + if (sep == -1) { throw new ArgumentException($"Unexpected format for enum value: {value}", nameof(value)); } - FullyQualifiedName = valueTokens[0]; - MemberName = valueTokens[1]; + FullyQualifiedName = value.Substring(0, sep); + MemberName = value.Substring(sep + 1); } public EnumValue(string fullyQualifiedName, string memberName) : this($"{fullyQualifiedName}/{memberName}") diff --git a/packages/jsii-dotnet-runtime/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs b/packages/jsii-dotnet-runtime/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs index 649ee69b9e..4f88815e44 100644 --- a/packages/jsii-dotnet-runtime/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs +++ b/packages/jsii-dotnet-runtime/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs @@ -266,6 +266,17 @@ public void GetAndSetEnumValues() Assert.Equal("<<[[{{(((1 * (0 + 9)) * (0 + 9)) * (0 + 9))}}]]>>", calc.ToString()); } + [Fact(DisplayName = Prefix + nameof(EnumFromScopedModule))] + public void UseEnumFromScopedModule() + { + ReferenceEnumFromScopedPackage obj = new ReferenceEnumFromScopedPackage(); + Assert.Equal(EnumFromScopedModule.Value2, obj.Foo); + obj.Foo = EnumFromScopedModule.Value1; + Assert.Equal(EnumFromScopedModule.Value1, obj.LoadFoo()); + obj.SaveFoo(EnumFromScopedModule.Value2); + Assert.Equal(EnumFromScopedModule.Value2, obj.Foo); + } + [Fact(DisplayName = Prefix + nameof(UndefinedAndNull))] public void UndefinedAndNull() { diff --git a/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java b/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java index 52d1ac6c25..bb224503c3 100644 --- a/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java +++ b/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java @@ -24,12 +24,14 @@ import software.amazon.jsii.tests.calculator.NumberGenerator; import software.amazon.jsii.tests.calculator.Polymorphism; import software.amazon.jsii.tests.calculator.Power; +import software.amazon.jsii.tests.calculator.ReferenceEnumFromScopedPackage; import software.amazon.jsii.tests.calculator.Statics; import software.amazon.jsii.tests.calculator.Sum; import software.amazon.jsii.tests.calculator.SyncVirtualMethods; import software.amazon.jsii.tests.calculator.UnionProperties; import software.amazon.jsii.tests.calculator.UsesInterfaceWithProperties; import software.amazon.jsii.tests.calculator.composition.CompositionStringStyle; +import software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule; import software.amazon.jsii.tests.calculator.lib.IFriendly; import software.amazon.jsii.tests.calculator.lib.MyFirstStruct; import software.amazon.jsii.tests.calculator.lib.Number; @@ -242,6 +244,16 @@ public void getAndSetEnumValues() { assertEquals("<<[[{{(((1 * (0 + 9)) * (0 + 9)) * (0 + 9))}}]]>>", calc.toString()); } + @Test + public void useEnumFromScopedModule() { + ReferenceEnumFromScopedPackage obj = new ReferenceEnumFromScopedPackage(); + assertEquals(EnumFromScopedModule.Value2, obj.getFoo()); + obj.setFoo(EnumFromScopedModule.Value1); + assertEquals(EnumFromScopedModule.Value1, obj.loadFoo()); + obj.saveFoo(EnumFromScopedModule.Value2); + assertEquals(EnumFromScopedModule.Value2, obj.getFoo()); + } + @Test public void undefinedAndNull() { Calculator calculator = new Calculator(); diff --git a/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java b/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java index 523156aca6..38fe133d8e 100644 --- a/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java +++ b/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java @@ -264,13 +264,13 @@ private JsiiObject createNative(final String fqn) { */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Enum findEnumValue(final String enumRef) { - String[] parts = enumRef.split("/"); - if (parts.length != 2) { + int sep = enumRef.lastIndexOf('/'); + if (sep == -1) { throw new JsiiException("Malformed enum reference: " + enumRef); } - String typeName = parts[0]; - String valueName = parts[1]; + String typeName = enumRef.substring(0, sep); + String valueName = enumRef.substring(sep + 1); String enumClass = resolveJavaClassName(typeName); try { diff --git a/packages/jsii-kernel/lib/kernel.ts b/packages/jsii-kernel/lib/kernel.ts index 4c54aee6aa..bdc340ffc5 100644 --- a/packages/jsii-kernel/lib/kernel.ts +++ b/packages/jsii-kernel/lib/kernel.ts @@ -855,14 +855,21 @@ export class Kernel { // enums if (typeof v === 'object' && TOKEN_ENUM in v) { this._debug('Enum:', v); - const parts = v[TOKEN_ENUM].split('/'); - if (parts.length !== 2) { + + const value = v[TOKEN_ENUM] as string; + const sep = value.lastIndexOf('/'); + if (sep === -1) { throw new Error(`Malformed enum value: ${v[TOKEN_ENUM]}`); } - const typeName = parts[0]; - const valueName = parts[1]; + + const typeName = value.substr(0, sep); + const valueName = value.substr(sep + 1); const enumValue = this._findSymbol(typeName)[valueName]; + if (enumValue === undefined) { + throw new Error(`No enum member named ${valueName} in ${typeName}`); + } + this._debug('resolved enum value:', enumValue); return enumValue; } diff --git a/packages/jsii-kernel/test/test.kernel.ts b/packages/jsii-kernel/test/test.kernel.ts index 7f7aea6009..f721623062 100644 --- a/packages/jsii-kernel/test/test.kernel.ts +++ b/packages/jsii-kernel/test/test.kernel.ts @@ -167,6 +167,29 @@ defineTest('in/out enum values', async (test, sandbox) => { test.deepEqual(sandbox.get({ objref: alltypes, property: 'enumProperty' }).value, { '$jsii.enum': 'jsii-calc.AllTypesEnum/ThisIsGreat' }); }); +defineTest('enum values from @scoped packages awslabs/jsii#138', async (test, sandbox) => { + const objref = sandbox.create({ fqn: 'jsii-calc.ReferenceEnumFromScopedPackage' }); + + const value = sandbox.get({ objref, property: 'foo' }); + test.deepEqual(value, { value: { '$jsii.enum': '@scope/jsii-calc-lib.EnumFromScopedModule/Value2' } }); + + sandbox.set({ objref, property: 'foo', value: { '$jsii.enum': '@scope/jsii-calc-lib.EnumFromScopedModule/Value1' }}); + const ret = sandbox.invoke({ objref, method: 'loadFoo' }); + test.deepEqual(ret, { result: { '$jsii.enum': '@scope/jsii-calc-lib.EnumFromScopedModule/Value1' } }); + + sandbox.invoke({ objref, method: 'saveFoo', args: [ { '$jsii.enum': '@scope/jsii-calc-lib.EnumFromScopedModule/Value2' } ] }); + const value2 = sandbox.get({ objref, property: 'foo' }); + test.deepEqual(value2, { value: { '$jsii.enum': '@scope/jsii-calc-lib.EnumFromScopedModule/Value2' } }); +}); + +defineTest('fails for invalid enum member name', async (test, sandbox) => { + const objref = sandbox.create({ fqn: 'jsii-calc.ReferenceEnumFromScopedPackage' }); + + test.throws(() => { + sandbox.set({ objref, property: 'foo', value: { '$jsii.enum': '@scope/jsii-calc-lib.EnumFromScopedModule/ValueX' }}); + }, /No enum member named ValueX/); +}); + defineTest('set for a non existing property', async (test, sandbox) => { const obj = sandbox.create({ fqn: 'jsii-calc.SyncVirtualMethods' }); test.throws(() => sandbox.set({ objref: obj, property: 'idontexist', value: 'Foo' })); diff --git a/packages/jsii-pacmak/bin/jsii-pacmak.ts b/packages/jsii-pacmak/bin/jsii-pacmak.ts index ccd9bfe64d..6d2b6b3828 100644 --- a/packages/jsii-pacmak/bin/jsii-pacmak.ts +++ b/packages/jsii-pacmak/bin/jsii-pacmak.ts @@ -87,6 +87,8 @@ import { SPEC_FILE_NAME } from '../node_modules/jsii-spec'; return; // already built } + visited.add(packageDir); + // read package.json and extract the "jsii" configuration from it. const pkg = await fs.readJson(path.join(packageDir, 'package.json')); if (!pkg.jsii || !pkg.jsii.outdir || !pkg.jsii.targets) { diff --git a/packages/jsii-pacmak/test/diff-test.sh b/packages/jsii-pacmak/test/diff-test.sh index 297a11ec1e..3c98940ddf 100755 --- a/packages/jsii-pacmak/test/diff-test.sh +++ b/packages/jsii-pacmak/test/diff-test.sh @@ -43,7 +43,7 @@ function assert-generator() { echo "The diff-test.sh harness will replace it with the real expected tarball" >> ${tarball_placeholder} done - if ! diff -arq ${outdir} ${expected}; then + if ! diff --strip-trailing-cr -arq ${outdir} ${expected}; then echo echo "------------------------------------------------------------------------" echo " diff-test for pacmak generator ${module} failed" diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/.jsii b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/.jsii index e879b8763b..48fd9e5788 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/.jsii +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/.jsii @@ -1,5 +1,5 @@ { - "fingerprint": "GbVnxjsdaq598NCRdOJ8entjQRwThRmFgdeLNaQbIZY=", + "fingerprint": "yzHGjyI4/53o87fPNjR/Nz/4G58kg5jVoKtgwdqaEU8=", "author": { "name": "Amazon Web Services", "organization": true, @@ -73,6 +73,24 @@ } }, "types": { + "@scope/jsii-calc-lib.EnumFromScopedModule": { + "assembly": "@scope/jsii-calc-lib", + "docs": { + "comment": "Check that enums from @scoped packages can be references.\nSee awslabs/jsii#138" + }, + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule", + "kind": "enum", + "members": [ + { + "name": "Value1" + }, + { + "name": "Value2" + } + ], + "name": "EnumFromScopedModule", + "namespace": "@scope/jsii-calc-lib" + }, "@scope/jsii-calc-lib.IFriendly": { "assembly": "@scope/jsii-calc-lib", "docs": { diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/EnumFromScopedModule.cs b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/EnumFromScopedModule.cs new file mode 100644 index 0000000000..0b5699377b --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.Calculator.Lib/EnumFromScopedModule.cs @@ -0,0 +1,17 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.Calculator.Lib +{ + /// + /// Check that enums from @scoped packages can be references. + /// See awslabs/jsii#138 + /// + [JsiiEnum(typeof(EnumFromScopedModule), "@scope/jsii-calc-lib.EnumFromScopedModule")] + public enum EnumFromScopedModule + { + [JsiiEnumMember("Value1")] + Value1, + [JsiiEnumMember("Value2")] + Value2 + } +} \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/java/src/main/java/software/amazon/jsii/tests/calculator/lib/EnumFromScopedModule.java b/packages/jsii-pacmak/test/expected.jsii-calc-lib/java/src/main/java/software/amazon/jsii/tests/calculator/lib/EnumFromScopedModule.java new file mode 100644 index 0000000000..91010a9c64 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/java/src/main/java/software/amazon/jsii/tests/calculator/lib/EnumFromScopedModule.java @@ -0,0 +1,10 @@ +package software.amazon.jsii.tests.calculator.lib; +/** + * Check that enums from @scoped packages can be references. + * See awslabs/jsii#138 + */ +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.lib.$Module.class, fqn = "@scope/jsii-calc-lib.EnumFromScopedModule") +public enum EnumFromScopedModule { + Value1, + Value2, +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/sphinx/_scope_jsii-calc-lib.rst b/packages/jsii-pacmak/test/expected.jsii-calc-lib/sphinx/_scope_jsii-calc-lib.rst index b31d09b9c8..c9c3e379a3 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-lib/sphinx/_scope_jsii-calc-lib.rst +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/sphinx/_scope_jsii-calc-lib.rst @@ -6,6 +6,16 @@ Reference .. py:module:: @scope/jsii-calc-lib +EnumFromScopedModule (enum) +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. py:class:: EnumFromScopedModule + + .. py:data:: Value1 + + .. py:data:: Value2 + + IFriendly (interface) ^^^^^^^^^^^^^^^^^^^^^ diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/.jsii b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/.jsii index e772ea90dd..053e97e215 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/.jsii +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/.jsii @@ -1,5 +1,5 @@ { - "fingerprint": "ZR90w/OQ/vVxm0Cg1sicOKwbZxbGK43MXqj2ksUyCrk=", + "fingerprint": "ENUxKESaYuaH8SRuMSsikJscFgsj+E8Ey1WvHIsNsZg=", "author": { "name": "Amazon Web Services", "organization": true, @@ -1919,6 +1919,48 @@ } ] }, + "jsii-calc.ReferenceEnumFromScopedPackage": { + "assembly": "jsii-calc", + "docs": { + "comment": "See awslabs/jsii#138" + }, + "fqn": "jsii-calc.ReferenceEnumFromScopedPackage", + "initializer": { + "initializer": true + }, + "kind": "class", + "methods": [ + { + "name": "loadFoo", + "returns": { + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule", + "optional": true + } + }, + { + "name": "saveFoo", + "parameters": [ + { + "name": "value", + "type": { + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule" + } + } + ] + } + ], + "name": "ReferenceEnumFromScopedPackage", + "namespace": "jsii-calc", + "properties": [ + { + "name": "foo", + "type": { + "fqn": "@scope/jsii-calc-lib.EnumFromScopedModule", + "optional": true + } + } + ] + }, "jsii-calc.ReturnsNumber": { "assembly": "jsii-calc", "fqn": "jsii-calc.ReturnsNumber", diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/ReferenceEnumFromScopedPackage.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/ReferenceEnumFromScopedPackage.cs new file mode 100644 index 0000000000..3cf2adbc4b --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.Calculator/ReferenceEnumFromScopedPackage.cs @@ -0,0 +1,41 @@ +using Amazon.JSII.Runtime.Deputy; +using Amazon.JSII.Tests.Calculator.Lib; + +namespace Amazon.JSII.Tests.Calculator +{ + /// See awslabs/jsii#138 + [JsiiClass(typeof(ReferenceEnumFromScopedPackage), "jsii-calc.ReferenceEnumFromScopedPackage", "[]")] + public class ReferenceEnumFromScopedPackage : DeputyBase + { + public ReferenceEnumFromScopedPackage(): base(new DeputyProps(new object[]{})) + { + } + + protected ReferenceEnumFromScopedPackage(ByRefValue reference): base(reference) + { + } + + protected ReferenceEnumFromScopedPackage(DeputyProps props): base(props) + { + } + + [JsiiProperty("foo", "{\"fqn\":\"@scope/jsii-calc-lib.EnumFromScopedModule\",\"optional\":true}")] + public virtual EnumFromScopedModule Foo + { + get => GetInstanceProperty(); + set => SetInstanceProperty(value); + } + + [JsiiMethod("loadFoo", "{\"fqn\":\"@scope/jsii-calc-lib.EnumFromScopedModule\",\"optional\":true}", "[]")] + public virtual EnumFromScopedModule LoadFoo() + { + return InvokeInstanceMethod(new object[]{}); + } + + [JsiiMethod("saveFoo", null, "[{\"name\":\"value\",\"type\":{\"fqn\":\"@scope/jsii-calc-lib.EnumFromScopedModule\"}}]")] + public virtual void SaveFoo(EnumFromScopedModule value) + { + InvokeInstanceVoidMethod(new object[]{value}); + } + } +} \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ReferenceEnumFromScopedPackage.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ReferenceEnumFromScopedPackage.java new file mode 100644 index 0000000000..3e3e65c34d --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ReferenceEnumFromScopedPackage.java @@ -0,0 +1,28 @@ +package software.amazon.jsii.tests.calculator; +/** + * See awslabs/jsii#138 + */ +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.ReferenceEnumFromScopedPackage") +public class ReferenceEnumFromScopedPackage extends software.amazon.jsii.JsiiObject { + protected ReferenceEnumFromScopedPackage(final software.amazon.jsii.JsiiObject.InitializationMode mode) { + super(mode); + } + public ReferenceEnumFromScopedPackage() { + super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + @javax.annotation.Nullable + public software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule loadFoo() { + return this.jsiiCall("loadFoo", software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule.class); + } + public void saveFoo(final software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule value) { + this.jsiiCall("saveFoo", Void.class, java.util.stream.Stream.of(java.util.Objects.requireNonNull(value, "value is required")).toArray()); + } + @javax.annotation.Nullable + public software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule getFoo() { + return this.jsiiGet("foo", software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule.class); + } + public void setFoo(@javax.annotation.Nullable final software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule value) { + this.jsiiSet("foo", value); + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst b/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst index 612b59ca50..e887a3b969 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst +++ b/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst @@ -1164,6 +1164,31 @@ Power :type: :py:class:`@scope/jsii-calc-lib.Value` *(readonly)* +ReferenceEnumFromScopedPackage +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. py:class:: ReferenceEnumFromScopedPackage() + + See awslabs/jsii#138 + + + + .. py:method:: loadFoo() -> @scope/jsii-calc-lib.EnumFromScopedModule + + :rtype: :py:class:`@scope/jsii-calc-lib.EnumFromScopedModule` or undefined + + + .. py:method:: saveFoo(value) + + :param value: + :type value: :py:class:`@scope/jsii-calc-lib.EnumFromScopedModule` + + + .. py:attribute:: foo + + :type: :py:class:`@scope/jsii-calc-lib.EnumFromScopedModule` or undefined + + ReturnsNumber (interface) ^^^^^^^^^^^^^^^^^^^^^^^^^