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

Added #pragma warning disable CS1591 to supress warnings in the source generated code #8940

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
67 changes: 58 additions & 9 deletions src/Orleans.CodeGenerator/CodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Orleans.CodeGenerator.SyntaxGeneration;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Orleans.CodeGenerator.Diagnostics;
using Orleans.CodeGenerator.Hashing;
using System.Text;
using Orleans.CodeGenerator.SyntaxGeneration;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using static Orleans.CodeGenerator.SyntaxGeneration.SymbolExtensions;
using Orleans.CodeGenerator.Diagnostics;

namespace Orleans.CodeGenerator
{
Expand All @@ -32,6 +32,7 @@ public class CodeGenerator
private readonly Dictionary<string, List<MemberDeclarationSyntax>> _namespacedMembers = new();
private readonly Dictionary<InvokableMethodId, InvokableMethodDescription> _invokableMethodDescriptions = new();
private readonly HashSet<INamedTypeSymbol> _visitedInterfaces = new(SymbolEqualityComparer.Default);
private readonly List<string> DisabledWarnings = new() { "CS1591" };

public CodeGenerator(Compilation compilation, CodeGeneratorOptions options)
{
Expand Down Expand Up @@ -166,7 +167,7 @@ public CompilationUnitSyntax GenerateCode(CancellationToken cancellationToken)
{
(_, GenerateFieldIds.PublicProperties) => GenerateFieldIds.PublicProperties,
(GenerateFieldIds.PublicProperties, _) => GenerateFieldIds.PublicProperties,
_ => GenerateFieldIds.None
_ => GenerateFieldIds.None
};
var fieldIdAssignmentHelper = new FieldIdAssignmentHelper(symbol, constructorParameters, implicitMemberSelectionStrategy, LibraryTypes);
if (!fieldIdAssignmentHelper.IsValidForSerialization)
Expand Down Expand Up @@ -315,6 +316,30 @@ bool ShouldIncludePrimaryConstructorParameters(INamedTypeSymbol t)
var assemblyAttributes = ApplicationPartAttributeGenerator.GenerateSyntax(LibraryTypes, MetadataModel);
assemblyAttributes.Add(metadataAttribute);

if (assemblyAttributes.Count > 0)
{
assemblyAttributes[0] = assemblyAttributes[0]
.WithLeadingTrivia(
SyntaxFactory.TriviaList(
new List<SyntaxTrivia>
{
Trivia(
PragmaWarningDirectiveTrivia(
Token(SyntaxKind.DisableKeyword),
SeparatedList(DisabledWarnings.Select(str =>
{
var syntaxToken = SyntaxFactory.Literal(
SyntaxFactory.TriviaList(),
str,
str,
SyntaxFactory.TriviaList());

return (ExpressionSyntax)SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, syntaxToken);
})),
isActive: true)),
}));
}

var usings = List(new[] { UsingDirective(ParseName("global::Orleans.Serialization.Codecs")), UsingDirective(ParseName("global::Orleans.Serialization.GeneratedCodeHelpers")) });
var namespaces = new List<MemberDeclarationSyntax>(_namespacedMembers.Count);
foreach (var pair in _namespacedMembers)
Expand All @@ -325,6 +350,30 @@ bool ShouldIncludePrimaryConstructorParameters(INamedTypeSymbol t)
namespaces.Add(NamespaceDeclaration(ParseName(ns)).WithMembers(List(member)).WithUsings(usings));
}

if (namespaces.Count > 0)
{
namespaces[0] = namespaces[0]
.WithTrailingTrivia(
SyntaxFactory.TriviaList(
new List<SyntaxTrivia>
{
Trivia(
PragmaWarningDirectiveTrivia(
Token(SyntaxKind.RestoreKeyword),
SeparatedList(DisabledWarnings.Select(str =>
{
var syntaxToken = SyntaxFactory.Literal(
SyntaxFactory.TriviaList(),
str,
str,
SyntaxFactory.TriviaList());

return (ExpressionSyntax)SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, syntaxToken);
})),
isActive: true)),
}));
}

return CompilationUnit()
.WithAttributeLists(List(assemblyAttributes))
.WithMembers(List(namespaces));
Expand Down
6 changes: 3 additions & 3 deletions src/Orleans.CodeGenerator/Orleans.CodeGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>

<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
Expand Down
7 changes: 4 additions & 3 deletions src/Orleans.CodeGenerator/OrleansSourceGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Orleans.CodeGenerator.Diagnostics;
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using Orleans.CodeGenerator.Diagnostics;

#pragma warning disable RS1035 // Do not use APIs banned for analyzers
namespace Orleans.CodeGenerator
Expand Down
Loading