Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Register module-level stability #515

Merged
merged 9 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,6 @@ export interface OptionalStruct {
*
* @see https://aws.amazon.com/
* @customAttribute hasAValue
* @deprecated Use something else please
* @stable
*/
export class ClassWithDocs {
Expand Down Expand Up @@ -1682,3 +1681,35 @@ export abstract class VoidCallback {
}
protected abstract overrideMe(): void;
}

RomainMuller marked this conversation as resolved.
Show resolved Hide resolved
/**
* This tests code generation of deprecation markers
*
* @deprecated without replacement
RomainMuller marked this conversation as resolved.
Show resolved Hide resolved
*/
export class DeprecatedClass {
/**
* @deprecated intentionally
*/
public readonly deprecatedAttribute: string;

/**
* @deprecated can be unexpectedly non-null!
*/
protected deprecatedProtected?: string;

/**
* @param argument some string
* @deprecated this is unsafe
*/
constructor(argument = 'tombstone!') {
this.deprecatedAttribute = argument;
}

/**
* @deprecated throws unexpected errors
*/
public deprecatedMethod() {
throw new Error();
}
}
1 change: 1 addition & 0 deletions packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"private": true,
"stability": "experimental",
RomainMuller marked this conversation as resolved.
Show resolved Hide resolved
"jsii": {
"outdir": "dist",
"targets": {
Expand Down
102 changes: 92 additions & 10 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
}
},
"description": "A simple calcuator built on JSII.",
"docs": {
"stability": "experimental"
},
"homepage": "https://github.com/awslabs/jsii.git",
"jsiiVersion": "0.11.0",
"license": "Apache-2.0",
Expand Down Expand Up @@ -1515,7 +1518,6 @@
"custom": {
"customAttribute": "hasAValue"
},
"deprecated": "Use something else please",
"example": "function anExample() {\n}",
"remarks": "The docs are great. They're a bunch of tags.",
"see": "https://aws.amazon.com/",
Expand All @@ -1527,7 +1529,7 @@
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1637
"line": 1636
},
"name": "ClassWithDocs"
},
Expand Down Expand Up @@ -1887,6 +1889,85 @@
}
]
},
"jsii-calc.DeprecatedClass": {
"assembly": "jsii-calc",
"docs": {
"deprecated": "without replacement",
"stability": "deprecated",
"summary": "This tests code generation of deprecation markers."
},
"fqn": "jsii-calc.DeprecatedClass",
"initializer": {
"docs": {
"deprecated": "this is unsafe",
"stability": "deprecated"
},
"parameters": [
{
"docs": {
"summary": "some string."
},
"name": "argument",
"optional": true,
"type": {
"primitive": "string"
}
}
]
},
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1690
},
"methods": [
{
"docs": {
"deprecated": "throws unexpected errors",
"stability": "deprecated"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1712
},
"name": "deprecatedMethod"
}
],
"name": "DeprecatedClass",
"properties": [
{
"docs": {
"deprecated": "intentionally",
"stability": "deprecated"
},
"immutable": true,
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1694
},
"name": "deprecatedAttribute",
"type": {
"primitive": "string"
}
},
{
"docs": {
"deprecated": "can be unexpectedly non-null!",
"stability": "deprecated"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1699
},
"name": "deprecatedProtected",
"optional": true,
"protected": true,
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.DerivedClassHasNoProperties.Base": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DerivedClassHasNoProperties.Base",
Expand Down Expand Up @@ -4828,6 +4909,7 @@
"assembly": "jsii-calc",
"docs": {
"deprecated": "Use the new class",
"stability": "deprecated",
"summary": "Old class."
},
"fqn": "jsii-calc.Old",
Expand Down Expand Up @@ -5673,13 +5755,13 @@
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1645
"line": 1644
},
"methods": [
{
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1648
"line": 1647
},
"name": "canAccessStaticContext",
"returns": {
Expand All @@ -5695,7 +5777,7 @@
{
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1656
"line": 1655
},
"name": "staticVariable",
"static": true,
Expand Down Expand Up @@ -6629,21 +6711,21 @@
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1674
"line": 1673
},
"methods": [
{
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1679
"line": 1678
},
"name": "callMe"
},
{
"abstract": true,
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1683
"line": 1682
},
"name": "overrideMe",
"protected": true
Expand All @@ -6655,7 +6737,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 1676
"line": 1675
},
"name": "methodWasCalled",
"type": {
Expand Down Expand Up @@ -6810,5 +6892,5 @@
}
},
"version": "0.11.0",
"fingerprint": "i8GdLx7YlhttP5/pB0dKItig1wFkp/DwDdUtbYsIdfc="
"fingerprint": "5R2rpEqEYZnuiNa8EnVDEierWuf4xkcuVJDj4a7hNPk="
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,31 @@ SyntaxList<AttributeListSyntax> CreateAttributes()
argumentList += $", parametersJson: {parametersJsonLiteral}";
}

return SF.List(new[] {
SF.AttributeList(SF.SeparatedList(new[] {
return SF.List(GetAttributeLists());

IEnumerable<AttributeListSyntax> GetAttributeLists()
{
yield return SF.AttributeList(SF.SeparatedList(new[] {
SF.Attribute(
SF.ParseName("JsiiClass"),
SF.ParseAttributeArgumentList($"({argumentList})")
)
}))
});
}));

if (Type.Docs?.Deprecated != null)
{
yield return SF.AttributeList(SF.SeparatedList(new[] {
SF.Attribute(
SF.ParseName("System.Obsolete"),
SF.AttributeArgumentList(
SF.SingletonSeparatedList(
SF.AttributeArgument(SF.LiteralExpression(SyntaxKind.StringLiteralExpression, SF.Literal(Type.Docs.Deprecated)))
)
)
)
}));
}
}
}

SyntaxTokenList CreateModifiers()
Expand Down Expand Up @@ -102,12 +119,13 @@ IEnumerable<MemberDeclarationSyntax> CreateMembers()
IEnumerable<MemberDeclarationSyntax> CreateConstructors()
{
SyntaxToken typeName = Symbols.GetNameSyntaxToken(Type);
var attributes = GetAttributeLists();

if (Type.Initializer != null)
{
yield return SF.ConstructorDeclaration
(
SF.List<AttributeListSyntax>(),
attributes,
SF.TokenList(SF.Token(
Type.IsAbstract || Type.Initializer.IsProtected
? SyntaxKind.ProtectedKeyword
Expand Down Expand Up @@ -141,7 +159,7 @@ IEnumerable<MemberDeclarationSyntax> CreateConstructors()

yield return SF.ConstructorDeclaration
(
SF.List<AttributeListSyntax>(),
attributes,
SF.TokenList(SF.Token(SyntaxKind.ProtectedKeyword)),
typeName,
SF.ParseParameterList("(ByRefValue reference)"),
Expand All @@ -157,7 +175,7 @@ IEnumerable<MemberDeclarationSyntax> CreateConstructors()
// This constructor allows child classes to supply their own parameter lists. It is always protected.
yield return SF.ConstructorDeclaration
(
SF.List<AttributeListSyntax>(),
attributes,
SF.TokenList(SF.Token(SyntaxKind.ProtectedKeyword)),
typeName,
SF.ParseParameterList("(DeputyProps props)"),
Expand Down Expand Up @@ -192,6 +210,25 @@ ArgumentSyntax GetBaseArgument()
)
);
}

SyntaxList<AttributeListSyntax> GetAttributeLists()
{
var deprecated = Type.Initializer?.Docs?.Deprecated;
if (deprecated == null)
{
return SF.List<AttributeListSyntax>();
}
return SF.List(new[] { SF.AttributeList(SF.SingletonSeparatedList(
SF.Attribute(
SF.ParseName("System.Obsolete"),
SF.AttributeArgumentList(
SF.SingletonSeparatedList(
SF.AttributeArgument(SF.LiteralExpression(SyntaxKind.StringLiteralExpression, SF.Literal(deprecated)))
)
)
)
)) });
}
}

IEnumerable<PropertyDeclarationSyntax> CreateProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
using System.Linq;
using SF = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

Expand Down Expand Up @@ -32,14 +33,31 @@ SyntaxList<AttributeListSyntax> CreateAttributes()
TypeOfExpressionSyntax typeOfExpression = SF.TypeOfExpression(Symbols.GetNameSyntax(Type));
SyntaxToken fullyQualifiedNameLiteral = SF.Literal(Type.FullyQualifiedName);

return SF.List(new[] {
SF.AttributeList(SF.SeparatedList(new[] {
return SF.List(GetAttributeLists());

IEnumerable<AttributeListSyntax> GetAttributeLists()
{
yield return SF.AttributeList(SF.SeparatedList(new[] {
SF.Attribute(
SF.ParseName("JsiiEnum"),
SF.ParseAttributeArgumentList($"(nativeType: {typeOfExpression}, fullyQualifiedName: {fullyQualifiedNameLiteral})")
)
}))
});
}));

if (Type.Docs?.Deprecated != null)
{
yield return SF.AttributeList(SF.SeparatedList(new[] {
SF.Attribute(
SF.ParseName("System.Obsolete"),
SF.AttributeArgumentList(
SF.SingletonSeparatedList(
SF.AttributeArgument(SF.LiteralExpression(SyntaxKind.StringLiteralExpression, SF.Literal(Type.Docs.Deprecated)))
)
)
)
}));
}
}
}

SeparatedSyntaxList<EnumMemberDeclarationSyntax> CreateValues()
Expand Down
Loading