Skip to content

Commit

Permalink
make unbound ctor protected
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvreony committed Jun 16, 2024
1 parent 7e2b9b4 commit 9e72cd9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@ private static IEnumerable<TypeParameterSyntax> GetTypeParameterSeparatedSyntaxL
}
}

private MemberDeclarationSyntax GetConstructorMethod(INamedTypeSymbol namedTypeSymbol,
private MemberDeclarationSyntax GetConstructorMethod(
INamedTypeSymbol namedTypeSymbol,
bool isDerivedType,
bool makeClassesPublic, TypeParameterListSyntax typeParameterList)
bool makeClassesPublic,
TypeParameterListSyntax typeParameterList)
{
var className = GetClassNameIdentifier(namedTypeSymbol);
var body = GetConstructorBody(isDerivedType);
Expand Down Expand Up @@ -306,16 +308,20 @@ private MemberDeclarationSyntax GetConstructorMethod(INamedTypeSymbol namedTypeS
("viewExpression", "expression representing the control on the view to bind to.")
};

var modifiers = GetConstructorModifiers(makeClassesPublic);

var declaration = SyntaxFactory.ConstructorDeclaration(className)
.WithInitializer(initializer)
.WithParameterList(parameters)
.AddModifiers(SyntaxFactory.Token(makeClassesPublic ? SyntaxKind.PublicKeyword : SyntaxKind.InternalKeyword))
.AddModifiers(modifiers)
.AddBodyStatements(body.ToArray())
.WithLeadingTrivia(XmlSyntaxFactory.GenerateSummaryComment(summaryText, summaryParameters));

return declaration;
}

protected abstract SyntaxToken[] GetConstructorModifiers(bool makeClassesPublic);

Check warning on line 323 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/AbstractControlBindingModelClassGenerator.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'AbstractControlBindingModelClassGenerator.GetConstructorModifiers(bool)'

Check warning on line 323 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/AbstractControlBindingModelClassGenerator.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Missing XML comment for publicly visible type or member 'AbstractControlBindingModelClassGenerator.GetConstructorModifiers(bool)'

Check warning on line 323 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/AbstractControlBindingModelClassGenerator.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'AbstractControlBindingModelClassGenerator.GetConstructorModifiers(bool)'

private TypeParameterListSyntax GetTypeParameterListSyntax(INamedTypeSymbol namedTypeSymbol)
{
var sep = GetTypeParameterSyntaxes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ protected override SeparatedSyntaxList<TypeParameterSyntax> GetTypeParameterSynt
return sep;
}

/// <inheritdoc />
protected override SyntaxToken[] GetConstructorModifiers(bool makeClassesPublic) =>
[SyntaxFactory.Token(makeClassesPublic ? SyntaxKind.PublicKeyword : SyntaxKind.InternalKeyword)];

/// <inheritdoc />
protected override ClassDeclarationSyntax ApplyBaseClassDeclarationSyntax(
INamedTypeSymbol namedTypeSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ protected override SeparatedSyntaxList<TypeParameterSyntax> GetTypeParameterSynt
return sep;
}

/// <inheritdoc />
protected override SyntaxToken[] GetConstructorModifiers(bool _) =>
[SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)];

/// <inheritdoc />
protected override ClassDeclarationSyntax ApplyBaseClassDeclarationSyntax(
INamedTypeSymbol namedTypeSymbol,
Expand Down

0 comments on commit 9e72cd9

Please sign in to comment.