From f38b1ce5ee2789fa17d579f93496581b0efb3ad5 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Fri, 25 Sep 2020 11:22:08 +0200 Subject: [PATCH] chore(python): documentation improvements (#2028) Improved the documentability of generated Python code by reducing the use of forward references through keeping track of types that were already emitted; and by emitting the kind of forward reference that `sphinx`' `autodoc` extension is able to resolve (forward references within a sub-package must be relative to that sub-package; and nested declarations can not use their surrounding type's name in forward references (those must be relative to the surrounding type's context). Additionally, removed duplicated headings that were generated for documentation segments (`see`, `returns`, ...), as those were causing redundant content to appear on the generated docsite. This completely removes `ForwardRef` instances from the Python reference documentation (as was checked by issuing a recursive `grep` on the generated documentation). Fixes #474 Related #1919 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- packages/jsii-calc/lib/compliance.ts | 20 + packages/jsii-calc/test/assembly.jsii | 144 +++++- packages/jsii-pacmak/lib/targets/python.ts | 74 ++- .../lib/targets/python/type-name.ts | 60 ++- .../__snapshots__/target-dotnet.test.ts.snap | 322 ++++++++++++- .../__snapshots__/target-go.test.ts.snap | 75 +++ .../__snapshots__/target-java.test.ts.snap | 428 ++++++++++++++++++ .../__snapshots__/target-python.test.ts.snap | 401 ++++++++-------- .../test/targets/python/type-name.test.ts | 48 +- .../test/__snapshots__/jsii-tree.test.js.snap | 48 ++ .../__snapshots__/type-system.test.js.snap | 1 + 11 files changed, 1355 insertions(+), 266 deletions(-) diff --git a/packages/jsii-calc/lib/compliance.ts b/packages/jsii-calc/lib/compliance.ts index a9850416d4..43a187a47c 100644 --- a/packages/jsii-calc/lib/compliance.ts +++ b/packages/jsii-calc/lib/compliance.ts @@ -2820,3 +2820,23 @@ export class DynamicPropertyBearerChild extends DynamicPropertyBearer { return oldValue; } } + +/** + * Validates that nested classes get correct code generation for the occasional + * forward reference. + */ +export class LevelOne { + public constructor(public readonly props: LevelOneProps) {} +} +export interface LevelOneProps { + readonly prop: LevelOne.PropProperty; +} +export namespace LevelOne { + export interface PropProperty { + readonly prop: PropBooleanValue; + } + + export interface PropBooleanValue { + readonly value: boolean; + } +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 0d66403a9c..b4b1d0bbda 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -8169,6 +8169,148 @@ ], "name": "JsonFormatter" }, + "jsii-calc.LevelOne": { + "assembly": "jsii-calc", + "docs": { + "stability": "stable", + "summary": "Validates that nested classes get correct code generation for the occasional forward reference." + }, + "fqn": "jsii-calc.LevelOne", + "initializer": { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2829 + }, + "parameters": [ + { + "name": "props", + "type": { + "fqn": "jsii-calc.LevelOneProps" + } + } + ] + }, + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2828 + }, + "name": "LevelOne", + "properties": [ + { + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2829 + }, + "name": "props", + "type": { + "fqn": "jsii-calc.LevelOneProps" + } + } + ] + }, + "jsii-calc.LevelOne.PropBooleanValue": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.LevelOne.PropBooleanValue", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2839 + }, + "name": "PropBooleanValue", + "namespace": "LevelOne", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2840 + }, + "name": "value", + "type": { + "primitive": "boolean" + } + } + ] + }, + "jsii-calc.LevelOne.PropProperty": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.LevelOne.PropProperty", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2835 + }, + "name": "PropProperty", + "namespace": "LevelOne", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2836 + }, + "name": "prop", + "type": { + "fqn": "jsii-calc.LevelOne.PropBooleanValue" + } + } + ] + }, + "jsii-calc.LevelOneProps": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.LevelOneProps", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2831 + }, + "name": "LevelOneProps", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2832 + }, + "name": "prop", + "type": { + "fqn": "jsii-calc.LevelOne.PropProperty" + } + } + ] + }, "jsii-calc.LoadBalancedFargateServiceProps": { "assembly": "jsii-calc", "datatype": true, @@ -13970,5 +14112,5 @@ } }, "version": "0.0.0", - "fingerprint": "Ddy05wOucU4yV7YP5fPUzEjiOsl5AGPrwJS7pXpJRPI=" + "fingerprint": "ary2D/3pPPIqMW0FmZnYMsKzvk8r29qmK5+1KyEcTQA=" } diff --git a/packages/jsii-pacmak/lib/targets/python.ts b/packages/jsii-pacmak/lib/targets/python.ts index ea60070814..48f2e3d7b6 100644 --- a/packages/jsii-pacmak/lib/targets/python.ts +++ b/packages/jsii-pacmak/lib/targets/python.ts @@ -89,6 +89,7 @@ export default class Python extends Target { { cwd: sourceDir, env, + retry: { maxAttempts: 5 }, }, ); await shell(python, ['-m', 'twine', 'check', path.join(outDir, '*')], { @@ -231,7 +232,7 @@ interface PythonBase { interface PythonType extends PythonBase { // The JSII FQN for this item, if this item doesn't exist as a JSII type, then it // doesn't have a FQN and it should be null; - readonly fqn: string | null; + readonly fqn?: string; addMember(member: PythonBase): void; } @@ -256,7 +257,7 @@ abstract class BasePythonClassType implements PythonType, ISortableType { public constructor( protected readonly generator: PythonGenerator, public readonly pythonName: string, - public readonly fqn: string | null, + public readonly fqn: string | undefined, opts: PythonTypeOpts, protected readonly docs: spec.Docs | undefined, ) { @@ -311,7 +312,7 @@ abstract class BasePythonClassType implements PythonType, ISortableType { } public emit(code: CodeMaker, context: EmitContext) { - context = { ...context, nestingScope: this.fqn! }; + context = nestedContext(context, this.fqn); const classParams = this.getClassParams(context); openSignature(code, 'class', this.pythonName, classParams); @@ -341,6 +342,10 @@ abstract class BasePythonClassType implements PythonType, ISortableType { } code.closeBlock(); + + if (this.fqn != null) { + context.emittedTypes.add(this.fqn); + } } protected boundResolver(resolver: TypeResolver): TypeResolver { @@ -464,7 +469,7 @@ abstract class BaseMethod implements PythonBase { pythonParams.push(`${paramName}: ${paramType}${paramDefault}`); } - const documentableArgs = this.parameters + const documentableArgs: DocumentableArgument[] = this.parameters // If there's liftedProps, the last argument is the struct and it won't be _actually_ emitted. .filter((_, index) => this.liftedProp != null ? index < this.parameters.length - 1 : true, @@ -788,7 +793,7 @@ abstract class BaseProperty implements PythonBase { class Interface extends BasePythonClassType { public emit(code: CodeMaker, context: EmitContext) { - context = { ...context, nestingScope: this.fqn! }; + context = nestedContext(context, this.fqn); emitList(code, '@jsii.interface(', [`jsii_type="${this.fqn}"`], ')'); // First we do our normal class logic for emitting our members. @@ -825,6 +830,10 @@ class Interface extends BasePythonClassType { } code.closeBlock(); + + if (this.fqn != null) { + context.emittedTypes.add(this.fqn); + } } protected getClassParams(context: EmitContext): string[] { @@ -878,7 +887,7 @@ class Struct extends BasePythonClassType { } public emit(code: CodeMaker, context: EmitContext) { - context = { ...context, nestingScope: this.fqn! }; + context = nestedContext(context, this.fqn); const baseInterfaces = this.getClassParams(context); code.indent('@jsii.data_type('); @@ -897,6 +906,10 @@ class Struct extends BasePythonClassType { this.emitMagicMethods(code); code.closeBlock(); + + if (this.fqn != null) { + context.emittedTypes.add(this.fqn); + } } public requiredImports(context: EmitContext) { @@ -922,7 +935,7 @@ class Struct extends BasePythonClassType { } private get thisInterface() { - if (this.fqn === null) { + if (this.fqn == null) { throw new Error('FQN not set'); } return this.generator.reflectAssembly.system.findInterface(this.fqn); @@ -1190,7 +1203,7 @@ class Class extends BasePythonClassType implements ISortableType { // this logic, except only emiting abstract methods and properties as non // abstract, and subclassing our initial class. if (this.abstract) { - context = { ...context, nestingScope: this.fqn! }; + context = nestedContext(context, this.fqn); const proxyBases = [this.pythonName]; for (const base of this.abstractBases) { @@ -1302,7 +1315,7 @@ class Enum extends BasePythonClassType { protected readonly separateMembers = false; public emit(code: CodeMaker, context: EmitContext) { - context = { ...context, nestingScope: this.fqn! }; + context = nestedContext(context, this.fqn); emitList(code, '@jsii.enum(', [`jsii_type="${this.fqn}"`], ')'); return super.emit(code, context); } @@ -1359,7 +1372,7 @@ class PythonModule implements PythonType { public constructor( public readonly pythonName: string, - public readonly fqn: string | null, + public readonly fqn: string | undefined, opts: ModuleOpts, ) { this.assembly = opts.assembly; @@ -1566,7 +1579,7 @@ class PythonModule implements PythonType { interface PackageData { filename: string; - data: string | null; + data: string | undefined; } class Package { @@ -1594,7 +1607,11 @@ class Package { this.modules.set(module.pythonName, module); } - public addData(module: PythonModule, filename: string, data: string | null) { + public addData( + module: PythonModule, + filename: string, + data: string | undefined, + ) { if (!this.data.has(module.pythonName)) { this.data.set(module.pythonName, []); } @@ -1995,15 +2012,14 @@ class PythonGenerator extends Generator { if (doBrk) { brk(); } - lines.push(heading); const contentLines = md2rst(content).split('\n'); if (contentLines.length <= 1) { - lines.push(`:${heading}: ${contentLines.join('')}`); + lines.push(`:${heading}: ${contentLines.join('')}`.trim()); } else { lines.push(`:${heading}:`); brk(); for (const line of contentLines) { - lines.push(`${line}`); + lines.push(line.trim()); } } if (doBrk) { @@ -2053,7 +2069,7 @@ class PythonGenerator extends Generator { } for (const [k, v] of Object.entries(docs.custom ?? {})) { - block(`${k}:`, v, false); + block(k, v, false); } if (docs.example) { @@ -2151,7 +2167,7 @@ class PythonGenerator extends Generator { // This is the '._jsii' module const assemblyModule = new PythonModule( this.getAssemblyModuleName(assm), - null, + undefined, { assembly: assm, assemblyFilename: this.getAssemblyFileName(), @@ -2161,7 +2177,7 @@ class PythonGenerator extends Generator { ); this.package.addModule(assemblyModule); - this.package.addData(assemblyModule, this.getAssemblyFileName(), null); + this.package.addData(assemblyModule, this.getAssemblyFileName(), undefined); } protected onEndAssembly(assm: spec.Assembly, _fingerprint: boolean) { @@ -2172,8 +2188,9 @@ class PythonGenerator extends Generator { ); this.package.write(this.code, { assembly: assm, - submodule: assm.name, + emittedTypes: new Set(), resolver, + submodule: assm.name, }); } @@ -2428,7 +2445,7 @@ class PythonGenerator extends Generator { private getParentFQN(fqn: string): string { const m = /^(.+)\.[^.]+$/.exec(fqn); - if (m === null) { + if (m == null) { throw new Error(`Could not determine parent FQN of: ${fqn}`); } @@ -2440,7 +2457,7 @@ class PythonGenerator extends Generator { } private addPythonType(type: PythonType) { - if (type.fqn === null) { + if (type.fqn == null) { throw new Error('Cannot add a Python type without a FQN.'); } @@ -2505,7 +2522,7 @@ interface DocumentableArgument { */ function onelineDescription(docs: spec.Docs | undefined) { // Only consider a subset of fields here, we don't have a lot of formatting space - if (!docs) { + if (!docs || Object.keys(docs).length === 0) { return '-'; } @@ -2763,3 +2780,16 @@ function totalSizeOf(strings: readonly string[], join: string) { joinSize: strings.length > 1 ? join.length * (strings.length - 1) : 0, }; } + +function nestedContext( + context: EmitContext, + fqn: string | undefined, +): EmitContext { + return { + ...context, + surroundingTypeFqns: + fqn != null + ? [...(context.surroundingTypeFqns ?? []), fqn] + : context.surroundingTypeFqns, + }; +} diff --git a/packages/jsii-pacmak/lib/targets/python/type-name.ts b/packages/jsii-pacmak/lib/targets/python/type-name.ts index d8cb56b020..3ef295d500 100644 --- a/packages/jsii-pacmak/lib/targets/python/type-name.ts +++ b/packages/jsii-pacmak/lib/targets/python/type-name.ts @@ -47,11 +47,15 @@ export interface NamingContext { readonly typeAnnotation?: boolean; /** - * The nesting scope in which the PythonType is expressed (if any) + * A an array representing the stack of declarations currently being + * initialized. All of these names can only be referred to using a forward + * reference (stringified type name) in the context of type signatures (but + * they can be used safely from implementations so long as those are not *run* + * as part of the declaration). * - * @default - none + * @default [] */ - readonly nestingScope?: string | undefined; + readonly surroundingTypeFqns?: readonly string[]; /** * Disables generating typing.Optional wrappers @@ -59,6 +63,13 @@ export interface NamingContext { * @internal */ readonly ignoreOptional?: boolean; + + /** + * The set of jsii type FQNs that have already been emitted so far. This is + * used to determine whether a given type reference is a forward declaration + * or not when emitting type signatures. + */ + readonly emittedTypes: Set; } export function toTypeName(ref?: OptionalValue | TypeReference): TypeName { @@ -269,8 +280,9 @@ class UserType implements TypeName { private resolve({ assembly, + emittedTypes, submodule, - nestingScope, + surroundingTypeFqns, typeAnnotation = true, }: NamingContext) { const { assemblyName, packageName, pythonFqn } = toPythonFqn( @@ -294,17 +306,37 @@ class UserType implements TypeName { ).pythonFqn; if (typeSubmodulePythonName === submodulePythonName) { - // Submodule-local type, so we'll just drop the submodule name prefix here, unless we are - // referencing a type within the current nesting context, where we'll want to make a context - // local reference by dropping the nesting type's name prefix. - const nestingParent = - nestingScope && toPythonFqn(nestingScope, assembly).pythonFqn; - const localName = - nestingParent && pythonFqn.startsWith(`${nestingParent}.`) - ? pythonFqn.substring(nestingParent.length + 1) - : pythonFqn.substring(typeSubmodulePythonName.length + 1); + // Identifiy declarations that are not yet initialized and hence cannot be + // used as part of a type qualification. Since this is not a forward + // reference, the type was already emitted and its un-qualified name must + // be used instead of it's locally qualified name. + const nestingParent = surroundingTypeFqns + ?.map((fqn) => toPythonFqn(fqn, assembly).pythonFqn) + ?.reverse() + ?.find((parent) => pythonFqn.startsWith(`${parent}.`)); + + if ( + typeAnnotation && + (!emittedTypes.has(this.#fqn) || nestingParent != null) + ) { + // Possibly a forward reference, outputting the stringifierd python FQN + return { + pythonType: JSON.stringify( + pythonFqn.substring(submodulePythonName.length + 1), + ), + }; + } + + if (!typeAnnotation && nestingParent) { + // This is not for a type annotation, so we should be at a point in time + // where the surrounding symbol has been defined entirely, so we can + // refer to it "normally" now. + return { pythonType: pythonFqn.substring(nestingParent.length + 1) }; + } + + // We'll just make a module-qualified reference at this point. return { - pythonType: typeAnnotation ? JSON.stringify(localName) : localName, + pythonType: pythonFqn.substring(submodulePythonName.length + 1), }; } 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 ae71a53ae1..4cd3959ede 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 @@ -3126,6 +3126,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ πŸ“„ IJsii487ExternalProxy.cs ┃ ┣━ πŸ“„ IJsii496.cs ┃ ┣━ πŸ“„ IJsii496Proxy.cs + ┃ ┣━ πŸ“„ ILevelOneProps.cs ┃ ┣━ πŸ“„ ILoadBalancedFargateServiceProps.cs ┃ ┣━ πŸ“„ Implementation.cs ┃ ┣━ πŸ“„ ImplementInternalInterface.cs @@ -3200,6 +3201,9 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ πŸ“„ JSObjectLiteralToNative.cs ┃ ┣━ πŸ“„ JSObjectLiteralToNativeClass.cs ┃ ┣━ πŸ“„ JsonFormatter.cs + ┃ ┣━ πŸ“„ LevelOne.cs + ┃ ┣━ πŸ“„ LevelOneProps.cs + ┃ ┣━ πŸ“„ LevelOnePropsProxy.cs ┃ ┣━ πŸ“„ LoadBalancedFargateServiceProps.cs ┃ ┣━ πŸ“„ LoadBalancedFargateServicePropsProxy.cs ┃ ┣━ πŸ“„ MethodNamedProperty.cs @@ -11505,6 +11509,148 @@ exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.Calcu ], "name": "JsonFormatter" }, + "jsii-calc.LevelOne": { + "assembly": "jsii-calc", + "docs": { + "stability": "stable", + "summary": "Validates that nested classes get correct code generation for the occasional forward reference." + }, + "fqn": "jsii-calc.LevelOne", + "initializer": { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2829 + }, + "parameters": [ + { + "name": "props", + "type": { + "fqn": "jsii-calc.LevelOneProps" + } + } + ] + }, + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2828 + }, + "name": "LevelOne", + "properties": [ + { + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2829 + }, + "name": "props", + "type": { + "fqn": "jsii-calc.LevelOneProps" + } + } + ] + }, + "jsii-calc.LevelOne.PropBooleanValue": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.LevelOne.PropBooleanValue", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2839 + }, + "name": "PropBooleanValue", + "namespace": "LevelOne", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2840 + }, + "name": "value", + "type": { + "primitive": "boolean" + } + } + ] + }, + "jsii-calc.LevelOne.PropProperty": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.LevelOne.PropProperty", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2835 + }, + "name": "PropProperty", + "namespace": "LevelOne", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2836 + }, + "name": "prop", + "type": { + "fqn": "jsii-calc.LevelOne.PropBooleanValue" + } + } + ] + }, + "jsii-calc.LevelOneProps": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.LevelOneProps", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2831 + }, + "name": "LevelOneProps", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2832 + }, + "name": "prop", + "type": { + "fqn": "jsii-calc.LevelOne.PropProperty" + } + } + ] + }, "jsii-calc.LoadBalancedFargateServiceProps": { "assembly": "jsii-calc", "datatype": true, @@ -17306,7 +17452,7 @@ exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.Calcu } }, "version": "0.0.0", - "fingerprint": "Ddy05wOucU4yV7YP5fPUzEjiOsl5AGPrwJS7pXpJRPI=" + "fingerprint": "ary2D/3pPPIqMW0FmZnYMsKzvk8r29qmK5+1KyEcTQA=" } `; @@ -23223,6 +23369,26 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ILevelOneProps.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + [JsiiInterface(nativeType: typeof(ILevelOneProps), fullyQualifiedName: "jsii-calc.LevelOneProps")] + public interface ILevelOneProps + { + [JsiiProperty(name: "prop", typeJson: "{\\"fqn\\":\\"jsii-calc.LevelOne.PropProperty\\"}")] + Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropProperty Prop + { + get; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ILoadBalancedFargateServiceProps.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; @@ -25848,6 +26014,160 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/LevelOne.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// Validates that nested classes get correct code generation for the occasional forward reference. + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.LevelOne), fullyQualifiedName: "jsii-calc.LevelOne", parametersJson: "[{\\"name\\":\\"props\\",\\"type\\":{\\"fqn\\":\\"jsii-calc.LevelOneProps\\"}}]")] + public class LevelOne : DeputyBase + { + public LevelOne(Amazon.JSII.Tests.CalculatorNamespace.ILevelOneProps props): base(new DeputyProps(new object[]{props})) + { + } + + /// 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 LevelOne(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 LevelOne(DeputyProps props): base(props) + { + } + + [JsiiProperty(name: "props", typeJson: "{\\"fqn\\":\\"jsii-calc.LevelOneProps\\"}")] + public virtual Amazon.JSII.Tests.CalculatorNamespace.ILevelOneProps Props + { + get => GetInstanceProperty(); + } + [JsiiInterface(nativeType: typeof(IPropBooleanValue), fullyQualifiedName: "jsii-calc.LevelOne.PropBooleanValue")] + public interface IPropBooleanValue + { + [JsiiProperty(name: "value", typeJson: "{\\"primitive\\":\\"boolean\\"}")] + bool Value + { + get; + } + } + [JsiiTypeProxy(nativeType: typeof(IPropBooleanValue), fullyQualifiedName: "jsii-calc.LevelOne.PropBooleanValue")] + internal sealed class PropBooleanValueProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropBooleanValue + { + private PropBooleanValueProxy(ByRefValue reference): base(reference) + { + } + + [JsiiProperty(name: "value", typeJson: "{\\"primitive\\":\\"boolean\\"}")] + public bool Value + { + get => GetInstanceProperty(); + } + } + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.LevelOne.PropBooleanValue")] + public class PropBooleanValue : Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropBooleanValue + { + [JsiiProperty(name: "value", typeJson: "{\\"primitive\\":\\"boolean\\"}", isOverride: true)] + public bool Value + { + get; + set; + } + } + [JsiiInterface(nativeType: typeof(IPropProperty), fullyQualifiedName: "jsii-calc.LevelOne.PropProperty")] + public interface IPropProperty + { + [JsiiProperty(name: "prop", typeJson: "{\\"fqn\\":\\"jsii-calc.LevelOne.PropBooleanValue\\"}")] + Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropBooleanValue Prop + { + get; + } + } + [JsiiTypeProxy(nativeType: typeof(IPropProperty), fullyQualifiedName: "jsii-calc.LevelOne.PropProperty")] + internal sealed class PropPropertyProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropProperty + { + private PropPropertyProxy(ByRefValue reference): base(reference) + { + } + + [JsiiProperty(name: "prop", typeJson: "{\\"fqn\\":\\"jsii-calc.LevelOne.PropBooleanValue\\"}")] + public Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropBooleanValue Prop + { + get => GetInstanceProperty(); + } + } + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.LevelOne.PropProperty")] + public class PropProperty : Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropProperty + { + [JsiiProperty(name: "prop", typeJson: "{\\"fqn\\":\\"jsii-calc.LevelOne.PropBooleanValue\\"}", isOverride: true)] + public Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropBooleanValue Prop + { + get; + set; + } + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/LevelOneProps.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.LevelOneProps")] + public class LevelOneProps : Amazon.JSII.Tests.CalculatorNamespace.ILevelOneProps + { + [JsiiProperty(name: "prop", typeJson: "{\\"fqn\\":\\"jsii-calc.LevelOne.PropProperty\\"}", isOverride: true)] + public Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropProperty Prop + { + get; + set; + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/LevelOnePropsProxy.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + [JsiiTypeProxy(nativeType: typeof(ILevelOneProps), fullyQualifiedName: "jsii-calc.LevelOneProps")] + internal sealed class LevelOnePropsProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.ILevelOneProps + { + private LevelOnePropsProxy(ByRefValue reference): base(reference) + { + } + + [JsiiProperty(name: "prop", typeJson: "{\\"fqn\\":\\"jsii-calc.LevelOne.PropProperty\\"}")] + public Amazon.JSII.Tests.CalculatorNamespace.LevelOne.IPropProperty Prop + { + get => GetInstanceProperty(); + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/LoadBalancedFargateServiceProps.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 43ccafe2a4..ec901f6684 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 @@ -5348,6 +5348,81 @@ func JsonFormatter_Stringify(value jsii.Any) string { return "NOOP_RETURN_STRING" } +// Class interface +type LevelOneIface interface { + GetProps() LevelOneProps + SetProps(val LevelOneProps) +} + +// Validates that nested classes get correct code generation for the occasional forward reference. +// Struct proxy +type LevelOne struct { + Props LevelOneProps +} + +func (l *LevelOne) GetProps() LevelOneProps { + return l.Props +} + + +func NewLevelOne(props LevelOneProps) LevelOneIface { + jsii.NoOpRequest(jsii.NoOpApiRequest { + Class: "LevelOne", + Method: "Constructor", + Args: []string{"jsii-calc.LevelOneProps",}, + }) + return &LevelOne{} +} + +func (l *LevelOne) SetProps(val LevelOneProps) { + l.Props = val +} + +// PropBooleanValueIface is the public interface for the custom type PropBooleanValue +type PropBooleanValueIface interface { + GetValue() bool +} + +// Struct proxy +type PropBooleanValue struct { + Value bool +} + +func (p *PropBooleanValue) GetValue() bool { + return p.Value +} + + +// PropPropertyIface is the public interface for the custom type PropProperty +type PropPropertyIface interface { + GetProp() PropBooleanValue +} + +// Struct proxy +type PropProperty struct { + Prop PropBooleanValue +} + +func (p *PropProperty) GetProp() PropBooleanValue { + return p.Prop +} + + +// LevelOnePropsIface is the public interface for the custom type LevelOneProps +type LevelOnePropsIface interface { + GetProp() PropProperty +} + +// Struct proxy +type LevelOneProps struct { + Prop PropProperty +} + +func (l *LevelOneProps) GetProp() PropProperty { + return l.Prop +} + + // LoadBalancedFargateServicePropsIface is the public interface for the custom type LoadBalancedFargateServiceProps type LoadBalancedFargateServicePropsIface interface { GetContainerPort() float64 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 580dbe373a..cff091900f 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 @@ -2530,6 +2530,8 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ πŸ“„ JSObjectLiteralToNative.java ┃ ┣━ πŸ“„ JSObjectLiteralToNativeClass.java ┃ ┣━ πŸ“„ JsonFormatter.java + ┃ ┣━ πŸ“„ LevelOne.java + ┃ ┣━ πŸ“„ LevelOneProps.java ┃ ┣━ πŸ“„ LoadBalancedFargateServiceProps.java ┃ ┣━ πŸ“„ MethodNamedProperty.java ┃ ┣━ πŸ“„ Multiply.java @@ -11751,6 +11753,428 @@ public class JsonFormatter extends software.amazon.jsii.JsiiObject { `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/LevelOne.java 1`] = ` +package software.amazon.jsii.tests.calculator; + +/** + * Validates that nested classes get correct code generation for the occasional forward reference. + */ +@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.LevelOne") +public class LevelOne extends software.amazon.jsii.JsiiObject { + + protected LevelOne(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected LevelOne(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + * @param props This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public LevelOne(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.LevelOneProps props) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(props, "props is required") }); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.LevelOneProps getProps() { + return this.jsiiGet("props", software.amazon.jsii.tests.calculator.LevelOneProps.class); + } + /** + */ + @software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.LevelOne.PropBooleanValue") + @software.amazon.jsii.Jsii.Proxy(PropBooleanValue.Jsii$Proxy.class) + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static interface PropBooleanValue extends software.amazon.jsii.JsiiSerializable { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull java.lang.Boolean getValue(); + + /** + * @return a {@link Builder} of {@link PropBooleanValue} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link PropBooleanValue} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private java.lang.Boolean value; + + /** + * Sets the value of {@link PropBooleanValue#getValue} + * @param value the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder value(java.lang.Boolean value) { + this.value = value; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link PropBooleanValue} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public PropBooleanValue build() { + return new Jsii$Proxy(value); + } + } + + /** + * An implementation for {@link PropBooleanValue} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements PropBooleanValue { + private final java.lang.Boolean value; + + /** + * 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.value = this.jsiiGet("value", java.lang.Boolean.class); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + private Jsii$Proxy(final java.lang.Boolean value) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.value = java.util.Objects.requireNonNull(value, "value is required"); + } + + @Override + public java.lang.Boolean getValue() { + return this.value; + } + + @Override + 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("value", om.valueToTree(this.getValue())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.LevelOne.PropBooleanValue")); + 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 boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PropBooleanValue.Jsii$Proxy that = (PropBooleanValue.Jsii$Proxy) o; + + return this.value.equals(that.value); + } + + @Override + public int hashCode() { + int result = this.value.hashCode(); + return result; + } + } + } + /** + */ + @software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.LevelOne.PropProperty") + @software.amazon.jsii.Jsii.Proxy(PropProperty.Jsii$Proxy.class) + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static interface PropProperty extends software.amazon.jsii.JsiiSerializable { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.LevelOne.PropBooleanValue getProp(); + + /** + * @return a {@link Builder} of {@link PropProperty} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link PropProperty} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private software.amazon.jsii.tests.calculator.LevelOne.PropBooleanValue prop; + + /** + * Sets the value of {@link PropProperty#getProp} + * @param prop the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder prop(software.amazon.jsii.tests.calculator.LevelOne.PropBooleanValue prop) { + this.prop = prop; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link PropProperty} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public PropProperty build() { + return new Jsii$Proxy(prop); + } + } + + /** + * An implementation for {@link PropProperty} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements PropProperty { + private final software.amazon.jsii.tests.calculator.LevelOne.PropBooleanValue prop; + + /** + * 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.prop = this.jsiiGet("prop", software.amazon.jsii.tests.calculator.LevelOne.PropBooleanValue.class); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + private Jsii$Proxy(final software.amazon.jsii.tests.calculator.LevelOne.PropBooleanValue prop) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.prop = java.util.Objects.requireNonNull(prop, "prop is required"); + } + + @Override + public software.amazon.jsii.tests.calculator.LevelOne.PropBooleanValue getProp() { + return this.prop; + } + + @Override + 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("prop", om.valueToTree(this.getProp())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.LevelOne.PropProperty")); + 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 boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PropProperty.Jsii$Proxy that = (PropProperty.Jsii$Proxy) o; + + return this.prop.equals(that.prop); + } + + @Override + public int hashCode() { + int result = this.prop.hashCode(); + return result; + } + } + } + + /** + * A fluent builder for {@link software.amazon.jsii.tests.calculator.LevelOne}. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + /** + * @return a new instance of {@link Builder}. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static Builder create() { + return new Builder(); + } + + private final software.amazon.jsii.tests.calculator.LevelOneProps.Builder props; + + private Builder() { + this.props = new software.amazon.jsii.tests.calculator.LevelOneProps.Builder(); + } + + /** + * @return {@code this} + * @param prop This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder prop(final software.amazon.jsii.tests.calculator.LevelOne.PropProperty prop) { + this.props.prop(prop); + return this; + } + + /** + * @returns a newly built instance of {@link software.amazon.jsii.tests.calculator.LevelOne}. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public software.amazon.jsii.tests.calculator.LevelOne build() { + return new software.amazon.jsii.tests.calculator.LevelOne( + this.props.build() + ); + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/LevelOneProps.java 1`] = ` +package software.amazon.jsii.tests.calculator; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.LevelOneProps") +@software.amazon.jsii.Jsii.Proxy(LevelOneProps.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +public interface LevelOneProps extends software.amazon.jsii.JsiiSerializable { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.LevelOne.PropProperty getProp(); + + /** + * @return a {@link Builder} of {@link LevelOneProps} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link LevelOneProps} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private software.amazon.jsii.tests.calculator.LevelOne.PropProperty prop; + + /** + * Sets the value of {@link LevelOneProps#getProp} + * @param prop the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder prop(software.amazon.jsii.tests.calculator.LevelOne.PropProperty prop) { + this.prop = prop; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link LevelOneProps} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public LevelOneProps build() { + return new Jsii$Proxy(prop); + } + } + + /** + * An implementation for {@link LevelOneProps} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements LevelOneProps { + private final software.amazon.jsii.tests.calculator.LevelOne.PropProperty prop; + + /** + * 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.prop = this.jsiiGet("prop", software.amazon.jsii.tests.calculator.LevelOne.PropProperty.class); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + private Jsii$Proxy(final software.amazon.jsii.tests.calculator.LevelOne.PropProperty prop) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.prop = java.util.Objects.requireNonNull(prop, "prop is required"); + } + + @Override + public software.amazon.jsii.tests.calculator.LevelOne.PropProperty getProp() { + return this.prop; + } + + @Override + 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("prop", om.valueToTree(this.getProp())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.LevelOneProps")); + 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 boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + LevelOneProps.Jsii$Proxy that = (LevelOneProps.Jsii$Proxy) o; + + return this.prop.equals(that.prop); + } + + @Override + public int hashCode() { + int result = this.prop.hashCode(); + return result; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/LoadBalancedFargateServiceProps.java 1`] = ` package software.amazon.jsii.tests.calculator; @@ -19524,6 +19948,10 @@ jsii-calc.Jsii487Derived=software.amazon.jsii.tests.calculator.Jsii487Derived jsii-calc.Jsii496Derived=software.amazon.jsii.tests.calculator.Jsii496Derived jsii-calc.JsiiAgent=software.amazon.jsii.tests.calculator.JsiiAgent jsii-calc.JsonFormatter=software.amazon.jsii.tests.calculator.JsonFormatter +jsii-calc.LevelOne=software.amazon.jsii.tests.calculator.LevelOne +jsii-calc.LevelOne.PropBooleanValue=software.amazon.jsii.tests.calculator.LevelOne$PropBooleanValue +jsii-calc.LevelOne.PropProperty=software.amazon.jsii.tests.calculator.LevelOne$PropProperty +jsii-calc.LevelOneProps=software.amazon.jsii.tests.calculator.LevelOneProps jsii-calc.LoadBalancedFargateServiceProps=software.amazon.jsii.tests.calculator.LoadBalancedFargateServiceProps jsii-calc.MethodNamedProperty=software.amazon.jsii.tests.calculator.MethodNamedProperty jsii-calc.Multiply=software.amazon.jsii.tests.calculator.Multiply 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 7feac69328..8af92b8c24 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 @@ -127,7 +127,6 @@ class Base(metaclass=jsii.JSIIAbstractClass, jsii_type="@scope/jsii-calc-base.Ba @jsii.member(jsii_name="typeName") def type_name(self) -> typing.Any: """ - return :return: the name of the class (to verify native type names are created for derived classes). """ return jsii.invoke(self, "typeName", []) @@ -394,7 +393,6 @@ class StaticConsumer( class Very(metaclass=jsii.JSIIMeta, jsii_type="@scope/jsii-calc-base-of-base.Very"): """(experimental) Something here. - stability :stability: experimental """ @@ -404,7 +402,6 @@ class Very(metaclass=jsii.JSIIMeta, jsii_type="@scope/jsii-calc-base-of-base.Ver @jsii.member(jsii_name="hey") def hey(self) -> jsii.Number: """ - stability :stability: experimental """ return jsii.invoke(self, "hey", []) @@ -416,7 +413,7 @@ class Very(metaclass=jsii.JSIIMeta, jsii_type="@scope/jsii-calc-base-of-base.Ver name_mapping={"foo": "foo"}, ) class VeryBaseProps: - def __init__(self, *, foo: "Very") -> None: + def __init__(self, *, foo: Very) -> None: """ :param foo: - """ @@ -425,7 +422,7 @@ class VeryBaseProps: } @builtins.property - def foo(self) -> "Very": + def foo(self) -> Very: result = self._values.get("foo") assert result is not None, "Required property 'foo' is missing" return result @@ -611,18 +608,15 @@ class EnumFromScopedModule(enum.Enum): See awslabs/jsii#138 - stability :stability: deprecated """ VALUE1 = "VALUE1" """ - stability :stability: deprecated """ VALUE2 = "VALUE2" """ - stability :stability: deprecated """ @@ -631,7 +625,6 @@ class EnumFromScopedModule(enum.Enum): class IDoublable(typing_extensions.Protocol): """(deprecated) The general contract for a concrete number. - stability :stability: deprecated """ @@ -643,7 +636,6 @@ class IDoublable(typing_extensions.Protocol): @jsii.member(jsii_name="doubleValue") def double_value(self) -> jsii.Number: """ - stability :stability: deprecated """ ... @@ -652,7 +644,6 @@ class IDoublable(typing_extensions.Protocol): class _IDoublableProxy: """(deprecated) The general contract for a concrete number. - stability :stability: deprecated """ @@ -662,7 +653,6 @@ class _IDoublableProxy: @jsii.member(jsii_name="doubleValue") def double_value(self) -> jsii.Number: """ - stability :stability: deprecated """ return jsii.get(self, "doubleValue") @@ -675,7 +665,6 @@ class IFriendly(typing_extensions.Protocol): These classes can be greeted with a "hello" or "goodbye" blessing and they will respond back in a fun and friendly manner. - stability :stability: deprecated """ @@ -687,7 +676,6 @@ class IFriendly(typing_extensions.Protocol): def hello(self) -> builtins.str: """(deprecated) Say hello! - stability :stability: deprecated """ ... @@ -699,7 +687,6 @@ class _IFriendlyProxy: These classes can be greeted with a "hello" or "goodbye" blessing and they will respond back in a fun and friendly manner. - stability :stability: deprecated """ @@ -709,7 +696,6 @@ class _IFriendlyProxy: def hello(self) -> builtins.str: """(deprecated) Say hello! - stability :stability: deprecated """ return jsii.invoke(self, "hello", []) @@ -725,7 +711,6 @@ class IThreeLevelsInterface( Their presence validates that .NET/Java/jsii-reflect can track all fields far enough up the tree. - stability :stability: deprecated """ @@ -736,7 +721,6 @@ class IThreeLevelsInterface( @jsii.member(jsii_name="baz") def baz(self) -> None: """ - stability :stability: deprecated """ ... @@ -750,7 +734,6 @@ class _IThreeLevelsInterfaceProxy( Their presence validates that .NET/Java/jsii-reflect can track all fields far enough up the tree. - stability :stability: deprecated """ @@ -759,7 +742,6 @@ class _IThreeLevelsInterfaceProxy( @jsii.member(jsii_name="baz") def baz(self) -> None: """ - stability :stability: deprecated """ return jsii.invoke(self, "baz", []) @@ -788,7 +770,6 @@ class MyFirstStruct: :param astring: (deprecated) A string value. :param first_optional: - stability :stability: deprecated """ self._values: typing.Dict[str, typing.Any] = { @@ -802,7 +783,6 @@ class MyFirstStruct: def anumber(self) -> jsii.Number: """(deprecated) An awesome number value. - stability :stability: deprecated """ result = self._values.get("anumber") @@ -813,7 +793,6 @@ class MyFirstStruct: def astring(self) -> builtins.str: """(deprecated) A string value. - stability :stability: deprecated """ result = self._values.get("astring") @@ -823,7 +802,6 @@ class MyFirstStruct: @builtins.property def first_optional(self) -> typing.Optional[typing.List[builtins.str]]: """ - stability :stability: deprecated """ result = self._values.get("first_optional") @@ -848,7 +826,6 @@ class NumericValue( ): """(deprecated) Abstract class which represents a numeric value. - stability :stability: deprecated """ @@ -863,7 +840,6 @@ class NumericValue( def to_string(self) -> builtins.str: """(deprecated) String representation of the value. - stability :stability: deprecated """ return jsii.invoke(self, "toString", []) @@ -874,7 +850,6 @@ class NumericValue( def value(self) -> jsii.Number: """(deprecated) The value. - stability :stability: deprecated """ ... @@ -888,7 +863,6 @@ class _NumericValueProxy( def value(self) -> jsii.Number: """(deprecated) The value. - stability :stability: deprecated """ return jsii.get(self, "value") @@ -901,7 +875,6 @@ class Operation( ): """(deprecated) Represents an operation on values. - stability :stability: deprecated """ @@ -917,7 +890,6 @@ class Operation( def to_string(self) -> builtins.str: """(deprecated) String representation of the value. - stability :stability: deprecated """ ... @@ -930,7 +902,6 @@ class _OperationProxy( def to_string(self) -> builtins.str: """(deprecated) String representation of the value. - stability :stability: deprecated """ return jsii.invoke(self, "toString", []) @@ -959,7 +930,6 @@ class StructWithOnlyOptionals: :param optional2: :param optional3: - stability :stability: deprecated """ self._values: typing.Dict[str, typing.Any] = {} @@ -974,7 +944,6 @@ class StructWithOnlyOptionals: def optional1(self) -> typing.Optional[builtins.str]: """(deprecated) The first optional! - stability :stability: deprecated """ result = self._values.get("optional1") @@ -983,7 +952,6 @@ class StructWithOnlyOptionals: @builtins.property def optional2(self) -> typing.Optional[jsii.Number]: """ - stability :stability: deprecated """ result = self._values.get("optional2") @@ -992,7 +960,6 @@ class StructWithOnlyOptionals: @builtins.property def optional3(self) -> typing.Optional[builtins.bool]: """ - stability :stability: deprecated """ result = self._values.get("optional3") @@ -1018,7 +985,6 @@ class Number( ): """(deprecated) Represents a concrete number. - stability :stability: deprecated """ @@ -1027,7 +993,6 @@ class Number( :param value: The number. - stability :stability: deprecated """ jsii.create(Number, self, [value]) @@ -1037,7 +1002,6 @@ class Number( def double_value(self) -> jsii.Number: """(deprecated) The number multiplied by 2. - stability :stability: deprecated """ return jsii.get(self, "doubleValue") @@ -1047,7 +1011,6 @@ class Number( def value(self) -> jsii.Number: """(deprecated) The number. - stability :stability: deprecated """ return jsii.get(self, "value") @@ -1114,7 +1077,6 @@ from .._jsii import * @jsii.interface(jsii_type="@scope/jsii-calc-lib.submodule.IReflectable") class IReflectable(typing_extensions.Protocol): """ - stability :stability: deprecated """ @@ -1126,7 +1088,6 @@ class IReflectable(typing_extensions.Protocol): @jsii.member(jsii_name="entries") def entries(self) -> typing.List["ReflectableEntry"]: """ - stability :stability: deprecated """ ... @@ -1134,7 +1095,6 @@ class IReflectable(typing_extensions.Protocol): class _IReflectableProxy: """ - stability :stability: deprecated """ @@ -1144,7 +1104,6 @@ class _IReflectableProxy: @jsii.member(jsii_name="entries") def entries(self) -> typing.List["ReflectableEntry"]: """ - stability :stability: deprecated """ return jsii.get(self, "entries") @@ -1156,7 +1115,6 @@ class NestingClass( ): """(deprecated) This class is here to show we can use nested classes across module boundaries. - stability :stability: deprecated """ @@ -1166,22 +1124,19 @@ class NestingClass( ): """(deprecated) This class is here to show we can use nested classes across module boundaries. - stability :stability: deprecated """ def __init__(self) -> None: """ - stability :stability: deprecated """ - jsii.create(NestingClass.NestedClass, self, []) + jsii.create(NestedClass, self, []) @builtins.property # type: ignore @jsii.member(jsii_name="property") def property(self) -> builtins.str: """ - stability :stability: deprecated """ return jsii.get(self, "property") @@ -1199,7 +1154,6 @@ class NestingClass( :param name: - stability :stability: deprecated """ self._values: typing.Dict[str, typing.Any] = { @@ -1209,7 +1163,6 @@ class NestingClass( @builtins.property def name(self) -> builtins.str: """ - stability :stability: deprecated """ result = self._values.get("name") @@ -1239,7 +1192,6 @@ class ReflectableEntry: :param key: :param value: - stability :stability: deprecated """ self._values: typing.Dict[str, typing.Any] = { @@ -1250,7 +1202,6 @@ class ReflectableEntry: @builtins.property def key(self) -> builtins.str: """ - stability :stability: deprecated """ result = self._values.get("key") @@ -1260,7 +1211,6 @@ class ReflectableEntry: @builtins.property def value(self) -> typing.Any: """ - stability :stability: deprecated """ result = self._values.get("value") @@ -1284,13 +1234,11 @@ class Reflector( jsii_type="@scope/jsii-calc-lib.submodule.Reflector", ): """ - stability :stability: deprecated """ def __init__(self) -> None: """ - stability :stability: deprecated """ jsii.create(Reflector, self, []) @@ -1298,12 +1246,11 @@ class Reflector( @jsii.member(jsii_name="asMap") def as_map( self, - reflectable: "IReflectable", + reflectable: IReflectable, ) -> typing.Mapping[builtins.str, typing.Any]: """ :param reflectable: - - stability :stability: deprecated """ return jsii.invoke(self, "asMap", [reflectable]) @@ -1576,7 +1523,7 @@ class AbstractClassReturner( @builtins.property # type: ignore @jsii.member(jsii_name="returnAbstractFromProperty") - def return_abstract_from_property(self) -> "AbstractClassBase": + def return_abstract_from_property(self) -> AbstractClassBase: return jsii.get(self, "returnAbstractFromProperty") @@ -2068,7 +2015,6 @@ class BurriedAnonymousObject( :param value: the value that should be returned. - return :return: \`\`value\`\` """ ... @@ -2081,7 +2027,6 @@ class _BurriedAnonymousObjectProxy(BurriedAnonymousObject): :param value: the value that should be returned. - return :return: \`\`value\`\` """ return jsii.invoke(self, "giveItBack", [value]) @@ -2249,7 +2194,6 @@ class CalculatorProps: NOTE: Any number works here, it's fine. - default :default: 0 """ result = self._values.get("initial_value") @@ -2259,7 +2203,6 @@ class CalculatorProps: def maximum_value(self) -> typing.Optional[jsii.Number]: """The maximum value the calculator can store. - default :default: none """ result = self._values.get("maximum_value") @@ -2344,10 +2287,8 @@ class ClassWithDocs(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.ClassWithDocs" The docs are great. They're a bunch of tags. - see :see: https://aws.amazon.com/ - customAttribute: - :customAttribute:: hasAValue + :customAttribute: hasAValue Example:: @@ -2406,7 +2347,6 @@ class ConfusingToJackson( ): """This tries to confuse Jackson by having overloaded property setters. - see :see: https://github.com/aws/aws-cdk/issues/4080 """ @@ -2771,10 +2711,8 @@ class Demonstrate982(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.Demonstrate98 class DeprecatedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DeprecatedClass"): """ - deprecated :deprecated: a pretty boring class - stability :stability: deprecated """ @@ -2787,10 +2725,8 @@ class DeprecatedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DeprecatedCl :param readonly_string: - :param mutable_number: - - deprecated :deprecated: this constructor is "just" okay - stability :stability: deprecated """ jsii.create(DeprecatedClass, self, [readonly_string, mutable_number]) @@ -2798,10 +2734,8 @@ class DeprecatedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DeprecatedCl @jsii.member(jsii_name="method") def method(self) -> None: """ - deprecated :deprecated: it was a bad idea - stability :stability: deprecated """ return jsii.invoke(self, "method", []) @@ -2810,10 +2744,8 @@ class DeprecatedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DeprecatedCl @jsii.member(jsii_name="readonlyProperty") def readonly_property(self) -> builtins.str: """ - deprecated :deprecated: this is not always "wazoo", be ready to be disappointed - stability :stability: deprecated """ return jsii.get(self, "readonlyProperty") @@ -2822,10 +2754,8 @@ class DeprecatedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DeprecatedCl @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - deprecated :deprecated: shouldn't have been mutable - stability :stability: deprecated """ return jsii.get(self, "mutableProperty") @@ -2838,27 +2768,21 @@ class DeprecatedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DeprecatedCl @jsii.enum(jsii_type="jsii-calc.DeprecatedEnum") class DeprecatedEnum(enum.Enum): """ - deprecated :deprecated: your deprecated selection of bad options - stability :stability: deprecated """ OPTION_A = "OPTION_A" """ - deprecated :deprecated: option A is not great - stability :stability: deprecated """ OPTION_B = "OPTION_B" """ - deprecated :deprecated: option B is kinda bad, too - stability :stability: deprecated """ @@ -2873,10 +2797,8 @@ class DeprecatedStruct: """ :param readonly_property: - deprecated :deprecated: it just wraps a string - stability :stability: deprecated """ self._values: typing.Dict[str, typing.Any] = { @@ -2886,10 +2808,8 @@ class DeprecatedStruct: @builtins.property def readonly_property(self) -> builtins.str: """ - deprecated :deprecated: well, yeah - stability :stability: deprecated """ result = self._values.get("readonly_property") @@ -2969,7 +2889,6 @@ class DerivedStruct(scope.jsii_calc_lib.MyFirstStruct): def anumber(self) -> jsii.Number: """(deprecated) An awesome number value. - stability :stability: deprecated """ result = self._values.get("anumber") @@ -2980,7 +2899,6 @@ class DerivedStruct(scope.jsii_calc_lib.MyFirstStruct): def astring(self) -> builtins.str: """(deprecated) A string value. - stability :stability: deprecated """ result = self._values.get("astring") @@ -2990,7 +2908,6 @@ class DerivedStruct(scope.jsii_calc_lib.MyFirstStruct): @builtins.property def first_optional(self) -> typing.Optional[typing.List[builtins.str]]: """ - stability :stability: deprecated """ result = self._values.get("first_optional") @@ -3342,7 +3259,6 @@ class DocumentedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DocumentedCl :param name: The name of the greetee. Default: world - return :return: A number that everyone knows very well """ greetee = Greetee(name=name) @@ -3353,7 +3269,6 @@ class DocumentedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DocumentedCl def hola(self) -> None: """(experimental) Say Β‘Hola! - stability :stability: experimental """ return jsii.invoke(self, "hola", []) @@ -3427,7 +3342,6 @@ class DynamicPropertyBearerChild( :param new_value: the new value to be set. - return :return: the old value that was set. """ return jsii.invoke(self, "overrideValue", [new_value]) @@ -3441,7 +3355,7 @@ class DynamicPropertyBearerChild( class EnumDispenser(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.EnumDispenser"): @jsii.member(jsii_name="randomIntegerLikeEnum") @builtins.classmethod - def random_integer_like_enum(cls) -> "AllTypesEnum": + def random_integer_like_enum(cls) -> AllTypesEnum: return jsii.sinvoke(cls, "randomIntegerLikeEnum", []) @jsii.member(jsii_name="randomStringLikeEnum") @@ -3536,7 +3450,6 @@ class ExperimentalClass( jsii_type="jsii-calc.ExperimentalClass", ): """ - stability :stability: experimental """ @@ -3549,7 +3462,6 @@ class ExperimentalClass( :param readonly_string: - :param mutable_number: - - stability :stability: experimental """ jsii.create(ExperimentalClass, self, [readonly_string, mutable_number]) @@ -3557,7 +3469,6 @@ class ExperimentalClass( @jsii.member(jsii_name="method") def method(self) -> None: """ - stability :stability: experimental """ return jsii.invoke(self, "method", []) @@ -3566,7 +3477,6 @@ class ExperimentalClass( @jsii.member(jsii_name="readonlyProperty") def readonly_property(self) -> builtins.str: """ - stability :stability: experimental """ return jsii.get(self, "readonlyProperty") @@ -3575,7 +3485,6 @@ class ExperimentalClass( @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - stability :stability: experimental """ return jsii.get(self, "mutableProperty") @@ -3588,18 +3497,15 @@ class ExperimentalClass( @jsii.enum(jsii_type="jsii-calc.ExperimentalEnum") class ExperimentalEnum(enum.Enum): """ - stability :stability: experimental """ OPTION_A = "OPTION_A" """ - stability :stability: experimental """ OPTION_B = "OPTION_B" """ - stability :stability: experimental """ @@ -3614,7 +3520,6 @@ class ExperimentalStruct: """ :param readonly_property: - stability :stability: experimental """ self._values: typing.Dict[str, typing.Any] = { @@ -3624,7 +3529,6 @@ class ExperimentalStruct: @builtins.property def readonly_property(self) -> builtins.str: """ - stability :stability: experimental """ result = self._values.get("readonly_property") @@ -3701,8 +3605,7 @@ class ExtendsInternalInterface: class ExternalClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.ExternalClass"): """ - external: - :external:: true + :external: true """ def __init__( @@ -3714,16 +3617,14 @@ class ExternalClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.ExternalClass" :param readonly_string: - :param mutable_number: - - external: - :external:: true + :external: true """ jsii.create(ExternalClass, self, [readonly_string, mutable_number]) @jsii.member(jsii_name="method") def method(self) -> None: """ - external: - :external:: true + :external: true """ return jsii.invoke(self, "method", []) @@ -3731,8 +3632,7 @@ class ExternalClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.ExternalClass" @jsii.member(jsii_name="readonlyProperty") def readonly_property(self) -> builtins.str: """ - external: - :external:: true + :external: true """ return jsii.get(self, "readonlyProperty") @@ -3740,8 +3640,7 @@ class ExternalClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.ExternalClass" @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - external: - :external:: true + :external: true """ return jsii.get(self, "mutableProperty") @@ -3753,19 +3652,16 @@ class ExternalClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.ExternalClass" @jsii.enum(jsii_type="jsii-calc.ExternalEnum") class ExternalEnum(enum.Enum): """ - external: - :external:: true + :external: true """ OPTION_A = "OPTION_A" """ - external: - :external:: true + :external: true """ OPTION_B = "OPTION_B" """ - external: - :external:: true + :external: true """ @@ -3779,8 +3675,7 @@ class ExternalStruct: """ :param readonly_property: - external: - :external:: true + :external: true """ self._values: typing.Dict[str, typing.Any] = { "readonly_property": readonly_property, @@ -3789,8 +3684,7 @@ class ExternalStruct: @builtins.property def readonly_property(self) -> builtins.str: """ - external: - :external:: true + :external: true """ result = self._values.get("readonly_property") assert result is not None, "Required property 'readonly_property' is missing" @@ -3937,7 +3831,6 @@ class Greetee: def name(self) -> typing.Optional[builtins.str]: """The name of the greetee. - default :default: world """ result = self._values.get("name") @@ -4087,7 +3980,7 @@ class IBellRinger(typing_extensions.Protocol): return _IBellRingerProxy @jsii.member(jsii_name="yourTurn") - def your_turn(self, bell: "IBell") -> None: + def your_turn(self, bell: IBell) -> None: """ :param bell: - """ @@ -4100,7 +3993,7 @@ class _IBellRingerProxy: __jsii_type__: typing.ClassVar[str] = "jsii-calc.IBellRinger" @jsii.member(jsii_name="yourTurn") - def your_turn(self, bell: "IBell") -> None: + def your_turn(self, bell: IBell) -> None: """ :param bell: - """ @@ -4139,10 +4032,8 @@ class _IConcreteBellRingerProxy: @jsii.interface(jsii_type="jsii-calc.IDeprecatedInterface") class IDeprecatedInterface(typing_extensions.Protocol): """ - deprecated :deprecated: useless interface - stability :stability: deprecated """ @@ -4154,10 +4045,8 @@ class IDeprecatedInterface(typing_extensions.Protocol): @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - deprecated :deprecated: could be better - stability :stability: deprecated """ ... @@ -4169,10 +4058,8 @@ class IDeprecatedInterface(typing_extensions.Protocol): @jsii.member(jsii_name="method") def method(self) -> None: """ - deprecated :deprecated: services no purpose - stability :stability: deprecated """ ... @@ -4180,10 +4067,8 @@ class IDeprecatedInterface(typing_extensions.Protocol): class _IDeprecatedInterfaceProxy: """ - deprecated :deprecated: useless interface - stability :stability: deprecated """ @@ -4193,10 +4078,8 @@ class _IDeprecatedInterfaceProxy: @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - deprecated :deprecated: could be better - stability :stability: deprecated """ return jsii.get(self, "mutableProperty") @@ -4208,10 +4091,8 @@ class _IDeprecatedInterfaceProxy: @jsii.member(jsii_name="method") def method(self) -> None: """ - deprecated :deprecated: services no purpose - stability :stability: deprecated """ return jsii.invoke(self, "method", []) @@ -4220,7 +4101,6 @@ class _IDeprecatedInterfaceProxy: @jsii.interface(jsii_type="jsii-calc.IExperimentalInterface") class IExperimentalInterface(typing_extensions.Protocol): """ - stability :stability: experimental """ @@ -4232,7 +4112,6 @@ class IExperimentalInterface(typing_extensions.Protocol): @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - stability :stability: experimental """ ... @@ -4244,7 +4123,6 @@ class IExperimentalInterface(typing_extensions.Protocol): @jsii.member(jsii_name="method") def method(self) -> None: """ - stability :stability: experimental """ ... @@ -4252,7 +4130,6 @@ class IExperimentalInterface(typing_extensions.Protocol): class _IExperimentalInterfaceProxy: """ - stability :stability: experimental """ @@ -4262,7 +4139,6 @@ class _IExperimentalInterfaceProxy: @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - stability :stability: experimental """ return jsii.get(self, "mutableProperty") @@ -4274,7 +4150,6 @@ class _IExperimentalInterfaceProxy: @jsii.member(jsii_name="method") def method(self) -> None: """ - stability :stability: experimental """ return jsii.invoke(self, "method", []) @@ -4322,8 +4197,7 @@ class _IExtendsPrivateInterfaceProxy: @jsii.interface(jsii_type="jsii-calc.IExternalInterface") class IExternalInterface(typing_extensions.Protocol): """ - external: - :external:: true + :external: true """ @builtins.staticmethod @@ -4334,8 +4208,7 @@ class IExternalInterface(typing_extensions.Protocol): @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - external: - :external:: true + :external: true """ ... @@ -4346,16 +4219,14 @@ class IExternalInterface(typing_extensions.Protocol): @jsii.member(jsii_name="method") def method(self) -> None: """ - external: - :external:: true + :external: true """ ... class _IExternalInterfaceProxy: """ - external: - :external:: true + :external: true """ __jsii_type__: typing.ClassVar[str] = "jsii-calc.IExternalInterface" @@ -4364,8 +4235,7 @@ class _IExternalInterfaceProxy: @jsii.member(jsii_name="mutableProperty") def mutable_property(self) -> typing.Optional[jsii.Number]: """ - external: - :external:: true + :external: true """ return jsii.get(self, "mutableProperty") @@ -4376,8 +4246,7 @@ class _IExternalInterfaceProxy: @jsii.member(jsii_name="method") def method(self) -> None: """ - external: - :external:: true + :external: true """ return jsii.invoke(self, "method", []) @@ -4399,7 +4268,6 @@ class IFriendlier(scope.jsii_calc_lib.IFriendly, typing_extensions.Protocol): def goodbye(self) -> builtins.str: """Say goodbye. - return :return: A goodbye blessing. """ ... @@ -4421,7 +4289,6 @@ class _IFriendlierProxy( def goodbye(self) -> builtins.str: """Say goodbye. - return :return: A goodbye blessing. """ return jsii.invoke(self, "goodbye", []) @@ -4890,7 +4757,6 @@ class IRandomNumberGenerator(typing_extensions.Protocol): def next(self) -> jsii.Number: """Returns another random number. - return :return: A random number. """ ... @@ -4905,7 +4771,6 @@ class _IRandomNumberGeneratorProxy: def next(self) -> jsii.Number: """Returns another random number. - return :return: A random number. """ return jsii.invoke(self, "next", []) @@ -5156,7 +5021,7 @@ class InterfaceCollections( @jsii.member(jsii_name="listOfInterfaces") @builtins.classmethod - def list_of_interfaces(cls) -> typing.List["IBell"]: + def list_of_interfaces(cls) -> typing.List[IBell]: return jsii.sinvoke(cls, "listOfInterfaces", []) @jsii.member(jsii_name="listOfStructs") @@ -5166,7 +5031,7 @@ class InterfaceCollections( @jsii.member(jsii_name="mapOfInterfaces") @builtins.classmethod - def map_of_interfaces(cls) -> typing.Mapping[builtins.str, "IBell"]: + def map_of_interfaces(cls) -> typing.Mapping[builtins.str, IBell]: return jsii.sinvoke(cls, "mapOfInterfaces", []) @jsii.member(jsii_name="mapOfStructs") @@ -5542,7 +5407,6 @@ class JsiiAgent(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.JsiiAgent"): class JsonFormatter(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.JsonFormatter"): """Make sure structs are un-decorated on the way in. - see :see: https://github.com/aws/aws-cdk/issues/5066 """ @@ -5620,6 +5484,121 @@ class JsonFormatter(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.JsonFormatter" return jsii.sinvoke(cls, "stringify", [value]) +class LevelOne(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.LevelOne"): + """Validates that nested classes get correct code generation for the occasional forward reference.""" + + def __init__(self, *, prop: "LevelOne.PropProperty") -> None: + """ + :param prop: + """ + props = LevelOneProps(prop=prop) + + jsii.create(LevelOne, self, [props]) + + @builtins.property # type: ignore + @jsii.member(jsii_name="props") + def props(self) -> "LevelOneProps": + return jsii.get(self, "props") + + @jsii.data_type( + jsii_type="jsii-calc.LevelOne.PropBooleanValue", + jsii_struct_bases=[], + name_mapping={"value": "value"}, + ) + class PropBooleanValue: + def __init__(self, *, value: builtins.bool) -> None: + """ + :param value: + """ + self._values: typing.Dict[str, typing.Any] = { + "value": value, + } + + @builtins.property + def value(self) -> builtins.bool: + result = self._values.get("value") + assert result is not None, "Required property 'value' is missing" + return 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 "PropBooleanValue(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + @jsii.data_type( + jsii_type="jsii-calc.LevelOne.PropProperty", + jsii_struct_bases=[], + name_mapping={"prop": "prop"}, + ) + class PropProperty: + def __init__(self, *, prop: "LevelOne.PropBooleanValue") -> None: + """ + :param prop: + """ + if isinstance(prop, dict): + prop = PropBooleanValue(**prop) + self._values: typing.Dict[str, typing.Any] = { + "prop": prop, + } + + @builtins.property + def prop(self) -> "LevelOne.PropBooleanValue": + result = self._values.get("prop") + assert result is not None, "Required property 'prop' is missing" + return 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 "PropProperty(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + +@jsii.data_type( + jsii_type="jsii-calc.LevelOneProps", + jsii_struct_bases=[], + name_mapping={"prop": "prop"}, +) +class LevelOneProps: + def __init__(self, *, prop: LevelOne.PropProperty) -> None: + """ + :param prop: + """ + if isinstance(prop, dict): + prop = LevelOne.PropProperty(**prop) + self._values: typing.Dict[str, typing.Any] = { + "prop": prop, + } + + @builtins.property + def prop(self) -> LevelOne.PropProperty: + result = self._values.get("prop") + assert result is not None, "Required property 'prop' is missing" + return 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 "LevelOneProps(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + @jsii.data_type( jsii_type="jsii-calc.LoadBalancedFargateServiceProps", jsii_struct_bases=[], @@ -5667,7 +5646,6 @@ class LoadBalancedFargateServiceProps: Corresponds to container port mapping. - default :default: 80 """ result = self._values.get("container_port") @@ -5686,7 +5664,6 @@ class LoadBalancedFargateServiceProps: This default is set in the underlying FargateTaskDefinition construct. - default :default: 256 """ result = self._values.get("cpu") @@ -5711,7 +5688,6 @@ class LoadBalancedFargateServiceProps: This default is set in the underlying FargateTaskDefinition construct. - default :default: 512 """ result = self._values.get("memory_mib") @@ -5721,7 +5697,6 @@ class LoadBalancedFargateServiceProps: def public_load_balancer(self) -> typing.Optional[builtins.bool]: """Determines whether the Application Load Balancer will be internet-facing. - default :default: true """ result = self._values.get("public_load_balancer") @@ -5731,7 +5706,6 @@ class LoadBalancedFargateServiceProps: def public_tasks(self) -> typing.Optional[builtins.bool]: """Determines whether your Fargate Service will be assigned a public IP address. - default :default: false """ result = self._values.get("public_tasks") @@ -5871,7 +5845,6 @@ class NodeStandardLibrary( def crypto_sha256(self) -> builtins.str: """Uses node.js "crypto" module to calculate sha256 of a string. - return :return: "6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50" """ return jsii.invoke(self, "cryptoSha256", []) @@ -5880,7 +5853,6 @@ class NodeStandardLibrary( def fs_read_file(self) -> builtins.str: """Reads a local resource file (resource.txt) asynchronously. - return :return: "Hello, resource!" """ return jsii.ainvoke(self, "fsReadFile", []) @@ -5889,7 +5861,6 @@ class NodeStandardLibrary( def fs_read_file_sync(self) -> builtins.str: """Sync version of fsReadFile. - return :return: "Hello, resource! SYNC!" """ return jsii.invoke(self, "fsReadFileSync", []) @@ -6006,14 +5977,14 @@ class NullShouldBeTreatedAsUndefinedData: class NumberGenerator(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.NumberGenerator"): """This allows us to test that a reference can be stored for objects that implement interfaces.""" - def __init__(self, generator: "IRandomNumberGenerator") -> None: + def __init__(self, generator: IRandomNumberGenerator) -> None: """ :param generator: - """ jsii.create(NumberGenerator, self, [generator]) @jsii.member(jsii_name="isSameGenerator") - def is_same_generator(self, gen: "IRandomNumberGenerator") -> builtins.bool: + def is_same_generator(self, gen: IRandomNumberGenerator) -> builtins.bool: """ :param gen: - """ @@ -6025,11 +5996,11 @@ class NumberGenerator(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.NumberGenera @builtins.property # type: ignore @jsii.member(jsii_name="generator") - def generator(self) -> "IRandomNumberGenerator": + def generator(self) -> IRandomNumberGenerator: return jsii.get(self, "generator") @generator.setter # type: ignore - def generator(self, value: "IRandomNumberGenerator") -> None: + def generator(self, value: IRandomNumberGenerator) -> None: jsii.set(self, "generator", value) @@ -6071,17 +6042,15 @@ class ObjectWithPropertyProvider( ): @jsii.member(jsii_name="provide") @builtins.classmethod - def provide(cls) -> "IObjectWithProperty": + def provide(cls) -> IObjectWithProperty: return jsii.sinvoke(cls, "provide", []) class Old(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.Old"): """(deprecated) Old class. - deprecated :deprecated: Use the new class - stability :stability: deprecated """ @@ -6092,7 +6061,6 @@ class Old(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.Old"): def do_a_thing(self) -> None: """(deprecated) Doo wop that thing. - stability :stability: deprecated """ return jsii.invoke(self, "doAThing", []) @@ -6102,7 +6070,7 @@ class OptionalArgumentInvoker( metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.OptionalArgumentInvoker", ): - def __init__(self, delegate: "IInterfaceWithOptionalMethodArguments") -> None: + def __init__(self, delegate: IInterfaceWithOptionalMethodArguments) -> None: """ :param delegate: - """ @@ -6209,7 +6177,6 @@ class OverridableProtectedMember( jsii_type="jsii-calc.OverridableProtectedMember", ): """ - see :see: https://github.com/aws/jsii/issues/903 """ @@ -6251,7 +6218,7 @@ class OverrideReturnsObject( jsii.create(OverrideReturnsObject, self, []) @jsii.member(jsii_name="test") - def test(self, obj: "IReturnsNumber") -> jsii.Number: + def test(self, obj: IReturnsNumber) -> jsii.Number: """ :param obj: - """ @@ -6306,9 +6273,9 @@ class PartiallyInitializedThisConsumer( @abc.abstractmethod def consume_partially_initialized_this( self, - obj: "ConstructorPassesThisOut", + obj: ConstructorPassesThisOut, dt: datetime.datetime, - ev: "AllTypesEnum", + ev: AllTypesEnum, ) -> builtins.str: """ :param obj: - @@ -6322,9 +6289,9 @@ class _PartiallyInitializedThisConsumerProxy(PartiallyInitializedThisConsumer): @jsii.member(jsii_name="consumePartiallyInitializedThis") def consume_partially_initialized_this( self, - obj: "ConstructorPassesThisOut", + obj: ConstructorPassesThisOut, dt: datetime.datetime, - ev: "AllTypesEnum", + ev: AllTypesEnum, ) -> builtins.str: """ :param obj: - @@ -6591,10 +6558,8 @@ class ReturnsPrivateImplementationOfInterface( ): """Helps ensure the JSII kernel & runtime cooperate correctly when an un-exported instance of a class is returned with a declared type that is an exported interface, and the instance inherits from an exported class. - return :return: an instance of an un-exported class that extends \`\`ExportedBaseClass\`\`, declared as \`\`IPrivatelyImplemented\`\`. - see :see: https://github.com/aws/jsii/issues/320 """ @@ -6603,7 +6568,7 @@ class ReturnsPrivateImplementationOfInterface( @builtins.property # type: ignore @jsii.member(jsii_name="privateImplementation") - def private_implementation(self) -> "IPrivatelyImplemented": + def private_implementation(self) -> IPrivatelyImplemented: return jsii.get(self, "privateImplementation") @@ -6617,7 +6582,7 @@ class RootStruct: self, *, string_prop: builtins.str, - nested_struct: typing.Optional["NestedStruct"] = None, + nested_struct: typing.Optional[NestedStruct] = None, ) -> None: """This is here to check that we can pass a nested struct into a kwargs by specifying it as an in-line dictionary. @@ -6643,7 +6608,7 @@ class RootStruct: return result @builtins.property - def nested_struct(self) -> typing.Optional["NestedStruct"]: + def nested_struct(self) -> typing.Optional[NestedStruct]: result = self._values.get("nested_struct") return result @@ -6669,7 +6634,7 @@ class RootStructValidator( cls, *, string_prop: builtins.str, - nested_struct: typing.Optional["NestedStruct"] = None, + nested_struct: typing.Optional[NestedStruct] = None, ) -> None: """ :param string_prop: May not be empty. @@ -6793,7 +6758,7 @@ class SingleInstanceTwoTypes( return jsii.invoke(self, "interface1", []) @jsii.member(jsii_name="interface2") - def interface2(self) -> "IPublicInterface": + def interface2(self) -> IPublicInterface: return jsii.invoke(self, "interface2", []) @@ -6897,7 +6862,7 @@ class SomeTypeJsii976(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.SomeTypeJsii @jsii.member(jsii_name="returnReturn") @builtins.classmethod - def return_return(cls) -> "IReturnJsii976": + def return_return(cls) -> IReturnJsii976: return jsii.sinvoke(cls, "returnReturn", []) @@ -7157,7 +7122,7 @@ class StructB: *, required_string: builtins.str, optional_boolean: typing.Optional[builtins.bool] = None, - optional_struct_a: typing.Optional["StructA"] = None, + optional_struct_a: typing.Optional[StructA] = None, ) -> None: """This intentionally overlaps with StructA (where only requiredString is provided) to test htat the kernel properly disambiguates those. @@ -7187,7 +7152,7 @@ class StructB: return result @builtins.property - def optional_struct_a(self) -> typing.Optional["StructA"]: + def optional_struct_a(self) -> typing.Optional[StructA]: result = self._values.get("optional_struct_a") return result @@ -7277,7 +7242,7 @@ class StructPassing(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.StructPassing" _positional: jsii.Number, *, required: builtins.str, - second_level: typing.Union[jsii.Number, "SecondLevelStruct"], + second_level: typing.Union[jsii.Number, SecondLevelStruct], optional: typing.Optional[builtins.str] = None, ) -> "TopLevelStruct": """ @@ -7299,7 +7264,7 @@ class StructUnionConsumer( ): @jsii.member(jsii_name="isStructA") @builtins.classmethod - def is_struct_a(cls, struct: typing.Union["StructA", "StructB"]) -> builtins.bool: + def is_struct_a(cls, struct: typing.Union[StructA, StructB]) -> builtins.bool: """ :param struct: - """ @@ -7307,7 +7272,7 @@ class StructUnionConsumer( @jsii.member(jsii_name="isStructB") @builtins.classmethod - def is_struct_b(cls, struct: typing.Union["StructA", "StructB"]) -> builtins.bool: + def is_struct_b(cls, struct: typing.Union[StructA, StructB]) -> builtins.bool: """ :param struct: - """ @@ -7634,7 +7599,7 @@ class TopLevelStruct: self, *, required: builtins.str, - second_level: typing.Union[jsii.Number, "SecondLevelStruct"], + second_level: typing.Union[jsii.Number, SecondLevelStruct], optional: typing.Optional[builtins.str] = None, ) -> None: """ @@ -7657,7 +7622,7 @@ class TopLevelStruct: return result @builtins.property - def second_level(self) -> typing.Union[jsii.Number, "SecondLevelStruct"]: + def second_level(self) -> typing.Union[jsii.Number, SecondLevelStruct]: """A union to really stress test our serialization.""" result = self._values.get("second_level") assert result is not None, "Required property 'second_level' is missing" @@ -7684,7 +7649,6 @@ class TopLevelStruct: class UmaskCheck(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.UmaskCheck"): """Checks the current file permissions are cool (no funky UMASK down-scoping happened). - see :see: https://github.com/aws/jsii/issues/1765 """ @@ -7733,7 +7697,7 @@ class UnionProperties: def __init__( self, *, - bar: typing.Union[builtins.str, jsii.Number, "AllTypes"], + bar: typing.Union[builtins.str, jsii.Number, AllTypes], foo: typing.Optional[typing.Union[builtins.str, jsii.Number]] = None, ) -> None: """ @@ -7747,7 +7711,7 @@ class UnionProperties: self._values["foo"] = foo @builtins.property - def bar(self) -> typing.Union[builtins.str, jsii.Number, "AllTypes"]: + def bar(self) -> typing.Union[builtins.str, jsii.Number, AllTypes]: result = self._values.get("bar") assert result is not None, "Required property 'bar' is missing" return result @@ -7822,7 +7786,7 @@ class UsesInterfaceWithProperties( metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.UsesInterfaceWithProperties", ): - def __init__(self, obj: "IInterfaceWithProperties") -> None: + def __init__(self, obj: IInterfaceWithProperties) -> None: """ :param obj: - """ @@ -7835,7 +7799,7 @@ class UsesInterfaceWithProperties( @jsii.member(jsii_name="readStringAndNumber") def read_string_and_number( self, - ext: "IInterfaceWithPropertiesExtension", + ext: IInterfaceWithPropertiesExtension, ) -> builtins.str: """ :param ext: - @@ -7851,7 +7815,7 @@ class UsesInterfaceWithProperties( @builtins.property # type: ignore @jsii.member(jsii_name="obj") - def obj(self) -> "IInterfaceWithProperties": + def obj(self) -> IInterfaceWithProperties: return jsii.get(self, "obj") @@ -8068,11 +8032,11 @@ class AnonymousImplementationProvider( jsii.create(AnonymousImplementationProvider, self, []) @jsii.member(jsii_name="provideAsClass") - def provide_as_class(self) -> "Implementation": + def provide_as_class(self) -> Implementation: return jsii.invoke(self, "provideAsClass", []) @jsii.member(jsii_name="provideAsInterface") - def provide_as_interface(self) -> "IAnonymouslyImplementMe": + def provide_as_interface(self) -> IAnonymouslyImplementMe: return jsii.invoke(self, "provideAsInterface", []) @@ -8433,7 +8397,7 @@ class SupportsNiceJavaBuilder( self, id: jsii.Number, default_bar: typing.Optional[jsii.Number] = None, - props: typing.Optional["SupportsNiceJavaBuilderProps"] = None, + props: typing.Optional[SupportsNiceJavaBuilderProps] = None, *rest: builtins.str, ) -> None: """ @@ -8595,6 +8559,8 @@ __all__ = [ "Jsii496Derived", "JsiiAgent", "JsonFormatter", + "LevelOne", + "LevelOneProps", "LoadBalancedFargateServiceProps", "MethodNamedProperty", "Multiply", @@ -8774,12 +8740,12 @@ class CompositeOperation( @builtins.property # type: ignore @jsii.member(jsii_name="stringStyle") - def string_style(self) -> "CompositionStringStyle": + def string_style(self) -> "CompositeOperation.CompositionStringStyle": """The .toString() style.""" return jsii.get(self, "stringStyle") @string_style.setter # type: ignore - def string_style(self, value: "CompositionStringStyle") -> None: + def string_style(self, value: "CompositeOperation.CompositionStringStyle") -> None: jsii.set(self, "stringStyle", value) @jsii.enum( @@ -9294,7 +9260,6 @@ class OuterClass( ): """Checks that classes can self-reference during initialization. - see :see: : https://github.com/aws/jsii/pull/1706 """ @@ -9303,7 +9268,7 @@ class OuterClass( @builtins.property # type: ignore @jsii.member(jsii_name="innerClass") - def inner_class(self) -> "InnerClass": + def inner_class(self) -> InnerClass: return jsii.get(self, "innerClass") @@ -9318,7 +9283,7 @@ class SomeEnum(enum.Enum): name_mapping={"prop": "prop"}, ) class SomeStruct: - def __init__(self, *, prop: "SomeEnum") -> None: + def __init__(self, *, prop: SomeEnum) -> None: """ :param prop: """ @@ -9327,7 +9292,7 @@ class SomeStruct: } @builtins.property - def prop(self) -> "SomeEnum": + def prop(self) -> SomeEnum: result = self._values.get("prop") assert result is not None, "Required property 'prop' is missing" return result @@ -9385,7 +9350,7 @@ class KwargsProps(SomeStruct): def __init__( self, *, - prop: "SomeEnum", + prop: SomeEnum, extra: typing.Optional[builtins.str] = None, ) -> None: """ @@ -9399,7 +9364,7 @@ class KwargsProps(SomeStruct): self._values["extra"] = extra @builtins.property - def prop(self) -> "SomeEnum": + def prop(self) -> SomeEnum: result = self._values.get("prop") assert result is not None, "Required property 'prop' is missing" return result diff --git a/packages/jsii-pacmak/test/targets/python/type-name.test.ts b/packages/jsii-pacmak/test/targets/python/type-name.test.ts index b52157abff..434ae86e30 100644 --- a/packages/jsii-pacmak/test/targets/python/type-name.test.ts +++ b/packages/jsii-pacmak/test/targets/python/type-name.test.ts @@ -1,9 +1,10 @@ import { Assembly, + CollectionKind, + NamedTypeReference, + PrimitiveType, SchemaVersion, TypeReference, - PrimitiveType, - CollectionKind, } from '@jsii/spec'; import { toTypeName, @@ -66,6 +67,8 @@ describe(toTypeName, () => { readonly input: TypeReference | undefined; /** The expected python name of the type */ readonly pythonType: string; + /** If different from pythonType, the forward declaration to use for the type */ + readonly forwardPythonType?: string; /** The optional version of the type's name (if not provided, typing.Optional[]) */ readonly optionalPythonType?: string; /** The required imports for this python type (if not provided, none) */ @@ -73,7 +76,7 @@ describe(toTypeName, () => { /** The submodule from which to generate names (if not provided, the root submodule) */ readonly inSubmodule?: string; /** The nesting context in which to generate names (if not provided, none) */ - readonly inNestingContext?: string; + readonly inNestingContext?: readonly string[]; }; const examples: readonly Example[] = [ @@ -165,12 +168,14 @@ describe(toTypeName, () => { { name: 'User Type (Local)', input: { fqn: `${assembly.name}.BoringClass` }, - pythonType: '"BoringClass"', + pythonType: 'BoringClass', + forwardPythonType: '"BoringClass"', }, { name: 'User Type (Local, Nested)', input: { fqn: `${assembly.name}.${BORING_TYPE}.${NESTED_TYPE}` }, - pythonType: '"BoringClass.NestedType"', + pythonType: 'BoringClass.NestedType', + forwardPythonType: '"BoringClass.NestedType"', }, { name: 'User Type (Local, Submodule)', @@ -195,13 +200,14 @@ describe(toTypeName, () => { }, }, { - name: 'User Type (Local, Nested)', + name: 'User Type (Locally Nested)', input: { fqn: `${assembly.name}.submodule.${SUBMODULE_TYPE}.${SUBMODULE_NESTED_TYPE}`, }, - pythonType: `"${SUBMODULE_NESTED_TYPE}"`, + // Always a forward reference, since the surrounding type isn't *defined* just yet! + pythonType: `"${SUBMODULE_TYPE}.${SUBMODULE_NESTED_TYPE}"`, inSubmodule: `${assembly.name}.submodule`, - inNestingContext: `${assembly.name}.submodule.${SUBMODULE_TYPE}`, + inNestingContext: [`${assembly.name}.submodule.${SUBMODULE_TYPE}`], }, { name: 'User Type (Local, Parent)', @@ -219,15 +225,30 @@ describe(toTypeName, () => { for (const example of examples) { const context: NamingContext = { assembly, + emittedTypes: new Set(), + surroundingTypeFqns: example.inNestingContext, submodule: example.inSubmodule ?? assembly.name, - nestingScope: example.inNestingContext, + }; + const contextWithEmittedType: NamingContext = { + ...context, + emittedTypes: new Set( + [ + // Sneak through to get the type's FQN, but be null-safe, etc... then filter. + (example.input as NamedTypeReference | undefined)?.fqn as string, + ].filter((v) => !!v), + ), }; describe(example.name, () => { const typeName = toTypeName(example.input); test('typeName.pythonType(context)', () => { - expect(typeName.pythonType(context)).toBe(example.pythonType); + expect(typeName.pythonType(context)).toBe( + example.forwardPythonType ?? example.pythonType, + ); + expect(typeName.pythonType(contextWithEmittedType)).toBe( + example.pythonType, + ); }); test('typeName.requiredImports(context)', () => { @@ -247,6 +268,13 @@ describe(toTypeName, () => { test('typeName.pythonType(context)', () => { expect(typeName.pythonType(context)).toBe( + example.optionalPythonType ?? + `typing.Optional[${ + example.forwardPythonType ?? example.pythonType + }]`, + ); + + expect(typeName.pythonType(contextWithEmittedType)).toBe( example.optionalPythonType ?? `typing.Optional[${example.pythonType}]`, ); diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap index f7eb1cf91b..3be89420bb 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap @@ -1205,6 +1205,15 @@ exports[`jsii-tree --all 1`] = ` β”‚ β”‚ β”‚ └─┬ value β”‚ β”‚ β”‚ └── type: any β”‚ β”‚ └── returns: Optional + β”‚ β”œβ”€β”¬ class LevelOne (stable) + β”‚ β”‚ └─┬ members + β”‚ β”‚ β”œβ”€β”¬ (props) initializer (stable) + β”‚ β”‚ β”‚ └─┬ parameters + β”‚ β”‚ β”‚ └─┬ props + β”‚ β”‚ β”‚ └── type: jsii-calc.LevelOneProps + β”‚ β”‚ └─┬ props property (stable) + β”‚ β”‚ β”œβ”€β”€ immutable + β”‚ β”‚ └── type: jsii-calc.LevelOneProps β”‚ β”œβ”€β”¬ class MethodNamedProperty (stable) β”‚ β”‚ └─┬ members β”‚ β”‚ β”œβ”€β”€ () initializer (stable) @@ -2330,6 +2339,24 @@ exports[`jsii-tree --all 1`] = ` β”‚ β”‚ β”œβ”€β”€ abstract β”‚ β”‚ β”œβ”€β”€ immutable β”‚ β”‚ └── type: date + β”‚ β”œβ”€β”¬ interface PropBooleanValue (stable) + β”‚ β”‚ └─┬ members + β”‚ β”‚ └─┬ value property (stable) + β”‚ β”‚ β”œβ”€β”€ abstract + β”‚ β”‚ β”œβ”€β”€ immutable + β”‚ β”‚ └── type: boolean + β”‚ β”œβ”€β”¬ interface PropProperty (stable) + β”‚ β”‚ └─┬ members + β”‚ β”‚ └─┬ prop property (stable) + β”‚ β”‚ β”œβ”€β”€ abstract + β”‚ β”‚ β”œβ”€β”€ immutable + β”‚ β”‚ └── type: jsii-calc.LevelOne.PropBooleanValue + β”‚ β”œβ”€β”¬ interface LevelOneProps (stable) + β”‚ β”‚ └─┬ members + β”‚ β”‚ └─┬ prop property (stable) + β”‚ β”‚ β”œβ”€β”€ abstract + β”‚ β”‚ β”œβ”€β”€ immutable + β”‚ β”‚ └── type: jsii-calc.LevelOne.PropProperty β”‚ β”œβ”€β”¬ interface LoadBalancedFargateServiceProps (stable) β”‚ β”‚ └─┬ members β”‚ β”‚ β”œβ”€β”¬ containerPort property (stable) @@ -2857,6 +2884,7 @@ exports[`jsii-tree --inheritance 1`] = ` β”‚ β”‚ └── interfaces: IJsii496 β”‚ β”œβ”€β”€ class JsiiAgent β”‚ β”œβ”€β”€ class JsonFormatter + β”‚ β”œβ”€β”€ class LevelOne β”‚ β”œβ”€β”€ class MethodNamedProperty β”‚ β”œβ”€β”¬ class Multiply β”‚ β”‚ β”œβ”€β”€ base: BinaryOperation @@ -2994,6 +3022,9 @@ exports[`jsii-tree --inheritance 1`] = ` β”‚ β”œβ”€β”¬ interface ImplictBaseOfBase β”‚ β”‚ └─┬ interfaces β”‚ β”‚ └── BaseProps + β”‚ β”œβ”€β”€ interface PropBooleanValue + β”‚ β”œβ”€β”€ interface PropProperty + β”‚ β”œβ”€β”€ interface LevelOneProps β”‚ β”œβ”€β”€ interface LoadBalancedFargateServiceProps β”‚ β”œβ”€β”€ interface NestedStruct β”‚ β”œβ”€β”€ interface NullShouldBeTreatedAsUndefinedData @@ -3617,6 +3648,10 @@ exports[`jsii-tree --members 1`] = ` β”‚ β”‚ β”œβ”€β”€ static anyUndefined() method β”‚ β”‚ β”œβ”€β”€ static anyZero() method β”‚ β”‚ └── static stringify(value) method + β”‚ β”œβ”€β”¬ class LevelOne + β”‚ β”‚ └─┬ members + β”‚ β”‚ β”œβ”€β”€ (props) initializer + β”‚ β”‚ └── props property β”‚ β”œβ”€β”¬ class MethodNamedProperty β”‚ β”‚ └─┬ members β”‚ β”‚ β”œβ”€β”€ () initializer @@ -4094,6 +4129,15 @@ exports[`jsii-tree --members 1`] = ` β”‚ β”œβ”€β”¬ interface ImplictBaseOfBase β”‚ β”‚ └─┬ members β”‚ β”‚ └── goo property + β”‚ β”œβ”€β”¬ interface PropBooleanValue + β”‚ β”‚ └─┬ members + β”‚ β”‚ └── value property + β”‚ β”œβ”€β”¬ interface PropProperty + β”‚ β”‚ └─┬ members + β”‚ β”‚ └── prop property + β”‚ β”œβ”€β”¬ interface LevelOneProps + β”‚ β”‚ └─┬ members + β”‚ β”‚ └── prop property β”‚ β”œβ”€β”¬ interface LoadBalancedFargateServiceProps β”‚ β”‚ └─┬ members β”‚ β”‚ β”œβ”€β”€ containerPort property @@ -4422,6 +4466,7 @@ exports[`jsii-tree --types 1`] = ` β”‚ β”œβ”€β”€ class Jsii496Derived β”‚ β”œβ”€β”€ class JsiiAgent β”‚ β”œβ”€β”€ class JsonFormatter + β”‚ β”œβ”€β”€ class LevelOne β”‚ β”œβ”€β”€ class MethodNamedProperty β”‚ β”œβ”€β”€ class Multiply β”‚ β”œβ”€β”€ class Negate @@ -4524,6 +4569,9 @@ exports[`jsii-tree --types 1`] = ` β”‚ β”œβ”€β”€ interface IStableInterface β”‚ β”œβ”€β”€ interface IStructReturningDelegate β”‚ β”œβ”€β”€ interface ImplictBaseOfBase + β”‚ β”œβ”€β”€ interface PropBooleanValue + β”‚ β”œβ”€β”€ interface PropProperty + β”‚ β”œβ”€β”€ interface LevelOneProps β”‚ β”œβ”€β”€ interface LoadBalancedFargateServiceProps β”‚ β”œβ”€β”€ interface NestedStruct β”‚ β”œβ”€β”€ interface NullShouldBeTreatedAsUndefinedData diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap index 3827deaab8..ad335bf767 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap @@ -90,6 +90,7 @@ Array [ "jsii-calc.Jsii496Derived", "jsii-calc.JsiiAgent", "jsii-calc.JsonFormatter", + "jsii-calc.LevelOne", "jsii-calc.MethodNamedProperty", "jsii-calc.Multiply", "jsii-calc.Negate",