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/5] 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/5] 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/5] 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/5] 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 99cf9d1aa71a170ca7f47471e42f0e89c9a77bdc Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 14 Mar 2021 18:48:23 +0200 Subject: [PATCH 5/5] 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",