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

New APIs for "Primary Constructors" #66914

Closed
AlekseyTs opened this issue Feb 16, 2023 · 4 comments
Closed

New APIs for "Primary Constructors" #66914

AlekseyTs opened this issue Feb 16, 2023 · 4 comments
Assignees
Labels
api-approved API was approved in API review, it can be implemented Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature - Primary Constructors Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@AlekseyTs
Copy link
Contributor

Proposed API

namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
     public abstract partial class TypeDeclarationSyntax
     {
+        public ParameterListSyntax? ParameterList { get; }
     }

     public sealed partial class ClassDeclarationSyntax : TypeDeclarationSyntax
     {
+        public new ParameterListSyntax? ParameterList { get; }

+        public ClassDeclarationSyntax WithParameterList(ParameterListSyntax? parameterList);

+        public ClassDeclarationSyntax AddParameterListParameters(params ParameterSyntax[] items);

+        public ClassDeclarationSyntax Update(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers,
+                                             SyntaxToken keyword, SyntaxToken identifier,
+                                             TypeParameterListSyntax? typeParameterList,
+                                             ParameterListSyntax? parameterList, BaseListSyntax? baseList,
+                                             SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                             SyntaxToken openBraceToken, SyntaxList<MemberDeclarationSyntax> members,
+                                             SyntaxToken closeBraceToken, SyntaxToken semicolonToken);
     }

    public sealed partial class StructDeclarationSyntax : TypeDeclarationSyntax
    {
+        public new ParameterListSyntax? ParameterList { get; }

+        public StructDeclarationSyntax WithParameterList(ParameterListSyntax? parameterList);

+        public StructDeclarationSyntax AddParameterListParameters(params ParameterSyntax[] items);

+        public StructDeclarationSyntax Update(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers,
+                                              SyntaxToken keyword, SyntaxToken identifier,
+                                              TypeParameterListSyntax? typeParameterList,
+                                              ParameterListSyntax? parameterList, BaseListSyntax? baseList,
+                                              SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                              SyntaxToken openBraceToken, SyntaxList<MemberDeclarationSyntax> members,
+                                              SyntaxToken closeBraceToken, SyntaxToken semicolonToken);
    }

    public static partial class SyntaxFactory
    {
+       public static ClassDeclarationSyntax ClassDeclaration(SyntaxList<AttributeListSyntax> attributeLists,
+                                                             SyntaxTokenList modifiers, SyntaxToken identifier,
+                                                             TypeParameterListSyntax? typeParameterList,
+                                                             ParameterListSyntax? parameterList,
+                                                             BaseListSyntax? baseList,
+                                                             SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                                             SyntaxList<MemberDeclarationSyntax> members);

+       public static ClassDeclarationSyntax ClassDeclaration(SyntaxList<AttributeListSyntax> attributeLists,
+                                                             SyntaxTokenList modifiers, SyntaxToken keyword,
+                                                             SyntaxToken identifier,
+                                                             TypeParameterListSyntax? typeParameterList,
+                                                             ParameterListSyntax? parameterList,
+                                                             BaseListSyntax? baseList,
+                                                             SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                                             SyntaxToken openBraceToken,
+                                                             SyntaxList<MemberDeclarationSyntax> members,
+                                                             SyntaxToken closeBraceToken, SyntaxToken semicolonToken);

+       public static StructDeclarationSyntax StructDeclaration(SyntaxList<AttributeListSyntax> attributeLists,
+                                                               SyntaxTokenList modifiers, SyntaxToken identifier,
+                                                               TypeParameterListSyntax? typeParameterList,
+                                                               ParameterListSyntax? parameterList,
+                                                               BaseListSyntax? baseList, 
+                                                               SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                                               SyntaxList<MemberDeclarationSyntax> members);

+       public static StructDeclarationSyntax StructDeclaration(SyntaxList<AttributeListSyntax> attributeLists,
+                                                               SyntaxTokenList modifiers, SyntaxToken keyword,
+                                                               SyntaxToken identifier,
+                                                               TypeParameterListSyntax? typeParameterList,
+                                                               ParameterListSyntax? parameterList,
+                                                               BaseListSyntax? baseList,
+                                                               SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                                               SyntaxToken openBraceToken,
+                                                               SyntaxList<MemberDeclarationSyntax> members,
+                                                               SyntaxToken closeBraceToken,
+                                                               SyntaxToken semicolonToken);
     }
}
@AlekseyTs AlekseyTs added Concept-API This issue involves adding, removing, clarification, or modification of an API. Area-Compilers Feature Request api-ready-for-review API is ready for review, it is NOT ready for implementation Feature - Primary Constructors labels Feb 16, 2023
@AlekseyTs AlekseyTs self-assigned this Feb 16, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Feb 16, 2023
@333fred
Copy link
Member

333fred commented Feb 16, 2023

API Review

  • We may want to move ParameterList up to BaseTypeDeclarationSyntax for error recovery purposes at some point
    • We will confirm that that won't a binary break. Otherwise, this is approved.

@333fred 333fred added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Feb 16, 2023
@AlekseyTs
Copy link
Contributor Author

Based on general feedback during API review I made the following changes in #66940:

namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
     public abstract partial class TypeDeclarationSyntax
     {
-        public ParameterListSyntax? ParameterList { get; }
+        public abstract ParameterListSyntax? ParameterList { get; }

+        public TypeDeclarationSyntax WithParameterList(ParameterListSyntax? parameterList);

+        public TypeDeclarationSyntax AddParameterListParameters(params ParameterSyntax[] items);
     }

     public sealed partial class ClassDeclarationSyntax : TypeDeclarationSyntax
     {
-        public new ParameterListSyntax? ParameterList { get; }
+        public override ParameterListSyntax? ParameterList { get; }
     }

     public sealed partial class RecordDeclarationSyntax : TypeDeclarationSyntax
     {
-        public ParameterListSyntax? ParameterList { get; }
+        public override ParameterListSyntax? ParameterList { get; }
     }

    public sealed partial class StructDeclarationSyntax : TypeDeclarationSyntax
    {
-        public new ParameterListSyntax? ParameterList { get; }
+        public override ParameterListSyntax? ParameterList { get; }
    }

     public sealed partial class InterfaceDeclarationSyntax
     {
+        public override ParameterListSyntax? ParameterList { get; }

+        public InterfaceDeclarationSyntax WithParameterList(ParameterListSyntax? parameterList);

+        public InterfaceDeclarationSyntax AddParameterListParameters(params ParameterSyntax[] items);

+        public InterfaceDeclarationSyntax Update(SyntaxList<AttributeListSyntax> attributeLists,
+                                                 SyntaxTokenList modifiers, SyntaxToken keyword,
+                                                 SyntaxToken identifier, TypeParameterListSyntax? typeParameterList,
+                                                 ParameterListSyntax? parameterList, BaseListSyntax? baseList,
+                                                 SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                                 SyntaxToken openBraceToken,
+                                                 SyntaxList<MemberDeclarationSyntax> members,
+                                                 SyntaxToken closeBraceToken, SyntaxToken semicolonToken);
     }

    public static partial class SyntaxFactory
    {
+        public static InterfaceDeclarationSyntax InterfaceDeclaration(SyntaxList<AttributeListSyntax> attributeLists,
+                                                                      SyntaxTokenList modifiers, SyntaxToken keyword,
+                                                                      SyntaxToken identifier,
+                                                                      TypeParameterListSyntax? typeParameterList,
+                                                                      ParameterListSyntax? parameterList,
+                                                                      BaseListSyntax? baseList,
+                                                                      SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
+                                                                      SyntaxToken openBraceToken,
+                                                                      SyntaxList<MemberDeclarationSyntax> members,'
+                                                                      SyntaxToken closeBraceToken,
+                                                                      SyntaxToken semicolonToken)
     }
}

@AlekseyTs AlekseyTs added the api-ready-for-review API is ready for review, it is NOT ready for implementation label Feb 21, 2023
@CyrusNajmabadi
Copy link
Member

Thanks very much, that is appreciated :)

@333fred
Copy link
Member

333fred commented Feb 22, 2023

API Review

Updated definitions are approved.

@333fred 333fred added api-approved API was approved in API review, it can be implemented and removed api-approved API was approved in API review, it can be implemented api-ready-for-review API is ready for review, it is NOT ready for implementation labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature - Primary Constructors Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants