From d73e69e0c42c845aeebdce3d795d5809f6c09d64 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 12:34:27 +0200 Subject: [PATCH 1/9] fix(go): missing imports needed by reimplemented members Go pacmak will reimplement methods and properties in case the class has more than a single "base" (interface/class). The Go code generator failed to include these members when determining which imports to generate. Add a calc test fixture to verify (failed without this change). Fixes #2647 --- packages/@scope/jsii-calc-lib/lib/index.ts | 13 ++ .../@scope/jsii-calc-lib/test/assembly.jsii | 45 ++++- packages/jsii-calc/lib/index.ts | 1 + packages/jsii-calc/lib/module2647/index.ts | 17 ++ packages/jsii-calc/test/assembly.jsii | 69 ++++++- .../jsii-pacmak/lib/targets/go/types/class.ts | 2 + .../__snapshots__/target-dotnet.test.ts.snap | 117 ++++++++++++ .../__snapshots__/target-go.test.ts.snap | 168 ++++++++++++++++++ .../__snapshots__/target-java.test.ts.snap | 101 +++++++++++ .../__snapshots__/target-python.test.ts.snap | 85 +++++++++ 10 files changed, 614 insertions(+), 4 deletions(-) create mode 100644 packages/jsii-calc/lib/module2647/index.ts diff --git a/packages/@scope/jsii-calc-lib/lib/index.ts b/packages/@scope/jsii-calc-lib/lib/index.ts index 7ffa4c17bd..f600bc35d5 100644 --- a/packages/@scope/jsii-calc-lib/lib/index.ts +++ b/packages/@scope/jsii-calc-lib/lib/index.ts @@ -109,5 +109,18 @@ export interface IThreeLevelsInterface extends base.IBaseInterface { baz(): void; } +/** + * A base class for testing #2647. The method `foo` has a parameter that uses a type + * from a dependent module. Since Go "reimplments" this method, it will also need + * to include an "import" statement for the calc-base module. + * + * @see https://github.com/aws/jsii/issues/2647 + */ +export class BaseFor2647 { + public foo(obj: base.IBaseInterface): void { + obj.bar(); + } +} + export * as submodule from './submodule'; export * from './duplicate-inherited-prop'; diff --git a/packages/@scope/jsii-calc-lib/test/assembly.jsii b/packages/@scope/jsii-calc-lib/test/assembly.jsii index bb45ca914f..b561dfbcc5 100644 --- a/packages/@scope/jsii-calc-lib/test/assembly.jsii +++ b/packages/@scope/jsii-calc-lib/test/assembly.jsii @@ -92,7 +92,7 @@ "@scope/jsii-calc-lib.submodule": { "locationInModule": { "filename": "lib/index.ts", - "line": 112 + "line": 125 }, "targets": { "dotnet": { @@ -133,6 +133,47 @@ } }, "types": { + "@scope/jsii-calc-lib.BaseFor2647": { + "assembly": "@scope/jsii-calc-lib", + "docs": { + "remarks": "The method `foo` has a parameter that uses a type\nfrom a dependent module. Since Go \"reimplments\" this method, it will also need\nto include an \"import\" statement for the calc-base module.", + "see": "https://github.com/aws/jsii/issues/2647", + "stability": "deprecated", + "summary": "A base class for testing #2647." + }, + "fqn": "@scope/jsii-calc-lib.BaseFor2647", + "initializer": { + "docs": { + "stability": "deprecated" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/index.ts", + "line": 119 + }, + "methods": [ + { + "docs": { + "stability": "deprecated" + }, + "locationInModule": { + "filename": "lib/index.ts", + "line": 120 + }, + "name": "foo", + "parameters": [ + { + "name": "obj", + "type": { + "fqn": "@scope/jsii-calc-base.IBaseInterface" + } + } + ] + } + ], + "name": "BaseFor2647" + }, "@scope/jsii-calc-lib.DiamondLeft": { "assembly": "@scope/jsii-calc-lib", "datatype": true, @@ -872,5 +913,5 @@ } }, "version": "0.0.0", - "fingerprint": "YlmxPtOusVTgKe2YUzZDpB4UnmnU3zZ0UUdXwSDcgOo=" + "fingerprint": "pW043fHp8icTWympphJfAKrI/5PT2F1nZyyNNyEmTjM=" } diff --git a/packages/jsii-calc/lib/index.ts b/packages/jsii-calc/lib/index.ts index 65d66f22cb..7f40a0c0a9 100644 --- a/packages/jsii-calc/lib/index.ts +++ b/packages/jsii-calc/lib/index.ts @@ -11,3 +11,4 @@ export * from './submodules'; export * as submodule from './submodule'; export * as onlystatic from './only-static'; export * as nodirect from './no-direct-types'; +export * as module2647 from './module2647'; diff --git a/packages/jsii-calc/lib/module2647/index.ts b/packages/jsii-calc/lib/module2647/index.ts new file mode 100644 index 0000000000..414359a0ae --- /dev/null +++ b/packages/jsii-calc/lib/module2647/index.ts @@ -0,0 +1,17 @@ +import { IFriendly, BaseFor2647 } from '@scope/jsii-calc-lib'; + +/** + * This class falls into the category of "multiple bases" from a different + * module from a go code gen perspective. + * + * @see https://github.com/aws/jsii/issues/2647 + */ +export class ExtendAndImplement extends BaseFor2647 implements IFriendly { + public localMethod() { + return 'hi'; + } + + public hello() { + return 'extends and implements'; + } +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 6a03cc06a9..95fa30dbba 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -96,7 +96,7 @@ "@scope/jsii-calc-lib.submodule": { "locationInModule": { "filename": "lib/index.ts", - "line": 112 + "line": 125 }, "targets": { "dotnet": { @@ -206,6 +206,12 @@ "line": 142 } }, + "jsii-calc.module2647": { + "locationInModule": { + "filename": "lib/index.ts", + "line": 14 + } + }, "jsii-calc.nodirect": { "locationInModule": { "filename": "lib/index.ts", @@ -14114,6 +14120,65 @@ "name": "CompositionStringStyle", "namespace": "composition.CompositeOperation" }, + "jsii-calc.module2647.ExtendAndImplement": { + "assembly": "jsii-calc", + "base": "@scope/jsii-calc-lib.BaseFor2647", + "docs": { + "see": "https://github.com/aws/jsii/issues/2647", + "stability": "stable", + "summary": "This class falls into the category of \"multiple bases\" from a different module from a go code gen perspective." + }, + "fqn": "jsii-calc.module2647.ExtendAndImplement", + "initializer": { + "docs": { + "stability": "deprecated" + } + }, + "interfaces": [ + "@scope/jsii-calc-lib.IFriendly" + ], + "kind": "class", + "locationInModule": { + "filename": "lib/module2647/index.ts", + "line": 9 + }, + "methods": [ + { + "docs": { + "stability": "stable", + "summary": "(deprecated) Say hello!" + }, + "locationInModule": { + "filename": "lib/module2647/index.ts", + "line": 14 + }, + "name": "hello", + "overrides": "@scope/jsii-calc-lib.IFriendly", + "returns": { + "type": { + "primitive": "string" + } + } + }, + { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2647/index.ts", + "line": 10 + }, + "name": "localMethod", + "returns": { + "type": { + "primitive": "string" + } + } + } + ], + "name": "ExtendAndImplement", + "namespace": "module2647" + }, "jsii-calc.nodirect.sub1.TypeFromSub1": { "assembly": "jsii-calc", "docs": { @@ -14870,5 +14935,5 @@ } }, "version": "3.20.120", - "fingerprint": "rH6rK3iHNatb4ojll7sd8rvJ4k/89Kybg89FRd96Hno=" + "fingerprint": "61fXjiesh/E+ejTgQ0gXmmToVljlc8IbNsEz4o5DDGY=" } diff --git a/packages/jsii-pacmak/lib/targets/go/types/class.ts b/packages/jsii-pacmak/lib/targets/go/types/class.ts index 9dff125484..0081b6c75a 100644 --- a/packages/jsii-pacmak/lib/targets/go/types/class.ts +++ b/packages/jsii-pacmak/lib/targets/go/types/class.ts @@ -181,6 +181,8 @@ export class GoClass extends GoType { ...this.properties, ...this.staticMethods, ...this.staticProperties, + ...(this.reimplementedMethods ?? []), + ...(this.reimplementedProperties ?? []), ]; } diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index 57e34d287b..4393f565b0 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -973,6 +973,7 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┗━ 📁 Tests ┃ ┣━ 📁 CalculatorNamespace ┃ ┃ ┗━ 📁 LibNamespace + ┃ ┃ ┣━ 📄 BaseFor2647.cs ┃ ┃ ┣━ 📄 DiamondLeft.cs ┃ ┃ ┣━ 📄 DiamondRight.cs ┃ ┃ ┣━ 📄 EnumFromScopedModule.cs @@ -1045,6 +1046,65 @@ exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII. +`; + +exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon/JSII/Tests/CalculatorNamespace/LibNamespace/BaseFor2647.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace +{ + /// (deprecated) A base class for testing #2647. + /// + /// The method foo has a parameter that uses a type + /// from a dependent module. Since Go "reimplments" this method, it will also need + /// to include an "import" statement for the calc-base module. + /// + /// Stability: Deprecated + /// + /// See: https://github.com/aws/jsii/issues/2647 + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.BaseFor2647), fullyQualifiedName: "@scope/jsii-calc-lib.BaseFor2647")] + [System.Obsolete()] + public class BaseFor2647 : DeputyBase + { + /// + /// Stability: Deprecated + /// + [System.Obsolete()] + public BaseFor2647(): base(new DeputyProps(System.Array.Empty())) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.Obsolete()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected BaseFor2647(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.Obsolete()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected BaseFor2647(DeputyProps props): base(props) + { + } + + /// + /// Stability: Deprecated + /// + [JsiiMethod(name: "foo", parametersJson: "[{\\"name\\":\\"obj\\",\\"type\\":{\\"fqn\\":\\"@scope/jsii-calc-base.IBaseInterface\\"}}]")] + [System.Obsolete()] + public virtual void Foo(Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IBaseInterface obj) + { + InvokeInstanceVoidMethod(new System.Type[]{typeof(Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IBaseInterface)}, new object[]{obj}); + } + } +} + `; exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon/JSII/Tests/CalculatorNamespace/LibNamespace/DiamondLeft.cs 1`] = ` @@ -2833,6 +2893,8 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 LevelOneProps.cs ┃ ┣━ 📄 LoadBalancedFargateServiceProps.cs ┃ ┣━ 📄 MethodNamedProperty.cs + ┃ ┣━ 📁 Module2647 + ┃ ┃ ┗━ 📄 ExtendAndImplement.cs ┃ ┣━ 📄 Multiply.cs ┃ ┣━ 📄 NamespaceDoc.cs ┃ ┣━ 📄 Negate.cs @@ -12059,6 +12121,61 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2647/ExtendAndImplement.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2647 +{ + /// This class falls into the category of "multiple bases" from a different module from a go code gen perspective. + /// + /// See: https://github.com/aws/jsii/issues/2647 + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2647.ExtendAndImplement), fullyQualifiedName: "jsii-calc.module2647.ExtendAndImplement")] + public class ExtendAndImplement : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.BaseFor2647, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IFriendly + { + /// + /// Stability: Deprecated + /// + [System.Obsolete()] + public ExtendAndImplement(): base(new DeputyProps(System.Array.Empty())) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.Obsolete()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected ExtendAndImplement(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.Obsolete()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected ExtendAndImplement(DeputyProps props): base(props) + { + } + + /// (deprecated) Say hello! + [JsiiMethod(name: "hello", returnsJson: "{\\"type\\":{\\"primitive\\":\\"string\\"}}", isOverride: true)] + public virtual string Hello() + { + return InvokeInstanceMethod(new System.Type[]{}, new object[]{})!; + } + + [JsiiMethod(name: "localMethod", returnsJson: "{\\"type\\":{\\"primitive\\":\\"string\\"}}")] + public virtual string LocalMethod() + { + return InvokeInstanceMethod(new System.Type[]{}, new object[]{})!; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Multiply.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index 54851fb22d..ae37f6096d 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -1138,6 +1138,49 @@ import ( "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" ) +// A base class for testing #2647. +// +// The method \`foo\` has a parameter that uses a type +// from a dependent module. Since Go "reimplments" this method, it will also need +// to include an "import" statement for the calc-base module. +// See: https://github.com/aws/jsii/issues/2647 +// +// Deprecated. +type BaseFor2647 interface { + Foo(obj scopejsiicalcbase.IBaseInterface) +} + +// The jsii proxy struct for BaseFor2647 +type jsiiProxy_BaseFor2647 struct { + _ byte // padding +} + +// Deprecated. +func NewBaseFor2647() BaseFor2647 { + _init_.Initialize() + + j := jsiiProxy_BaseFor2647{} + + _jsii_.Create( + "@scope/jsii-calc-lib.BaseFor2647", + nil /* no parameters */, + []_jsii_.FQN{}, + nil, // no overrides + &j, + ) + + return &j +} + +// Deprecated. +func (b *jsiiProxy_BaseFor2647) Foo(obj scopejsiicalcbase.IBaseInterface) { + _jsii_.InvokeVoid( + b, + "foo", + []interface{}{obj}, + ) +} + // Deprecated. type DiamondLeft struct { // Deprecated. @@ -1462,6 +1505,16 @@ import ( ) func init() { + _jsii_.RegisterClass( + "@scope/jsii-calc-lib.BaseFor2647", + reflect.TypeOf((*BaseFor2647)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "foo", GoMethod: "Foo"}, + }, + func() interface{} { + return &jsiiProxy_BaseFor2647{} + }, + ) _jsii_.RegisterStruct( "@scope/jsii-calc-lib.DiamondLeft", reflect.TypeOf((*DiamondLeft)(nil)).Elem(), @@ -1795,6 +1848,9 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┣━ 📄 jsiicalc.go ┣━ 📄 jsiicalc.init.go ┣━ 📄 LICENSE + ┣━ 📁 module2647 + ┃ ┣━ 📄 module2647.go + ┃ ┗━ 📄 module2647.init.go ┣━ 📁 nodirect ┃ ┣━ 📄 nodirect.go ┃ ┣━ 📁 sub1 @@ -14743,6 +14799,118 @@ func init() { `; +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2647/module2647.go 1`] = ` +package module2647 + +import ( + _jsii_ "github.com/aws/jsii-runtime-go" + _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" + + "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" +) + +// This class falls into the category of "multiple bases" from a different module from a go code gen perspective. +// See: https://github.com/aws/jsii/issues/2647 +// +type ExtendAndImplement interface { + scopejsiicalclib.BaseFor2647 + scopejsiicalclib.IFriendly + Hello() string + LocalMethod() string +} + +// The jsii proxy struct for ExtendAndImplement +type jsiiProxy_ExtendAndImplement struct { + scopejsiicalclib.BaseFor2647 // extends @scope/jsii-calc-lib.BaseFor2647 + scopejsiicalclib.IFriendly // implements @scope/jsii-calc-lib.IFriendly +} + +// Deprecated. +func NewExtendAndImplement() ExtendAndImplement { + _init_.Initialize() + + j := jsiiProxy_ExtendAndImplement{} + + _jsii_.Create( + "jsii-calc.module2647.ExtendAndImplement", + nil /* no parameters */, + []_jsii_.FQN{"@scope/jsii-calc-lib.IFriendly"}, + nil, // no overrides + &j, + ) + + return &j +} + +// (deprecated) Say hello! +func (e *jsiiProxy_ExtendAndImplement) Hello() string { + var returns string + + _jsii_.Invoke( + e, + "hello", + nil /* no parameters */, + &returns, + ) + + return returns +} + +func (e *jsiiProxy_ExtendAndImplement) LocalMethod() string { + var returns string + + _jsii_.Invoke( + e, + "localMethod", + nil /* no parameters */, + &returns, + ) + + return returns +} + +// Deprecated. +func (e *jsiiProxy_ExtendAndImplement) Foo(obj scopejsiicalcbase.IBaseInterface) { + _jsii_.InvokeVoid( + e, + "foo", + []interface{}{obj}, + ) +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2647/module2647.init.go 1`] = ` +package module2647 + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterClass( + "jsii-calc.module2647.ExtendAndImplement", + reflect.TypeOf((*ExtendAndImplement)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "foo", GoMethod: "Foo"}, + _jsii_.MemberMethod{JsiiMethod: "hello", GoMethod: "Hello"}, + _jsii_.MemberMethod{JsiiMethod: "localMethod", GoMethod: "LocalMethod"}, + }, + func() interface{} { + j := jsiiProxy_ExtendAndImplement{} + _jsii_.InitJsiiProxy(&j.BaseFor2647) + _jsii_.InitJsiiProxy(&j.IFriendly) + return &j + }, + ) +} + +`; + exports[`Generated code for "jsii-calc": /go/jsiicalc/nodirect/nodirect.go 1`] = ` package nodirect diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap index b734ed9816..36e10c1a47 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap @@ -1422,6 +1422,7 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┃ ┗━ 📄 Reflector.java ┃ ┗━ 📁 lib ┃ ┣━ 📄 $Module.java + ┃ ┣━ 📄 BaseFor2647.java ┃ ┣━ 📄 DiamondLeft.java ┃ ┣━ 📄 DiamondRight.java ┃ ┣━ 📄 EnumFromScopedModule.java @@ -2328,6 +2329,53 @@ public final class $Module extends JsiiModule { `; +exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/java/software/amazon/jsii/tests/calculator/lib/BaseFor2647.java 1`] = ` +package software.amazon.jsii.tests.calculator.lib; + +/** + * (deprecated) A base class for testing #2647. + *

+ * The method foo has a parameter that uses a type + * from a dependent module. Since Go "reimplments" this method, it will also need + * to include an "import" statement for the calc-base module. + *

+ * @see https://github.com/aws/jsii/issues/2647 + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) +@Deprecated +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.lib.$Module.class, fqn = "@scope/jsii-calc-lib.BaseFor2647") +public class BaseFor2647 extends software.amazon.jsii.JsiiObject { + + protected BaseFor2647(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected BaseFor2647(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + public BaseFor2647() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + * @param obj This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + public void foo(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.base.IBaseInterface obj) { + software.amazon.jsii.Kernel.call(this, "foo", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(obj, "obj is required") }); + } +} + +`; + exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/java/software/amazon/jsii/tests/calculator/lib/DiamondLeft.java 1`] = ` package software.amazon.jsii.tests.calculator.lib; @@ -3481,6 +3529,7 @@ package software.amazon.jsii.tests.calculator.lib; `; exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/resources/software/amazon/jsii/tests/calculator/lib/$Module.txt 1`] = ` +@scope/jsii-calc-lib.BaseFor2647=software.amazon.jsii.tests.calculator.lib.BaseFor2647 @scope/jsii-calc-lib.DiamondLeft=software.amazon.jsii.tests.calculator.lib.DiamondLeft @scope/jsii-calc-lib.DiamondRight=software.amazon.jsii.tests.calculator.lib.DiamondRight @scope/jsii-calc-lib.EnumFromScopedModule=software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule @@ -3660,6 +3709,8 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 LevelOneProps.java ┃ ┣━ 📄 LoadBalancedFargateServiceProps.java ┃ ┣━ 📄 MethodNamedProperty.java + ┃ ┣━ 📁 module2647 + ┃ ┃ ┗━ 📄 ExtendAndImplement.java ┃ ┣━ 📄 Multiply.java ┃ ┣━ 📄 Negate.java ┃ ┣━ 📄 NestedClassInstance.java @@ -21662,6 +21713,55 @@ public interface Hello extends software.amazon.jsii.JsiiSerializable { `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2647/ExtendAndImplement.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2647; + +/** + * This class falls into the category of "multiple bases" from a different module from a go code gen perspective. + *

+ * @see https://github.com/aws/jsii/issues/2647 + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2647.ExtendAndImplement") +public class ExtendAndImplement extends software.amazon.jsii.tests.calculator.lib.BaseFor2647 implements software.amazon.jsii.tests.calculator.lib.IFriendly { + + protected ExtendAndImplement(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected ExtendAndImplement(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + public ExtendAndImplement() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + * (deprecated) Say hello! + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public @org.jetbrains.annotations.NotNull java.lang.String hello() { + return software.amazon.jsii.Kernel.call(this, "hello", software.amazon.jsii.NativeType.forClass(java.lang.String.class)); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull java.lang.String localMethod() { + return software.amazon.jsii.Kernel.call(this, "localMethod", software.amazon.jsii.NativeType.forClass(java.lang.String.class)); + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/nodirect/sub1/TypeFromSub1.java 1`] = ` package software.amazon.jsii.tests.calculator.nodirect.sub1; @@ -23511,6 +23611,7 @@ jsii-calc.VoidCallback=software.amazon.jsii.tests.calculator.VoidCallback jsii-calc.WithPrivatePropertyInConstructor=software.amazon.jsii.tests.calculator.WithPrivatePropertyInConstructor jsii-calc.composition.CompositeOperation=software.amazon.jsii.tests.calculator.composition.CompositeOperation jsii-calc.composition.CompositeOperation.CompositionStringStyle=software.amazon.jsii.tests.calculator.composition.CompositeOperation$CompositionStringStyle +jsii-calc.module2647.ExtendAndImplement=software.amazon.jsii.tests.calculator.module2647.ExtendAndImplement jsii-calc.nodirect.sub1.TypeFromSub1=software.amazon.jsii.tests.calculator.nodirect.sub1.TypeFromSub1 jsii-calc.nodirect.sub2.TypeFromSub2=software.amazon.jsii.tests.calculator.nodirect.sub2.TypeFromSub2 jsii-calc.onlystatic.OnlyStaticMethods=software.amazon.jsii.tests.calculator.onlystatic.OnlyStaticMethods diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index 6f302ae5a9..4bebe28ab8 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -1266,6 +1266,36 @@ from ._jsii import * import scope.jsii_calc_base +class BaseFor2647( + metaclass=jsii.JSIIMeta, + jsii_type="@scope/jsii-calc-lib.BaseFor2647", +): + '''(deprecated) A base class for testing #2647. + + The method \`\`foo\`\` has a parameter that uses a type + from a dependent module. Since Go "reimplments" this method, it will also need + to include an "import" statement for the calc-base module. + + :see: https://github.com/aws/jsii/issues/2647 + :stability: deprecated + ''' + + def __init__(self) -> None: + ''' + :stability: deprecated + ''' + jsii.create(BaseFor2647, self, []) + + @jsii.member(jsii_name="foo") + def foo(self, obj: scope.jsii_calc_base.IBaseInterface) -> None: + ''' + :param obj: - + + :stability: deprecated + ''' + return typing.cast(None, jsii.invoke(self, "foo", [obj])) + + @jsii.data_type( jsii_type="@scope/jsii-calc-lib.DiamondLeft", jsii_struct_bases=[], @@ -1785,6 +1815,7 @@ class Number( __all__ = [ + "BaseFor2647", "DiamondLeft", "DiamondRight", "EnumFromScopedModule", @@ -2067,6 +2098,8 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┗━ 📄 __init__.py ┣━ 📁 interface_in_namespace_only_interface ┃ ┗━ 📄 __init__.py + ┣━ 📁 module2647 + ┃ ┗━ 📄 __init__.py ┣━ 📁 nodirect ┃ ┣━ 📄 __init__.py ┃ ┣━ 📁 sub1 @@ -2380,6 +2413,7 @@ kwargs = json.loads( "jsii_calc.derived_class_has_no_properties", "jsii_calc.interface_in_namespace_includes_classes", "jsii_calc.interface_in_namespace_only_interface", + "jsii_calc.module2647", "jsii_calc.nodirect", "jsii_calc.nodirect.sub1", "jsii_calc.nodirect.sub2", @@ -10327,6 +10361,57 @@ publication.publish() `; +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2647/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from .._jsii import * + +import scope.jsii_calc_lib + + +@jsii.implements(scope.jsii_calc_lib.IFriendly) +class ExtendAndImplement( + scope.jsii_calc_lib.BaseFor2647, + metaclass=jsii.JSIIMeta, + jsii_type="jsii-calc.module2647.ExtendAndImplement", +): + '''This class falls into the category of "multiple bases" from a different module from a go code gen perspective. + + :see: https://github.com/aws/jsii/issues/2647 + ''' + + def __init__(self) -> None: + ''' + :stability: deprecated + ''' + jsii.create(ExtendAndImplement, self, []) + + @jsii.member(jsii_name="hello") + def hello(self) -> builtins.str: + '''(deprecated) Say hello!''' + return typing.cast(builtins.str, jsii.invoke(self, "hello", [])) + + @jsii.member(jsii_name="localMethod") + def local_method(self) -> builtins.str: + return typing.cast(builtins.str, jsii.invoke(self, "localMethod", [])) + + +__all__ = [ + "ExtendAndImplement", +] + +publication.publish() + +`; + exports[`Generated code for "jsii-calc": /python/src/jsii_calc/nodirect/__init__.py 1`] = ` import abc import builtins From c047a34ead6aba2e355fcbc0d2a77f8b1eb801b4 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 14:22:58 +0200 Subject: [PATCH 2/9] update snapshots --- .../test/__snapshots__/jsii-tree.test.ts.snap | 42 +++++++++++++++++++ .../test/__snapshots__/tree.test.ts.snap | 27 ++++++++++++ .../__snapshots__/type-system.test.ts.snap | 2 + 3 files changed, 71 insertions(+) diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap index 415a3c44c6..ed329100bf 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap @@ -102,6 +102,17 @@ exports[`jsii-tree --all 1`] = ` │ │ │ └─┬ enum CompositionStringStyle (stable) │ │ │ ├── NORMAL (stable) │ │ │ └── DECORATED (stable) + │ │ ├─┬ module2647 + │ │ │ └─┬ types + │ │ │ └─┬ class ExtendAndImplement (stable) + │ │ │ ├── base: BaseFor2647 + │ │ │ ├── interfaces: IFriendly + │ │ │ └─┬ members + │ │ │ ├── () initializer (deprecated) + │ │ │ ├─┬ hello() method (stable) + │ │ │ │ └── returns: string + │ │ │ └─┬ localMethod() method (stable) + │ │ │ └── returns: string │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -2803,6 +2814,14 @@ exports[`jsii-tree --all 1`] = ` │ ├── immutable │ └── type: any └─┬ types + ├─┬ class BaseFor2647 (deprecated) + │ └─┬ members + │ ├── () initializer (deprecated) + │ └─┬ foo(obj) method (deprecated) + │ ├─┬ parameters + │ │ └─┬ obj + │ │ └── type: @scope/jsii-calc-base.IBaseInterface + │ └── returns: void ├─┬ class Number (deprecated) │ ├── base: NumericValue │ ├── interfaces: IDoublable @@ -2933,6 +2952,11 @@ exports[`jsii-tree --inheritance 1`] = ` │ │ │ ├─┬ class CompositeOperation │ │ │ │ └── base: Operation │ │ │ └── enum CompositionStringStyle + │ │ ├─┬ module2647 + │ │ │ └─┬ types + │ │ │ └─┬ class ExtendAndImplement + │ │ │ ├── base: BaseFor2647 + │ │ │ └── interfaces: IFriendly │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -3277,6 +3301,7 @@ exports[`jsii-tree --inheritance 1`] = ` │ ├── interface NestedStruct │ └── interface ReflectableEntry └─┬ types + ├── class BaseFor2647 ├─┬ class Number │ ├── base: NumericValue │ └── interfaces: IDoublable @@ -3355,6 +3380,13 @@ exports[`jsii-tree --members 1`] = ` │ │ │ └─┬ enum CompositionStringStyle │ │ │ ├── NORMAL │ │ │ └── DECORATED + │ │ ├─┬ module2647 + │ │ │ └─┬ types + │ │ │ └─┬ class ExtendAndImplement + │ │ │ └─┬ members + │ │ │ ├── () initializer + │ │ │ ├── hello() method + │ │ │ └── localMethod() method │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -4566,6 +4598,10 @@ exports[`jsii-tree --members 1`] = ` │ ├── key property │ └── value property └─┬ types + ├─┬ class BaseFor2647 + │ └─┬ members + │ ├── () initializer + │ └── foo(obj) method ├─┬ class Number │ └─┬ members │ ├── (value) initializer @@ -4622,6 +4658,7 @@ exports[`jsii-tree --signatures 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2647 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -4670,6 +4707,9 @@ exports[`jsii-tree --types 1`] = ` │ │ │ └─┬ types │ │ │ ├── class CompositeOperation │ │ │ └── enum CompositionStringStyle + │ │ ├─┬ module2647 + │ │ │ └─┬ types + │ │ │ └── class ExtendAndImplement │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -4947,6 +4987,7 @@ exports[`jsii-tree --types 1`] = ` │ ├── interface NestedStruct │ └── interface ReflectableEntry └─┬ types + ├── class BaseFor2647 ├── class Number ├── class NumericValue ├── class Operation @@ -4970,6 +5011,7 @@ exports[`jsii-tree 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2647 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap index 0f057f66c1..42b4b18796 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap @@ -9,6 +9,7 @@ exports[`defaults 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2647 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -41,6 +42,7 @@ exports[`inheritance 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2647 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -73,6 +75,7 @@ exports[`members 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2647 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -198,6 +201,17 @@ exports[`showAll 1`] = ` │ │ │ └─┬ enum CompositionStringStyle │ │ │ ├── NORMAL │ │ │ └── DECORATED + │ │ ├─┬ module2647 + │ │ │ └─┬ types + │ │ │ └─┬ class ExtendAndImplement + │ │ │ ├── base: BaseFor2647 + │ │ │ ├── interfaces: IFriendly + │ │ │ └─┬ members + │ │ │ ├── () initializer + │ │ │ ├─┬ hello() method + │ │ │ │ └── returns: string + │ │ │ └─┬ localMethod() method + │ │ │ └── returns: string │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -2899,6 +2913,14 @@ exports[`showAll 1`] = ` │ ├── immutable │ └── type: any └─┬ types + ├─┬ class BaseFor2647 + │ └─┬ members + │ ├── () initializer + │ └─┬ foo(obj) method + │ ├─┬ parameters + │ │ └─┬ obj + │ │ └── type: @scope/jsii-calc-base.IBaseInterface + │ └── returns: void ├─┬ class Number │ ├── base: NumericValue │ ├── interfaces: IDoublable @@ -3011,6 +3033,7 @@ exports[`signatures 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2647 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -3059,6 +3082,9 @@ exports[`types 1`] = ` │ │ │ └─┬ types │ │ │ ├── class CompositeOperation │ │ │ └── enum CompositionStringStyle + │ │ ├─┬ module2647 + │ │ │ └─┬ types + │ │ │ └── class ExtendAndImplement │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -3336,6 +3362,7 @@ exports[`types 1`] = ` │ ├── interface NestedStruct │ └── interface ReflectableEntry └─┬ types + ├── class BaseFor2647 ├── class Number ├── class NumericValue ├── class Operation diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap index f7ceb755ab..0cb209e9d1 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap @@ -15,6 +15,7 @@ Array [ "@scope/jsii-calc-base-of-base.Very", "@scope/jsii-calc-base.Base", "@scope/jsii-calc-base.StaticConsumer", + "@scope/jsii-calc-lib.BaseFor2647", "@scope/jsii-calc-lib.Number", "@scope/jsii-calc-lib.NumericValue", "@scope/jsii-calc-lib.Operation", @@ -153,6 +154,7 @@ Array [ "jsii-calc.VoidCallback", "jsii-calc.WithPrivatePropertyInConstructor", "jsii-calc.composition.CompositeOperation", + "jsii-calc.module2647.ExtendAndImplement", "jsii-calc.nodirect.sub1.TypeFromSub1", "jsii-calc.nodirect.sub2.TypeFromSub2", "jsii-calc.onlystatic.OnlyStaticMethods", From 158372188a976033ad4a04ecef430e684698215e Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 15:29:00 +0200 Subject: [PATCH 3/9] imports from ctors --- packages/@scope/jsii-calc-lib/lib/index.ts | 5 +++++ .../lib/targets/go/runtime/method-call.ts | 3 ++- packages/jsii-pacmak/lib/targets/go/types/class.ts | 13 +++++++------ .../lib/targets/go/types/type-member.ts | 7 +++---- .../__snapshots__/target-dotnet.test.ts.snap | 8 ++++---- .../__snapshots__/target-go.test.ts.snap | 10 ++++++---- .../__snapshots__/target-java.test.ts.snap | 10 ++++++---- .../__snapshots__/target-python.test.ts.snap | 14 ++++++++++---- .../test/__snapshots__/jsii-tree.test.ts.snap | 14 ++++++++++---- .../test/__snapshots__/tree.test.ts.snap | 10 ++++++++-- 10 files changed, 61 insertions(+), 33 deletions(-) diff --git a/packages/@scope/jsii-calc-lib/lib/index.ts b/packages/@scope/jsii-calc-lib/lib/index.ts index f600bc35d5..beeee50442 100644 --- a/packages/@scope/jsii-calc-lib/lib/index.ts +++ b/packages/@scope/jsii-calc-lib/lib/index.ts @@ -1,4 +1,5 @@ import * as base from '@scope/jsii-calc-base'; +import { Very } from '@scope/jsii-calc-base-of-base'; /** * Abstract class which represents a numeric value. @@ -117,6 +118,10 @@ export interface IThreeLevelsInterface extends base.IBaseInterface { * @see https://github.com/aws/jsii/issues/2647 */ export class BaseFor2647 { + public constructor(very: Very) { + very.hey(); + } + public foo(obj: base.IBaseInterface): void { obj.bar(); } diff --git a/packages/jsii-pacmak/lib/targets/go/runtime/method-call.ts b/packages/jsii-pacmak/lib/targets/go/runtime/method-call.ts index 01b617e2ca..83abd692a3 100644 --- a/packages/jsii-pacmak/lib/targets/go/runtime/method-call.ts +++ b/packages/jsii-pacmak/lib/targets/go/runtime/method-call.ts @@ -1,4 +1,5 @@ import { CodeMaker } from 'codemaker'; +import { Method } from 'jsii-reflect'; import { GoMethod } from '../types'; import { @@ -86,7 +87,7 @@ export class MethodCall extends FunctionCall { } private get inStatic(): boolean { - return this.parent.method.static; + return Method.isMethod(this.parent.method) && this.parent.method.static; } private get argsString(): string { diff --git a/packages/jsii-pacmak/lib/targets/go/types/class.ts b/packages/jsii-pacmak/lib/targets/go/types/class.ts index 0081b6c75a..2efaad5387 100644 --- a/packages/jsii-pacmak/lib/targets/go/types/class.ts +++ b/packages/jsii-pacmak/lib/targets/go/types/class.ts @@ -15,7 +15,7 @@ import { getMemberDependencies, getParamDependencies } from '../util'; import { GoType } from './go-type'; import { GoTypeRef } from './go-type-reference'; import { GoInterface } from './interface'; -import { GoParameter, GoMethod, GoProperty, GoTypeMember } from './type-member'; +import { GoMethod, GoProperty, GoTypeMember } from './type-member'; /* * GoClass wraps a Typescript class as a Go custom struct type @@ -177,6 +177,7 @@ export class GoClass extends GoType { public get members(): GoTypeMember[] { return [ + ...(this.initializer ? [this.initializer] : []), ...this.methods, ...this.properties, ...this.staticMethods, @@ -326,18 +327,18 @@ export class GoClass extends GoType { } } -export class GoClassConstructor { +export class GoClassConstructor extends GoMethod { + public readonly usesInitPackage = false; + public readonly usesRuntimePackage = false; + private readonly constructorRuntimeCall: ClassConstructor; - public readonly parameters: GoParameter[]; public constructor( public readonly parent: GoClass, private readonly type: Initializer, ) { + super(parent, type); this.constructorRuntimeCall = new ClassConstructor(this); - this.parameters = this.type.parameters.map( - (param) => new GoParameter(parent, param), - ); } public emit(context: EmitContext) { diff --git a/packages/jsii-pacmak/lib/targets/go/types/type-member.ts b/packages/jsii-pacmak/lib/targets/go/types/type-member.ts index 5dc3f235b1..ed8a5a6cb6 100644 --- a/packages/jsii-pacmak/lib/targets/go/types/type-member.ts +++ b/packages/jsii-pacmak/lib/targets/go/types/type-member.ts @@ -1,5 +1,5 @@ import { toPascalCase } from 'codemaker'; -import { Method, Parameter, Property } from 'jsii-reflect'; +import { Callable, Method, Parameter, Property } from 'jsii-reflect'; import { EmitContext } from '../emit-context'; import { GetProperty, JSII_RT_ALIAS, SetProperty } from '../runtime'; @@ -145,11 +145,10 @@ export abstract class GoMethod implements GoTypeMember { public constructor( public readonly parent: GoClass | GoInterface, - public readonly method: Method, + public readonly method: Callable, ) { this.name = toPascalCase(method.name); - - if (method.returns.type) { + if (Method.isMethod(method) && method.returns.type) { this.reference = new GoTypeRef(parent.pkg.root, method.returns.type); } this.parameters = this.method.parameters.map( diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index 4393f565b0..cbcd354145 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -1065,7 +1065,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// /// See: https://github.com/aws/jsii/issues/2647 /// - [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.BaseFor2647), fullyQualifiedName: "@scope/jsii-calc-lib.BaseFor2647")] + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.BaseFor2647), fullyQualifiedName: "@scope/jsii-calc-lib.BaseFor2647", parametersJson: "[{\\"name\\":\\"very\\",\\"type\\":{\\"fqn\\":\\"@scope/jsii-calc-base-of-base.Very\\"}}]")] [System.Obsolete()] public class BaseFor2647 : DeputyBase { @@ -1073,7 +1073,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// Stability: Deprecated /// [System.Obsolete()] - public BaseFor2647(): base(new DeputyProps(System.Array.Empty())) + public BaseFor2647(Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very very): base(new DeputyProps(new object?[]{very})) { } @@ -12132,14 +12132,14 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.Module2647 /// /// See: https://github.com/aws/jsii/issues/2647 /// - [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2647.ExtendAndImplement), fullyQualifiedName: "jsii-calc.module2647.ExtendAndImplement")] + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2647.ExtendAndImplement), fullyQualifiedName: "jsii-calc.module2647.ExtendAndImplement", parametersJson: "[{\\"name\\":\\"very\\",\\"type\\":{\\"fqn\\":\\"@scope/jsii-calc-base-of-base.Very\\"}}]")] public class ExtendAndImplement : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.BaseFor2647, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IFriendly { /// /// Stability: Deprecated /// [System.Obsolete()] - public ExtendAndImplement(): base(new DeputyProps(System.Array.Empty())) + public ExtendAndImplement(Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very very): base(new DeputyProps(new object?[]{very})) { } diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index ae37f6096d..6372713c67 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -1136,6 +1136,7 @@ import ( _init_ "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib/jsii" "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbaseofbase/v2" ) // A base class for testing #2647. @@ -1156,14 +1157,14 @@ type jsiiProxy_BaseFor2647 struct { } // Deprecated. -func NewBaseFor2647() BaseFor2647 { +func NewBaseFor2647(very scopejsiicalcbaseofbase.Very) BaseFor2647 { _init_.Initialize() j := jsiiProxy_BaseFor2647{} _jsii_.Create( "@scope/jsii-calc-lib.BaseFor2647", - nil /* no parameters */, + []interface{}{very}, []_jsii_.FQN{}, nil, // no overrides &j, @@ -14807,6 +14808,7 @@ import ( _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbaseofbase/v2" "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" ) @@ -14827,14 +14829,14 @@ type jsiiProxy_ExtendAndImplement struct { } // Deprecated. -func NewExtendAndImplement() ExtendAndImplement { +func NewExtendAndImplement(very scopejsiicalcbaseofbase.Very) ExtendAndImplement { _init_.Initialize() j := jsiiProxy_ExtendAndImplement{} _jsii_.Create( "jsii-calc.module2647.ExtendAndImplement", - nil /* no parameters */, + []interface{}{very}, []_jsii_.FQN{"@scope/jsii-calc-lib.IFriendly"}, nil, // no overrides &j, diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap index 36e10c1a47..ad1b732858 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap @@ -2356,12 +2356,13 @@ public class BaseFor2647 extends software.amazon.jsii.JsiiObject { } /** + * @param very This parameter is required. */ @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) @Deprecated - public BaseFor2647() { + public BaseFor2647(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.baseofbase.Very very) { super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); - software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(very, "very is required") }); } /** @@ -21735,12 +21736,13 @@ public class ExtendAndImplement extends software.amazon.jsii.tests.calculator.li } /** + * @param very This parameter is required. */ @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) @Deprecated - public ExtendAndImplement() { + public ExtendAndImplement(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.baseofbase.Very very) { super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); - software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(very, "very is required") }); } /** diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index 4bebe28ab8..c853d1f10e 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -1264,6 +1264,7 @@ import typing_extensions from ._jsii import * import scope.jsii_calc_base +import scope.jsii_calc_base_of_base class BaseFor2647( @@ -1280,11 +1281,13 @@ class BaseFor2647( :stability: deprecated ''' - def __init__(self) -> None: + def __init__(self, very: scope.jsii_calc_base_of_base.Very) -> None: ''' + :param very: - + :stability: deprecated ''' - jsii.create(BaseFor2647, self, []) + jsii.create(BaseFor2647, self, [very]) @jsii.member(jsii_name="foo") def foo(self, obj: scope.jsii_calc_base.IBaseInterface) -> None: @@ -10374,6 +10377,7 @@ import typing_extensions from .._jsii import * +import scope.jsii_calc_base_of_base import scope.jsii_calc_lib @@ -10388,11 +10392,13 @@ class ExtendAndImplement( :see: https://github.com/aws/jsii/issues/2647 ''' - def __init__(self) -> None: + def __init__(self, very: scope.jsii_calc_base_of_base.Very) -> None: ''' + :param very: - + :stability: deprecated ''' - jsii.create(ExtendAndImplement, self, []) + jsii.create(ExtendAndImplement, self, [very]) @jsii.member(jsii_name="hello") def hello(self) -> builtins.str: diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap index ed329100bf..2463cf3987 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap @@ -108,7 +108,10 @@ exports[`jsii-tree --all 1`] = ` │ │ │ ├── base: BaseFor2647 │ │ │ ├── interfaces: IFriendly │ │ │ └─┬ members - │ │ │ ├── () initializer (deprecated) + │ │ │ ├─┬ (very) initializer (deprecated) + │ │ │ │ └─┬ parameters + │ │ │ │ └─┬ very + │ │ │ │ └── type: @scope/jsii-calc-base-of-base.Very │ │ │ ├─┬ hello() method (stable) │ │ │ │ └── returns: string │ │ │ └─┬ localMethod() method (stable) @@ -2816,7 +2819,10 @@ exports[`jsii-tree --all 1`] = ` └─┬ types ├─┬ class BaseFor2647 (deprecated) │ └─┬ members - │ ├── () initializer (deprecated) + │ ├─┬ (very) initializer (deprecated) + │ │ └─┬ parameters + │ │ └─┬ very + │ │ └── type: @scope/jsii-calc-base-of-base.Very │ └─┬ foo(obj) method (deprecated) │ ├─┬ parameters │ │ └─┬ obj @@ -3384,7 +3390,7 @@ exports[`jsii-tree --members 1`] = ` │ │ │ └─┬ types │ │ │ └─┬ class ExtendAndImplement │ │ │ └─┬ members - │ │ │ ├── () initializer + │ │ │ ├── (very) initializer │ │ │ ├── hello() method │ │ │ └── localMethod() method │ │ ├─┬ nodirect @@ -4600,7 +4606,7 @@ exports[`jsii-tree --members 1`] = ` └─┬ types ├─┬ class BaseFor2647 │ └─┬ members - │ ├── () initializer + │ ├── (very) initializer │ └── foo(obj) method ├─┬ class Number │ └─┬ members diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap index 42b4b18796..6eaa378b93 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap @@ -207,7 +207,10 @@ exports[`showAll 1`] = ` │ │ │ ├── base: BaseFor2647 │ │ │ ├── interfaces: IFriendly │ │ │ └─┬ members - │ │ │ ├── () initializer + │ │ │ ├─┬ (very) initializer + │ │ │ │ └─┬ parameters + │ │ │ │ └─┬ very + │ │ │ │ └── type: @scope/jsii-calc-base-of-base.Very │ │ │ ├─┬ hello() method │ │ │ │ └── returns: string │ │ │ └─┬ localMethod() method @@ -2915,7 +2918,10 @@ exports[`showAll 1`] = ` └─┬ types ├─┬ class BaseFor2647 │ └─┬ members - │ ├── () initializer + │ ├─┬ (very) initializer + │ │ └─┬ parameters + │ │ └─┬ very + │ │ └── type: @scope/jsii-calc-base-of-base.Very │ └─┬ foo(obj) method │ ├─┬ parameters │ │ └─┬ obj From c068bb50c1ce085ddb9b92e87e3c2ac3dc9ed61a Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 16:37:21 +0200 Subject: [PATCH 4/9] update --- packages/jsii-pacmak/lib/targets/go/types/class.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/go/types/class.ts b/packages/jsii-pacmak/lib/targets/go/types/class.ts index 2efaad5387..1141b81d63 100644 --- a/packages/jsii-pacmak/lib/targets/go/types/class.ts +++ b/packages/jsii-pacmak/lib/targets/go/types/class.ts @@ -328,8 +328,8 @@ export class GoClass extends GoType { } export class GoClassConstructor extends GoMethod { - public readonly usesInitPackage = false; - public readonly usesRuntimePackage = false; + public readonly usesInitPackage = true; + public readonly usesRuntimePackage = true; private readonly constructorRuntimeCall: ClassConstructor; From 086d3297750da70794895fbf274d759353204827 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 17:43:08 +0200 Subject: [PATCH 5/9] fix(go): missing imports required by complex types When a foreign type is referenced within a complex type (array/list), it wasn't included in the import rendering. Fixes #2689 --- packages/jsii-calc/lib/index.ts | 1 + packages/jsii-calc/lib/module2689/index.ts | 10 + .../jsii-calc/lib/module2689/methods/index.ts | 12 + .../jsii-calc/lib/module2689/props/index.ts | 7 + .../jsii-calc/lib/module2689/retval/index.ts | 12 + .../jsii-calc/lib/module2689/structs/index.ts | 7 + packages/jsii-calc/test/assembly.jsii | 301 ++++++++++++++++- .../lib/targets/go/types/go-type-reference.ts | 32 ++ packages/jsii-pacmak/lib/targets/go/util.ts | 16 +- .../__snapshots__/target-dotnet.test.ts.snap | 218 ++++++++++++ .../__snapshots__/target-go.test.ts.snap | 313 ++++++++++++++++++ .../__snapshots__/target-java.test.ts.snap | 296 +++++++++++++++++ .../__snapshots__/target-python.test.ts.snap | 231 +++++++++++++ 13 files changed, 1442 insertions(+), 14 deletions(-) create mode 100644 packages/jsii-calc/lib/module2689/index.ts create mode 100644 packages/jsii-calc/lib/module2689/methods/index.ts create mode 100644 packages/jsii-calc/lib/module2689/props/index.ts create mode 100644 packages/jsii-calc/lib/module2689/retval/index.ts create mode 100644 packages/jsii-calc/lib/module2689/structs/index.ts diff --git a/packages/jsii-calc/lib/index.ts b/packages/jsii-calc/lib/index.ts index 7f40a0c0a9..724888b22e 100644 --- a/packages/jsii-calc/lib/index.ts +++ b/packages/jsii-calc/lib/index.ts @@ -12,3 +12,4 @@ export * as submodule from './submodule'; export * as onlystatic from './only-static'; export * as nodirect from './no-direct-types'; export * as module2647 from './module2647'; +export * as module2689 from './module2689'; diff --git a/packages/jsii-calc/lib/module2689/index.ts b/packages/jsii-calc/lib/module2689/index.ts new file mode 100644 index 0000000000..6d0a18f778 --- /dev/null +++ b/packages/jsii-calc/lib/module2689/index.ts @@ -0,0 +1,10 @@ +// +// Verifies that the correct imports are generated for Go code when forien types +// are referenced in complex fields (array and map). +// +// @see https://github.com/aws/jsii/issues/2689 + +export * as structs from './structs'; +export * as methods from './methods'; +export * as props from './props'; +export * as retval from './retval'; diff --git a/packages/jsii-calc/lib/module2689/methods/index.ts b/packages/jsii-calc/lib/module2689/methods/index.ts new file mode 100644 index 0000000000..bf7221cd83 --- /dev/null +++ b/packages/jsii-calc/lib/module2689/methods/index.ts @@ -0,0 +1,12 @@ +import { BaseProps } from '@scope/jsii-calc-base'; +import { Number as NumberClass } from '@scope/jsii-calc-lib'; + +export class MyClass { + public foo(_values: NumberClass[]) { + return; + } + + public bar(_bar: { [k: string]: BaseProps }) { + return; + } +} diff --git a/packages/jsii-calc/lib/module2689/props/index.ts b/packages/jsii-calc/lib/module2689/props/index.ts new file mode 100644 index 0000000000..8d622f549a --- /dev/null +++ b/packages/jsii-calc/lib/module2689/props/index.ts @@ -0,0 +1,7 @@ +import { BaseProps } from '@scope/jsii-calc-base'; +import { Number as NumberClass } from '@scope/jsii-calc-lib'; + +export class MyClass { + public readonly foo: NumberClass[] = []; + public readonly bar: { [key: string]: BaseProps } = {}; +} diff --git a/packages/jsii-calc/lib/module2689/retval/index.ts b/packages/jsii-calc/lib/module2689/retval/index.ts new file mode 100644 index 0000000000..551ada82b8 --- /dev/null +++ b/packages/jsii-calc/lib/module2689/retval/index.ts @@ -0,0 +1,12 @@ +import { BaseProps } from '@scope/jsii-calc-base'; +import { Number as NumberClass } from '@scope/jsii-calc-lib'; + +export class MyClass { + public foo(): NumberClass[] { + return []; + } + + public bar(): { [k: string]: BaseProps } { + return {}; + } +} diff --git a/packages/jsii-calc/lib/module2689/structs/index.ts b/packages/jsii-calc/lib/module2689/structs/index.ts new file mode 100644 index 0000000000..5aa1393f40 --- /dev/null +++ b/packages/jsii-calc/lib/module2689/structs/index.ts @@ -0,0 +1,7 @@ +import { BaseProps } from '@scope/jsii-calc-base'; +import { Number as NumberClass } from '@scope/jsii-calc-lib'; + +export interface MyStruct { + readonly numbers: NumberClass[]; + readonly baseMap: { [key: string]: BaseProps }; +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 95fa30dbba..73ceb343b1 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -48,7 +48,8 @@ "packageId": "Amazon.JSII.Tests.CalculatorPackageId.BasePackageId" }, "go": { - "moduleName": "github.com/aws/jsii/jsii-calc/go" + "moduleName": "github.com/aws/jsii/jsii-calc/go", + "packageName": "jcb" }, "java": { "maven": { @@ -96,12 +97,15 @@ "@scope/jsii-calc-lib.submodule": { "locationInModule": { "filename": "lib/index.ts", - "line": 125 + "line": 130 }, "targets": { "dotnet": { "namespace": "Amazon.JSII.Tests.CustomSubmoduleName" }, + "go": { + "packageName": "customsubmodulename" + }, "java": { "package": "software.amazon.jsii.tests.calculator.custom_submodule_name" }, @@ -118,7 +122,8 @@ "versionSuffix": "-devpreview" }, "go": { - "moduleName": "github.com/aws/jsii/jsii-calc/go" + "moduleName": "github.com/aws/jsii/jsii-calc/go", + "versionSuffix": "-devpreview" }, "java": { "maven": { @@ -212,6 +217,36 @@ "line": 14 } }, + "jsii-calc.module2689": { + "locationInModule": { + "filename": "lib/index.ts", + "line": 15 + } + }, + "jsii-calc.module2689.methods": { + "locationInModule": { + "filename": "lib/module2689/index.ts", + "line": 8 + } + }, + "jsii-calc.module2689.props": { + "locationInModule": { + "filename": "lib/module2689/index.ts", + "line": 9 + } + }, + "jsii-calc.module2689.retval": { + "locationInModule": { + "filename": "lib/module2689/index.ts", + "line": 10 + } + }, + "jsii-calc.module2689.structs": { + "locationInModule": { + "filename": "lib/module2689/index.ts", + "line": 7 + } + }, "jsii-calc.nodirect": { "locationInModule": { "filename": "lib/index.ts", @@ -14132,7 +14167,19 @@ "initializer": { "docs": { "stability": "deprecated" - } + }, + "locationInModule": { + "filename": "lib/index.ts", + "line": 121 + }, + "parameters": [ + { + "name": "very", + "type": { + "fqn": "@scope/jsii-calc-base-of-base.Very" + } + } + ] }, "interfaces": [ "@scope/jsii-calc-lib.IFriendly" @@ -14179,6 +14226,250 @@ "name": "ExtendAndImplement", "namespace": "module2647" }, + "jsii-calc.module2689.methods.MyClass": { + "assembly": "jsii-calc", + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.module2689.methods.MyClass", + "initializer": { + "docs": { + "stability": "stable" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/module2689/methods/index.ts", + "line": 4 + }, + "methods": [ + { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2689/methods/index.ts", + "line": 9 + }, + "name": "bar", + "parameters": [ + { + "name": "_bar", + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-base.BaseProps" + }, + "kind": "map" + } + } + } + ] + }, + { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2689/methods/index.ts", + "line": 5 + }, + "name": "foo", + "parameters": [ + { + "name": "_values", + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-lib.Number" + }, + "kind": "array" + } + } + } + ] + } + ], + "name": "MyClass", + "namespace": "module2689.methods" + }, + "jsii-calc.module2689.props.MyClass": { + "assembly": "jsii-calc", + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.module2689.props.MyClass", + "initializer": { + "docs": { + "stability": "stable" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/module2689/props/index.ts", + "line": 4 + }, + "name": "MyClass", + "namespace": "module2689.props", + "properties": [ + { + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/module2689/props/index.ts", + "line": 6 + }, + "name": "bar", + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-base.BaseProps" + }, + "kind": "map" + } + } + }, + { + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/module2689/props/index.ts", + "line": 5 + }, + "name": "foo", + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-lib.Number" + }, + "kind": "array" + } + } + } + ] + }, + "jsii-calc.module2689.retval.MyClass": { + "assembly": "jsii-calc", + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.module2689.retval.MyClass", + "initializer": { + "docs": { + "stability": "stable" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/module2689/retval/index.ts", + "line": 4 + }, + "methods": [ + { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2689/retval/index.ts", + "line": 9 + }, + "name": "bar", + "returns": { + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-base.BaseProps" + }, + "kind": "map" + } + } + } + }, + { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2689/retval/index.ts", + "line": 5 + }, + "name": "foo", + "returns": { + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-lib.Number" + }, + "kind": "array" + } + } + } + } + ], + "name": "MyClass", + "namespace": "module2689.retval" + }, + "jsii-calc.module2689.structs.MyStruct": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.module2689.structs.MyStruct", + "kind": "interface", + "locationInModule": { + "filename": "lib/module2689/structs/index.ts", + "line": 4 + }, + "name": "MyStruct", + "namespace": "module2689.structs", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/module2689/structs/index.ts", + "line": 6 + }, + "name": "baseMap", + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-base.BaseProps" + }, + "kind": "map" + } + } + }, + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/module2689/structs/index.ts", + "line": 5 + }, + "name": "numbers", + "type": { + "collection": { + "elementtype": { + "fqn": "@scope/jsii-calc-lib.Number" + }, + "kind": "array" + } + } + } + ] + }, "jsii-calc.nodirect.sub1.TypeFromSub1": { "assembly": "jsii-calc", "docs": { @@ -14935,5 +15226,5 @@ } }, "version": "3.20.120", - "fingerprint": "61fXjiesh/E+ejTgQ0gXmmToVljlc8IbNsEz4o5DDGY=" + "fingerprint": "bEIqxJjC2BFJEo5AIzysYAdDCVZcHPAm+paBHx0vvKE=" } diff --git a/packages/jsii-pacmak/lib/targets/go/types/go-type-reference.ts b/packages/jsii-pacmak/lib/targets/go/types/go-type-reference.ts index 8b1afc42e5..adeba2cfe4 100644 --- a/packages/jsii-pacmak/lib/targets/go/types/go-type-reference.ts +++ b/packages/jsii-pacmak/lib/targets/go/types/go-type-reference.ts @@ -87,6 +87,38 @@ export class GoTypeRef { return this._typeMap; } + /** + * The go `import`s required in order to be able to use this type in code. + */ + public get dependencies(): readonly Package[] { + const ret = new Array(); + + switch (this.typeMap.type) { + case 'interface': + if (this.type?.pkg) { + ret.push(this.type?.pkg); + } + break; + + case 'array': + case 'map': + ret.push(...(this.typeMap.value.dependencies ?? [])); + break; + + case 'union': + for (const t of this.typeMap.value) { + ret.push(...(t.dependencies ?? [])); + } + break; + + case 'void': + case 'primitive': + break; + } + + return ret; + } + /* * Return the name of a type for reference from the `Package` passed in */ diff --git a/packages/jsii-pacmak/lib/targets/go/util.ts b/packages/jsii-pacmak/lib/targets/go/util.ts index 2c8a66dec3..a3055923c3 100644 --- a/packages/jsii-pacmak/lib/targets/go/util.ts +++ b/packages/jsii-pacmak/lib/targets/go/util.ts @@ -43,21 +43,19 @@ export function flatMap( export function getMemberDependencies( members: readonly GoTypeMember[], ): Package[] { - return members.reduce((accum: Package[], member) => { - return member.reference?.type?.pkg - ? [...accum, member.reference?.type.pkg] - : accum; - }, []); + const deps = new Array(); + for (const member of members) { + deps.push(...(member.reference?.dependencies ?? [])); + } + + return deps; } export function getParamDependencies(methods: GoMethod[]): Package[] { const dependencies: Package[] = []; for (const method of methods) { for (const param of method.parameters) { - const pkg = param.reference?.type?.pkg; - if (pkg) { - dependencies.push(pkg); - } + dependencies.push(...(param.reference?.dependencies ?? [])); } } return dependencies; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index cbcd354145..2bf9a80efe 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -2895,6 +2895,16 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 MethodNamedProperty.cs ┃ ┣━ 📁 Module2647 ┃ ┃ ┗━ 📄 ExtendAndImplement.cs + ┃ ┣━ 📁 Module2689 + ┃ ┃ ┣━ 📁 Methods + ┃ ┃ ┃ ┗━ 📄 MyClass.cs + ┃ ┃ ┣━ 📁 Props + ┃ ┃ ┃ ┗━ 📄 MyClass.cs + ┃ ┃ ┣━ 📁 Retval + ┃ ┃ ┃ ┗━ 📄 MyClass.cs + ┃ ┃ ┗━ 📁 Structs + ┃ ┃ ┣━ 📄 IMyStruct.cs + ┃ ┃ ┗━ 📄 MyStruct.cs ┃ ┣━ 📄 Multiply.cs ┃ ┣━ 📄 NamespaceDoc.cs ┃ ┣━ 📄 Negate.cs @@ -12176,6 +12186,214 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.Module2647 `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2689/Methods/MyClass.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2689.Methods +{ + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2689.Methods.MyClass), fullyQualifiedName: "jsii-calc.module2689.methods.MyClass")] + public class MyClass : DeputyBase + { + public MyClass(): base(new DeputyProps(System.Array.Empty())) + { + } + + ///

Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(DeputyProps props): base(props) + { + } + + [JsiiMethod(name: "bar", parametersJson: "[{\\"name\\":\\"_bar\\",\\"type\\":{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-base.BaseProps\\"},\\"kind\\":\\"map\\"}}}]")] + public virtual void Bar(System.Collections.Generic.IDictionary bar) + { + InvokeInstanceVoidMethod(new System.Type[]{typeof(System.Collections.Generic.IDictionary)}, new object[]{bar}); + } + + [JsiiMethod(name: "foo", parametersJson: "[{\\"name\\":\\"_values\\",\\"type\\":{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-lib.Number\\"},\\"kind\\":\\"array\\"}}}]")] + public virtual void Foo(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number[] values) + { + InvokeInstanceVoidMethod(new System.Type[]{typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number[])}, new object[]{values}); + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2689/Props/MyClass.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2689.Props +{ + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2689.Props.MyClass), fullyQualifiedName: "jsii-calc.module2689.props.MyClass")] + public class MyClass : DeputyBase + { + public MyClass(): base(new DeputyProps(System.Array.Empty())) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(DeputyProps props): base(props) + { + } + + [JsiiProperty(name: "bar", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-base.BaseProps\\"},\\"kind\\":\\"map\\"}}")] + public virtual System.Collections.Generic.IDictionary Bar + { + get => GetInstanceProperty>()!; + } + + [JsiiProperty(name: "foo", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-lib.Number\\"},\\"kind\\":\\"array\\"}}")] + public virtual Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number[] Foo + { + get => GetInstanceProperty()!; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2689/Retval/MyClass.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2689.Retval +{ + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2689.Retval.MyClass), fullyQualifiedName: "jsii-calc.module2689.retval.MyClass")] + public class MyClass : DeputyBase + { + public MyClass(): base(new DeputyProps(System.Array.Empty())) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(DeputyProps props): base(props) + { + } + + [JsiiMethod(name: "bar", returnsJson: "{\\"type\\":{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-base.BaseProps\\"},\\"kind\\":\\"map\\"}}}")] + public virtual System.Collections.Generic.IDictionary Bar() + { + return InvokeInstanceMethod>(new System.Type[]{}, new object[]{})!; + } + + [JsiiMethod(name: "foo", returnsJson: "{\\"type\\":{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-lib.Number\\"},\\"kind\\":\\"array\\"}}}")] + public virtual Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number[] Foo() + { + return InvokeInstanceMethod(new System.Type[]{}, new object[]{})!; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2689/Structs/IMyStruct.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2689.Structs +{ + [JsiiInterface(nativeType: typeof(IMyStruct), fullyQualifiedName: "jsii-calc.module2689.structs.MyStruct")] + public interface IMyStruct + { + [JsiiProperty(name: "baseMap", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-base.BaseProps\\"},\\"kind\\":\\"map\\"}}")] + System.Collections.Generic.IDictionary BaseMap + { + get; + } + + [JsiiProperty(name: "numbers", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-lib.Number\\"},\\"kind\\":\\"array\\"}}")] + Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number[] Numbers + { + get; + } + + [JsiiTypeProxy(nativeType: typeof(IMyStruct), fullyQualifiedName: "jsii-calc.module2689.structs.MyStruct")] + internal sealed class _Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.Module2689.Structs.IMyStruct + { + private _Proxy(ByRefValue reference): base(reference) + { + } + + [JsiiProperty(name: "baseMap", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-base.BaseProps\\"},\\"kind\\":\\"map\\"}}")] + public System.Collections.Generic.IDictionary BaseMap + { + get => GetInstanceProperty>()!; + } + + [JsiiProperty(name: "numbers", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-lib.Number\\"},\\"kind\\":\\"array\\"}}")] + public Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number[] Numbers + { + get => GetInstanceProperty()!; + } + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2689/Structs/MyStruct.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2689.Structs +{ + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.module2689.structs.MyStruct")] + public class MyStruct : Amazon.JSII.Tests.CalculatorNamespace.Module2689.Structs.IMyStruct + { + [JsiiProperty(name: "baseMap", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-base.BaseProps\\"},\\"kind\\":\\"map\\"}}", isOverride: true)] + public System.Collections.Generic.IDictionary BaseMap + { + get; + set; + } + + [JsiiProperty(name: "numbers", typeJson: "{\\"collection\\":{\\"elementtype\\":{\\"fqn\\":\\"@scope/jsii-calc-lib.Number\\"},\\"kind\\":\\"array\\"}}", isOverride: true)] + public Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number[] Numbers + { + get; + set; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Multiply.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index 6372713c67..55ec6edd00 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -1852,6 +1852,20 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┣━ 📁 module2647 ┃ ┣━ 📄 module2647.go ┃ ┗━ 📄 module2647.init.go + ┣━ 📁 module2689 + ┃ ┣━ 📁 methods + ┃ ┃ ┣━ 📄 methods.go + ┃ ┃ ┗━ 📄 methods.init.go + ┃ ┣━ 📄 module2689.go + ┃ ┣━ 📁 props + ┃ ┃ ┣━ 📄 props.go + ┃ ┃ ┗━ 📄 props.init.go + ┃ ┣━ 📁 retval + ┃ ┃ ┣━ 📄 retval.go + ┃ ┃ ┗━ 📄 retval.init.go + ┃ ┗━ 📁 structs + ┃ ┣━ 📄 structs.go + ┃ ┗━ 📄 structs.init.go ┣━ 📁 nodirect ┃ ┣━ 📄 nodirect.go ┃ ┣━ 📁 sub1 @@ -14913,6 +14927,305 @@ func init() { `; +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/methods/methods.go 1`] = ` +package methods + +import ( + _jsii_ "github.com/aws/jsii-runtime-go" + _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" + + "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" +) + +type MyClass interface { + Bar(_bar map[string]scopejsiicalcbase.BaseProps) + Foo(_values []scopejsiicalclib.Number) +} + +// The jsii proxy struct for MyClass +type jsiiProxy_MyClass struct { + _ byte // padding +} + +func NewMyClass() MyClass { + _init_.Initialize() + + j := jsiiProxy_MyClass{} + + _jsii_.Create( + "jsii-calc.module2689.methods.MyClass", + nil /* no parameters */, + []_jsii_.FQN{}, + nil, // no overrides + &j, + ) + + return &j +} + +func (m *jsiiProxy_MyClass) Bar(_bar map[string]scopejsiicalcbase.BaseProps) { + _jsii_.InvokeVoid( + m, + "bar", + []interface{}{_bar}, + ) +} + +func (m *jsiiProxy_MyClass) Foo(_values []scopejsiicalclib.Number) { + _jsii_.InvokeVoid( + m, + "foo", + []interface{}{_values}, + ) +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/methods/methods.init.go 1`] = ` +package methods + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterClass( + "jsii-calc.module2689.methods.MyClass", + reflect.TypeOf((*MyClass)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "bar", GoMethod: "Bar"}, + _jsii_.MemberMethod{JsiiMethod: "foo", GoMethod: "Foo"}, + }, + func() interface{} { + return &jsiiProxy_MyClass{} + }, + ) +} + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/module2689.go 1`] = ` +package module2689 + + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/props/props.go 1`] = ` +package props + +import ( + _jsii_ "github.com/aws/jsii-runtime-go" + _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" + + "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" +) + +type MyClass interface { + Bar() map[string]scopejsiicalcbase.BaseProps + Foo() []scopejsiicalclib.Number +} + +// The jsii proxy struct for MyClass +type jsiiProxy_MyClass struct { + _ byte // padding +} + +func (j *jsiiProxy_MyClass) Bar() map[string]scopejsiicalcbase.BaseProps { + var returns map[string]scopejsiicalcbase.BaseProps + _jsii_.Get( + j, + "bar", + &returns, + ) + return returns +} + +func (j *jsiiProxy_MyClass) Foo() []scopejsiicalclib.Number { + var returns []scopejsiicalclib.Number + _jsii_.Get( + j, + "foo", + &returns, + ) + return returns +} + + +func NewMyClass() MyClass { + _init_.Initialize() + + j := jsiiProxy_MyClass{} + + _jsii_.Create( + "jsii-calc.module2689.props.MyClass", + nil /* no parameters */, + []_jsii_.FQN{}, + nil, // no overrides + &j, + ) + + return &j +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/props/props.init.go 1`] = ` +package props + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterClass( + "jsii-calc.module2689.props.MyClass", + reflect.TypeOf((*MyClass)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberProperty{JsiiProperty: "bar", GoGetter: "Bar"}, + _jsii_.MemberProperty{JsiiProperty: "foo", GoGetter: "Foo"}, + }, + func() interface{} { + return &jsiiProxy_MyClass{} + }, + ) +} + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/retval/retval.go 1`] = ` +package retval + +import ( + _jsii_ "github.com/aws/jsii-runtime-go" + _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" + + "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" +) + +type MyClass interface { + Bar() map[string]scopejsiicalcbase.BaseProps + Foo() []scopejsiicalclib.Number +} + +// The jsii proxy struct for MyClass +type jsiiProxy_MyClass struct { + _ byte // padding +} + +func NewMyClass() MyClass { + _init_.Initialize() + + j := jsiiProxy_MyClass{} + + _jsii_.Create( + "jsii-calc.module2689.retval.MyClass", + nil /* no parameters */, + []_jsii_.FQN{}, + nil, // no overrides + &j, + ) + + return &j +} + +func (m *jsiiProxy_MyClass) Bar() map[string]scopejsiicalcbase.BaseProps { + var returns map[string]scopejsiicalcbase.BaseProps + + _jsii_.Invoke( + m, + "bar", + nil /* no parameters */, + &returns, + ) + + return returns +} + +func (m *jsiiProxy_MyClass) Foo() []scopejsiicalclib.Number { + var returns []scopejsiicalclib.Number + + _jsii_.Invoke( + m, + "foo", + nil /* no parameters */, + &returns, + ) + + return returns +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/retval/retval.init.go 1`] = ` +package retval + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterClass( + "jsii-calc.module2689.retval.MyClass", + reflect.TypeOf((*MyClass)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "bar", GoMethod: "Bar"}, + _jsii_.MemberMethod{JsiiMethod: "foo", GoMethod: "Foo"}, + }, + func() interface{} { + return &jsiiProxy_MyClass{} + }, + ) +} + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/structs/structs.go 1`] = ` +package structs + +import ( + "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" +) + +type MyStruct struct { + BaseMap map[string]scopejsiicalcbase.BaseProps \`json:"baseMap"\` + Numbers []scopejsiicalclib.Number \`json:"numbers"\` +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2689/structs/structs.init.go 1`] = ` +package structs + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterStruct( + "jsii-calc.module2689.structs.MyStruct", + reflect.TypeOf((*MyStruct)(nil)).Elem(), + ) +} + +`; + exports[`Generated code for "jsii-calc": /go/jsiicalc/nodirect/nodirect.go 1`] = ` package nodirect diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap index ad1b732858..7ba7f3159c 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap @@ -3712,6 +3712,15 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 MethodNamedProperty.java ┃ ┣━ 📁 module2647 ┃ ┃ ┗━ 📄 ExtendAndImplement.java + ┃ ┣━ 📁 module2689 + ┃ ┃ ┣━ 📁 methods + ┃ ┃ ┃ ┗━ 📄 MyClass.java + ┃ ┃ ┣━ 📁 props + ┃ ┃ ┃ ┗━ 📄 MyClass.java + ┃ ┃ ┣━ 📁 retval + ┃ ┃ ┃ ┗━ 📄 MyClass.java + ┃ ┃ ┗━ 📁 structs + ┃ ┃ ┗━ 📄 MyStruct.java ┃ ┣━ 📄 Multiply.java ┃ ┣━ 📄 Negate.java ┃ ┣━ 📄 NestedClassInstance.java @@ -21764,6 +21773,289 @@ public class ExtendAndImplement extends software.amazon.jsii.tests.calculator.li `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2689/methods/MyClass.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2689.methods; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2689.methods.MyClass") +public class MyClass extends software.amazon.jsii.JsiiObject { + + protected MyClass(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected MyClass(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public MyClass() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + * @param _bar This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public void bar(final @org.jetbrains.annotations.NotNull java.util.Map _bar) { + software.amazon.jsii.Kernel.call(this, "bar", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(_bar, "_bar is required") }); + } + + /** + * @param _values This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public void foo(final @org.jetbrains.annotations.NotNull java.util.List _values) { + software.amazon.jsii.Kernel.call(this, "foo", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(_values, "_values is required") }); + } +} + +`; + +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2689/props/MyClass.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2689.props; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2689.props.MyClass") +public class MyClass extends software.amazon.jsii.JsiiObject { + + protected MyClass(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected MyClass(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public MyClass() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull java.util.Map getBar() { + return java.util.Collections.unmodifiableMap(software.amazon.jsii.Kernel.get(this, "bar", software.amazon.jsii.NativeType.mapOf(software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.base.BaseProps.class)))); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull java.util.List getFoo() { + return java.util.Collections.unmodifiableList(software.amazon.jsii.Kernel.get(this, "foo", software.amazon.jsii.NativeType.listOf(software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.lib.Number.class)))); + } +} + +`; + +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2689/retval/MyClass.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2689.retval; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2689.retval.MyClass") +public class MyClass extends software.amazon.jsii.JsiiObject { + + protected MyClass(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected MyClass(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public MyClass() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull java.util.Map bar() { + return java.util.Collections.unmodifiableMap(software.amazon.jsii.Kernel.call(this, "bar", software.amazon.jsii.NativeType.mapOf(software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.base.BaseProps.class)))); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull java.util.List foo() { + return java.util.Collections.unmodifiableList(software.amazon.jsii.Kernel.call(this, "foo", software.amazon.jsii.NativeType.listOf(software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.lib.Number.class)))); + } +} + +`; + +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2689/structs/MyStruct.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2689.structs; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2689.structs.MyStruct") +@software.amazon.jsii.Jsii.Proxy(MyStruct.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +public interface MyStruct extends software.amazon.jsii.JsiiSerializable { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull java.util.Map getBaseMap(); + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull java.util.List getNumbers(); + + /** + * @return a {@link Builder} of {@link MyStruct} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link MyStruct} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private java.util.Map baseMap; + private java.util.List numbers; + + /** + * Sets the value of {@link MyStruct#getBaseMap} + * @param baseMap the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @SuppressWarnings("unchecked") + public Builder baseMap(java.util.Map baseMap) { + this.baseMap = (java.util.Map)baseMap; + return this; + } + + /** + * Sets the value of {@link MyStruct#getNumbers} + * @param numbers the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @SuppressWarnings("unchecked") + public Builder numbers(java.util.List numbers) { + this.numbers = (java.util.List)numbers; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link MyStruct} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public MyStruct build() { + return new Jsii$Proxy(baseMap, numbers); + } + } + + /** + * An implementation for {@link MyStruct} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @software.amazon.jsii.Internal + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements MyStruct { + private final java.util.Map baseMap; + private final java.util.List numbers; + + /** + * Constructor that initializes the object based on values retrieved from the JsiiObject. + * @param objRef Reference to the JSII managed object. + */ + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + this.baseMap = software.amazon.jsii.Kernel.get(this, "baseMap", software.amazon.jsii.NativeType.mapOf(software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.base.BaseProps.class))); + this.numbers = software.amazon.jsii.Kernel.get(this, "numbers", software.amazon.jsii.NativeType.listOf(software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.lib.Number.class))); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + @SuppressWarnings("unchecked") + protected Jsii$Proxy(final java.util.Map baseMap, final java.util.List numbers) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.baseMap = (java.util.Map)java.util.Objects.requireNonNull(baseMap, "baseMap is required"); + this.numbers = (java.util.List)java.util.Objects.requireNonNull(numbers, "numbers is required"); + } + + @Override + public final java.util.Map getBaseMap() { + return this.baseMap; + } + + @Override + public final java.util.List getNumbers() { + return this.numbers; + } + + @Override + @software.amazon.jsii.Internal + public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { + final com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; + final com.fasterxml.jackson.databind.node.ObjectNode data = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + + data.set("baseMap", om.valueToTree(this.getBaseMap())); + data.set("numbers", om.valueToTree(this.getNumbers())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.module2689.structs.MyStruct")); + struct.set("data", data); + + final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + obj.set("$jsii.struct", struct); + + return obj; + } + + @Override + public final boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MyStruct.Jsii$Proxy that = (MyStruct.Jsii$Proxy) o; + + if (!baseMap.equals(that.baseMap)) return false; + return this.numbers.equals(that.numbers); + } + + @Override + public final int hashCode() { + int result = this.baseMap.hashCode(); + result = 31 * result + (this.numbers.hashCode()); + return result; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/nodirect/sub1/TypeFromSub1.java 1`] = ` package software.amazon.jsii.tests.calculator.nodirect.sub1; @@ -23614,6 +23906,10 @@ jsii-calc.WithPrivatePropertyInConstructor=software.amazon.jsii.tests.calculator jsii-calc.composition.CompositeOperation=software.amazon.jsii.tests.calculator.composition.CompositeOperation jsii-calc.composition.CompositeOperation.CompositionStringStyle=software.amazon.jsii.tests.calculator.composition.CompositeOperation$CompositionStringStyle jsii-calc.module2647.ExtendAndImplement=software.amazon.jsii.tests.calculator.module2647.ExtendAndImplement +jsii-calc.module2689.methods.MyClass=software.amazon.jsii.tests.calculator.module2689.methods.MyClass +jsii-calc.module2689.props.MyClass=software.amazon.jsii.tests.calculator.module2689.props.MyClass +jsii-calc.module2689.retval.MyClass=software.amazon.jsii.tests.calculator.module2689.retval.MyClass +jsii-calc.module2689.structs.MyStruct=software.amazon.jsii.tests.calculator.module2689.structs.MyStruct jsii-calc.nodirect.sub1.TypeFromSub1=software.amazon.jsii.tests.calculator.nodirect.sub1.TypeFromSub1 jsii-calc.nodirect.sub2.TypeFromSub2=software.amazon.jsii.tests.calculator.nodirect.sub2.TypeFromSub2 jsii-calc.onlystatic.OnlyStaticMethods=software.amazon.jsii.tests.calculator.onlystatic.OnlyStaticMethods diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index c853d1f10e..fae2560f1a 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -2103,6 +2103,16 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┗━ 📄 __init__.py ┣━ 📁 module2647 ┃ ┗━ 📄 __init__.py + ┣━ 📁 module2689 + ┃ ┣━ 📄 __init__.py + ┃ ┣━ 📁 methods + ┃ ┃ ┗━ 📄 __init__.py + ┃ ┣━ 📁 props + ┃ ┃ ┗━ 📄 __init__.py + ┃ ┣━ 📁 retval + ┃ ┃ ┗━ 📄 __init__.py + ┃ ┗━ 📁 structs + ┃ ┗━ 📄 __init__.py ┣━ 📁 nodirect ┃ ┣━ 📄 __init__.py ┃ ┣━ 📁 sub1 @@ -2417,6 +2427,11 @@ kwargs = json.loads( "jsii_calc.interface_in_namespace_includes_classes", "jsii_calc.interface_in_namespace_only_interface", "jsii_calc.module2647", + "jsii_calc.module2689", + "jsii_calc.module2689.methods", + "jsii_calc.module2689.props", + "jsii_calc.module2689.retval", + "jsii_calc.module2689.structs", "jsii_calc.nodirect", "jsii_calc.nodirect.sub1", "jsii_calc.nodirect.sub2", @@ -10418,6 +10433,222 @@ publication.publish() `; +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2689/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from .._jsii import * + + +publication.publish() + +`; + +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2689/methods/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from ..._jsii import * + +import scope.jsii_calc_base +import scope.jsii_calc_lib + + +class MyClass( + metaclass=jsii.JSIIMeta, + jsii_type="jsii-calc.module2689.methods.MyClass", +): + def __init__(self) -> None: + jsii.create(MyClass, self, []) + + @jsii.member(jsii_name="bar") + def bar( + self, + _bar: typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps], + ) -> None: + ''' + :param _bar: - + ''' + return typing.cast(None, jsii.invoke(self, "bar", [_bar])) + + @jsii.member(jsii_name="foo") + def foo(self, _values: typing.List[scope.jsii_calc_lib.Number]) -> None: + ''' + :param _values: - + ''' + return typing.cast(None, jsii.invoke(self, "foo", [_values])) + + +__all__ = [ + "MyClass", +] + +publication.publish() + +`; + +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2689/props/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from ..._jsii import * + +import scope.jsii_calc_base +import scope.jsii_calc_lib + + +class MyClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.module2689.props.MyClass"): + def __init__(self) -> None: + jsii.create(MyClass, self, []) + + @builtins.property # type: ignore[misc] + @jsii.member(jsii_name="bar") + def bar(self) -> typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps]: + return typing.cast(typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps], jsii.get(self, "bar")) + + @builtins.property # type: ignore[misc] + @jsii.member(jsii_name="foo") + def foo(self) -> typing.List[scope.jsii_calc_lib.Number]: + return typing.cast(typing.List[scope.jsii_calc_lib.Number], jsii.get(self, "foo")) + + +__all__ = [ + "MyClass", +] + +publication.publish() + +`; + +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2689/retval/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from ..._jsii import * + +import scope.jsii_calc_base +import scope.jsii_calc_lib + + +class MyClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.module2689.retval.MyClass"): + def __init__(self) -> None: + jsii.create(MyClass, self, []) + + @jsii.member(jsii_name="bar") + def bar(self) -> typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps]: + return typing.cast(typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps], jsii.invoke(self, "bar", [])) + + @jsii.member(jsii_name="foo") + def foo(self) -> typing.List[scope.jsii_calc_lib.Number]: + return typing.cast(typing.List[scope.jsii_calc_lib.Number], jsii.invoke(self, "foo", [])) + + +__all__ = [ + "MyClass", +] + +publication.publish() + +`; + +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2689/structs/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from ..._jsii import * + +import scope.jsii_calc_base +import scope.jsii_calc_lib + + +@jsii.data_type( + jsii_type="jsii-calc.module2689.structs.MyStruct", + jsii_struct_bases=[], + name_mapping={"base_map": "baseMap", "numbers": "numbers"}, +) +class MyStruct: + def __init__( + self, + *, + base_map: typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps], + numbers: typing.List[scope.jsii_calc_lib.Number], + ) -> None: + ''' + :param base_map: + :param numbers: + ''' + self._values: typing.Dict[str, typing.Any] = { + "base_map": base_map, + "numbers": numbers, + } + + @builtins.property + def base_map(self) -> typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps]: + result = self._values.get("base_map") + assert result is not None, "Required property 'base_map' is missing" + return typing.cast(typing.Mapping[builtins.str, scope.jsii_calc_base.BaseProps], result) + + @builtins.property + def numbers(self) -> typing.List[scope.jsii_calc_lib.Number]: + result = self._values.get("numbers") + assert result is not None, "Required property 'numbers' is missing" + return typing.cast(typing.List[scope.jsii_calc_lib.Number], result) + + def __eq__(self, rhs: typing.Any) -> builtins.bool: + return isinstance(rhs, self.__class__) and rhs._values == self._values + + def __ne__(self, rhs: typing.Any) -> builtins.bool: + return not (rhs == self) + + def __repr__(self) -> str: + return "MyStruct(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + +__all__ = [ + "MyStruct", +] + +publication.publish() + +`; + exports[`Generated code for "jsii-calc": /python/src/jsii_calc/nodirect/__init__.py 1`] = ` import abc import builtins From 99cf9d1aa71a170ca7f47471e42f0e89c9a77bdc Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 18:48:23 +0200 Subject: [PATCH 6/9] update snapshots --- .../@scope/jsii-calc-lib/test/assembly.jsii | 70 +++++++++++-------- packages/jsii-calc/test/assembly.jsii | 18 ++++- .../__snapshots__/target-go.test.ts.snap | 8 +-- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/packages/@scope/jsii-calc-lib/test/assembly.jsii b/packages/@scope/jsii-calc-lib/test/assembly.jsii index 4ecee638c0..95ac759049 100644 --- a/packages/@scope/jsii-calc-lib/test/assembly.jsii +++ b/packages/@scope/jsii-calc-lib/test/assembly.jsii @@ -93,7 +93,7 @@ "@scope/jsii-calc-lib.submodule": { "locationInModule": { "filename": "lib/index.ts", - "line": 125 + "line": 130 }, "targets": { "dotnet": { @@ -150,12 +150,24 @@ "initializer": { "docs": { "stability": "deprecated" - } + }, + "locationInModule": { + "filename": "lib/index.ts", + "line": 121 + }, + "parameters": [ + { + "name": "very", + "type": { + "fqn": "@scope/jsii-calc-base-of-base.Very" + } + } + ] }, "kind": "class", "locationInModule": { "filename": "lib/index.ts", - "line": 119 + "line": 120 }, "methods": [ { @@ -164,7 +176,7 @@ }, "locationInModule": { "filename": "lib/index.ts", - "line": 120 + "line": 125 }, "name": "foo", "parameters": [ @@ -286,7 +298,7 @@ "kind": "enum", "locationInModule": { "filename": "lib/index.ts", - "line": 97 + "line": 98 }, "members": [ { @@ -314,7 +326,7 @@ "kind": "interface", "locationInModule": { "filename": "lib/index.ts", - "line": 23 + "line": 24 }, "name": "IDoublable", "properties": [ @@ -326,7 +338,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 24 + "line": 25 }, "name": "doubleValue", "type": { @@ -346,7 +358,7 @@ "kind": "interface", "locationInModule": { "filename": "lib/index.ts", - "line": 58 + "line": 59 }, "methods": [ { @@ -357,7 +369,7 @@ }, "locationInModule": { "filename": "lib/index.ts", - "line": 62 + "line": 63 }, "name": "hello", "returns": { @@ -383,7 +395,7 @@ "kind": "interface", "locationInModule": { "filename": "lib/index.ts", - "line": 108 + "line": 109 }, "methods": [ { @@ -393,7 +405,7 @@ }, "locationInModule": { "filename": "lib/index.ts", - "line": 109 + "line": 110 }, "name": "baz" } @@ -411,7 +423,7 @@ "kind": "interface", "locationInModule": { "filename": "lib/index.ts", - "line": 68 + "line": 69 }, "name": "MyFirstStruct", "properties": [ @@ -424,7 +436,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 77 + "line": 78 }, "name": "anumber", "type": { @@ -440,7 +452,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 72 + "line": 73 }, "name": "astring", "type": { @@ -455,7 +467,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 78 + "line": 79 }, "name": "firstOptional", "optional": true, @@ -485,7 +497,7 @@ }, "locationInModule": { "filename": "lib/index.ts", - "line": 35 + "line": 36 }, "parameters": [ { @@ -505,7 +517,7 @@ "kind": "class", "locationInModule": { "filename": "lib/index.ts", - "line": 30 + "line": 31 }, "name": "Number", "properties": [ @@ -517,7 +529,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 42 + "line": 43 }, "name": "doubleValue", "overrides": "@scope/jsii-calc-lib.IDoublable", @@ -533,7 +545,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 35 + "line": 36 }, "name": "value", "overrides": "@scope/jsii-calc-lib.NumericValue", @@ -556,7 +568,7 @@ "kind": "class", "locationInModule": { "filename": "lib/index.ts", - "line": 6 + "line": 7 }, "methods": [ { @@ -566,7 +578,7 @@ }, "locationInModule": { "filename": "lib/index.ts", - "line": 15 + "line": 16 }, "name": "toString", "returns": { @@ -587,7 +599,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 10 + "line": 11 }, "name": "value", "type": { @@ -609,7 +621,7 @@ "kind": "class", "locationInModule": { "filename": "lib/index.ts", - "line": 50 + "line": 51 }, "methods": [ { @@ -620,7 +632,7 @@ }, "locationInModule": { "filename": "lib/index.ts", - "line": 51 + "line": 52 }, "name": "toString", "overrides": "@scope/jsii-calc-lib.NumericValue", @@ -644,7 +656,7 @@ "kind": "interface", "locationInModule": { "filename": "lib/index.ts", - "line": 84 + "line": 85 }, "name": "StructWithOnlyOptionals", "properties": [ @@ -657,7 +669,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 88 + "line": 89 }, "name": "optional1", "optional": true, @@ -673,7 +685,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 89 + "line": 90 }, "name": "optional2", "optional": true, @@ -689,7 +701,7 @@ "immutable": true, "locationInModule": { "filename": "lib/index.ts", - "line": 90 + "line": 91 }, "name": "optional3", "optional": true, @@ -918,5 +930,5 @@ } }, "version": "0.0.0", - "fingerprint": "pW043fHp8icTWympphJfAKrI/5PT2F1nZyyNNyEmTjM=" + "fingerprint": "yaW4nEkJcW4ZyHTJGV9YSAtkrzeBBoXkDffMJBD8dGQ=" } diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 02c16ee585..ff8a023301 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -97,7 +97,7 @@ "@scope/jsii-calc-lib.submodule": { "locationInModule": { "filename": "lib/index.ts", - "line": 125 + "line": 130 }, "targets": { "dotnet": { @@ -14137,7 +14137,19 @@ "initializer": { "docs": { "stability": "deprecated" - } + }, + "locationInModule": { + "filename": "lib/index.ts", + "line": 121 + }, + "parameters": [ + { + "name": "very", + "type": { + "fqn": "@scope/jsii-calc-base-of-base.Very" + } + } + ] }, "interfaces": [ "@scope/jsii-calc-lib.IFriendly" @@ -14940,5 +14952,5 @@ } }, "version": "3.20.120", - "fingerprint": "61fXjiesh/E+ejTgQ0gXmmToVljlc8IbNsEz4o5DDGY=" + "fingerprint": "jhFZc5fa0gXEmH6s8wlAhaQm8CX/ZCHNvpY1jXxwMgE=" } diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index 8de38239c9..1aa712043b 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -1347,7 +1347,7 @@ import ( // // Deprecated. type BaseFor2647 interface { - Foo(obj scopejsiicalcbase.IBaseInterface) + Foo(obj jcb.IBaseInterface) } // The jsii proxy struct for BaseFor2647 @@ -1373,7 +1373,7 @@ func NewBaseFor2647(very scopejsiicalcbaseofbase.Very) BaseFor2647 { } // Deprecated. -func (b *jsiiProxy_BaseFor2647) Foo(obj scopejsiicalcbase.IBaseInterface) { +func (b *jsiiProxy_BaseFor2647) Foo(obj jcb.IBaseInterface) { _jsii_.InvokeVoid( b, "foo", @@ -14807,7 +14807,7 @@ import ( _jsii_ "github.com/aws/jsii-runtime-go" _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" - "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbase" + "github.com/aws/jsii/jsii-calc/go/jcb" "github.com/aws/jsii/jsii-calc/go/scopejsiicalcbaseofbase/v2" "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" ) @@ -14873,7 +14873,7 @@ func (e *jsiiProxy_ExtendAndImplement) LocalMethod() string { } // Deprecated. -func (e *jsiiProxy_ExtendAndImplement) Foo(obj scopejsiicalcbase.IBaseInterface) { +func (e *jsiiProxy_ExtendAndImplement) Foo(obj jcb.IBaseInterface) { _jsii_.InvokeVoid( e, "foo", From fc80dfeebfa43d70f8e03074d043b08e93874f0b Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 22:39:50 +0200 Subject: [PATCH 7/9] update snapshots --- .../test/__snapshots__/jsii-tree.test.ts.snap | 122 ++++++++++++++++++ .../test/__snapshots__/tree.test.ts.snap | 89 +++++++++++++ .../__snapshots__/type-system.test.ts.snap | 3 + 3 files changed, 214 insertions(+) diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap index 2463cf3987..919bf194c9 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap @@ -116,6 +116,56 @@ exports[`jsii-tree --all 1`] = ` │ │ │ │ └── returns: string │ │ │ └─┬ localMethod() method (stable) │ │ │ └── returns: string + │ │ ├─┬ module2689 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ methods + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass (stable) + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer (stable) + │ │ │ │ │ ├─┬ bar(_bar) method (stable) + │ │ │ │ │ │ ├─┬ parameters + │ │ │ │ │ │ │ └─┬ _bar + │ │ │ │ │ │ │ └── type: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ │ │ └── returns: void + │ │ │ │ │ └─┬ foo(_values) method (stable) + │ │ │ │ │ ├─┬ parameters + │ │ │ │ │ │ └─┬ _values + │ │ │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> + │ │ │ │ │ └── returns: void + │ │ │ │ ├─┬ props + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass (stable) + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer (stable) + │ │ │ │ │ ├─┬ bar property (stable) + │ │ │ │ │ │ ├── immutable + │ │ │ │ │ │ └── type: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ │ └─┬ foo property (stable) + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> + │ │ │ │ ├─┬ retval + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass (stable) + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer (stable) + │ │ │ │ │ ├─┬ bar() method (stable) + │ │ │ │ │ │ └── returns: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ │ └─┬ foo() method (stable) + │ │ │ │ │ └── returns: Array<@scope/jsii-calc-lib.Number> + │ │ │ │ └─┬ structs + │ │ │ │ └─┬ types + │ │ │ │ └─┬ interface MyStruct (stable) + │ │ │ │ └─┬ members + │ │ │ │ ├─┬ baseMap property (stable) + │ │ │ │ │ ├── abstract + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ └─┬ numbers property (stable) + │ │ │ │ ├── abstract + │ │ │ │ ├── immutable + │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -2963,6 +3013,21 @@ exports[`jsii-tree --inheritance 1`] = ` │ │ │ └─┬ class ExtendAndImplement │ │ │ ├── base: BaseFor2647 │ │ │ └── interfaces: IFriendly + │ │ ├─┬ module2689 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ methods + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ ├─┬ props + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ ├─┬ retval + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ └─┬ structs + │ │ │ │ └─┬ types + │ │ │ │ └── interface MyStruct + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -3393,6 +3458,36 @@ exports[`jsii-tree --members 1`] = ` │ │ │ ├── (very) initializer │ │ │ ├── hello() method │ │ │ └── localMethod() method + │ │ ├─┬ module2689 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ methods + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer + │ │ │ │ │ ├── bar(_bar) method + │ │ │ │ │ └── foo(_values) method + │ │ │ │ ├─┬ props + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer + │ │ │ │ │ ├── bar property + │ │ │ │ │ └── foo property + │ │ │ │ ├─┬ retval + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer + │ │ │ │ │ ├── bar() method + │ │ │ │ │ └── foo() method + │ │ │ │ └─┬ structs + │ │ │ │ └─┬ types + │ │ │ │ └─┬ interface MyStruct + │ │ │ │ └─┬ members + │ │ │ │ ├── baseMap property + │ │ │ │ └── numbers property + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -4665,6 +4760,12 @@ exports[`jsii-tree --signatures 1`] = ` │ ├── PythonSelf │ ├── composition │ ├── module2647 + │ ├─┬ module2689 + │ │ └─┬ submodules + │ │ ├── methods + │ │ ├── props + │ │ ├── retval + │ │ └── structs │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -4716,6 +4817,21 @@ exports[`jsii-tree --types 1`] = ` │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └── class ExtendAndImplement + │ │ ├─┬ module2689 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ methods + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ ├─┬ props + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ ├─┬ retval + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ └─┬ structs + │ │ │ │ └─┬ types + │ │ │ │ └── interface MyStruct + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -5018,6 +5134,12 @@ exports[`jsii-tree 1`] = ` │ ├── PythonSelf │ ├── composition │ ├── module2647 + │ ├─┬ module2689 + │ │ └─┬ submodules + │ │ ├── methods + │ │ ├── props + │ │ ├── retval + │ │ └── structs │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap index 6eaa378b93..93f71ec70a 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap @@ -10,6 +10,12 @@ exports[`defaults 1`] = ` │ ├── PythonSelf │ ├── composition │ ├── module2647 + │ ├─┬ module2689 + │ │ └─┬ submodules + │ │ ├── methods + │ │ ├── props + │ │ ├── retval + │ │ └── structs │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -43,6 +49,12 @@ exports[`inheritance 1`] = ` │ ├── PythonSelf │ ├── composition │ ├── module2647 + │ ├─┬ module2689 + │ │ └─┬ submodules + │ │ ├── methods + │ │ ├── props + │ │ ├── retval + │ │ └── structs │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -76,6 +88,12 @@ exports[`members 1`] = ` │ ├── PythonSelf │ ├── composition │ ├── module2647 + │ ├─┬ module2689 + │ │ └─┬ submodules + │ │ ├── methods + │ │ ├── props + │ │ ├── retval + │ │ └── structs │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -215,6 +233,56 @@ exports[`showAll 1`] = ` │ │ │ │ └── returns: string │ │ │ └─┬ localMethod() method │ │ │ └── returns: string + │ │ ├─┬ module2689 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ methods + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer + │ │ │ │ │ ├─┬ bar(_bar) method + │ │ │ │ │ │ ├─┬ parameters + │ │ │ │ │ │ │ └─┬ _bar + │ │ │ │ │ │ │ └── type: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ │ │ └── returns: void + │ │ │ │ │ └─┬ foo(_values) method + │ │ │ │ │ ├─┬ parameters + │ │ │ │ │ │ └─┬ _values + │ │ │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> + │ │ │ │ │ └── returns: void + │ │ │ │ ├─┬ props + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer + │ │ │ │ │ ├─┬ bar property + │ │ │ │ │ │ ├── immutable + │ │ │ │ │ │ └── type: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ │ └─┬ foo property + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> + │ │ │ │ ├─┬ retval + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ class MyClass + │ │ │ │ │ └─┬ members + │ │ │ │ │ ├── () initializer + │ │ │ │ │ ├─┬ bar() method + │ │ │ │ │ │ └── returns: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ │ └─┬ foo() method + │ │ │ │ │ └── returns: Array<@scope/jsii-calc-lib.Number> + │ │ │ │ └─┬ structs + │ │ │ │ └─┬ types + │ │ │ │ └─┬ interface MyStruct + │ │ │ │ └─┬ members + │ │ │ │ ├─┬ baseMap property + │ │ │ │ │ ├── abstract + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: Map @scope/jsii-calc-base.BaseProps> + │ │ │ │ └─┬ numbers property + │ │ │ │ ├── abstract + │ │ │ │ ├── immutable + │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -3040,6 +3108,12 @@ exports[`signatures 1`] = ` │ ├── PythonSelf │ ├── composition │ ├── module2647 + │ ├─┬ module2689 + │ │ └─┬ submodules + │ │ ├── methods + │ │ ├── props + │ │ ├── retval + │ │ └── structs │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -3091,6 +3165,21 @@ exports[`types 1`] = ` │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └── class ExtendAndImplement + │ │ ├─┬ module2689 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ methods + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ ├─┬ props + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ ├─┬ retval + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── class MyClass + │ │ │ │ └─┬ structs + │ │ │ │ └─┬ types + │ │ │ │ └── interface MyStruct + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap index 0cb209e9d1..a752a4b7b4 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap @@ -155,6 +155,9 @@ Array [ "jsii-calc.WithPrivatePropertyInConstructor", "jsii-calc.composition.CompositeOperation", "jsii-calc.module2647.ExtendAndImplement", + "jsii-calc.module2689.methods.MyClass", + "jsii-calc.module2689.props.MyClass", + "jsii-calc.module2689.retval.MyClass", "jsii-calc.nodirect.sub1.TypeFromSub1", "jsii-calc.nodirect.sub2.TypeFromSub2", "jsii-calc.onlystatic.OnlyStaticMethods", From 99b3b71f727c9c8fe29a0c1000bbfb1fffbf422c Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 15 Mar 2021 08:52:28 +0200 Subject: [PATCH 8/9] fix(go): duplicate conversion functions when parent structs have the same base name If a struct has two parent structs with the same base name (but different packages), the emitted conversion function will have the same name (`ToParentStruct` and `ToParentStruct`). Since we are not even sure that these base conversion functions are required, omit them for now and we can decide to restore them at a later stage if the use case is clearer. Fixes #2692 --- packages/jsii-calc/lib/index.ts | 1 + packages/jsii-calc/lib/module2692/index.ts | 2 + .../lib/module2692/submodule1/index.ts | 3 + .../lib/module2692/submodule2/index.ts | 9 + packages/jsii-calc/test/assembly.jsii | 120 ++++- .../lib/targets/go/types/struct.ts | 33 -- .../__snapshots__/target-dotnet.test.ts.snap | 206 +++++++++ .../__snapshots__/target-go.test.ts.snap | 97 ++++ .../__snapshots__/target-java.test.ts.snap | 418 ++++++++++++++++++ .../__snapshots__/target-python.test.ts.snap | 192 ++++++++ .../test/__snapshots__/jsii-tree.test.ts.snap | 75 ++++ .../test/__snapshots__/tree.test.ts.snap | 54 +++ 12 files changed, 1176 insertions(+), 34 deletions(-) create mode 100644 packages/jsii-calc/lib/module2692/index.ts create mode 100644 packages/jsii-calc/lib/module2692/submodule1/index.ts create mode 100644 packages/jsii-calc/lib/module2692/submodule2/index.ts diff --git a/packages/jsii-calc/lib/index.ts b/packages/jsii-calc/lib/index.ts index 724888b22e..c13846b335 100644 --- a/packages/jsii-calc/lib/index.ts +++ b/packages/jsii-calc/lib/index.ts @@ -13,3 +13,4 @@ export * as onlystatic from './only-static'; export * as nodirect from './no-direct-types'; export * as module2647 from './module2647'; export * as module2689 from './module2689'; +export * as module2692 from './module2692'; diff --git a/packages/jsii-calc/lib/module2692/index.ts b/packages/jsii-calc/lib/module2692/index.ts new file mode 100644 index 0000000000..b99b106127 --- /dev/null +++ b/packages/jsii-calc/lib/module2692/index.ts @@ -0,0 +1,2 @@ +export * as submodule1 from './submodule1'; +export * as submodule2 from './submodule2'; diff --git a/packages/jsii-calc/lib/module2692/submodule1/index.ts b/packages/jsii-calc/lib/module2692/submodule1/index.ts new file mode 100644 index 0000000000..0f415657c4 --- /dev/null +++ b/packages/jsii-calc/lib/module2692/submodule1/index.ts @@ -0,0 +1,3 @@ +export interface Bar { + readonly bar1: string; +} diff --git a/packages/jsii-calc/lib/module2692/submodule2/index.ts b/packages/jsii-calc/lib/module2692/submodule2/index.ts new file mode 100644 index 0000000000..78499f65a1 --- /dev/null +++ b/packages/jsii-calc/lib/module2692/submodule2/index.ts @@ -0,0 +1,9 @@ +import { Bar as Bar1 } from '../submodule1'; + +export interface Bar { + readonly bar2: string; +} + +export interface Foo extends Bar, Bar1 { + readonly foo2: string; +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 73ceb343b1..cd425e9665 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -247,6 +247,24 @@ "line": 7 } }, + "jsii-calc.module2692": { + "locationInModule": { + "filename": "lib/index.ts", + "line": 16 + } + }, + "jsii-calc.module2692.submodule1": { + "locationInModule": { + "filename": "lib/module2692/index.ts", + "line": 1 + } + }, + "jsii-calc.module2692.submodule2": { + "locationInModule": { + "filename": "lib/module2692/index.ts", + "line": 2 + } + }, "jsii-calc.nodirect": { "locationInModule": { "filename": "lib/index.ts", @@ -14470,6 +14488,106 @@ } ] }, + "jsii-calc.module2692.submodule1.Bar": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.module2692.submodule1.Bar", + "kind": "interface", + "locationInModule": { + "filename": "lib/module2692/submodule1/index.ts", + "line": 1 + }, + "name": "Bar", + "namespace": "module2692.submodule1", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/module2692/submodule1/index.ts", + "line": 2 + }, + "name": "bar1", + "type": { + "primitive": "string" + } + } + ] + }, + "jsii-calc.module2692.submodule2.Bar": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.module2692.submodule2.Bar", + "kind": "interface", + "locationInModule": { + "filename": "lib/module2692/submodule2/index.ts", + "line": 3 + }, + "name": "Bar", + "namespace": "module2692.submodule2", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/module2692/submodule2/index.ts", + "line": 4 + }, + "name": "bar2", + "type": { + "primitive": "string" + } + } + ] + }, + "jsii-calc.module2692.submodule2.Foo": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.module2692.submodule2.Foo", + "interfaces": [ + "jsii-calc.module2692.submodule2.Bar", + "jsii-calc.module2692.submodule1.Bar" + ], + "kind": "interface", + "locationInModule": { + "filename": "lib/module2692/submodule2/index.ts", + "line": 7 + }, + "name": "Foo", + "namespace": "module2692.submodule2", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/module2692/submodule2/index.ts", + "line": 8 + }, + "name": "foo2", + "type": { + "primitive": "string" + } + } + ] + }, "jsii-calc.nodirect.sub1.TypeFromSub1": { "assembly": "jsii-calc", "docs": { @@ -15226,5 +15344,5 @@ } }, "version": "3.20.120", - "fingerprint": "bEIqxJjC2BFJEo5AIzysYAdDCVZcHPAm+paBHx0vvKE=" + "fingerprint": "zzayVZr0GAzkOZJ5SHHy3UvRxdZ1DZAPChbY/MkerHU=" } diff --git a/packages/jsii-pacmak/lib/targets/go/types/struct.ts b/packages/jsii-pacmak/lib/targets/go/types/struct.ts index 0666e948fd..07b80d1b23 100644 --- a/packages/jsii-pacmak/lib/targets/go/types/struct.ts +++ b/packages/jsii-pacmak/lib/targets/go/types/struct.ts @@ -7,7 +7,6 @@ import { Package } from '../package'; import { JSII_RT_ALIAS } from '../runtime'; import { getMemberDependencies } from '../util'; import { GoType } from './go-type'; -import { GoTypeRef } from './go-type-reference'; import { GoProperty } from './type-member'; /* @@ -50,8 +49,6 @@ export class Struct extends GoType { } code.closeBlock(); code.line(); - - this.emitBaseConversions(context); } public emitRegistration(code: CodeMaker): void { @@ -60,34 +57,4 @@ export class Struct extends GoType { code.line(`reflect.TypeOf((*${this.name})(nil)).Elem(),`); code.close(')'); } - - private emitBaseConversions({ code }: EmitContext) { - for (const base of this.type.getInterfaces(true)) { - const baseType = this.pkg.root.findType(base.fqn) as Struct; - const funcName = `To${baseType.name}`; - const instanceVar = this.name[0].toLowerCase(); - const valType = new GoTypeRef(this.pkg.root, base.reference).scopedName( - this.pkg, - ); - - code.line( - `// ${funcName} is a convenience function to obtain a new ${valType} from this ${this.name}.`, - ); - // Note - using a pointer receiver here as a convenience, as otherwise - // user code that somehow has only a pointer would need to first - // dereference it, which tends to be a code smell. - code.openBlock( - `func (${instanceVar} *${this.name}) ${funcName}() ${valType}`, - ); - - code.openBlock(`return ${valType}`); - for (const prop of baseType.properties) { - code.line(`${prop.name}: ${instanceVar}.${prop.name},`); - } - code.closeBlock(); - - code.closeBlock(); - code.line(); - } - } } diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index 2bf9a80efe..d96afa4f88 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -2905,6 +2905,15 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┃ ┗━ 📁 Structs ┃ ┃ ┣━ 📄 IMyStruct.cs ┃ ┃ ┗━ 📄 MyStruct.cs + ┃ ┣━ 📁 Module2692 + ┃ ┃ ┣━ 📁 Submodule1 + ┃ ┃ ┃ ┣━ 📄 Bar.cs + ┃ ┃ ┃ ┗━ 📄 IBar.cs + ┃ ┃ ┗━ 📁 Submodule2 + ┃ ┃ ┣━ 📄 Bar.cs + ┃ ┃ ┣━ 📄 Foo.cs + ┃ ┃ ┣━ 📄 IBar.cs + ┃ ┃ ┗━ 📄 IFoo.cs ┃ ┣━ 📄 Multiply.cs ┃ ┣━ 📄 NamespaceDoc.cs ┃ ┣━ 📄 Negate.cs @@ -12394,6 +12403,203 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.Module2689.Structs `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2692/Submodule1/Bar.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule1 +{ + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.module2692.submodule1.Bar")] + public class Bar : Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule1.IBar + { + [JsiiProperty(name: "bar1", typeJson: "{\\"primitive\\":\\"string\\"}", isOverride: true)] + public string Bar1 + { + get; + set; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2692/Submodule1/IBar.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule1 +{ + [JsiiInterface(nativeType: typeof(IBar), fullyQualifiedName: "jsii-calc.module2692.submodule1.Bar")] + public interface IBar + { + [JsiiProperty(name: "bar1", typeJson: "{\\"primitive\\":\\"string\\"}")] + string Bar1 + { + get; + } + + [JsiiTypeProxy(nativeType: typeof(IBar), fullyQualifiedName: "jsii-calc.module2692.submodule1.Bar")] + internal sealed class _Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule1.IBar + { + private _Proxy(ByRefValue reference): base(reference) + { + } + + [JsiiProperty(name: "bar1", typeJson: "{\\"primitive\\":\\"string\\"}")] + public string Bar1 + { + get => GetInstanceProperty()!; + } + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2692/Submodule2/Bar.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2 +{ + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.module2692.submodule2.Bar")] + public class Bar : Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2.IBar + { + [JsiiProperty(name: "bar2", typeJson: "{\\"primitive\\":\\"string\\"}", isOverride: true)] + public string Bar2 + { + get; + set; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2692/Submodule2/Foo.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2 +{ + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.module2692.submodule2.Foo")] + public class Foo : Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2.IFoo + { + [JsiiProperty(name: "foo2", typeJson: "{\\"primitive\\":\\"string\\"}", isOverride: true)] + public string Foo2 + { + get; + set; + } + + [JsiiProperty(name: "bar2", typeJson: "{\\"primitive\\":\\"string\\"}", isOverride: true)] + public string Bar2 + { + get; + set; + } + + [JsiiProperty(name: "bar1", typeJson: "{\\"primitive\\":\\"string\\"}", isOverride: true)] + public string Bar1 + { + get; + set; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2692/Submodule2/IBar.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2 +{ + [JsiiInterface(nativeType: typeof(IBar), fullyQualifiedName: "jsii-calc.module2692.submodule2.Bar")] + public interface IBar + { + [JsiiProperty(name: "bar2", typeJson: "{\\"primitive\\":\\"string\\"}")] + string Bar2 + { + get; + } + + [JsiiTypeProxy(nativeType: typeof(IBar), fullyQualifiedName: "jsii-calc.module2692.submodule2.Bar")] + internal sealed class _Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2.IBar + { + private _Proxy(ByRefValue reference): base(reference) + { + } + + [JsiiProperty(name: "bar2", typeJson: "{\\"primitive\\":\\"string\\"}")] + public string Bar2 + { + get => GetInstanceProperty()!; + } + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2692/Submodule2/IFoo.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2 +{ + [JsiiInterface(nativeType: typeof(IFoo), fullyQualifiedName: "jsii-calc.module2692.submodule2.Foo")] + public interface IFoo : Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2.IBar, Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule1.IBar + { + [JsiiProperty(name: "foo2", typeJson: "{\\"primitive\\":\\"string\\"}")] + string Foo2 + { + get; + } + + [JsiiTypeProxy(nativeType: typeof(IFoo), fullyQualifiedName: "jsii-calc.module2692.submodule2.Foo")] + new internal sealed class _Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.Module2692.Submodule2.IFoo + { + private _Proxy(ByRefValue reference): base(reference) + { + } + + [JsiiProperty(name: "foo2", typeJson: "{\\"primitive\\":\\"string\\"}")] + public string Foo2 + { + get => GetInstanceProperty()!; + } + + [JsiiProperty(name: "bar2", typeJson: "{\\"primitive\\":\\"string\\"}")] + public string Bar2 + { + get => GetInstanceProperty()!; + } + + [JsiiProperty(name: "bar1", typeJson: "{\\"primitive\\":\\"string\\"}")] + public string Bar1 + { + get => GetInstanceProperty()!; + } + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Multiply.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index eb15d0b961..02855a12f4 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -1866,6 +1866,14 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┗━ 📁 structs ┃ ┣━ 📄 structs.go ┃ ┗━ 📄 structs.init.go + ┣━ 📁 module2692 + ┃ ┣━ 📄 module2692.go + ┃ ┣━ 📁 submodule1 + ┃ ┃ ┣━ 📄 submodule1.go + ┃ ┃ ┗━ 📄 submodule1.init.go + ┃ ┗━ 📁 submodule2 + ┃ ┣━ 📄 submodule2.go + ┃ ┗━ 📄 submodule2.init.go ┣━ 📁 nodirect ┃ ┣━ 📄 nodirect.go ┃ ┣━ 📁 sub1 @@ -15226,6 +15234,95 @@ func init() { `; +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2692/module2692.go 1`] = ` +package module2692 + + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2692/submodule1/submodule1.go 1`] = ` +package submodule1 + + +type Bar struct { + Bar1 string \`json:"bar1"\` +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2692/submodule1/submodule1.init.go 1`] = ` +package submodule1 + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterStruct( + "jsii-calc.module2692.submodule1.Bar", + reflect.TypeOf((*Bar)(nil)).Elem(), + ) +} + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2692/submodule2/submodule2.go 1`] = ` +package submodule2 + + +type Bar struct { + Bar2 string \`json:"bar2"\` +} + +type Foo struct { + Bar2 string \`json:"bar2"\` + Bar1 string \`json:"bar1"\` + Foo2 string \`json:"foo2"\` +} + +// ToBar is a convenience function to obtain a new Bar from this Foo. +func (f *Foo) ToBar() Bar { + return Bar { + Bar2: f.Bar2, + } +} + +// ToBar is a convenience function to obtain a new submodule1.Bar from this Foo. +func (f *Foo) ToBar() submodule1.Bar { + return submodule1.Bar { + Bar1: f.Bar1, + } +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2692/submodule2/submodule2.init.go 1`] = ` +package submodule2 + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterStruct( + "jsii-calc.module2692.submodule2.Bar", + reflect.TypeOf((*Bar)(nil)).Elem(), + ) + _jsii_.RegisterStruct( + "jsii-calc.module2692.submodule2.Foo", + reflect.TypeOf((*Foo)(nil)).Elem(), + ) +} + +`; + exports[`Generated code for "jsii-calc": /go/jsiicalc/nodirect/nodirect.go 1`] = ` package nodirect diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap index 7ba7f3159c..0326cb25f7 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap @@ -3721,6 +3721,12 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┃ ┃ ┗━ 📄 MyClass.java ┃ ┃ ┗━ 📁 structs ┃ ┃ ┗━ 📄 MyStruct.java + ┃ ┣━ 📁 module2692 + ┃ ┃ ┣━ 📁 submodule1 + ┃ ┃ ┃ ┗━ 📄 Bar.java + ┃ ┃ ┗━ 📁 submodule2 + ┃ ┃ ┣━ 📄 Bar.java + ┃ ┃ ┗━ 📄 Foo.java ┃ ┣━ 📄 Multiply.java ┃ ┣━ 📄 Negate.java ┃ ┣━ 📄 NestedClassInstance.java @@ -22056,6 +22062,415 @@ public interface MyStruct extends software.amazon.jsii.JsiiSerializable { `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2692/submodule1/Bar.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2692.submodule1; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2692.submodule1.Bar") +@software.amazon.jsii.Jsii.Proxy(Bar.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +public interface Bar extends software.amazon.jsii.JsiiSerializable { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull java.lang.String getBar1(); + + /** + * @return a {@link Builder} of {@link Bar} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link Bar} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private java.lang.String bar1; + + /** + * Sets the value of {@link Bar#getBar1} + * @param bar1 the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder bar1(java.lang.String bar1) { + this.bar1 = bar1; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link Bar} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public Bar build() { + return new Jsii$Proxy(bar1); + } + } + + /** + * An implementation for {@link Bar} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @software.amazon.jsii.Internal + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements Bar { + private final java.lang.String bar1; + + /** + * Constructor that initializes the object based on values retrieved from the JsiiObject. + * @param objRef Reference to the JSII managed object. + */ + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + this.bar1 = software.amazon.jsii.Kernel.get(this, "bar1", software.amazon.jsii.NativeType.forClass(java.lang.String.class)); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + protected Jsii$Proxy(final java.lang.String bar1) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.bar1 = java.util.Objects.requireNonNull(bar1, "bar1 is required"); + } + + @Override + public final java.lang.String getBar1() { + return this.bar1; + } + + @Override + @software.amazon.jsii.Internal + public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { + final com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; + final com.fasterxml.jackson.databind.node.ObjectNode data = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + + data.set("bar1", om.valueToTree(this.getBar1())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.module2692.submodule1.Bar")); + struct.set("data", data); + + final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + obj.set("$jsii.struct", struct); + + return obj; + } + + @Override + public final boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Bar.Jsii$Proxy that = (Bar.Jsii$Proxy) o; + + return this.bar1.equals(that.bar1); + } + + @Override + public final int hashCode() { + int result = this.bar1.hashCode(); + return result; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2692/submodule2/Bar.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2692.submodule2; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2692.submodule2.Bar") +@software.amazon.jsii.Jsii.Proxy(Bar.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +public interface Bar extends software.amazon.jsii.JsiiSerializable { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull java.lang.String getBar2(); + + /** + * @return a {@link Builder} of {@link Bar} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link Bar} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private java.lang.String bar2; + + /** + * Sets the value of {@link Bar#getBar2} + * @param bar2 the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder bar2(java.lang.String bar2) { + this.bar2 = bar2; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link Bar} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public Bar build() { + return new Jsii$Proxy(bar2); + } + } + + /** + * An implementation for {@link Bar} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @software.amazon.jsii.Internal + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements Bar { + private final java.lang.String bar2; + + /** + * Constructor that initializes the object based on values retrieved from the JsiiObject. + * @param objRef Reference to the JSII managed object. + */ + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + this.bar2 = software.amazon.jsii.Kernel.get(this, "bar2", software.amazon.jsii.NativeType.forClass(java.lang.String.class)); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + protected Jsii$Proxy(final java.lang.String bar2) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.bar2 = java.util.Objects.requireNonNull(bar2, "bar2 is required"); + } + + @Override + public final java.lang.String getBar2() { + return this.bar2; + } + + @Override + @software.amazon.jsii.Internal + public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { + final com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; + final com.fasterxml.jackson.databind.node.ObjectNode data = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + + data.set("bar2", om.valueToTree(this.getBar2())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.module2692.submodule2.Bar")); + struct.set("data", data); + + final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + obj.set("$jsii.struct", struct); + + return obj; + } + + @Override + public final boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Bar.Jsii$Proxy that = (Bar.Jsii$Proxy) o; + + return this.bar2.equals(that.bar2); + } + + @Override + public final int hashCode() { + int result = this.bar2.hashCode(); + return result; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2692/submodule2/Foo.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2692.submodule2; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2692.submodule2.Foo") +@software.amazon.jsii.Jsii.Proxy(Foo.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +public interface Foo extends software.amazon.jsii.JsiiSerializable, software.amazon.jsii.tests.calculator.module2692.submodule2.Bar, software.amazon.jsii.tests.calculator.module2692.submodule1.Bar { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull java.lang.String getFoo2(); + + /** + * @return a {@link Builder} of {@link Foo} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link Foo} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private java.lang.String foo2; + private java.lang.String bar2; + private java.lang.String bar1; + + /** + * Sets the value of {@link Foo#getFoo2} + * @param foo2 the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder foo2(java.lang.String foo2) { + this.foo2 = foo2; + return this; + } + + /** + * Sets the value of {@link Foo#getBar2} + * @param bar2 the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder bar2(java.lang.String bar2) { + this.bar2 = bar2; + return this; + } + + /** + * Sets the value of {@link Foo#getBar1} + * @param bar1 the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder bar1(java.lang.String bar1) { + this.bar1 = bar1; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link Foo} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public Foo build() { + return new Jsii$Proxy(foo2, bar2, bar1); + } + } + + /** + * An implementation for {@link Foo} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @software.amazon.jsii.Internal + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements Foo { + private final java.lang.String foo2; + private final java.lang.String bar2; + private final java.lang.String bar1; + + /** + * Constructor that initializes the object based on values retrieved from the JsiiObject. + * @param objRef Reference to the JSII managed object. + */ + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + this.foo2 = software.amazon.jsii.Kernel.get(this, "foo2", software.amazon.jsii.NativeType.forClass(java.lang.String.class)); + this.bar2 = software.amazon.jsii.Kernel.get(this, "bar2", software.amazon.jsii.NativeType.forClass(java.lang.String.class)); + this.bar1 = software.amazon.jsii.Kernel.get(this, "bar1", software.amazon.jsii.NativeType.forClass(java.lang.String.class)); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + protected Jsii$Proxy(final java.lang.String foo2, final java.lang.String bar2, final java.lang.String bar1) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.foo2 = java.util.Objects.requireNonNull(foo2, "foo2 is required"); + this.bar2 = java.util.Objects.requireNonNull(bar2, "bar2 is required"); + this.bar1 = java.util.Objects.requireNonNull(bar1, "bar1 is required"); + } + + @Override + public final java.lang.String getFoo2() { + return this.foo2; + } + + @Override + public final java.lang.String getBar2() { + return this.bar2; + } + + @Override + public final java.lang.String getBar1() { + return this.bar1; + } + + @Override + @software.amazon.jsii.Internal + public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { + final com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; + final com.fasterxml.jackson.databind.node.ObjectNode data = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + + data.set("foo2", om.valueToTree(this.getFoo2())); + data.set("bar2", om.valueToTree(this.getBar2())); + data.set("bar1", om.valueToTree(this.getBar1())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.module2692.submodule2.Foo")); + struct.set("data", data); + + final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + obj.set("$jsii.struct", struct); + + return obj; + } + + @Override + public final boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Foo.Jsii$Proxy that = (Foo.Jsii$Proxy) o; + + if (!foo2.equals(that.foo2)) return false; + if (!bar2.equals(that.bar2)) return false; + return this.bar1.equals(that.bar1); + } + + @Override + public final int hashCode() { + int result = this.foo2.hashCode(); + result = 31 * result + (this.bar2.hashCode()); + result = 31 * result + (this.bar1.hashCode()); + return result; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/nodirect/sub1/TypeFromSub1.java 1`] = ` package software.amazon.jsii.tests.calculator.nodirect.sub1; @@ -23910,6 +24325,9 @@ jsii-calc.module2689.methods.MyClass=software.amazon.jsii.tests.calculator.modul jsii-calc.module2689.props.MyClass=software.amazon.jsii.tests.calculator.module2689.props.MyClass jsii-calc.module2689.retval.MyClass=software.amazon.jsii.tests.calculator.module2689.retval.MyClass jsii-calc.module2689.structs.MyStruct=software.amazon.jsii.tests.calculator.module2689.structs.MyStruct +jsii-calc.module2692.submodule1.Bar=software.amazon.jsii.tests.calculator.module2692.submodule1.Bar +jsii-calc.module2692.submodule2.Bar=software.amazon.jsii.tests.calculator.module2692.submodule2.Bar +jsii-calc.module2692.submodule2.Foo=software.amazon.jsii.tests.calculator.module2692.submodule2.Foo jsii-calc.nodirect.sub1.TypeFromSub1=software.amazon.jsii.tests.calculator.nodirect.sub1.TypeFromSub1 jsii-calc.nodirect.sub2.TypeFromSub2=software.amazon.jsii.tests.calculator.nodirect.sub2.TypeFromSub2 jsii-calc.onlystatic.OnlyStaticMethods=software.amazon.jsii.tests.calculator.onlystatic.OnlyStaticMethods diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index fae2560f1a..05dc72ab03 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -2113,6 +2113,12 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┃ ┗━ 📄 __init__.py ┃ ┗━ 📁 structs ┃ ┗━ 📄 __init__.py + ┣━ 📁 module2692 + ┃ ┣━ 📄 __init__.py + ┃ ┣━ 📁 submodule1 + ┃ ┃ ┗━ 📄 __init__.py + ┃ ┗━ 📁 submodule2 + ┃ ┗━ 📄 __init__.py ┣━ 📁 nodirect ┃ ┣━ 📄 __init__.py ┃ ┣━ 📁 sub1 @@ -2432,6 +2438,9 @@ kwargs = json.loads( "jsii_calc.module2689.props", "jsii_calc.module2689.retval", "jsii_calc.module2689.structs", + "jsii_calc.module2692", + "jsii_calc.module2692.submodule1", + "jsii_calc.module2692.submodule2", "jsii_calc.nodirect", "jsii_calc.nodirect.sub1", "jsii_calc.nodirect.sub2", @@ -10649,6 +10658,189 @@ publication.publish() `; +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2692/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from .._jsii import * + + +publication.publish() + +`; + +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2692/submodule1/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from ..._jsii import * + + +@jsii.data_type( + jsii_type="jsii-calc.module2692.submodule1.Bar", + jsii_struct_bases=[], + name_mapping={"bar1": "bar1"}, +) +class Bar: + def __init__(self, *, bar1: builtins.str) -> None: + ''' + :param bar1: + ''' + self._values: typing.Dict[str, typing.Any] = { + "bar1": bar1, + } + + @builtins.property + def bar1(self) -> builtins.str: + result = self._values.get("bar1") + assert result is not None, "Required property 'bar1' is missing" + return typing.cast(builtins.str, result) + + def __eq__(self, rhs: typing.Any) -> builtins.bool: + return isinstance(rhs, self.__class__) and rhs._values == self._values + + def __ne__(self, rhs: typing.Any) -> builtins.bool: + return not (rhs == self) + + def __repr__(self) -> str: + return "Bar(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + +__all__ = [ + "Bar", +] + +publication.publish() + +`; + +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2692/submodule2/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from ..._jsii import * + +from ..submodule1 import Bar as _Bar_ec7eccad + + +@jsii.data_type( + jsii_type="jsii-calc.module2692.submodule2.Bar", + jsii_struct_bases=[], + name_mapping={"bar2": "bar2"}, +) +class Bar: + def __init__(self, *, bar2: builtins.str) -> None: + ''' + :param bar2: + ''' + self._values: typing.Dict[str, typing.Any] = { + "bar2": bar2, + } + + @builtins.property + def bar2(self) -> builtins.str: + result = self._values.get("bar2") + assert result is not None, "Required property 'bar2' is missing" + return typing.cast(builtins.str, result) + + def __eq__(self, rhs: typing.Any) -> builtins.bool: + return isinstance(rhs, self.__class__) and rhs._values == self._values + + def __ne__(self, rhs: typing.Any) -> builtins.bool: + return not (rhs == self) + + def __repr__(self) -> str: + return "Bar(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + +@jsii.data_type( + jsii_type="jsii-calc.module2692.submodule2.Foo", + jsii_struct_bases=[Bar, _Bar_ec7eccad], + name_mapping={"bar2": "bar2", "bar1": "bar1", "foo2": "foo2"}, +) +class Foo(Bar, _Bar_ec7eccad): + def __init__( + self, + *, + bar2: builtins.str, + bar1: builtins.str, + foo2: builtins.str, + ) -> None: + ''' + :param bar2: + :param bar1: + :param foo2: + ''' + self._values: typing.Dict[str, typing.Any] = { + "bar2": bar2, + "bar1": bar1, + "foo2": foo2, + } + + @builtins.property + def bar2(self) -> builtins.str: + result = self._values.get("bar2") + assert result is not None, "Required property 'bar2' is missing" + return typing.cast(builtins.str, result) + + @builtins.property + def bar1(self) -> builtins.str: + result = self._values.get("bar1") + assert result is not None, "Required property 'bar1' is missing" + return typing.cast(builtins.str, result) + + @builtins.property + def foo2(self) -> builtins.str: + result = self._values.get("foo2") + assert result is not None, "Required property 'foo2' is missing" + return typing.cast(builtins.str, result) + + def __eq__(self, rhs: typing.Any) -> builtins.bool: + return isinstance(rhs, self.__class__) and rhs._values == self._values + + def __ne__(self, rhs: typing.Any) -> builtins.bool: + return not (rhs == self) + + def __repr__(self) -> str: + return "Foo(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + +__all__ = [ + "Bar", + "Foo", +] + +publication.publish() + +`; + exports[`Generated code for "jsii-calc": /python/src/jsii_calc/nodirect/__init__.py 1`] = ` import abc import builtins diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap index 919bf194c9..29647a6ab0 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap @@ -166,6 +166,34 @@ exports[`jsii-tree --all 1`] = ` │ │ │ │ ├── immutable │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> │ │ │ └── types + │ │ ├─┬ module2692 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ submodule1 + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ interface Bar (stable) + │ │ │ │ │ └─┬ members + │ │ │ │ │ └─┬ bar1 property (stable) + │ │ │ │ │ ├── abstract + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: string + │ │ │ │ └─┬ submodule2 + │ │ │ │ └─┬ types + │ │ │ │ ├─┬ interface Bar (stable) + │ │ │ │ │ └─┬ members + │ │ │ │ │ └─┬ bar2 property (stable) + │ │ │ │ │ ├── abstract + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: string + │ │ │ │ └─┬ interface Foo (stable) + │ │ │ │ ├─┬ interfaces + │ │ │ │ │ ├── Bar + │ │ │ │ │ └── Bar + │ │ │ │ └─┬ members + │ │ │ │ └─┬ foo2 property (stable) + │ │ │ │ ├── abstract + │ │ │ │ ├── immutable + │ │ │ │ └── type: string + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -3028,6 +3056,19 @@ exports[`jsii-tree --inheritance 1`] = ` │ │ │ │ └─┬ types │ │ │ │ └── interface MyStruct │ │ │ └── types + │ │ ├─┬ module2692 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ submodule1 + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── interface Bar + │ │ │ │ └─┬ submodule2 + │ │ │ │ └─┬ types + │ │ │ │ ├── interface Bar + │ │ │ │ └─┬ interface Foo + │ │ │ │ └─┬ interfaces + │ │ │ │ ├── Bar + │ │ │ │ └── Bar + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -3488,6 +3529,22 @@ exports[`jsii-tree --members 1`] = ` │ │ │ │ ├── baseMap property │ │ │ │ └── numbers property │ │ │ └── types + │ │ ├─┬ module2692 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ submodule1 + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ interface Bar + │ │ │ │ │ └─┬ members + │ │ │ │ │ └── bar1 property + │ │ │ │ └─┬ submodule2 + │ │ │ │ └─┬ types + │ │ │ │ ├─┬ interface Bar + │ │ │ │ │ └─┬ members + │ │ │ │ │ └── bar2 property + │ │ │ │ └─┬ interface Foo + │ │ │ │ └─┬ members + │ │ │ │ └── foo2 property + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -4766,6 +4823,10 @@ exports[`jsii-tree --signatures 1`] = ` │ │ ├── props │ │ ├── retval │ │ └── structs + │ ├─┬ module2692 + │ │ └─┬ submodules + │ │ ├── submodule1 + │ │ └── submodule2 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -4832,6 +4893,16 @@ exports[`jsii-tree --types 1`] = ` │ │ │ │ └─┬ types │ │ │ │ └── interface MyStruct │ │ │ └── types + │ │ ├─┬ module2692 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ submodule1 + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── interface Bar + │ │ │ │ └─┬ submodule2 + │ │ │ │ └─┬ types + │ │ │ │ ├── interface Bar + │ │ │ │ └── interface Foo + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -5140,6 +5211,10 @@ exports[`jsii-tree 1`] = ` │ │ ├── props │ │ ├── retval │ │ └── structs + │ ├─┬ module2692 + │ │ └─┬ submodules + │ │ ├── submodule1 + │ │ └── submodule2 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap index 93f71ec70a..fd6a13272e 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap @@ -16,6 +16,10 @@ exports[`defaults 1`] = ` │ │ ├── props │ │ ├── retval │ │ └── structs + │ ├─┬ module2692 + │ │ └─┬ submodules + │ │ ├── submodule1 + │ │ └── submodule2 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -55,6 +59,10 @@ exports[`inheritance 1`] = ` │ │ ├── props │ │ ├── retval │ │ └── structs + │ ├─┬ module2692 + │ │ └─┬ submodules + │ │ ├── submodule1 + │ │ └── submodule2 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -94,6 +102,10 @@ exports[`members 1`] = ` │ │ ├── props │ │ ├── retval │ │ └── structs + │ ├─┬ module2692 + │ │ └─┬ submodules + │ │ ├── submodule1 + │ │ └── submodule2 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -283,6 +295,34 @@ exports[`showAll 1`] = ` │ │ │ │ ├── immutable │ │ │ │ └── type: Array<@scope/jsii-calc-lib.Number> │ │ │ └── types + │ │ ├─┬ module2692 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ submodule1 + │ │ │ │ │ └─┬ types + │ │ │ │ │ └─┬ interface Bar + │ │ │ │ │ └─┬ members + │ │ │ │ │ └─┬ bar1 property + │ │ │ │ │ ├── abstract + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: string + │ │ │ │ └─┬ submodule2 + │ │ │ │ └─┬ types + │ │ │ │ ├─┬ interface Bar + │ │ │ │ │ └─┬ members + │ │ │ │ │ └─┬ bar2 property + │ │ │ │ │ ├── abstract + │ │ │ │ │ ├── immutable + │ │ │ │ │ └── type: string + │ │ │ │ └─┬ interface Foo + │ │ │ │ ├─┬ interfaces + │ │ │ │ │ ├── Bar + │ │ │ │ │ └── Bar + │ │ │ │ └─┬ members + │ │ │ │ └─┬ foo2 property + │ │ │ │ ├── abstract + │ │ │ │ ├── immutable + │ │ │ │ └── type: string + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 @@ -3114,6 +3154,10 @@ exports[`signatures 1`] = ` │ │ ├── props │ │ ├── retval │ │ └── structs + │ ├─┬ module2692 + │ │ └─┬ submodules + │ │ ├── submodule1 + │ │ └── submodule2 │ ├─┬ nodirect │ │ └─┬ submodules │ │ ├── sub1 @@ -3180,6 +3224,16 @@ exports[`types 1`] = ` │ │ │ │ └─┬ types │ │ │ │ └── interface MyStruct │ │ │ └── types + │ │ ├─┬ module2692 + │ │ │ ├─┬ submodules + │ │ │ │ ├─┬ submodule1 + │ │ │ │ │ └─┬ types + │ │ │ │ │ └── interface Bar + │ │ │ │ └─┬ submodule2 + │ │ │ │ └─┬ types + │ │ │ │ ├── interface Bar + │ │ │ │ └── interface Foo + │ │ │ └── types │ │ ├─┬ nodirect │ │ │ ├─┬ submodules │ │ │ │ ├─┬ sub1 From 27969628e52d45e9abc72234af19fbc65560f021 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 15 Mar 2021 09:08:11 +0200 Subject: [PATCH 9/9] fix(go): arguments named "_" result in invalid code It is common in TypeScript to use `_` as an argument name if the argument is not used. This is an invalid name in Go, so replace it with `_arg`. Fixes #2530 --- packages/jsii-calc/lib/index.ts | 1 + packages/jsii-calc/lib/module2530/index.ts | 17 ++ packages/jsii-calc/test/assembly.jsii | 80 ++++++- packages/jsii-pacmak/lib/targets/go/util.ts | 1 + .../__snapshots__/target-dotnet.test.ts.snap | 50 +++++ .../__snapshots__/target-go.test.ts.snap | 196 ++++++++---------- .../__snapshots__/target-java.test.ts.snap | 52 +++++ .../__snapshots__/target-python.test.ts.snap | 53 +++++ .../test/__snapshots__/jsii-tree.test.ts.snap | 34 +++ .../test/__snapshots__/tree.test.ts.snap | 26 +++ .../__snapshots__/type-system.test.ts.snap | 1 + 11 files changed, 398 insertions(+), 113 deletions(-) create mode 100644 packages/jsii-calc/lib/module2530/index.ts diff --git a/packages/jsii-calc/lib/index.ts b/packages/jsii-calc/lib/index.ts index c13846b335..59cc6566c7 100644 --- a/packages/jsii-calc/lib/index.ts +++ b/packages/jsii-calc/lib/index.ts @@ -14,3 +14,4 @@ export * as nodirect from './no-direct-types'; export * as module2647 from './module2647'; export * as module2689 from './module2689'; export * as module2692 from './module2692'; +export * as module2530 from './module2530'; diff --git a/packages/jsii-calc/lib/module2530/index.ts b/packages/jsii-calc/lib/module2530/index.ts new file mode 100644 index 0000000000..5bf1737738 --- /dev/null +++ b/packages/jsii-calc/lib/module2530/index.ts @@ -0,0 +1,17 @@ +/** + * Verifies a method with parameters "_" can be generated. + * @see https://github.com/aws/jsii/issues/2530 + */ +export class MyClass { + public static bar(_: boolean) { + return; + } + + public constructor(_: number) { + return; + } + + public foo(_: string) { + return; + } +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index cd425e9665..59f8a3a8bc 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -211,6 +211,12 @@ "line": 142 } }, + "jsii-calc.module2530": { + "locationInModule": { + "filename": "lib/index.ts", + "line": 17 + } + }, "jsii-calc.module2647": { "locationInModule": { "filename": "lib/index.ts", @@ -14173,6 +14179,78 @@ "name": "CompositionStringStyle", "namespace": "composition.CompositeOperation" }, + "jsii-calc.module2530.MyClass": { + "assembly": "jsii-calc", + "docs": { + "see": "https://github.com/aws/jsii/issues/2530", + "stability": "stable", + "summary": "Verifies a method with parameters \"_\" can be generated." + }, + "fqn": "jsii-calc.module2530.MyClass", + "initializer": { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2530/index.ts", + "line": 10 + }, + "parameters": [ + { + "name": "_", + "type": { + "primitive": "number" + } + } + ] + }, + "kind": "class", + "locationInModule": { + "filename": "lib/module2530/index.ts", + "line": 5 + }, + "methods": [ + { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2530/index.ts", + "line": 6 + }, + "name": "bar", + "parameters": [ + { + "name": "_", + "type": { + "primitive": "boolean" + } + } + ], + "static": true + }, + { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/module2530/index.ts", + "line": 14 + }, + "name": "foo", + "parameters": [ + { + "name": "_", + "type": { + "primitive": "string" + } + } + ] + } + ], + "name": "MyClass", + "namespace": "module2530" + }, "jsii-calc.module2647.ExtendAndImplement": { "assembly": "jsii-calc", "base": "@scope/jsii-calc-lib.BaseFor2647", @@ -15344,5 +15422,5 @@ } }, "version": "3.20.120", - "fingerprint": "zzayVZr0GAzkOZJ5SHHy3UvRxdZ1DZAPChbY/MkerHU=" + "fingerprint": "hBZRskNm0XPeSO9U+PMqKKVZ2faqmKnE9eVN2tY1Wik=" } diff --git a/packages/jsii-pacmak/lib/targets/go/util.ts b/packages/jsii-pacmak/lib/targets/go/util.ts index dfaf47cab9..82e2a634dd 100644 --- a/packages/jsii-pacmak/lib/targets/go/util.ts +++ b/packages/jsii-pacmak/lib/targets/go/util.ts @@ -94,6 +94,7 @@ const RESERVED_WORDS: { [word: string]: string } = { import: 'import_', return: 'return_', var: 'var_', + _: '_arg', }; /* diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index d96afa4f88..3fb31c5bb0 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -2893,6 +2893,8 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 LevelOneProps.cs ┃ ┣━ 📄 LoadBalancedFargateServiceProps.cs ┃ ┣━ 📄 MethodNamedProperty.cs + ┃ ┣━ 📁 Module2530 + ┃ ┃ ┗━ 📄 MyClass.cs ┃ ┣━ 📁 Module2647 ┃ ┃ ┗━ 📄 ExtendAndImplement.cs ┃ ┣━ 📁 Module2689 @@ -12140,6 +12142,54 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2530/MyClass.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Module2530 +{ + /// Verifies a method with parameters "_" can be generated. + /// + /// See: https://github.com/aws/jsii/issues/2530 + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2530.MyClass), fullyQualifiedName: "jsii-calc.module2530.MyClass", parametersJson: "[{\\"name\\":\\"_\\",\\"type\\":{\\"primitive\\":\\"number\\"}}]")] + public class MyClass : DeputyBase + { + public MyClass(double _): base(new DeputyProps(new object?[]{_})) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected MyClass(DeputyProps props): base(props) + { + } + + [JsiiMethod(name: "bar", parametersJson: "[{\\"name\\":\\"_\\",\\"type\\":{\\"primitive\\":\\"boolean\\"}}]")] + public static void Bar(bool _) + { + InvokeStaticVoidMethod(typeof(Amazon.JSII.Tests.CalculatorNamespace.Module2530.MyClass), new System.Type[]{typeof(bool)}, new object[]{_}); + } + + [JsiiMethod(name: "foo", parametersJson: "[{\\"name\\":\\"_\\",\\"type\\":{\\"primitive\\":\\"string\\"}}]")] + public virtual void Foo(string _) + { + InvokeInstanceVoidMethod(new System.Type[]{typeof(string)}, new object[]{_}); + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Module2647/ExtendAndImplement.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index 02855a12f4..d1763ed700 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -294,13 +294,6 @@ type BaseProps struct { Bar string \`json:"bar"\` } -// ToVeryBaseProps is a convenience function to obtain a new scopejsiicalcbaseofbase.VeryBaseProps from this BaseProps. -func (b *BaseProps) ToVeryBaseProps() scopejsiicalcbaseofbase.VeryBaseProps { - return scopejsiicalcbaseofbase.VeryBaseProps { - Foo: b.Foo, - } -} - type IBaseInterface interface { scopejsiicalcbaseofbase.IVeryBaseInterface Bar() @@ -1849,6 +1842,9 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┣━ 📄 jsiicalc.go ┣━ 📄 jsiicalc.init.go ┣━ 📄 LICENSE + ┣━ 📁 module2530 + ┃ ┣━ 📄 module2530.go + ┃ ┗━ 📄 module2530.init.go ┣━ 📁 module2647 ┃ ┣━ 📄 module2647.go ┃ ┗━ 📄 module2647.init.go @@ -4149,13 +4145,6 @@ type ChildStruct982 struct { Bar float64 \`json:"bar"\` } -// ToParentStruct982 is a convenience function to obtain a new ParentStruct982 from this ChildStruct982. -func (c *ChildStruct982) ToParentStruct982() ParentStruct982 { - return ParentStruct982 { - Foo: c.Foo, - } -} - type ClassThatImplementsTheInternalInterface interface { INonInternalInterface A() string @@ -5487,15 +5476,6 @@ type DerivedStruct struct { OptionalArray []string \`json:"optionalArray"\` } -// ToMyFirstStruct is a convenience function to obtain a new scopejsiicalclib.MyFirstStruct from this DerivedStruct. -func (d *DerivedStruct) ToMyFirstStruct() scopejsiicalclib.MyFirstStruct { - return scopejsiicalclib.MyFirstStruct { - Anumber: d.Anumber, - Astring: d.Astring, - FirstOptional: d.FirstOptional, - } -} - type DiamondBottom struct { // Deprecated. HoistedTop string \`json:"hoistedTop"\` @@ -5506,22 +5486,6 @@ type DiamondBottom struct { Bottom string \`json:"bottom"\` } -// ToDiamondLeft is a convenience function to obtain a new scopejsiicalclib.DiamondLeft from this DiamondBottom. -func (d *DiamondBottom) ToDiamondLeft() scopejsiicalclib.DiamondLeft { - return scopejsiicalclib.DiamondLeft { - HoistedTop: d.HoistedTop, - Left: d.Left, - } -} - -// ToDiamondRight is a convenience function to obtain a new scopejsiicalclib.DiamondRight from this DiamondBottom. -func (d *DiamondBottom) ToDiamondRight() scopejsiicalclib.DiamondRight { - return scopejsiicalclib.DiamondRight { - HoistedTop: d.HoistedTop, - Right: d.Right, - } -} - type DiamondInheritanceBaseLevelStruct struct { BaseLevelProperty string \`json:"baseLevelProperty"\` } @@ -5531,25 +5495,11 @@ type DiamondInheritanceFirstMidLevelStruct struct { FirstMidLevelProperty string \`json:"firstMidLevelProperty"\` } -// ToDiamondInheritanceBaseLevelStruct is a convenience function to obtain a new DiamondInheritanceBaseLevelStruct from this DiamondInheritanceFirstMidLevelStruct. -func (d *DiamondInheritanceFirstMidLevelStruct) ToDiamondInheritanceBaseLevelStruct() DiamondInheritanceBaseLevelStruct { - return DiamondInheritanceBaseLevelStruct { - BaseLevelProperty: d.BaseLevelProperty, - } -} - type DiamondInheritanceSecondMidLevelStruct struct { BaseLevelProperty string \`json:"baseLevelProperty"\` SecondMidLevelProperty string \`json:"secondMidLevelProperty"\` } -// ToDiamondInheritanceBaseLevelStruct is a convenience function to obtain a new DiamondInheritanceBaseLevelStruct from this DiamondInheritanceSecondMidLevelStruct. -func (d *DiamondInheritanceSecondMidLevelStruct) ToDiamondInheritanceBaseLevelStruct() DiamondInheritanceBaseLevelStruct { - return DiamondInheritanceBaseLevelStruct { - BaseLevelProperty: d.BaseLevelProperty, - } -} - type DiamondInheritanceTopLevelStruct struct { BaseLevelProperty string \`json:"baseLevelProperty"\` FirstMidLevelProperty string \`json:"firstMidLevelProperty"\` @@ -5557,29 +5507,6 @@ type DiamondInheritanceTopLevelStruct struct { TopLevelProperty string \`json:"topLevelProperty"\` } -// ToDiamondInheritanceBaseLevelStruct is a convenience function to obtain a new DiamondInheritanceBaseLevelStruct from this DiamondInheritanceTopLevelStruct. -func (d *DiamondInheritanceTopLevelStruct) ToDiamondInheritanceBaseLevelStruct() DiamondInheritanceBaseLevelStruct { - return DiamondInheritanceBaseLevelStruct { - BaseLevelProperty: d.BaseLevelProperty, - } -} - -// ToDiamondInheritanceFirstMidLevelStruct is a convenience function to obtain a new DiamondInheritanceFirstMidLevelStruct from this DiamondInheritanceTopLevelStruct. -func (d *DiamondInheritanceTopLevelStruct) ToDiamondInheritanceFirstMidLevelStruct() DiamondInheritanceFirstMidLevelStruct { - return DiamondInheritanceFirstMidLevelStruct { - BaseLevelProperty: d.BaseLevelProperty, - FirstMidLevelProperty: d.FirstMidLevelProperty, - } -} - -// ToDiamondInheritanceSecondMidLevelStruct is a convenience function to obtain a new DiamondInheritanceSecondMidLevelStruct from this DiamondInheritanceTopLevelStruct. -func (d *DiamondInheritanceTopLevelStruct) ToDiamondInheritanceSecondMidLevelStruct() DiamondInheritanceSecondMidLevelStruct { - return DiamondInheritanceSecondMidLevelStruct { - BaseLevelProperty: d.BaseLevelProperty, - SecondMidLevelProperty: d.SecondMidLevelProperty, - } -} - // Verifies that null/undefined can be returned for optional collections. // // This source of collections is disappointing - it'll always give you nothing :( @@ -7683,21 +7610,6 @@ type ImplictBaseOfBase struct { Goo string \`json:"goo"\` } -// ToVeryBaseProps is a convenience function to obtain a new scopejsiicalcbaseofbase.VeryBaseProps from this ImplictBaseOfBase. -func (i *ImplictBaseOfBase) ToVeryBaseProps() scopejsiicalcbaseofbase.VeryBaseProps { - return scopejsiicalcbaseofbase.VeryBaseProps { - Foo: i.Foo, - } -} - -// ToBaseProps is a convenience function to obtain a new jcb.BaseProps from this ImplictBaseOfBase. -func (i *ImplictBaseOfBase) ToBaseProps() jcb.BaseProps { - return jcb.BaseProps { - Foo: i.Foo, - Bar: i.Bar, - } -} - type InbetweenClass interface { PublicClass IPublicInterface2 @@ -14822,6 +14734,87 @@ func init() { `; +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2530/module2530.go 1`] = ` +package module2530 + +import ( + _jsii_ "github.com/aws/jsii-runtime-go" + _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" +) + +// Verifies a method with parameters "_" can be generated. +// See: https://github.com/aws/jsii/issues/2530 +// +type MyClass interface { + Foo(_arg string) +} + +// The jsii proxy struct for MyClass +type jsiiProxy_MyClass struct { + _ byte // padding +} + +func NewMyClass(_arg float64) MyClass { + _init_.Initialize() + + j := jsiiProxy_MyClass{} + + _jsii_.Create( + "jsii-calc.module2530.MyClass", + []interface{}{_arg}, + []_jsii_.FQN{}, + nil, // no overrides + &j, + ) + + return &j +} + +func MyClass_Bar(_arg bool) { + _init_.Initialize() + + _jsii_.StaticInvokeVoid( + "jsii-calc.module2530.MyClass", + "bar", + []interface{}{_arg}, + ) +} + +func (m *jsiiProxy_MyClass) Foo(_arg string) { + _jsii_.InvokeVoid( + m, + "foo", + []interface{}{_arg}, + ) +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/module2530/module2530.init.go 1`] = ` +package module2530 + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go" +) + +func init() { + _jsii_.RegisterClass( + "jsii-calc.module2530.MyClass", + reflect.TypeOf((*MyClass)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "foo", GoMethod: "Foo"}, + }, + func() interface{} { + return &jsiiProxy_MyClass{} + }, + ) +} + +`; + exports[`Generated code for "jsii-calc": /go/jsiicalc/module2647/module2647.go 1`] = ` package module2647 @@ -15284,20 +15277,6 @@ type Foo struct { Foo2 string \`json:"foo2"\` } -// ToBar is a convenience function to obtain a new Bar from this Foo. -func (f *Foo) ToBar() Bar { - return Bar { - Bar2: f.Bar2, - } -} - -// ToBar is a convenience function to obtain a new submodule1.Bar from this Foo. -func (f *Foo) ToBar() submodule1.Bar { - return submodule1.Bar { - Bar1: f.Bar1, - } -} - `; @@ -15799,13 +15778,6 @@ type KwargsProps struct { Extra string \`json:"extra"\` } -// ToSomeStruct is a convenience function to obtain a new SomeStruct from this KwargsProps. -func (k *KwargsProps) ToSomeStruct() SomeStruct { - return SomeStruct { - Prop: k.Prop, - } -} - // Checks that classes can self-reference during initialization. // See: : https://github.com/aws/jsii/pull/1706 // diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap index 0326cb25f7..9f5938badb 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap @@ -3710,6 +3710,8 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 LevelOneProps.java ┃ ┣━ 📄 LoadBalancedFargateServiceProps.java ┃ ┣━ 📄 MethodNamedProperty.java + ┃ ┣━ 📁 module2530 + ┃ ┃ ┗━ 📄 MyClass.java ┃ ┣━ 📁 module2647 ┃ ┃ ┗━ 📄 ExtendAndImplement.java ┃ ┣━ 📁 module2689 @@ -21729,6 +21731,55 @@ public interface Hello extends software.amazon.jsii.JsiiSerializable { `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2530/MyClass.java 1`] = ` +package software.amazon.jsii.tests.calculator.module2530; + +/** + * Verifies a method with parameters "_" can be generated. + *

+ * @see https://github.com/aws/jsii/issues/2530 + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.module2530.MyClass") +public class MyClass extends software.amazon.jsii.JsiiObject { + + protected MyClass(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected MyClass(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + * @param _ This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public MyClass(final @org.jetbrains.annotations.NotNull java.lang.Number _) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(_, "_ is required") }); + } + + /** + * @param _ This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static void bar(final @org.jetbrains.annotations.NotNull java.lang.Boolean _) { + software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.jsii.tests.calculator.module2530.MyClass.class, "bar", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(_, "_ is required") }); + } + + /** + * @param _ This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public void foo(final @org.jetbrains.annotations.NotNull java.lang.String _) { + software.amazon.jsii.Kernel.call(this, "foo", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(_, "_ is required") }); + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/module2647/ExtendAndImplement.java 1`] = ` package software.amazon.jsii.tests.calculator.module2647; @@ -24320,6 +24371,7 @@ jsii-calc.VoidCallback=software.amazon.jsii.tests.calculator.VoidCallback jsii-calc.WithPrivatePropertyInConstructor=software.amazon.jsii.tests.calculator.WithPrivatePropertyInConstructor jsii-calc.composition.CompositeOperation=software.amazon.jsii.tests.calculator.composition.CompositeOperation jsii-calc.composition.CompositeOperation.CompositionStringStyle=software.amazon.jsii.tests.calculator.composition.CompositeOperation$CompositionStringStyle +jsii-calc.module2530.MyClass=software.amazon.jsii.tests.calculator.module2530.MyClass jsii-calc.module2647.ExtendAndImplement=software.amazon.jsii.tests.calculator.module2647.ExtendAndImplement jsii-calc.module2689.methods.MyClass=software.amazon.jsii.tests.calculator.module2689.methods.MyClass jsii-calc.module2689.props.MyClass=software.amazon.jsii.tests.calculator.module2689.props.MyClass diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index 05dc72ab03..6164747308 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -2101,6 +2101,8 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┗━ 📄 __init__.py ┣━ 📁 interface_in_namespace_only_interface ┃ ┗━ 📄 __init__.py + ┣━ 📁 module2530 + ┃ ┗━ 📄 __init__.py ┣━ 📁 module2647 ┃ ┗━ 📄 __init__.py ┣━ 📁 module2689 @@ -2432,6 +2434,7 @@ kwargs = json.loads( "jsii_calc.derived_class_has_no_properties", "jsii_calc.interface_in_namespace_includes_classes", "jsii_calc.interface_in_namespace_only_interface", + "jsii_calc.module2530", "jsii_calc.module2647", "jsii_calc.module2689", "jsii_calc.module2689.methods", @@ -10388,6 +10391,56 @@ publication.publish() `; +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2530/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from .._jsii import * + + +class MyClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.module2530.MyClass"): + '''Verifies a method with parameters "_" can be generated. + + :see: https://github.com/aws/jsii/issues/2530 + ''' + + def __init__(self, _: jsii.Number) -> None: + ''' + :param _: - + ''' + jsii.create(MyClass, self, [_]) + + @jsii.member(jsii_name="bar") # type: ignore[misc] + @builtins.classmethod + def bar(cls, _: builtins.bool) -> None: + ''' + :param _: - + ''' + return typing.cast(None, jsii.sinvoke(cls, "bar", [_])) + + @jsii.member(jsii_name="foo") + def foo(self, _: builtins.str) -> None: + ''' + :param _: - + ''' + return typing.cast(None, jsii.invoke(self, "foo", [_])) + + +__all__ = [ + "MyClass", +] + +publication.publish() + +`; + exports[`Generated code for "jsii-calc": /python/src/jsii_calc/module2647/__init__.py 1`] = ` import abc import builtins diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap index 29647a6ab0..64f0e22032 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap @@ -102,6 +102,25 @@ exports[`jsii-tree --all 1`] = ` │ │ │ └─┬ enum CompositionStringStyle (stable) │ │ │ ├── NORMAL (stable) │ │ │ └── DECORATED (stable) + │ │ ├─┬ module2530 + │ │ │ └─┬ types + │ │ │ └─┬ class MyClass (stable) + │ │ │ └─┬ members + │ │ │ ├─┬ (_) initializer (stable) + │ │ │ │ └─┬ parameters + │ │ │ │ └─┬ _ + │ │ │ │ └── type: number + │ │ │ ├─┬ static bar(_) method (stable) + │ │ │ │ ├── static + │ │ │ │ ├─┬ parameters + │ │ │ │ │ └─┬ _ + │ │ │ │ │ └── type: boolean + │ │ │ │ └── returns: void + │ │ │ └─┬ foo(_) method (stable) + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ _ + │ │ │ │ └── type: string + │ │ │ └── returns: void │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └─┬ class ExtendAndImplement (stable) @@ -3036,6 +3055,9 @@ exports[`jsii-tree --inheritance 1`] = ` │ │ │ ├─┬ class CompositeOperation │ │ │ │ └── base: Operation │ │ │ └── enum CompositionStringStyle + │ │ ├─┬ module2530 + │ │ │ └─┬ types + │ │ │ └── class MyClass │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └─┬ class ExtendAndImplement @@ -3492,6 +3514,13 @@ exports[`jsii-tree --members 1`] = ` │ │ │ └─┬ enum CompositionStringStyle │ │ │ ├── NORMAL │ │ │ └── DECORATED + │ │ ├─┬ module2530 + │ │ │ └─┬ types + │ │ │ └─┬ class MyClass + │ │ │ └─┬ members + │ │ │ ├── (_) initializer + │ │ │ ├── static bar(_) method + │ │ │ └── foo(_) method │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └─┬ class ExtendAndImplement @@ -4816,6 +4845,7 @@ exports[`jsii-tree --signatures 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2530 │ ├── module2647 │ ├─┬ module2689 │ │ └─┬ submodules @@ -4875,6 +4905,9 @@ exports[`jsii-tree --types 1`] = ` │ │ │ └─┬ types │ │ │ ├── class CompositeOperation │ │ │ └── enum CompositionStringStyle + │ │ ├─┬ module2530 + │ │ │ └─┬ types + │ │ │ └── class MyClass │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └── class ExtendAndImplement @@ -5204,6 +5237,7 @@ exports[`jsii-tree 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2530 │ ├── module2647 │ ├─┬ module2689 │ │ └─┬ submodules diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap index fd6a13272e..46d74b4f92 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap @@ -9,6 +9,7 @@ exports[`defaults 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2530 │ ├── module2647 │ ├─┬ module2689 │ │ └─┬ submodules @@ -52,6 +53,7 @@ exports[`inheritance 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2530 │ ├── module2647 │ ├─┬ module2689 │ │ └─┬ submodules @@ -95,6 +97,7 @@ exports[`members 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2530 │ ├── module2647 │ ├─┬ module2689 │ │ └─┬ submodules @@ -231,6 +234,25 @@ exports[`showAll 1`] = ` │ │ │ └─┬ enum CompositionStringStyle │ │ │ ├── NORMAL │ │ │ └── DECORATED + │ │ ├─┬ module2530 + │ │ │ └─┬ types + │ │ │ └─┬ class MyClass + │ │ │ └─┬ members + │ │ │ ├─┬ (_) initializer + │ │ │ │ └─┬ parameters + │ │ │ │ └─┬ _ + │ │ │ │ └── type: number + │ │ │ ├─┬ static bar(_) method + │ │ │ │ ├── static + │ │ │ │ ├─┬ parameters + │ │ │ │ │ └─┬ _ + │ │ │ │ │ └── type: boolean + │ │ │ │ └── returns: void + │ │ │ └─┬ foo(_) method + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ _ + │ │ │ │ └── type: string + │ │ │ └── returns: void │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └─┬ class ExtendAndImplement @@ -3147,6 +3169,7 @@ exports[`signatures 1`] = ` │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf │ ├── composition + │ ├── module2530 │ ├── module2647 │ ├─┬ module2689 │ │ └─┬ submodules @@ -3206,6 +3229,9 @@ exports[`types 1`] = ` │ │ │ └─┬ types │ │ │ ├── class CompositeOperation │ │ │ └── enum CompositionStringStyle + │ │ ├─┬ module2530 + │ │ │ └─┬ types + │ │ │ └── class MyClass │ │ ├─┬ module2647 │ │ │ └─┬ types │ │ │ └── class ExtendAndImplement diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap index a752a4b7b4..6d92c85d98 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap @@ -154,6 +154,7 @@ Array [ "jsii-calc.VoidCallback", "jsii-calc.WithPrivatePropertyInConstructor", "jsii-calc.composition.CompositeOperation", + "jsii-calc.module2530.MyClass", "jsii-calc.module2647.ExtendAndImplement", "jsii-calc.module2689.methods.MyClass", "jsii-calc.module2689.props.MyClass",