diff --git a/packages/jsii-calc/lib/compliance.ts b/packages/jsii-calc/lib/compliance.ts index b5a0a7f858..a5194ccd75 100644 --- a/packages/jsii-calc/lib/compliance.ts +++ b/packages/jsii-calc/lib/compliance.ts @@ -1692,3 +1692,37 @@ export class WithPrivatePropertyInConstructor { return this.privateField === 'Success!'; } } + +/** + * Verifies that singleton enums are handled correctly + * + * https://github.com/awslabs/jsii/issues/231 + */ +export class SingletonString { + private constructor() { } + + public isSingletonString(value: string): boolean { + return value === SingletonStringEnum.SingletonString; + } +} +/** A singleton string */ +export enum SingletonStringEnum { + /** 1337 */ + SingletonString = '3L1T3!' +} +/** + * Verifies that singleton enums are handled correctly + * + * https://github.com/awslabs/jsii/issues/231 + */ +export class SingletonInt { + private constructor() { } + public isSingletonInt(value: number): boolean { + return value === SingletonIntEnum.SingletonInt; + } +} +/** A singleton integer. */ +export enum SingletonIntEnum { + /** Elite! */ + SingletonInt = 1337 +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 5246a4694d..23f1aa9ffe 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -7121,6 +7121,132 @@ ], "name": "SingleInstanceTwoTypes" }, + "jsii-calc.SingletonInt": { + "assembly": "jsii-calc", + "docs": { + "remarks": "https://github.com/awslabs/jsii/issues/231", + "stability": "experimental", + "summary": "Verifies that singleton enums are handled correctly." + }, + "fqn": "jsii-calc.SingletonInt", + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1718 + }, + "methods": [ + { + "docs": { + "stability": "experimental" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1720 + }, + "name": "isSingletonInt", + "parameters": [ + { + "name": "value", + "type": { + "primitive": "number" + } + } + ], + "returns": { + "type": { + "primitive": "boolean" + } + } + } + ], + "name": "SingletonInt" + }, + "jsii-calc.SingletonIntEnum": { + "assembly": "jsii-calc", + "docs": { + "stability": "experimental", + "summary": "A singleton integer." + }, + "fqn": "jsii-calc.SingletonIntEnum", + "kind": "enum", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1725 + }, + "members": [ + { + "docs": { + "stability": "experimental", + "summary": "Elite!" + }, + "name": "SingletonInt" + } + ], + "name": "SingletonIntEnum" + }, + "jsii-calc.SingletonString": { + "assembly": "jsii-calc", + "docs": { + "remarks": "https://github.com/awslabs/jsii/issues/231", + "stability": "experimental", + "summary": "Verifies that singleton enums are handled correctly." + }, + "fqn": "jsii-calc.SingletonString", + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1701 + }, + "methods": [ + { + "docs": { + "stability": "experimental" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1704 + }, + "name": "isSingletonString", + "parameters": [ + { + "name": "value", + "type": { + "primitive": "string" + } + } + ], + "returns": { + "type": { + "primitive": "boolean" + } + } + } + ], + "name": "SingletonString" + }, + "jsii-calc.SingletonStringEnum": { + "assembly": "jsii-calc", + "docs": { + "stability": "experimental", + "summary": "A singleton string." + }, + "fqn": "jsii-calc.SingletonStringEnum", + "kind": "enum", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1709 + }, + "members": [ + { + "docs": { + "stability": "experimental", + "summary": "1337." + }, + "name": "SingletonString" + } + ], + "name": "SingletonStringEnum" + }, "jsii-calc.StableClass": { "assembly": "jsii-calc", "docs": { @@ -8648,5 +8774,5 @@ } }, "version": "0.11.2", - "fingerprint": "eQpFH3EHC2GlCSnThymTxnuO9HyZBFvsvddZqu1Fy+8=" + "fingerprint": "5TwMNffhxUueZQEAGZG6+JIfS6jcTwCJWc9vixH5aLc=" } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii index 5246a4694d..23f1aa9ffe 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii @@ -7121,6 +7121,132 @@ ], "name": "SingleInstanceTwoTypes" }, + "jsii-calc.SingletonInt": { + "assembly": "jsii-calc", + "docs": { + "remarks": "https://github.com/awslabs/jsii/issues/231", + "stability": "experimental", + "summary": "Verifies that singleton enums are handled correctly." + }, + "fqn": "jsii-calc.SingletonInt", + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1718 + }, + "methods": [ + { + "docs": { + "stability": "experimental" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1720 + }, + "name": "isSingletonInt", + "parameters": [ + { + "name": "value", + "type": { + "primitive": "number" + } + } + ], + "returns": { + "type": { + "primitive": "boolean" + } + } + } + ], + "name": "SingletonInt" + }, + "jsii-calc.SingletonIntEnum": { + "assembly": "jsii-calc", + "docs": { + "stability": "experimental", + "summary": "A singleton integer." + }, + "fqn": "jsii-calc.SingletonIntEnum", + "kind": "enum", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1725 + }, + "members": [ + { + "docs": { + "stability": "experimental", + "summary": "Elite!" + }, + "name": "SingletonInt" + } + ], + "name": "SingletonIntEnum" + }, + "jsii-calc.SingletonString": { + "assembly": "jsii-calc", + "docs": { + "remarks": "https://github.com/awslabs/jsii/issues/231", + "stability": "experimental", + "summary": "Verifies that singleton enums are handled correctly." + }, + "fqn": "jsii-calc.SingletonString", + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1701 + }, + "methods": [ + { + "docs": { + "stability": "experimental" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1704 + }, + "name": "isSingletonString", + "parameters": [ + { + "name": "value", + "type": { + "primitive": "string" + } + } + ], + "returns": { + "type": { + "primitive": "boolean" + } + } + } + ], + "name": "SingletonString" + }, + "jsii-calc.SingletonStringEnum": { + "assembly": "jsii-calc", + "docs": { + "stability": "experimental", + "summary": "A singleton string." + }, + "fqn": "jsii-calc.SingletonStringEnum", + "kind": "enum", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1709 + }, + "members": [ + { + "docs": { + "stability": "experimental", + "summary": "1337." + }, + "name": "SingletonString" + } + ], + "name": "SingletonStringEnum" + }, "jsii-calc.StableClass": { "assembly": "jsii-calc", "docs": { @@ -8648,5 +8774,5 @@ } }, "version": "0.11.2", - "fingerprint": "eQpFH3EHC2GlCSnThymTxnuO9HyZBFvsvddZqu1Fy+8=" + "fingerprint": "5TwMNffhxUueZQEAGZG6+JIfS6jcTwCJWc9vixH5aLc=" } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonInt.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonInt.cs new file mode 100644 index 0000000000..fdd7df5e7b --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonInt.cs @@ -0,0 +1,28 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// Verifies that singleton enums are handled correctly. + /// + /// https://github.com/awslabs/jsii/issues/231 + /// stability: Experimental + /// + [JsiiClass(nativeType: typeof(SingletonInt), fullyQualifiedName: "jsii-calc.SingletonInt")] + public class SingletonInt : DeputyBase + { + protected SingletonInt(ByRefValue reference): base(reference) + { + } + + protected SingletonInt(DeputyProps props): base(props) + { + } + + /// stability: Experimental + [JsiiMethod(name: "isSingletonInt", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}", parametersJson: "[{\"name\":\"value\",\"type\":{\"primitive\":\"number\"}}]")] + public virtual bool IsSingletonInt(double value) + { + return InvokeInstanceMethod(new object[]{value}); + } + } +} \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonIntEnum.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonIntEnum.cs new file mode 100644 index 0000000000..ac0c53ce28 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonIntEnum.cs @@ -0,0 +1,15 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// A singleton integer. + /// stability: Experimental + [JsiiEnum(nativeType: typeof(SingletonIntEnum), fullyQualifiedName: "jsii-calc.SingletonIntEnum")] + public enum SingletonIntEnum + { + /// Elite! + /// stability: Experimental + [JsiiEnumMember(name: "SingletonInt")] + SingletonInt + } +} \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonString.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonString.cs new file mode 100644 index 0000000000..073abec455 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonString.cs @@ -0,0 +1,28 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// Verifies that singleton enums are handled correctly. + /// + /// https://github.com/awslabs/jsii/issues/231 + /// stability: Experimental + /// + [JsiiClass(nativeType: typeof(SingletonString), fullyQualifiedName: "jsii-calc.SingletonString")] + public class SingletonString : DeputyBase + { + protected SingletonString(ByRefValue reference): base(reference) + { + } + + protected SingletonString(DeputyProps props): base(props) + { + } + + /// stability: Experimental + [JsiiMethod(name: "isSingletonString", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}", parametersJson: "[{\"name\":\"value\",\"type\":{\"primitive\":\"string\"}}]")] + public virtual bool IsSingletonString(string value) + { + return InvokeInstanceMethod(new object[]{value}); + } + } +} \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonStringEnum.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonStringEnum.cs new file mode 100644 index 0000000000..4d4556d68e --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonStringEnum.cs @@ -0,0 +1,15 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// A singleton string. + /// stability: Experimental + [JsiiEnum(nativeType: typeof(SingletonStringEnum), fullyQualifiedName: "jsii-calc.SingletonStringEnum")] + public enum SingletonStringEnum + { + /// 1337. + /// stability: Experimental + [JsiiEnumMember(name: "SingletonString")] + SingletonString + } +} \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java index b208408dfc..29e3a98ea7 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java @@ -126,6 +126,10 @@ protected Class resolveClass(final String fqn) throws ClassNotFoundException case "jsii-calc.ReturnsPrivateImplementationOfInterface": return software.amazon.jsii.tests.calculator.ReturnsPrivateImplementationOfInterface.class; case "jsii-calc.RuntimeTypeChecking": return software.amazon.jsii.tests.calculator.RuntimeTypeChecking.class; case "jsii-calc.SingleInstanceTwoTypes": return software.amazon.jsii.tests.calculator.SingleInstanceTwoTypes.class; + case "jsii-calc.SingletonInt": return software.amazon.jsii.tests.calculator.SingletonInt.class; + case "jsii-calc.SingletonIntEnum": return software.amazon.jsii.tests.calculator.SingletonIntEnum.class; + case "jsii-calc.SingletonString": return software.amazon.jsii.tests.calculator.SingletonString.class; + case "jsii-calc.SingletonStringEnum": return software.amazon.jsii.tests.calculator.SingletonStringEnum.class; case "jsii-calc.StableClass": return software.amazon.jsii.tests.calculator.StableClass.class; case "jsii-calc.StableEnum": return software.amazon.jsii.tests.calculator.StableEnum.class; case "jsii-calc.StableStruct": return software.amazon.jsii.tests.calculator.StableStruct.class; diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonInt.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonInt.java new file mode 100644 index 0000000000..d9b9f1aa18 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonInt.java @@ -0,0 +1,25 @@ +package software.amazon.jsii.tests.calculator; + +/** + * Verifies that singleton enums are handled correctly. + * + * https://github.com/awslabs/jsii/issues/231 + * + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.SingletonInt") +public class SingletonInt extends software.amazon.jsii.JsiiObject { + protected SingletonInt(final software.amazon.jsii.JsiiObject.InitializationMode mode) { + super(mode); + } + + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public java.lang.Boolean isSingletonInt(final java.lang.Number value) { + return this.jsiiCall("isSingletonInt", java.lang.Boolean.class, new Object[] { java.util.Objects.requireNonNull(value, "value is required") }); + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonIntEnum.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonIntEnum.java new file mode 100644 index 0000000000..976868f731 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonIntEnum.java @@ -0,0 +1,19 @@ +package software.amazon.jsii.tests.calculator; + +/** + * A singleton integer. + * + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.SingletonIntEnum") +public enum SingletonIntEnum { + /** + * Elite! + * + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + SingletonInt, +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonString.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonString.java new file mode 100644 index 0000000000..386a7aab02 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonString.java @@ -0,0 +1,25 @@ +package software.amazon.jsii.tests.calculator; + +/** + * Verifies that singleton enums are handled correctly. + * + * https://github.com/awslabs/jsii/issues/231 + * + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.SingletonString") +public class SingletonString extends software.amazon.jsii.JsiiObject { + protected SingletonString(final software.amazon.jsii.JsiiObject.InitializationMode mode) { + super(mode); + } + + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public java.lang.Boolean isSingletonString(final java.lang.String value) { + return this.jsiiCall("isSingletonString", java.lang.Boolean.class, new Object[] { java.util.Objects.requireNonNull(value, "value is required") }); + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonStringEnum.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonStringEnum.java new file mode 100644 index 0000000000..7c2a5e84d2 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/SingletonStringEnum.java @@ -0,0 +1,19 @@ +package software.amazon.jsii.tests.calculator; + +/** + * A singleton string. + * + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.SingletonStringEnum") +public enum SingletonStringEnum { + /** + * 1337. + * + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + SingletonString, +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py b/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py index 49474c4c6f..0c77586621 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py +++ b/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py @@ -4718,6 +4718,74 @@ def interface2(self) -> "IPublicInterface": return jsii.invoke(self, "interface2", []) +class SingletonInt(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.SingletonInt"): + """Verifies that singleton enums are handled correctly. + + https://github.com/awslabs/jsii/issues/231 + + Stability: + experimental + """ + @jsii.member(jsii_name="isSingletonInt") + def is_singleton_int(self, value: jsii.Number) -> bool: + """ + Arguments: + value: - + + Stability: + experimental + """ + return jsii.invoke(self, "isSingletonInt", [value]) + + +@jsii.enum(jsii_type="jsii-calc.SingletonIntEnum") +class SingletonIntEnum(enum.Enum): + """A singleton integer. + + Stability: + experimental + """ + SingletonInt = "SingletonInt" + """Elite! + + Stability: + experimental + """ + +class SingletonString(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.SingletonString"): + """Verifies that singleton enums are handled correctly. + + https://github.com/awslabs/jsii/issues/231 + + Stability: + experimental + """ + @jsii.member(jsii_name="isSingletonString") + def is_singleton_string(self, value: str) -> bool: + """ + Arguments: + value: - + + Stability: + experimental + """ + return jsii.invoke(self, "isSingletonString", [value]) + + +@jsii.enum(jsii_type="jsii-calc.SingletonStringEnum") +class SingletonStringEnum(enum.Enum): + """A singleton string. + + Stability: + experimental + """ + SingletonString = "SingletonString" + """1337. + + Stability: + experimental + """ + class StableClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.StableClass"): """ Stability: @@ -5913,6 +5981,6 @@ def parts(self, value: typing.List[scope.jsii_calc_lib.Value]): return jsii.set(self, "parts", value) -__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "WithPrivatePropertyInConstructor", "__jsii_assembly__", "composition"] +__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "SingletonInt", "SingletonIntEnum", "SingletonString", "SingletonStringEnum", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "WithPrivatePropertyInConstructor", "__jsii_assembly__", "composition"] publication.publish() diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst b/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst index 0bf8ce4668..ccfe7c2ae1 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst +++ b/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst @@ -5831,6 +5831,168 @@ SingleInstanceTwoTypes :rtype: :py:class:`~jsii-calc.IPublicInterface`\ +SingletonInt +^^^^^^^^^^^^ + +.. py:class:: SingletonInt + + **Language-specific names:** + + .. tabs:: + + .. code-tab:: c# + + using Amazon.JSII.Tests.CalculatorNamespace; + + .. code-tab:: java + + import software.amazon.jsii.tests.calculator.SingletonInt; + + .. code-tab:: javascript + + const { SingletonInt } = require('jsii-calc'); + + .. code-tab:: typescript + + import { SingletonInt } from 'jsii-calc'; + + + + Verifies that singleton enums are handled correctly. + + + + https://github.com/awslabs/jsii/issues/231 + + + + + .. py:method:: isSingletonInt(value) -> boolean + + :param value: + :type value: number + :rtype: boolean + + +SingletonIntEnum (enum) +^^^^^^^^^^^^^^^^^^^^^^^ + +.. py:class:: SingletonIntEnum + + **Language-specific names:** + + .. tabs:: + + .. code-tab:: c# + + using Amazon.JSII.Tests.CalculatorNamespace; + + .. code-tab:: java + + import software.amazon.jsii.tests.calculator.SingletonIntEnum; + + .. code-tab:: javascript + + const { SingletonIntEnum } = require('jsii-calc'); + + .. code-tab:: typescript + + import { SingletonIntEnum } from 'jsii-calc'; + + + + A singleton integer. + + + + .. py:data:: SingletonInt + + Elite! + + + + +SingletonString +^^^^^^^^^^^^^^^ + +.. py:class:: SingletonString + + **Language-specific names:** + + .. tabs:: + + .. code-tab:: c# + + using Amazon.JSII.Tests.CalculatorNamespace; + + .. code-tab:: java + + import software.amazon.jsii.tests.calculator.SingletonString; + + .. code-tab:: javascript + + const { SingletonString } = require('jsii-calc'); + + .. code-tab:: typescript + + import { SingletonString } from 'jsii-calc'; + + + + Verifies that singleton enums are handled correctly. + + + + https://github.com/awslabs/jsii/issues/231 + + + + + .. py:method:: isSingletonString(value) -> boolean + + :param value: + :type value: string + :rtype: boolean + + +SingletonStringEnum (enum) +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. py:class:: SingletonStringEnum + + **Language-specific names:** + + .. tabs:: + + .. code-tab:: c# + + using Amazon.JSII.Tests.CalculatorNamespace; + + .. code-tab:: java + + import software.amazon.jsii.tests.calculator.SingletonStringEnum; + + .. code-tab:: javascript + + const { SingletonStringEnum } = require('jsii-calc'); + + .. code-tab:: typescript + + import { SingletonStringEnum } from 'jsii-calc'; + + + + A singleton string. + + + + .. py:data:: SingletonString + + 1337. + + + + StableClass ^^^^^^^^^^^ diff --git a/packages/jsii-reflect/test/classes.expected.txt b/packages/jsii-reflect/test/classes.expected.txt index 37f16cd47e..824626299b 100644 --- a/packages/jsii-reflect/test/classes.expected.txt +++ b/packages/jsii-reflect/test/classes.expected.txt @@ -68,6 +68,8 @@ ReferenceEnumFromScopedPackage ReturnsPrivateImplementationOfInterface RuntimeTypeChecking SingleInstanceTwoTypes +SingletonInt +SingletonString StableClass StaticContext Statics diff --git a/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt index 7439bc6896..e813402066 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt @@ -988,6 +988,20 @@ assemblies │ │ │ └── returns: jsii-calc.InbetweenClass │ │ └─┬ interface2() method │ │ └── returns: jsii-calc.IPublicInterface + │ ├─┬ class SingletonInt + │ │ └─┬ members + │ │ └─┬ isSingletonInt(value) method + │ │ ├─┬ parameters + │ │ │ └─┬ value + │ │ │ └── type: number + │ │ └── returns: boolean + │ ├─┬ class SingletonString + │ │ └─┬ members + │ │ └─┬ isSingletonString(value) method + │ │ ├─┬ parameters + │ │ │ └─┬ value + │ │ │ └── type: string + │ │ └── returns: boolean │ ├─┬ class StableClass │ │ └─┬ members │ │ ├─┬ (readonlyString,mutableNumber) initializer @@ -1588,6 +1602,10 @@ assemblies │ ├─┬ enum ExperimentalEnum │ │ ├── OptionA │ │ └── OptionB + │ ├─┬ enum SingletonIntEnum + │ │ └── SingletonInt + │ ├─┬ enum SingletonStringEnum + │ │ └── SingletonString │ ├─┬ enum StableEnum │ │ ├── OptionA │ │ └── OptionB diff --git a/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt index 0222f01813..65419eb49b 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt @@ -90,6 +90,8 @@ assemblies │ ├── class ReturnsPrivateImplementationOfInterface │ ├── class RuntimeTypeChecking │ ├── class SingleInstanceTwoTypes + │ ├── class SingletonInt + │ ├── class SingletonString │ ├── class StableClass │ ├── class StaticContext │ ├── class Statics @@ -170,6 +172,8 @@ assemblies │ ├── enum AllTypesEnum │ ├── enum DeprecatedEnum │ ├── enum ExperimentalEnum + │ ├── enum SingletonIntEnum + │ ├── enum SingletonStringEnum │ ├── enum StableEnum │ ├── enum StringEnum │ └── enum CompositionStringStyle diff --git a/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt index 207b924487..6f0e05404e 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt @@ -451,6 +451,12 @@ assemblies │ │ ├── () initializer │ │ ├── interface1() method │ │ └── interface2() method + │ ├─┬ class SingletonInt + │ │ └─┬ members + │ │ └── isSingletonInt(value) method + │ ├─┬ class SingletonString + │ │ └─┬ members + │ │ └── isSingletonString(value) method │ ├─┬ class StableClass │ │ └─┬ members │ │ ├── (readonlyString,mutableNumber) initializer @@ -710,6 +716,10 @@ assemblies │ ├─┬ enum ExperimentalEnum │ │ ├── OptionA │ │ └── OptionB + │ ├─┬ enum SingletonIntEnum + │ │ └── SingletonInt + │ ├─┬ enum SingletonStringEnum + │ │ └── SingletonString │ ├─┬ enum StableEnum │ │ ├── OptionA │ │ └── OptionB diff --git a/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt index 9912394562..405d82278c 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt @@ -67,6 +67,8 @@ assemblies │ ├── class ReturnsPrivateImplementationOfInterface │ ├── class RuntimeTypeChecking │ ├── class SingleInstanceTwoTypes + │ ├── class SingletonInt + │ ├── class SingletonString │ ├── class StableClass │ ├── class StaticContext │ ├── class Statics @@ -127,6 +129,8 @@ assemblies │ ├── enum AllTypesEnum │ ├── enum DeprecatedEnum │ ├── enum ExperimentalEnum + │ ├── enum SingletonIntEnum + │ ├── enum SingletonStringEnum │ ├── enum StableEnum │ ├── enum StringEnum │ └── enum CompositionStringStyle diff --git a/packages/jsii/lib/assembler.ts b/packages/jsii/lib/assembler.ts index 5bf1b68990..860f752d3c 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -735,11 +735,17 @@ export class Assembler implements Emitter { LOG.trace(`Processing enum: ${colors.gray(ctx.namespace.join('.'))}.${colors.cyan(type.symbol.name)}`); } - if (_hasInternalJsDocTag(type.symbol)) { + // Forcefully resolving to the EnumDeclaration symbol for single-valued enums + const symbol: ts.Symbol = type.isLiteral() ? (type.symbol as any).parent : type.symbol; + if (!symbol) { + throw new Error(`Unable to resolve enum declaration for ${type.symbol.name}!`); + } + + if (_hasInternalJsDocTag(symbol)) { return undefined; } - const decl = type.symbol.valueDeclaration; + const decl = symbol.valueDeclaration; const flags = ts.getCombinedModifierFlags(decl); // tslint:disable-next-line:no-bitwise if (flags & ts.ModifierFlags.Const) { @@ -748,19 +754,20 @@ export class Assembler implements Emitter { `Exported enum cannot be declared 'const'`); } - const docs = this._visitDocumentation(type.symbol, ctx); + const docs = this._visitDocumentation(symbol, ctx); const typeContext = ctx.replaceStability(docs && docs.stability); + const members = type.isUnion() ? type.types : [type]; const jsiiType: spec.EnumType = { assembly: this.projectInfo.name, - fqn: `${[this.projectInfo.name, ...ctx.namespace].join('.')}.${type.symbol.name}`, + fqn: `${[this.projectInfo.name, ...ctx.namespace].join('.')}.${symbol.name}`, kind: spec.TypeKind.Enum, - members: ((type as ts.UnionType).types || []).map(m => ({ + members: members.map(m => ({ name: m.symbol.name, docs: this._visitDocumentation(m.symbol, typeContext), })), - name: type.symbol.name, + name: symbol.name, namespace: ctx.namespace.length > 0 ? ctx.namespace.join('.') : undefined, docs };