Skip to content

Commit

Permalink
Snap to Roslyn 4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer committed Jul 20, 2023
1 parent 131ada7 commit efda71d
Show file tree
Hide file tree
Showing 374 changed files with 615 additions and 1,649 deletions.
5 changes: 0 additions & 5 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
<NoWarn Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0'">$(NoWarn);CA1062</NoWarn>
</PropertyGroup>

<PropertyGroup>
<!-- Ignore RS1024: Compare symbols correctly (https://github.com/dotnet/extensions/issues/4127) -->
<NoWarn>$(NoWarn);RS1024</NoWarn>
</PropertyGroup>

<!-- Ignore SuppressTfmSupportBuildWarnings warning for .NET Core 3.1 due to System.Diagnostic.DiagnosticSource 7.0.0 version -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions eng/MSBuild/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

<ItemGroup Condition="'$(SkipAnalyzers)' != 'true'">
<!-- We can't use $(RepoRoot) here as slngen tool is failing to resolve it... -->
<ProjectReference Condition="'$(SkipExtraAnalyzers)' != 'true'" Include="$(MSBuildThisFileDirectory)\..\..\src\Analyzers\Microsoft.Extensions.ExtraAnalyzers\Microsoft.Extensions.ExtraAnalyzers.Roslyn4.0\Microsoft.Extensions.ExtraAnalyzers.Roslyn4.0.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<ProjectReference Condition="'$(SkipLocalAnalyzers)' != 'true'" Include="$(MSBuildThisFileDirectory)\..\..\src\Analyzers\Microsoft.Extensions.LocalAnalyzers\Microsoft.Extensions.LocalAnalyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<ProjectReference Condition="'$(SkipExtraAnalyzers)' != 'true'" Include="$(MSBuildThisFileDirectory)\..\..\src\Analyzers\Microsoft.Analyzers.Extra\Microsoft.Analyzers.Extra.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<ProjectReference Condition="'$(SkipLocalAnalyzers)' != 'true'" Include="$(MSBuildThisFileDirectory)\..\..\src\Analyzers\Microsoft.Analyzers.Local\Microsoft.Analyzers.Local.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion eng/MSBuild/Analyzers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PropertyGroup>
<_MultiTargetRoslynComponentTargetsTemplate>$(MSBuildThisFileDirectory)MultiTargetRoslynComponent.targets.template</_MultiTargetRoslynComponentTargetsTemplate>
<MultiTargetRoslynComponentTargetsFileIntermediatePath>$(IntermediateOutputPath)MultiTargetRoslynComponent.targets</MultiTargetRoslynComponentTargetsFileIntermediatePath>
<IncludeMultiTargetRoslynComponentTargets Condition="'$(IncludeMultiTargetRoslynComponentTargets)' == ''">true</IncludeMultiTargetRoslynComponentTargets>
<IncludeMultiTargetRoslynComponentTargets Condition="'$(IncludeMultiTargetRoslynComponentTargets)' == ''">false</IncludeMultiTargetRoslynComponentTargets>
</PropertyGroup>

<!-- In packages that contain Analyzers, include a .targets file that will select the correct analyzer. -->
Expand Down
8 changes: 4 additions & 4 deletions eng/MSBuild/Generators.props
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project>
<ItemGroup Condition="'$(UseLoggingGenerator)' == 'true' and '$(BuildingSlnForDocs)' != 'true'">
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.Logging\Roslyn4.0\Microsoft.Gen.Logging.Roslyn4.0.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.Logging\Microsoft.Gen.Logging.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<ItemGroup Condition="'$(UseEnumStringsGenerator)' == 'true' and '$(BuildingSlnForDocs)' != 'true'">
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.EnumStrings\Roslyn4.0\Microsoft.Gen.EnumStrings.Roslyn4.0.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.EnumStrings\Microsoft.Gen.EnumStrings.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<ItemGroup Condition="'$(UseMeteringGenerator)' == 'true' and '$(BuildingSlnForDocs)' != 'true'">
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.Metering\Roslyn4.0\Microsoft.Gen.Metering.Roslyn4.0.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.Metering\Microsoft.Gen.Metering.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<ItemGroup Condition="'$(UseContextualOptionsGenerator)' == 'true' and '$(BuildingSlnForDocs)' != 'true'">
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.ContextualOptions\Roslyn4.0\Microsoft.Gen.ContextualOptions.Roslyn4.0.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\src\Generators\Microsoft.Gen.ContextualOptions\Microsoft.Gen.ContextualOptions.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Private="false" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions eng/packages/General.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageVersion Include="Microsoft.Bcl.TimeProvider" Version="$(MicrosoftBclTimeProviderVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.4.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="$(MicrosoftExtensionsConfigurationAbstractionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="$(MicrosoftExtensionsConfigurationAbstractionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="$(MicrosoftExtensionsConfigurationAbstractionsVersion)" />
Expand Down
4 changes: 2 additions & 2 deletions scripts/MergeAnalyzerMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ $AspNetCorePath = Join-Path -Path $DotNetPath -ChildPath packs\Microsoft.AspNetC

Write-Output "Processing analyzer assemblies"

& $Command $Diags analyzer merge $Artifacts\bin\Microsoft.Extensions.ExtraAnalyzers.Roslyn4.0\Debug\netstandard2.0\Microsoft.Extensions.ExtraAnalyzers.Roslyn4.0.dll
& $Command $Diags analyzer merge $Artifacts\bin\Microsoft.Extensions.LocalAnalyzers\Debug\netstandard2.0\Microsoft.Extensions.LocalAnalyzers.dll
& $Command $Diags analyzer merge $Artifacts\bin\Microsoft.Analyzers.Extra\Debug\netstandard2.0\Microsoft.Analyzers.Extra.dll
& $Command $Diags analyzer merge $Artifacts\bin\Microsoft.Analyzers.Local\Debug\netstandard2.0\Microsoft.Analyzers.Local.dll
& $Command $Diags analyzer merge $PackagePath\stylecop.analyzers.unstable\1.2.0.435\analyzers\dotnet\cs\StyleCop.Analyzers.dll
& $Command $Diags analyzer merge $PackagePath\sonaranalyzer.csharp\8.52.0.60960\analyzers\SonarAnalyzer.CSharp.dll
& $Command $Diags analyzer merge $PackagePath\microsoft.visualstudio.threading.analyzers\17.5.22\analyzers\cs\Microsoft.VisualStudio.Threading.Analyzers.dll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private static bool SymbolInArguments(IInvocationOperation invocation, ILocalSym
{
if (argument
.Value
.Children
.ChildOperations
.Any(operation => ReferencesSymbol(operation, symbol)))
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FixDetails(
if (MessageParamIndex >= 0)
{
var op = invocationOp.Arguments[MessageParamIndex];
var children = op.Children.ToArray();
var children = op.ChildOperations.ToArray();
if (children.Length == 1)
{
if (children[0].ConstantValue.HasValue)
Expand All @@ -58,16 +58,16 @@ public FixDetails(

var sb = new StringBuilder();
int argCount = 0;
foreach (var o in children[0].Children)
foreach (var o in children[0].ChildOperations)
{
switch (o)
{
case IInterpolatedStringTextOperation stringOp:
_ = sb.Append(stringOp.Children.First().ConstantValue.Value as string);
_ = sb.Append(stringOp.ChildOperations.First().ConstantValue.Value as string);
break;

case IInterpolationOperation intOp:
var operation = intOp.Children.First();
var operation = intOp.ChildOperations.First();
var argName = operation.Syntax.GetLastToken().Text;

if (argName.Length == 0)
Expand All @@ -89,7 +89,7 @@ public FixDetails(

_ = sb.Append("{" + argName + "}");
messageArgs.Add(argName);
interpolationArgs.Add(intOp.Children.First());
interpolationArgs.Add(intOp.ChildOperations.First());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal enum LogLevel
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(DiagDescriptors.LegacyLogging.Id);

/// <inheritdoc/>
public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;
public override FixAllProvider? GetFixAllProvider() => null;

/// <inheritdoc/>
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
Expand Down Expand Up @@ -305,11 +305,7 @@ static partial class {details.TargetClassName}

private static string GetNamespace(ClassDeclarationSyntax cl)
{
#if ROSLYN_4_0_OR_GREATER
var ns = cl.Parent as BaseNamespaceDeclarationSyntax;
#else
var ns = cl.Parent as NamespaceDeclarationSyntax;
#endif
if (ns == null)
{
if (cl.Parent is not CompilationUnitSyntax)
Expand All @@ -324,12 +320,7 @@ private static string GetNamespace(ClassDeclarationSyntax cl)
var nspace = ns.Name.ToString();
while (true)
{
#if ROSLYN_4_0_OR_GREATER
ns = ns.Parent as BaseNamespaceDeclarationSyntax;
#else
ns = ns.Parent as NamespaceDeclarationSyntax;
#endif

if (ns == null)
{
break;
Expand Down Expand Up @@ -369,15 +360,15 @@ private static IReadOnlyList<SyntaxNode> MakeParameterList(

if (details.ExceptionParamIndex >= 0)
{
parameters.Add(gen.ParameterDeclaration("exception", gen.TypeExpression(invocationOp.Arguments[details.ExceptionParamIndex].Value.Type)));
parameters.Add(gen.ParameterDeclaration("exception", gen.TypeExpression(invocationOp.Arguments[details.ExceptionParamIndex].Value.Type!)));
}

var index = 0;
if (details.InterpolationArgs != null)
{
foreach (var o in details.InterpolationArgs)
{
parameters.Add(gen.ParameterDeclaration(details.MessageArgs[index++], gen.TypeExpression(o.Type)));
parameters.Add(gen.ParameterDeclaration(details.MessageArgs[index++], gen.TypeExpression(o.Type!)));
}
}

Expand All @@ -387,7 +378,7 @@ private static IReadOnlyList<SyntaxNode> MakeParameterList(
var arrayCreation = (IArrayCreationOperation)paramsArg.Value;
foreach (var e in arrayCreation.Initializer!.ElementValues)
{
var type = e.SemanticModel?.GetTypeInfo(e.Syntax).Type;
var type = e.SemanticModel?.GetTypeInfo(e.Syntax).Type!;

string name;
if (index < details.MessageArgs.Count)
Expand Down Expand Up @@ -578,7 +569,7 @@ private async Task<Solution> InsertLoggingMethodSignatureAsync(
var attrArgs = new[]
{
gen.LiteralExpression(CalcEventId(comp, targetClass, cancellationToken)),
gen.MemberAccessExpression(gen.TypeExpression(comp.GetTypeByMetadataName("Microsoft.Extensions.Logging.LogLevel")), details.Level),
gen.MemberAccessExpression(gen.TypeExpression(comp.GetTypeByMetadataName("Microsoft.Extensions.Logging.LogLevel")!), details.Level),
gen.LiteralExpression(details.Message),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Microsoft.Extesions.ExtraAnalyzers</RootNamespace>
<RootNamespace>Microsoft.Extensions.ExtraAnalyzers</RootNamespace>
<Description>Code analyzers and fixers</Description>
<Workstream>Fundamentals</Workstream>
<Category>Static Analysis</Category>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -15,11 +12,11 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="../Common/**/*.cs" />
<Compile Update="Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\Common\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" CustomToolNamespace="Microsoft.Extensions.ExtraAnalyzers" />
<EmbeddedResource Update="Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
</ItemGroup>

<ItemGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

<PropertyGroup>
<SkipLocalAnalyzers>true</SkipLocalAnalyzers>
<AnalyzerLanguage>cs</AnalyzerLanguage>
<AnalyzerRoslynVersion>4.0</AnalyzerRoslynVersion>
<DefineConstants>$(DefineConstants);ROSLYN_4_0_OR_GREATER</DefineConstants>
<AnalyzerLanguage>cs</AnalyzerLanguage>
</PropertyGroup>

<PropertyGroup>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if ROSLYN_4_0_OR_GREATER

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -57,50 +55,3 @@ private static void HandleAnnotatedTypes(Compilation compilation, IEnumerable<Sy
}
}
}

#else

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Gen.Shared;

namespace Microsoft.Gen.AutoClient;

[Generator]
[ExcludeFromCodeCoverage]
public class AutoClientGenerator : ISourceGenerator
{
public void Initialize(GeneratorInitializationContext context)
{
context.RegisterForSyntaxNotifications(TypeDeclarationSyntaxReceiver.Create);
}

public void Execute(GeneratorExecutionContext context)
{
var receiver = context.SyntaxReceiver as TypeDeclarationSyntaxReceiver;
if (receiver == null || receiver.TypeDeclarations.Count == 0)
{
// nothing to do yet
return;
}

var parser = new Parser(context.Compilation, context.ReportDiagnostic, context.CancellationToken);

var restApiClasses = parser.GetRestApiClasses(receiver.TypeDeclarations.OfType<InterfaceDeclarationSyntax>());

if (restApiClasses.Count > 0)
{
var emitter = new Emitter();

var restApiCode = emitter.EmitRestApis(restApiClasses, context.CancellationToken);
context.AddSource($"AutoClients.g.cs", SourceText.From(restApiCode, Encoding.UTF8));
}
}
}

#endif
Loading

0 comments on commit efda71d

Please sign in to comment.