提交 7a3f8b1b 编写于 作者: G Gen Lu

Remove src/Diagnostics/CodeAnalysis from dotnet/roslyn repo

Everything under dotnet/roslyn/src/Diagnostics/CodeAnalysis is moved to dotnet/roslyn-analyzers/src/CodeAnalysis.
上级 af2cb4b5
......@@ -235,18 +235,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Diagnostics", "Diagnostics"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetadataVisualizer", "src\Tools\Source\MetadataVisualizer\MetadataVisualizer.csproj", "{4C7847DB-C412-4D5E-B573-F12FA0A76127}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeAnalysis", "CodeAnalysis", "{2344BE45-7F6B-4A4E-9418-567FA2D9CA8C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeAnalysisDiagnosticAnalyzers", "src\Diagnostics\CodeAnalysis\Core\CodeAnalysisDiagnosticAnalyzers.csproj", "{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpCodeAnalysisDiagnosticAnalyzers", "src\Diagnostics\CodeAnalysis\CSharp\CSharpCodeAnalysisDiagnosticAnalyzers.csproj", "{921B412A-5551-4853-82B4-46AD5A05A03E}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "BasicCodeAnalysisDiagnosticAnalyzers", "src\Diagnostics\CodeAnalysis\VisualBasic\BasicCodeAnalysisDiagnosticAnalyzers.vbproj", "{B1A6A74B-E484-48FB-8745-7A30A06DB631}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeAnalysisDiagnosticAnalyzersTest", "src\Diagnostics\CodeAnalysis\Test\CodeAnalysisDiagnosticAnalyzersTest.csproj", "{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeAnalysisDiagnosticsSetup", "src\Diagnostics\CodeAnalysis\Setup\CodeAnalysisDiagnosticsSetup.csproj", "{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "System.Runtime.Analyzers", "System.Runtime.Analyzers", "{F24D89AC-5A93-4F21-A329-DCEFD41EC0FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemRuntimeAnalyzers", "src\Diagnostics\FxCop\System.Runtime.Analyzers\Core\SystemRuntimeAnalyzers.csproj", "{BAA0FEE4-93C8-46F0-BB36-53A6053776C8}"
......@@ -382,8 +370,8 @@ Global
src\ExpressionEvaluator\CSharp\Source\ResultProvider\CSharpResultProvider.projitems*{bf9dac1e-3a5e-4dc3-bb44-9a64e0d4e9d3}*SharedItemsImports = 4
src\Compilers\Core\SharedCollections\SharedCollections.projitems*{afde6bea-5038-4a4a-a88e-dbd2e4088eed}*SharedItemsImports = 4
src\ExpressionEvaluator\Core\Source\ResultProvider\ResultProvider.projitems*{fa0e905d-ec46-466d-b7b2-3b5557f9428c}*SharedItemsImports = 4
src\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
src\Compilers\Core\SharedCollections\SharedCollections.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
src\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
src\Compilers\CSharp\CSharpAnalyzerDriver\CSharpAnalyzerDriver.projitems*{3973b09a-4fbf-44a5-8359-3d22ceb71f71}*SharedItemsImports = 4
src\ExpressionEvaluator\Core\Source\ResultProvider\ResultProvider.projitems*{bedc5a4a-809e-4017-9cfd-6c8d4e1847f0}*SharedItemsImports = 4
src\Compilers\CSharp\CSharpAnalyzerDriver\CSharpAnalyzerDriver.projitems*{b501a547-c911-4a05-ac6e-274a50dff30e}*SharedItemsImports = 4
......@@ -2297,96 +2285,6 @@ Global
{4C7847DB-C412-4D5E-B573-F12FA0A76127}.Release|x64.Build.0 = Release|Any CPU
{4C7847DB-C412-4D5E-B573-F12FA0A76127}.Release|x86.ActiveCfg = Release|Any CPU
{4C7847DB-C412-4D5E-B573-F12FA0A76127}.Release|x86.Build.0 = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|ARM.Build.0 = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|x64.ActiveCfg = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|x64.Build.0 = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|x86.ActiveCfg = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Debug|x86.Build.0 = Debug|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|ARM.ActiveCfg = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|ARM.Build.0 = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|x64.ActiveCfg = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|x64.Build.0 = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|x86.ActiveCfg = Release|Any CPU
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}.Release|x86.Build.0 = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|ARM.ActiveCfg = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|ARM.Build.0 = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|x64.ActiveCfg = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|x64.Build.0 = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|x86.ActiveCfg = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Debug|x86.Build.0 = Debug|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|ARM.ActiveCfg = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|ARM.Build.0 = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|x64.ActiveCfg = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|x64.Build.0 = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|x86.ActiveCfg = Release|Any CPU
{921B412A-5551-4853-82B4-46AD5A05A03E}.Release|x86.Build.0 = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|ARM.Build.0 = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|x64.Build.0 = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|x86.ActiveCfg = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Debug|x86.Build.0 = Debug|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|ARM.ActiveCfg = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|ARM.Build.0 = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|x64.ActiveCfg = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|x64.Build.0 = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|x86.ActiveCfg = Release|Any CPU
{B1A6A74B-E484-48FB-8745-7A30A06DB631}.Release|x86.Build.0 = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|ARM.ActiveCfg = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|ARM.Build.0 = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|x64.ActiveCfg = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|x64.Build.0 = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|x86.ActiveCfg = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Debug|x86.Build.0 = Debug|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|ARM.ActiveCfg = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|ARM.Build.0 = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|x64.ActiveCfg = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|x64.Build.0 = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|x86.ActiveCfg = Release|Any CPU
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}.Release|x86.Build.0 = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|ARM.ActiveCfg = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|ARM.Build.0 = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|x64.ActiveCfg = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|x64.Build.0 = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|x86.ActiveCfg = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Debug|x86.Build.0 = Debug|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|ARM.ActiveCfg = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|ARM.Build.0 = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|x64.ActiveCfg = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|x64.Build.0 = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|x86.ActiveCfg = Release|Any CPU
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}.Release|x86.Build.0 = Release|Any CPU
{BAA0FEE4-93C8-46F0-BB36-53A6053776C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAA0FEE4-93C8-46F0-BB36-53A6053776C8}.Debug|ARM.ActiveCfg = Debug|Any CPU
{BAA0FEE4-93C8-46F0-BB36-53A6053776C8}.Debug|ARM.Build.0 = Debug|Any CPU
......@@ -3247,12 +3145,6 @@ Global
{5002636A-FE8D-40BF-8818-AB513A2194FA} = {998CAFE8-06E4-4683-A151-0F6AA4BFF6C6}
{ABDBAC1E-350E-4DC3-BB45-3504404545EE} = {998CAFE8-06E4-4683-A151-0F6AA4BFF6C6}
{4C7847DB-C412-4D5E-B573-F12FA0A76127} = {64BDF58B-41BA-A19E-0D34-B5FA598403B6}
{2344BE45-7F6B-4A4E-9418-567FA2D9CA8C} = {5F5DD61A-746D-40AE-A89C-EF82B39C036E}
{D8762A0A-3832-47BE-BCF6-8B1060BE6B28} = {2344BE45-7F6B-4A4E-9418-567FA2D9CA8C}
{921B412A-5551-4853-82B4-46AD5A05A03E} = {2344BE45-7F6B-4A4E-9418-567FA2D9CA8C}
{B1A6A74B-E484-48FB-8745-7A30A06DB631} = {2344BE45-7F6B-4A4E-9418-567FA2D9CA8C}
{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8} = {2344BE45-7F6B-4A4E-9418-567FA2D9CA8C}
{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF} = {2344BE45-7F6B-4A4E-9418-567FA2D9CA8C}
{F24D89AC-5A93-4F21-A329-DCEFD41EC0FE} = {24E8CBFA-38D2-486F-B772-C10AB2DC7F01}
{BAA0FEE4-93C8-46F0-BB36-53A6053776C8} = {F24D89AC-5A93-4F21-A329-DCEFD41EC0FE}
{A36451EC-1127-40CE-B841-47F393D24624} = {F24D89AC-5A93-4F21-A329-DCEFD41EC0FE}
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="Settings">
<Import Project="..\..\..\..\build\Targets\VSL.Settings.targets" />
</ImportGroup>
<PropertyGroup>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{921B412A-5551-4853-82B4-46AD5A05A03E}</ProjectGuid>
<OutputType>Library</OutputType>
<AnalyzerProject>true</AnalyzerProject>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Analyzers</RootNamespace>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.Analyzers</AssemblyName>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .NET Framework is automatically included -->
<ProjectReference Include="..\..\..\Compilers\Core\Portable\CodeAnalysis.csproj">
<Project>{1ee8cad3-55f9-4d91-96b2-084641da9a6c}</Project>
<Name>CodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj">
<Project>{b501a547-c911-4a05-ac6e-274a50dff30e}</Project>
<Name>CSharpCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Workspaces.csproj">
<Project>{5f8d2414-064a-4b3a-9b42-8e2a04246be5}</Project>
<Name>Workspaces</Name>
</ProjectReference>
<ProjectReference Include="..\Core\CodeAnalysisDiagnosticAnalyzers.csproj">
<Project>{d8762a0a-3832-47be-bcf6-8b1060be6b28}</Project>
<Name>CodeAnalysisDiagnosticAnalyzers</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Collections.Immutable">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\System.Collections.Immutable.$(SystemCollectionsImmutableVersion)\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Composition.AttributedModel">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\Microsoft.Composition.$(MicrosoftCompositionVersion)\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
</Reference>
<Reference Include="System.Composition.Convention">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\Microsoft.Composition.$(MicrosoftCompositionVersion)\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll</HintPath>
</Reference>
<Reference Include="System.Composition.Hosting">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\Microsoft.Composition.$(MicrosoftCompositionVersion)\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll</HintPath>
</Reference>
<Reference Include="System.Composition.Runtime">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\Microsoft.Composition.$(MicrosoftCompositionVersion)\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Composition.TypedParts">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\Microsoft.Composition.$(MicrosoftCompositionVersion)\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Compile Include="FixAnalyzers\CSharpFixerWithFixAllAnalyzer.cs" />
<Compile Include="MetaAnalyzers\CSharpDiagnosticDescriptorCreationAnalyzer.cs" />
<Compile Include="MetaAnalyzers\CSharpRegisterActionAnalyzer.cs" />
<Compile Include="MetaAnalyzers\CSharpDiagnosticAnalyzerFieldsAnalyzer.cs" />
<Compile Include="MetaAnalyzers\CSharpReportDiagnosticAnalyzer.cs" />
<Compile Include="MetaAnalyzers\Fixers\CSharpApplyDiagnosticAnalyzerAttributeFix.cs" />
</ItemGroup>
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
</Project>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.Analyzers.FixAnalyzers;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers
{
/// <summary>
/// A <see cref="CodeFixProvider"/> that intends to support fix all occurrences must classify the registered code actions into equivalence classes by assigning it an explicit, non-null equivalence key which is unique across all registered code actions by this fixer.
/// This enables the <see cref="FixAllProvider"/> to fix all diagnostics in the required scope by applying code actions from this fixer that are in the equivalence class of the trigger code action.
/// This analyzer catches violations of this requirement in the code actions registered by a fixer that supports <see cref="FixAllProvider"/>.
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class CSharpFixerWithFixAllAnalyzer : FixerWithFixAllAnalyzer<SyntaxKind>
{
protected override CompilationAnalyzer GetCompilationAnalyzer(INamedTypeSymbol codeFixProviderSymbol, IMethodSymbol getFixAllProvider, INamedTypeSymbol codeActionSymbol, ImmutableHashSet<IMethodSymbol> createMethods, IPropertySymbol equivalenceKeyProperty)
{
return new CSharpCompilationAnalyzer(codeFixProviderSymbol, getFixAllProvider, codeActionSymbol, createMethods, equivalenceKeyProperty);
}
private sealed class CSharpCompilationAnalyzer : CompilationAnalyzer
{
public CSharpCompilationAnalyzer(
INamedTypeSymbol codeFixProviderSymbol,
IMethodSymbol getFixAllProvider,
INamedTypeSymbol codeActionSymbol,
ImmutableHashSet<IMethodSymbol> createMethods,
IPropertySymbol equivalenceKeyProperty)
: base(codeFixProviderSymbol, getFixAllProvider, codeActionSymbol, createMethods, equivalenceKeyProperty)
{
}
protected override SyntaxKind GetInvocationKind => SyntaxKind.InvocationExpression;
protected override SyntaxKind GetObjectCreationKind => SyntaxKind.ObjectCreationExpression;
protected override bool HasNonNullArgumentForParameter(SyntaxNode node, IParameterSymbol parameter, int indexOfParameter, SemanticModel model, CancellationToken cancellationToken)
{
var invocation = (InvocationExpressionSyntax)node;
if (invocation.ArgumentList == null)
{
return false;
}
var seenNamedArgument = false;
var indexOfArgument = 0;
foreach (var argument in invocation.ArgumentList.Arguments)
{
if (argument.NameColon != null)
{
seenNamedArgument = true;
if (parameter.Name.Equals(argument.NameColon.Name.Identifier.ValueText))
{
return !HasNullConstantValue(argument.Expression, model, cancellationToken);
}
}
else if (!seenNamedArgument)
{
if (indexOfArgument == indexOfParameter)
{
return !HasNullConstantValue(argument.Expression, model, cancellationToken);
}
indexOfArgument++;
}
}
return false;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CSharpDiagnosticAnalyzerFieldsAnalyzer : DiagnosticAnalyzerFieldsAnalyzer<ClassDeclarationSyntax, FieldDeclarationSyntax, TypeSyntax, VariableDeclarationSyntax>
{
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CSharpDiagnosticDescriptorCreationAnalyzer : DiagnosticDescriptorCreationAnalyzer<ClassDeclarationSyntax, ObjectCreationExpressionSyntax, SyntaxKind>
{
protected override ImmutableArray<SyntaxKind> SyntaxKindsOfInterest
{
get
{
return ImmutableArray.Create(SyntaxKind.ObjectCreationExpression);
}
}
protected override CompilationAnalyzer GetAnalyzer(Compilation compilation, INamedTypeSymbol diagnosticDescriptorType)
{
return new CSharpCompilationAnalyzer(diagnosticDescriptorType);
}
private sealed class CSharpCompilationAnalyzer : CompilationAnalyzer
{
public CSharpCompilationAnalyzer(INamedTypeSymbol diagnosticDescriptorType)
: base(diagnosticDescriptorType)
{
}
protected override SyntaxNode GetObjectCreationType(ObjectCreationExpressionSyntax objectCreation)
{
return objectCreation.Type;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CSharpRegisterActionAnalyzer : RegisterActionAnalyzer<ClassDeclarationSyntax, InvocationExpressionSyntax, ArgumentSyntax, SyntaxKind>
{
internal static readonly string CSharpSyntaxKindName = typeof(SyntaxKind).FullName;
internal static readonly string BasicSyntaxKindName = @"Microsoft.CodeAnalysis.VisualBasic.SyntaxKind";
protected override RegisterActionCodeBlockAnalyzer GetCodeBlockAnalyzer(Compilation compilation, INamedTypeSymbol analysisContext, INamedTypeSymbol compilationStartAnalysisContext, INamedTypeSymbol codeBlockStartAnalysisContext, INamedTypeSymbol symbolKind, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
{
var csharpSyntaxKind = compilation.GetTypeByMetadataName(CSharpSyntaxKindName);
var basicSyntaxKind = compilation.GetTypeByMetadataName(BasicSyntaxKindName);
return new CSharpRegisterActionCodeBlockAnalyzer(csharpSyntaxKind, basicSyntaxKind, analysisContext, compilationStartAnalysisContext, codeBlockStartAnalysisContext, symbolKind, diagnosticAnalyzer, diagnosticAnalyzerAttribute);
}
private sealed class CSharpRegisterActionCodeBlockAnalyzer : RegisterActionCodeBlockAnalyzer
{
private readonly ITypeSymbol _csharpSyntaxKind, _basicSyntaxKind;
public CSharpRegisterActionCodeBlockAnalyzer(
INamedTypeSymbol csharpSyntaxKind,
INamedTypeSymbol basicSyntaxKind,
INamedTypeSymbol analysisContext,
INamedTypeSymbol compilationStartAnalysisContext,
INamedTypeSymbol codeBlockStartAnalysisContext,
INamedTypeSymbol symbolKind,
INamedTypeSymbol diagnosticAnalyzer,
INamedTypeSymbol diagnosticAnalyzerAttribute)
: base(analysisContext, compilationStartAnalysisContext, codeBlockStartAnalysisContext, symbolKind, diagnosticAnalyzer, diagnosticAnalyzerAttribute)
{
_csharpSyntaxKind = csharpSyntaxKind;
_basicSyntaxKind = basicSyntaxKind;
}
protected override SyntaxKind InvocationExpressionKind => SyntaxKind.InvocationExpression;
protected override SyntaxKind ArgumentSyntaxKind => SyntaxKind.Argument;
protected override SyntaxKind ParameterSyntaxKind => SyntaxKind.Parameter;
protected override IEnumerable<SyntaxNode> GetArgumentExpressions(InvocationExpressionSyntax invocation)
{
if (invocation.ArgumentList != null)
{
return invocation.ArgumentList.Arguments.Select(a => a.Expression);
}
return null;
}
protected override SyntaxNode GetArgumentExpression(ArgumentSyntax argument)
{
return argument.Expression;
}
protected override SyntaxNode GetInvocationExpression(InvocationExpressionSyntax invocation)
{
return invocation.Expression;
}
protected override SyntaxNode GetInvocationReceiver(InvocationExpressionSyntax invocation)
{
return (invocation.Expression as MemberAccessExpressionSyntax)?.Expression;
}
protected override bool IsSyntaxKind(ITypeSymbol type)
{
return (_csharpSyntaxKind != null && type.Equals(_csharpSyntaxKind)) ||
(_basicSyntaxKind != null && type.Equals(_basicSyntaxKind));
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CSharpReportDiagnosticAnalyzer : ReportDiagnosticAnalyzer<ClassDeclarationSyntax, InvocationExpressionSyntax, IdentifierNameSyntax, VariableDeclaratorSyntax>
{
protected override ReportDiagnosticCompilationAnalyzer GetAnalyzer(ImmutableHashSet<INamedTypeSymbol> contextTypes, INamedTypeSymbol diagnosticType, INamedTypeSymbol diagnosticDescriptorType, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
{
return new CSharpReportDiagnosticCompilationAnalyzer(contextTypes, diagnosticType, diagnosticDescriptorType, diagnosticAnalyzer, diagnosticAnalyzerAttribute);
}
private sealed class CSharpReportDiagnosticCompilationAnalyzer : ReportDiagnosticCompilationAnalyzer
{
public CSharpReportDiagnosticCompilationAnalyzer(ImmutableHashSet<INamedTypeSymbol> contextTypes, INamedTypeSymbol diagnosticType, INamedTypeSymbol diagnosticDescriptorType, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
: base(contextTypes, diagnosticType, diagnosticDescriptorType, diagnosticAnalyzer, diagnosticAnalyzerAttribute)
{
}
protected override IEnumerable<SyntaxNode> GetArgumentExpressions(InvocationExpressionSyntax invocation)
{
if (invocation.ArgumentList != null)
{
return invocation.ArgumentList.Arguments.Select(a => a.Expression);
}
return null;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.CodeFixes;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Simplification;
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CodeFixes
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CSharpApplyDiagnosticAnalyzerAttributeFix)), Shared]
public sealed class CSharpApplyDiagnosticAnalyzerAttributeFix : ApplyDiagnosticAnalyzerAttributeFix
{
protected override SyntaxNode ParseExpression(string expression)
{
return SyntaxFactory.ParseExpression(expression).WithAdditionalAnnotations(Simplifier.Annotation);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
</packages>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="Settings">
<Import Project="..\..\..\..\build\Targets\VSL.Settings.targets" />
</ImportGroup>
<PropertyGroup>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D8762A0A-3832-47BE-BCF6-8B1060BE6B28}</ProjectGuid>
<OutputType>Library</OutputType>
<AnalyzerProject>true</AnalyzerProject>
<RootNamespace>Microsoft.CodeAnalysis.Analyzers</RootNamespace>
<AssemblyName>Microsoft.CodeAnalysis.Analyzers</AssemblyName>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .NET Framework is automatically included -->
<ProjectReference Include="..\..\..\Compilers\Core\Portable\CodeAnalysis.csproj">
<Project>{1ee8cad3-55f9-4d91-96b2-084641da9a6c}</Project>
<Name>CodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Workspaces.csproj">
<Project>{5f8d2414-064a-4b3a-9b42-8e2a04246be5}</Project>
<Name>Workspaces</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Collections.Immutable">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\System.Collections.Immutable.$(SystemCollectionsImmutableVersion)\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.Analyzers" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.Analyzers" />
<InternalsVisibleToTest Include="Roslyn.CodeAnalysis.Analyzers.UnitTests" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="CodeAnalysisDiagnosticsResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CodeAnalysisDiagnosticsResources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Include="CodeAnalysisDiagnosticsResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CodeAnalysisDiagnosticsResources.resx</DependentUpon>
</Compile>
<Compile Include="DiagnosticCategory.cs" />
<Compile Include="DiagnosticIds.cs" />
<Compile Include="FixAnalyzers\FixerWithFixAllAnalyzer.cs" />
<Compile Include="Helpers\AttributeHelpers.cs" />
<Compile Include="Helpers\DocumentChangedAction.cs" />
<Compile Include="Helpers\ITypeSymbolExtensions.cs" />
<Compile Include="InternalImplementationOnlyAnalyzer.cs" />
<Compile Include="MetaAnalyzers\DiagnosticAnalyzerCorrectnessAnalyzer.SyntaxNodeWithinAnalyzerTypeCompilationAnalyzer.cs" />
<Compile Include="MetaAnalyzers\DiagnosticAnalyzerFieldsAnalyzer.cs" />
<Compile Include="MetaAnalyzers\DiagnosticAnalyzerAttributeAnalyzer.cs" />
<Compile Include="MetaAnalyzers\DiagnosticAnalyzerCorrectnessAnalyzer.DiagnosticAnalyzerSymbolAnalyzer.cs" />
<Compile Include="MetaAnalyzers\DiagnosticAnalyzerCorrectnessAnalyzer.cs" />
<Compile Include="MetaAnalyzers\DiagnosticDescriptorCreationAnalyzer.cs" />
<Compile Include="MetaAnalyzers\Fixers\ApplyDiagnosticAnalyzerAttributeFix.cs" />
<Compile Include="MetaAnalyzers\RegisterActionAnalyzer.cs" />
<Compile Include="MetaAnalyzers\ReportDiagnosticAnalyzer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="MissingAttributeMessage" xml:space="preserve">
<value>Missing '{0}' attribute.</value>
</data>
<data name="MissingDiagnosticAnalyzerAttributeTitle" xml:space="preserve">
<value>Missing diagnostic analyzer attribute.</value>
</data>
<data name="MissingDiagnosticAnalyzerAttributeDescription" xml:space="preserve">
<value>Non-abstract sub-types of DiagnosticAnalyzer should be marked with DiagnosticAnalyzerAttribute(s). The argument to this attribute(s), if any, determine the supported languages for the analyzer. Analyzer types without this attribute will be ignored by the analysis engine.</value>
</data>
<data name="AddLanguageSupportToAnalyzerMessage" xml:space="preserve">
<value>Diagnostic analyzer '{0}' may be able to support both C# and Visual Basic. Consider adding an argument to DiagnosticAnalyzerAttribute for '{1}' language support.</value>
</data>
<data name="AddLanguageSupportToAnalyzerTitle" xml:space="preserve">
<value>Recommend adding language support to diagnostic analyzer.</value>
</data>
<data name="AddLanguageSupportToAnalyzerDescription" xml:space="preserve">
<value>Diagnostic analyzer is marked as supporting only one language, but the analyzer assembly doesn't seem to refer to any language specific CodeAnalysis assemblies, and so is likely to work for more than one language. Consider adding an additional language argument to DiagnosticAnalyzerAttribute.</value>
</data>
<data name="ApplyDiagnosticAnalyzerAttribute_1" xml:space="preserve">
<value>Apply DiagnosticAnalyzer attribute for '{0}'.</value>
</data>
<data name="ApplyDiagnosticAnalyzerAttribute_2" xml:space="preserve">
<value>Apply DiagnosticAnalyzer attribute for both '{0}' and '{1}'.</value>
</data>
<data name="MissingKindArgumentToRegisterActionMessage" xml:space="preserve">
<value>Specify at least one '{0}' of interest while registering a {1} analyzer action.</value>
</data>
<data name="MissingKindArgumentToRegisterActionTitle" xml:space="preserve">
<value>Missing kind argument while registering an analyzer action.</value>
</data>
<data name="MissingKindArgumentToRegisterActionDescription" xml:space="preserve">
<value>You must specify at least one syntax/symbol kinds of interest while registering a syntax/symbol analyzer action. Otherwise, the registered action will be dead code and will never be invoked during analysis.</value>
</data>
<data name="UnsupportedSymbolKindArgumentToRegisterActionMessage" xml:space="preserve">
<value>SymbolKind '{0}' is not supported for symbol analyzer actions.</value>
</data>
<data name="UnsupportedSymbolKindArgumentToRegisterActionTitle" xml:space="preserve">
<value>Unsupported SymbolKind argument while registering a symbol analyzer action.</value>
</data>
<data name="InvalidReportDiagnosticMessage" xml:space="preserve">
<value>ReportDiagnostic invoked with an unsupported DiagnosticDescriptor '{0}'.</value>
</data>
<data name="InvalidReportDiagnosticTitle" xml:space="preserve">
<value>ReportDiagnostic invoked with an unsupported DiagnosticDescriptor.</value>
</data>
<data name="InvalidReportDiagnosticDescription" xml:space="preserve">
<value>ReportDiagnostic should only be invoked with supported DiagnosticDescriptors that are returned from DiagnosticAnalyzer.SupportedDiagnostics property. Otherwise, the reported diagnostic will be filtered out by the analysis engine.</value>
</data>
<data name="InvalidSyntaxKindTypeArgumentMessage" xml:space="preserve">
<value>Type argument '{0}' for type parameter '{1}' of method '{2}' is not a SyntaxKind enum.</value>
</data>
<data name="InvalidSyntaxKindTypeArgumentTitle" xml:space="preserve">
<value>Invalid type argument for DiagnosticAnalyzer's Register method.</value>
</data>
<data name="InvalidSyntaxKindTypeArgumentDescription" xml:space="preserve">
<value>DiagnosticAnalyzer's language-specific Register methods, such as RegisterSyntaxNodeAction, RegisterCodeBlockStartAction and RegisterCodeBlockEndAction, expect a language-specific 'SyntaxKind' type argument for it's '{0}' type parameter. Otherwise, the registered analyzer action can never be invoked during analysis.</value>
</data>
<data name="StartActionWithOnlyEndActionTitle" xml:space="preserve">
<value>Start action has no registered non-end actions.</value>
</data>
<data name="StartActionWithNoRegisteredActionsMessage" xml:space="preserve">
<value>'{0}' does not register any analyzer actions. Consider moving actions registered in '{1}' that depend on this start action to '{0}'.</value>
</data>
<data name="StartActionWithNoRegisteredActionsTitle" xml:space="preserve">
<value>Start action has no registered actions.</value>
</data>
<data name="StartActionWithOnlyEndActionMessage" xml:space="preserve">
<value>'{0}' does not register any analyzer actions, except for a '{1}'. Consider replacing this start/end action pair with a '{2}' or moving actions registered in '{3}' that depend on this start action to '{0}'.</value>
</data>
<data name="StatefulAnalyzerRegisterActionsDescription" xml:space="preserve">
<value>An analyzer start action enables performing stateful analysis over a given code unit, such as a code block, compilation, etc. Careful design is necessary to achieve efficient analyzer execution without memory leaks. Use the following guidelines for writing such analyzers:
1. Define a new scope for the registered start action, possibly with a private nested type for analyzing each code unit.
2. If required, define and initialize state in the start action.
3. Register at least one non-end action that refers to this state in the start action. If no such action is necessary, consider replacing the start action with a non-start action. For example, a CodeBlockStartAction with no registered actions or only a registered CodeBlockEndAction should be replaced with a CodeBlockAction.
4. If required, register an end action to report diagnostics based on the final state.
</value>
</data>
<data name="UseLocalizableStringsInDescriptorMessage" xml:space="preserve">
<value>Consider providing localizable arguments of type '{0}' to diagnostic descriptor constructor to ensure the descriptor is localizable.</value>
</data>
<data name="UseLocalizableStringsInDescriptorTitle" xml:space="preserve">
<value>Provide localizable arguments to diagnostic descriptor constructor.</value>
</data>
<data name="UseLocalizableStringsInDescriptorDescription" xml:space="preserve">
<value>If your diagnostic analyzer and it's reported diagnostics need to be localizable, then the supported DiagnosticDescriptors used for constructing the diagnostics must also be localizable. If so, then localizable argument(s) must be provided for parameter 'title' (and optionally 'description') to the diagnostic descriptor constructor to ensure that the descriptor is localizable.</value>
</data>
<data name="DoNotStorePerCompilationDataOntoFieldsMessage" xml:space="preserve">
<value>Avoid storing per-compilation data of type '{0}' into the fields of a diagnostic analyzer.</value>
</data>
<data name="DoNotStorePerCompilationDataOntoFieldsTitle" xml:space="preserve">
<value>Avoid storing per-compilation data into the fields of a diagnostic analyzer.</value>
</data>
<data name="DoNotStorePerCompilationDataOntoFieldsDescription" xml:space="preserve">
<value>Instance of a diagnostic analyzer might outlive the lifetime of compilation. Hence, storing per-compilation data, such as symbols, into the fields of a diagnostic analyzer might cause stale compilations to stay alive and cause memory leaks. Instead, you should store this data on a separate type instantiated in a compilation start action, registered using '{0}.{1}' API. An instance of this type will be created per-compilation and it won't outlive compilation's lifetime, hence avoiding memory leaks.</value>
</data>
<data name="InternalImplementationOnlyDescription" xml:space="preserve">
<value>The author of this interface did not intend to have third party implementations of this interface and reserves the right to change it. Implementing this interface could therefore result in a source or binary compatibility issue with a future version of this interface.</value>
</data>
<data name="InternalImplementationOnlyMessage" xml:space="preserve">
<value>Type {0} cannot implement interface {1} because {1} is not available for public implementation.</value>
</data>
<data name="InternalImplementationOnlyTitle" xml:space="preserve">
<value>Only internal implementations of this interface are allowed.</value>
</data>
<data name="CodeActionNeedsEquivalenceKeyDescription" xml:space="preserve">
<value>A CodeFixProvider that intends to support fix all occurrences must classify the registered code actions into equivalence classes by assigning it an explicit, non-null equivalence key which is unique across all registered code actions by this fixer. This enables the FixAllProvider to fix all diagnostics in the required scope by applying code actions from this fixer that are in the equivalence class of the trigger code action.</value>
</data>
<data name="CreateCodeActionWithEquivalenceKeyMessage" xml:space="preserve">
<value>Provide an explicit argument for optional parameter '{0}', which is non-null and unique across all code actions created by this fixer.</value>
</data>
<data name="CreateCodeActionWithEquivalenceKeyTitle" xml:space="preserve">
<value>Create code actions should have a unique EquivalenceKey for FixAll occurrences support.</value>
</data>
<data name="OverrideCodeActionEquivalenceKeyMessage" xml:space="preserve">
<value>'{0}' has the default value of 'null' for property '{1}'. Either override this property on '{0}' to return a non-null and unique value across all code actions per-fixer or use such an existing code action.</value>
</data>
<data name="OverrideCodeActionEquivalenceKeyTitle" xml:space="preserve">
<value>Use code actions that have a unique EquivalenceKey for FixAll occurrences support.</value>
</data>
</root>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Analyzers
{
internal static class DiagnosticCategory
{
public const string AnalyzerCorrectness = "AnalyzerCorrectness";
public const string AnalyzerLocalization = "AnalyzerLocalization";
public const string AnalyzerPerformance = "AnalyzerPerformance";
public const string Compatibility = "Compatibility";
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Analyzers
{
internal static class DiagnosticIds
{
public const string MissingDiagnosticAnalyzerAttributeRuleId = "RS1001";
public const string MissingKindArgumentToRegisterActionRuleId = "RS1002";
public const string UnsupportedSymbolKindArgumentRuleId = "RS1003";
public const string AddLanguageSupportToAnalyzerRuleId = "RS1004";
public const string InvalidReportDiagnosticRuleId = "RS1005";
public const string InvalidSyntaxKindTypeArgumentRuleId = "RS1006";
public const string UseLocalizableStringsInDescriptorRuleId = "RS1007";
public const string DoNotStorePerCompilationDataOntoFieldsRuleId = "RS1008";
public const string InternalImplementationOnlyRuleId = "RS1009";
public const string CreateCodeActionWithEquivalenceKeyRuleId = "RS1010";
public const string OverrideCodeActionEquivalenceKeyRuleId = "RS1011";
public const string StartActionWithNoRegisteredActionsRuleId = "RS1012";
public const string StartActionWithOnlyEndActionRuleId = "RS1013";
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers.FixAnalyzers
{
/// <summary>
/// A <see cref="CodeFixProvider"/> that intends to support fix all occurrences must classify the registered code actions into equivalence classes by assigning it an explicit, non-null equivalence key which is unique across all registered code actions by this fixer.
/// This enables the <see cref="FixAllProvider"/> to fix all diagnostics in the required scope by applying code actions from this fixer that are in the equivalence class of the trigger code action.
/// This analyzer catches violations of this requirement in the code actions registered by a <see cref="CodeFixProvider"/> that supports <see cref="FixAllProvider"/>.
/// </summary>
public abstract class FixerWithFixAllAnalyzer<TLanguageKindEnum> : DiagnosticAnalyzer
where TLanguageKindEnum: struct
{
private static string s_codeFixProviderMetadataName = "Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider";
private static string s_codeActionMetadataName = "Microsoft.CodeAnalysis.CodeActions.CodeAction";
private const string GetFixAllProviderMethodName = "GetFixAllProvider";
private const string CreateMethodName = "Create";
private const string EquivalenceKeyPropertyName = "EquivalenceKey";
private const string EquivalenceKeyParameterName = "equivalenceKey";
private static readonly LocalizableString s_localizableCreateCodeActionWithEquivalenceKeyTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.CreateCodeActionWithEquivalenceKeyTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableCreateCodeActionWithEquivalenceKeyMessage = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.CreateCodeActionWithEquivalenceKeyMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableOverrideCodeActionEquivalenceKeyTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.OverrideCodeActionEquivalenceKeyTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableOverrideCodeActionEquivalenceKeyMessage = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.OverrideCodeActionEquivalenceKeyMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableCodeActionNeedsEquivalenceKeyDescription = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.CodeActionNeedsEquivalenceKeyDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
internal static readonly DiagnosticDescriptor CreateCodeActionEquivalenceKeyRule = new DiagnosticDescriptor(
DiagnosticIds.CreateCodeActionWithEquivalenceKeyRuleId,
s_localizableCreateCodeActionWithEquivalenceKeyTitle,
s_localizableCreateCodeActionWithEquivalenceKeyMessage,
"Correctness",
DiagnosticSeverity.Warning,
description: s_localizableCodeActionNeedsEquivalenceKeyDescription,
isEnabledByDefault: true,
customTags: WellKnownDiagnosticTags.Telemetry);
internal static readonly DiagnosticDescriptor OverrideCodeActionEquivalenceKeyRule = new DiagnosticDescriptor(
DiagnosticIds.OverrideCodeActionEquivalenceKeyRuleId,
s_localizableOverrideCodeActionEquivalenceKeyTitle,
s_localizableOverrideCodeActionEquivalenceKeyMessage,
"Correctness",
DiagnosticSeverity.Warning,
description: s_localizableCodeActionNeedsEquivalenceKeyDescription,
isEnabledByDefault: true,
customTags: WellKnownDiagnosticTags.Telemetry);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get { return ImmutableArray.Create(CreateCodeActionEquivalenceKeyRule, OverrideCodeActionEquivalenceKeyRule); }
}
public override void Initialize(AnalysisContext context)
{
context.RegisterCompilationStartAction(CreateAnalyzerWithinCompilation);
}
private void CreateAnalyzerWithinCompilation(CompilationStartAnalysisContext context)
{
context.CancellationToken.ThrowIfCancellationRequested();
var codeFixProviderSymbol = context.Compilation.GetTypeByMetadataName(s_codeFixProviderMetadataName);
if (codeFixProviderSymbol == null)
{
return;
}
var getFixAllProviderMethod = codeFixProviderSymbol.GetMembers(GetFixAllProviderMethodName).OfType<IMethodSymbol>().SingleOrDefault();
if (getFixAllProviderMethod == null)
{
return;
}
var codeActionSymbol = context.Compilation.GetTypeByMetadataName(s_codeActionMetadataName);
if (codeActionSymbol == null)
{
return;
}
var createSymbols = codeActionSymbol.GetMembers(CreateMethodName).OfType<IMethodSymbol>();
if (createSymbols == null)
{
return;
}
var equivalenceKeyProperty = codeActionSymbol.GetMembers(EquivalenceKeyPropertyName).OfType<IPropertySymbol>().SingleOrDefault();
if (equivalenceKeyProperty == null)
{
return;
}
var compilationAnalyzer = GetCompilationAnalyzer(codeFixProviderSymbol, getFixAllProviderMethod,
codeActionSymbol, ImmutableHashSet.CreateRange(createSymbols), equivalenceKeyProperty);
context.RegisterSymbolAction(compilationAnalyzer.AnalyzeNamedTypeSymbol, SymbolKind.NamedType);
context.RegisterCodeBlockStartAction<TLanguageKindEnum>(compilationAnalyzer.CodeBlockStart);
context.RegisterCompilationEndAction(compilationAnalyzer.CompilationEnd);
}
protected abstract CompilationAnalyzer GetCompilationAnalyzer(
INamedTypeSymbol codeFixProviderSymbol,
IMethodSymbol getFixAllProvider,
INamedTypeSymbol codeActionSymbol,
ImmutableHashSet<IMethodSymbol> createMethods,
IPropertySymbol equivalenceKeyProperty);
protected abstract class CompilationAnalyzer
{
private readonly INamedTypeSymbol _codeFixProviderSymbol;
private readonly IMethodSymbol _getFixAllProvider;
private readonly INamedTypeSymbol _codeActionSymbol;
private readonly ImmutableHashSet<IMethodSymbol> _createMethods;
private readonly IPropertySymbol _equivalenceKeyProperty;
/// <summary>
/// Set of all non-abstract sub-types of <see cref="CodeFixProvider"/> in this compilation.
/// </summary>
private HashSet<INamedTypeSymbol> _codeFixProviders;
/// <summary>
/// Set of all non-abstract sub-types of <see cref="CodeAction"/> which override <see cref="CodeAction.EquivalenceKey"/> in this compilation.
/// </summary>
private HashSet<INamedTypeSymbol> _codeActionsWithEquivalenceKey;
/// <summary>
/// Map of invocations from code fix providers to invocation nodes (and symbols) that create a code action using the static "Create" methods on <see cref="CodeAction"/>.
/// </summary>
private Dictionary<INamedTypeSymbol, HashSet<NodeAndSymbol>> _codeActionCreateInvocations;
/// <summary>
/// Map of invocations from code fix providers to object creation nodes (and symbols) that create a code action using sub-types of <see cref="CodeAction"/>.
/// </summary>
private Dictionary<INamedTypeSymbol, HashSet<NodeAndSymbol>> _codeActionObjectCreations;
private struct NodeAndSymbol
{
public SyntaxNode Node { get; set; }
public IMethodSymbol Symbol { get; set; }
}
protected CompilationAnalyzer(
INamedTypeSymbol codeFixProviderSymbol,
IMethodSymbol getFixAllProvider,
INamedTypeSymbol codeActionSymbol,
ImmutableHashSet<IMethodSymbol> createMethods,
IPropertySymbol equivalenceKeyProperty)
{
_codeFixProviderSymbol = codeFixProviderSymbol;
_getFixAllProvider = getFixAllProvider;
_codeActionSymbol = codeActionSymbol;
_createMethods = createMethods;
_equivalenceKeyProperty = equivalenceKeyProperty;
_codeFixProviders = null;
_codeActionsWithEquivalenceKey = null;
_codeActionCreateInvocations = null;
_codeActionObjectCreations = null;
}
internal void AnalyzeNamedTypeSymbol(SymbolAnalysisContext context)
{
var namedType = (INamedTypeSymbol)context.Symbol;
if (namedType.IsAbstract)
{
return;
}
if (namedType.DerivesFrom(_codeFixProviderSymbol))
{
_codeFixProviders = _codeFixProviders ?? new HashSet<INamedTypeSymbol>();
_codeFixProviders.Add(namedType);
}
else if (namedType.DerivesFrom(_codeActionSymbol))
{
var equivalenceKeyProperty = namedType.GetMembers(EquivalenceKeyPropertyName).OfType<IPropertySymbol>().SingleOrDefault();
if (equivalenceKeyProperty != null && equivalenceKeyProperty.IsOverride)
{
_codeActionsWithEquivalenceKey = _codeActionsWithEquivalenceKey ?? new HashSet<INamedTypeSymbol>();
_codeActionsWithEquivalenceKey.Add(namedType);
}
}
}
protected abstract TLanguageKindEnum GetInvocationKind { get; }
protected abstract TLanguageKindEnum GetObjectCreationKind { get; }
protected abstract bool HasNonNullArgumentForParameter(SyntaxNode invocation, IParameterSymbol parameter, int indexOfParameter, SemanticModel semanticModel, CancellationToken cancellationToken);
protected bool HasNullConstantValue(SyntaxNode expression, SemanticModel model, CancellationToken cancellationToken)
{
if (expression == null)
{
return false;
}
var constantValue = model.GetConstantValue(expression, cancellationToken);
return constantValue.HasValue && constantValue.Value == null;
}
internal void CodeBlockStart(CodeBlockStartAnalysisContext<TLanguageKindEnum> context)
{
var method = context.OwningSymbol as IMethodSymbol;
if (method == null)
{
return;
}
var namedType = method.ContainingType;
if (!namedType.DerivesFrom(_codeFixProviderSymbol))
{
return;
}
context.RegisterSyntaxNodeAction(invocationContext =>
{
var invocationSym = invocationContext.SemanticModel.GetSymbolInfo(invocationContext.Node).Symbol as IMethodSymbol;
if (invocationSym != null && _createMethods.Contains(invocationSym))
{
_codeActionCreateInvocations = _codeActionCreateInvocations ?? new Dictionary<INamedTypeSymbol, HashSet<NodeAndSymbol>>();
AddNodeAndSymbol(namedType, invocationContext.Node, invocationSym, _codeActionCreateInvocations);
}
},
GetInvocationKind);
context.RegisterSyntaxNodeAction(objectCreationContext =>
{
var constructor = objectCreationContext.SemanticModel.GetSymbolInfo(objectCreationContext.Node).Symbol as IMethodSymbol;
if (constructor != null && constructor.ContainingType.DerivesFrom(_codeActionSymbol))
{
_codeActionObjectCreations = _codeActionObjectCreations ?? new Dictionary<INamedTypeSymbol, HashSet<NodeAndSymbol>>();
AddNodeAndSymbol(namedType, objectCreationContext.Node, constructor, _codeActionObjectCreations);
}
},
GetObjectCreationKind);
}
private static void AddNodeAndSymbol(INamedTypeSymbol namedType, SyntaxNode node, IMethodSymbol symbol, Dictionary<INamedTypeSymbol, HashSet<NodeAndSymbol>> map)
{
HashSet<NodeAndSymbol> value;
if (!map.TryGetValue(namedType, out value))
{
value = new HashSet<NodeAndSymbol>();
map[namedType] = value;
}
value.Add(new NodeAndSymbol { Node = node, Symbol = symbol });
}
internal void CompilationEnd(CompilationAnalysisContext context)
{
if (_codeFixProviders == null)
{
// No fixers.
return;
}
if (_codeActionCreateInvocations == null && _codeActionObjectCreations == null)
{
// No registered fixes.
return;
}
// Analyze all fixers that have FixAll support.
foreach (var fixer in _codeFixProviders)
{
if (OverridesGetFixAllProvider(fixer))
{
AnalyzeFixerWithFixAll(fixer, context);
}
}
}
private bool OverridesGetFixAllProvider(INamedTypeSymbol fixer)
{
foreach (var type in fixer.GetBaseTypesAndThis())
{
if (!type.Equals(_codeFixProviderSymbol))
{
var getFixAllProviderProperty = type.GetMembers(GetFixAllProviderMethodName).OfType<IMethodSymbol>().SingleOrDefault();
if (getFixAllProviderProperty != null && getFixAllProviderProperty.IsOverride)
{
return true;
}
}
}
return false;
}
private void AnalyzeFixerWithFixAll(INamedTypeSymbol fixer, CompilationAnalysisContext context)
{
if (_codeActionCreateInvocations != null)
{
HashSet<NodeAndSymbol> nodeAndSymbolSet;
if (_codeActionCreateInvocations.TryGetValue(fixer, out nodeAndSymbolSet))
{
foreach (var nodeAndSymbol in nodeAndSymbolSet)
{
var model = context.Compilation.GetSemanticModel(nodeAndSymbol.Node.SyntaxTree);
if (IsViolatingCodeActionCreateInvocation(nodeAndSymbol.Node, nodeAndSymbol.Symbol, model, context.CancellationToken))
{
var diagnostic = Diagnostic.Create(CreateCodeActionEquivalenceKeyRule, nodeAndSymbol.Node.GetLocation(), EquivalenceKeyParameterName);
context.ReportDiagnostic(diagnostic);
}
}
}
}
if (_codeActionObjectCreations != null)
{
HashSet<NodeAndSymbol> nodeAndSymbolSet;
if (_codeActionObjectCreations.TryGetValue(fixer, out nodeAndSymbolSet))
{
foreach (var nodeAndSymbol in nodeAndSymbolSet)
{
if (IsViolatingCodeActionObjectCreation(nodeAndSymbol.Node, nodeAndSymbol.Symbol))
{
var diagnostic = Diagnostic.Create(OverrideCodeActionEquivalenceKeyRule, nodeAndSymbol.Node.GetLocation(), nodeAndSymbol.Symbol.ContainingType, EquivalenceKeyPropertyName);
context.ReportDiagnostic(diagnostic);
}
}
}
}
}
private bool IsViolatingCodeActionCreateInvocation(SyntaxNode invocation, IMethodSymbol invocationSym, SemanticModel model, CancellationToken cancellationToken)
{
var param = invocationSym.Parameters.SingleOrDefault(p => p.Name == EquivalenceKeyParameterName);
if (param == null)
{
return true;
}
var index = invocationSym.Parameters.IndexOf(param);
return !HasNonNullArgumentForParameter(invocation, param, index, model, cancellationToken);
}
private bool IsViolatingCodeActionObjectCreation(SyntaxNode objectCreation, IMethodSymbol constructor)
{
return _codeActionsWithEquivalenceKey == null ||
!constructor.ContainingType.GetBaseTypesAndThis().Any(_codeActionsWithEquivalenceKey.Contains);
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.CodeAnalysis.Analyzers
{
internal static class AttributeHelpers
{
internal static IEnumerable<AttributeData> GetApplicableAttributes(INamedTypeSymbol type)
{
var attributes = new List<AttributeData>();
while (type != null)
{
attributes.AddRange(type.GetAttributes());
type = type.BaseType;
}
return attributes;
}
internal static bool DerivesFrom(this INamedTypeSymbol symbol, INamedTypeSymbol candidateBaseType)
{
while (symbol != null)
{
if (symbol.Equals(candidateBaseType))
{
return true;
}
symbol = symbol.BaseType;
}
return false;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
namespace Microsoft.CodeAnalysis
{
internal class DocumentChangeAction : CodeAction
{
private readonly string _title;
private readonly Func<CancellationToken, Task<Document>> _createChangedDocument;
private readonly string _equivalenceKey;
public DocumentChangeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument, string equivalenceKey = null)
{
_title = title;
_createChangedDocument = createChangedDocument;
_equivalenceKey = equivalenceKey;
}
public override string Title
{
get { return _title; }
}
public override string EquivalenceKey
{
get { return _equivalenceKey; }
}
protected override Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
{
return _createChangedDocument(cancellationToken);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.CodeAnalysis.Analyzers
{
internal static class ITypeSymbolExtensions
{
public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol type)
{
var current = type;
while (current != null)
{
yield return current;
current = current.BaseType;
}
}
public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol type)
{
var current = type.BaseType;
while (current != null)
{
yield return current;
current = current.BaseType;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public class InternalImplementationOnlyAnalyzer : DiagnosticAnalyzer
{
private const string InternalImplementationOnlyAttributeName = "InternalImplementationOnlyAttribute";
private const string InternalImplementationOnlyAttributeFullName = "System.Runtime.CompilerServices.InternalImplementationOnlyAttribute";
private readonly static LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.InternalImplementationOnlyTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private readonly static LocalizableString s_localizableMessageFormat = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.InternalImplementationOnlyMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private readonly static LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.InternalImplementationOnlyDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
public static DiagnosticDescriptor Rule = new DiagnosticDescriptor(
DiagnosticIds.InternalImplementationOnlyRuleId,
s_localizableTitle,
s_localizableMessageFormat,
DiagnosticCategory.Compatibility,
DiagnosticSeverity.Error,
true,
s_localizableDescription);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
public override void Initialize(AnalysisContext context) => context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.NamedType);
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
var namedTypeSymbol = (INamedTypeSymbol)context.Symbol;
// If any interface implemented by this type has the attribute and if the interface and this type are not
// in "internals visible" context, then issue an error.
foreach (var iface in namedTypeSymbol.AllInterfaces)
{
var attributes = AttributeHelpers.GetApplicableAttributes(iface);
// We are doing a string comparison of the name here because we don't care where the attribute comes from.
// CodeAnalysis.dll itself has this attribute and if the user assembly also had it, symbol equality will fail
// but we should still issue the error.
if (attributes.Any(a => a.AttributeClass.Name.Equals(InternalImplementationOnlyAttributeName)
&& a.AttributeClass.ToDisplayString().Equals(InternalImplementationOnlyAttributeFullName)))
{
if (!iface.ContainingAssembly.GivesAccessTo(namedTypeSymbol.ContainingAssembly))
{
context.ReportDiagnostic(Diagnostic.Create(Rule, namedTypeSymbol.Locations.First(), namedTypeSymbol.Name, iface.Name));
break;
}
}
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class DiagnosticAnalyzerAttributeAnalyzer : DiagnosticAnalyzerCorrectnessAnalyzer
{
private static readonly LocalizableString s_localizableTitleMissingAttribute = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingDiagnosticAnalyzerAttributeTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableMessageMissingAttribute = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingAttributeMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources), DiagnosticAnalyzerAttributeFullName);
private static readonly LocalizableString s_localizableDescriptionMissingAttribute = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingDiagnosticAnalyzerAttributeDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
public static DiagnosticDescriptor MissingDiagnosticAnalyzerAttributeRule = new DiagnosticDescriptor(
DiagnosticIds.MissingDiagnosticAnalyzerAttributeRuleId,
s_localizableTitleMissingAttribute,
s_localizableMessageMissingAttribute,
DiagnosticCategory.AnalyzerCorrectness,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: s_localizableDescriptionMissingAttribute,
customTags: WellKnownDiagnosticTags.Telemetry);
private static readonly LocalizableString s_localizableTitleAddLanguageSupportToAnalyzer = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.AddLanguageSupportToAnalyzerTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableMessageAddLanguageSupportToAnalyzer = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.AddLanguageSupportToAnalyzerMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableDescriptionAddLanguageSupportToAnalyzer = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.AddLanguageSupportToAnalyzerDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
public static DiagnosticDescriptor AddLanguageSupportToAnalyzerRule = new DiagnosticDescriptor(
DiagnosticIds.AddLanguageSupportToAnalyzerRuleId,
s_localizableTitleAddLanguageSupportToAnalyzer,
s_localizableMessageAddLanguageSupportToAnalyzer,
DiagnosticCategory.AnalyzerCorrectness,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: s_localizableDescriptionAddLanguageSupportToAnalyzer,
customTags: WellKnownDiagnosticTags.Telemetry);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(MissingDiagnosticAnalyzerAttributeRule, AddLanguageSupportToAnalyzerRule);
}
}
protected override DiagnosticAnalyzerSymbolAnalyzer GetDiagnosticAnalyzerSymbolAnalyzer(CompilationStartAnalysisContext compilationContext, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
{
return new AttributeAnalyzer(diagnosticAnalyzer, diagnosticAnalyzerAttribute);
}
private sealed class AttributeAnalyzer : DiagnosticAnalyzerSymbolAnalyzer
{
private static readonly string s_csharpCompilationFullName = @"Microsoft.CodeAnalysis.CSharp.CSharpCompilation";
private static readonly string s_basicCompilationFullName = @"Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilation";
public AttributeAnalyzer(INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
: base(diagnosticAnalyzer, diagnosticAnalyzerAttribute)
{
}
protected override void AnalyzeDiagnosticAnalyzer(SymbolAnalysisContext symbolContext)
{
var namedType = (INamedTypeSymbol)symbolContext.Symbol;
if (namedType.IsAbstract)
{
return;
}
// 1) MissingDiagnosticAnalyzerAttributeRule: DiagnosticAnalyzer has no DiagnosticAnalyzerAttribute.
// 2) AddLanguageSupportToAnalyzerRule: For analyzer supporting only one of C# or VB languages, detect if it can support the other language.
var hasAttribute = false;
SyntaxNode attributeSyntax = null;
bool supportsCSharp = false;
bool supportsVB = false;
var namedTypeAttributes = AttributeHelpers.GetApplicableAttributes(namedType);
foreach (var attribute in namedTypeAttributes)
{
if (AttributeHelpers.DerivesFrom(attribute.AttributeClass, DiagnosticAnalyzerAttribute))
{
hasAttribute = true;
// The attribute constructor's signature is "(string, params string[])",
// so process both string arguments and string[] arguments.
foreach (TypedConstant arg in attribute.ConstructorArguments)
{
CheckLanguage(arg, ref supportsCSharp, ref supportsVB);
if (arg.Kind == TypedConstantKind.Array)
{
foreach (TypedConstant element in arg.Values)
{
CheckLanguage(element, ref supportsCSharp, ref supportsVB);
}
}
}
attributeSyntax = attribute.ApplicationSyntaxReference.GetSyntax(symbolContext.CancellationToken);
}
}
if (!hasAttribute)
{
var diagnostic = Diagnostic.Create(MissingDiagnosticAnalyzerAttributeRule, namedType.Locations[0]);
symbolContext.ReportDiagnostic(diagnostic);
}
else if (supportsCSharp ^ supportsVB)
{
Debug.Assert(attributeSyntax != null);
// If the analyzer assembly doesn't reference either C# or VB CodeAnalysis assemblies,
// then the analyzer is pretty likely a language-agnostic analyzer.
var compilation = symbolContext.Compilation;
var compilationTypeNameToCheck = supportsCSharp ? s_csharpCompilationFullName : s_basicCompilationFullName;
var compilationType = compilation.GetTypeByMetadataName(compilationTypeNameToCheck);
if (compilationType == null)
{
var missingLanguage = supportsCSharp ? LanguageNames.VisualBasic : LanguageNames.CSharp;
var diagnostic = Diagnostic.Create(AddLanguageSupportToAnalyzerRule, attributeSyntax.GetLocation(), namedType.Name, missingLanguage);
symbolContext.ReportDiagnostic(diagnostic);
}
}
}
}
private static void CheckLanguage(TypedConstant argument, ref bool supportsCSharp, ref bool supportsVB)
{
if (argument.Kind == TypedConstantKind.Primitive &&
argument.Type != null &&
argument.Type.SpecialType == SpecialType.System_String)
{
string supportedLanguage = (string)argument.Value;
if (supportedLanguage == LanguageNames.CSharp)
{
supportsCSharp = true;
}
else if (supportedLanguage == LanguageNames.VisualBasic)
{
supportsVB = true;
}
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
{
public abstract partial class DiagnosticAnalyzerCorrectnessAnalyzer : DiagnosticAnalyzer
{
protected abstract class DiagnosticAnalyzerSymbolAnalyzer
{
private readonly INamedTypeSymbol _diagnosticAnalyzer;
private readonly INamedTypeSymbol _diagnosticAnalyzerAttribute;
protected DiagnosticAnalyzerSymbolAnalyzer(INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
{
_diagnosticAnalyzer = diagnosticAnalyzer;
_diagnosticAnalyzerAttribute = diagnosticAnalyzerAttribute;
}
protected INamedTypeSymbol DiagnosticAnalyzer { get { return _diagnosticAnalyzer; } }
protected INamedTypeSymbol DiagnosticAnalyzerAttribute { get { return _diagnosticAnalyzerAttribute; } }
protected bool IsDiagnosticAnalyzer(INamedTypeSymbol type)
{
return type.Equals(_diagnosticAnalyzer);
}
internal void AnalyzeSymbol(SymbolAnalysisContext symbolContext)
{
var namedType = (INamedTypeSymbol)symbolContext.Symbol;
if (namedType.GetBaseTypes().Any(IsDiagnosticAnalyzer))
{
AnalyzeDiagnosticAnalyzer(symbolContext);
}
}
protected abstract void AnalyzeDiagnosticAnalyzer(SymbolAnalysisContext symbolContext);
protected bool HasDiagnosticAnalyzerAttribute(INamedTypeSymbol namedType)
{
foreach (var attribute in AttributeHelpers.GetApplicableAttributes(namedType))
{
if (AttributeHelpers.DerivesFrom(attribute.AttributeClass, DiagnosticAnalyzerAttribute))
{
return true;
}
}
return false;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
{
public abstract partial class DiagnosticAnalyzerCorrectnessAnalyzer : DiagnosticAnalyzer
{
protected abstract class SyntaxNodeWithinAnalyzerTypeCompilationAnalyzer<TClassDeclarationSyntax, TSyntaxNodeOfInterest> : DiagnosticAnalyzerSymbolAnalyzer
where TClassDeclarationSyntax : SyntaxNode
where TSyntaxNodeOfInterest : SyntaxNode
{
protected SyntaxNodeWithinAnalyzerTypeCompilationAnalyzer(INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
: base(diagnosticAnalyzer, diagnosticAnalyzerAttribute)
{
}
internal IEnumerable<TClassDeclarationSyntax> GetClassDeclarationNodes(INamedTypeSymbol namedType, CancellationToken cancellationToken)
{
foreach (var syntax in namedType.DeclaringSyntaxReferences.Select(s => s.GetSyntax(cancellationToken)))
{
if (syntax != null)
{
var classDecl = syntax.FirstAncestorOrSelf<TClassDeclarationSyntax>(ascendOutOfTrivia: false);
if (classDecl != null)
{
yield return classDecl;
}
}
}
}
protected override void AnalyzeDiagnosticAnalyzer(SymbolAnalysisContext symbolContext)
{
var namedType = (INamedTypeSymbol)symbolContext.Symbol;
var classDecls = GetClassDeclarationNodes(namedType, symbolContext.CancellationToken);
foreach (var classDecl in classDecls)
{
var syntaxNodes = classDecl.DescendantNodes(n => !(n is TClassDeclarationSyntax) || ReferenceEquals(n, classDecl)).OfType<TSyntaxNodeOfInterest>();
if (syntaxNodes.Any())
{
var semanticModel = symbolContext.Compilation.GetSemanticModel(classDecl.SyntaxTree);
foreach (var syntaxNode in syntaxNodes)
{
AnalyzeNode(symbolContext, syntaxNode, semanticModel);
}
}
}
}
protected abstract void AnalyzeNode(SymbolAnalysisContext symbolContext, TSyntaxNodeOfInterest syntaxNode, SemanticModel semanticModel);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
{
public abstract partial class DiagnosticAnalyzerCorrectnessAnalyzer : DiagnosticAnalyzer
{
internal static readonly string DiagnosticAnalyzerTypeFullName = typeof(DiagnosticAnalyzer).FullName;
internal static readonly string DiagnosticAnalyzerAttributeFullName = typeof(DiagnosticAnalyzerAttribute).FullName;
internal static readonly string DiagnosticFullName = typeof(Diagnostic).FullName;
internal static readonly string DiagnosticDescriptorFullName = typeof(DiagnosticDescriptor).FullName;
internal static readonly string LocalizableStringFullName = typeof(LocalizableString).FullName;
internal static readonly string AnalysisContextFullName = typeof(AnalysisContext).FullName;
internal static readonly string CompilationStartAnalysisContextFullName = typeof(CompilationStartAnalysisContext).FullName;
internal static readonly string CompilationEndAnalysisContextFullName = typeof(CompilationAnalysisContext).FullName;
internal static readonly string SemanticModelAnalysisContextFullName = typeof(SemanticModelAnalysisContext).FullName;
internal static readonly string SymbolAnalysisContextFullName = typeof(SymbolAnalysisContext).FullName;
internal static readonly string SyntaxNodeAnalysisContextFullName = typeof(SyntaxNodeAnalysisContext).FullName;
internal static readonly string SyntaxTreeAnalysisContextFullName = typeof(SyntaxTreeAnalysisContext).FullName;
internal static readonly string CodeBlockStartAnalysisContextFullName = typeof(CodeBlockStartAnalysisContext<>).FullName;
internal static readonly string CodeBlockEndAnalysisContextFullName = typeof(CodeBlockAnalysisContext).FullName;
internal static readonly string SymbolKindFullName = typeof(SymbolKind).FullName;
internal const string RegisterSyntaxNodeActionName = nameof(AnalysisContext.RegisterSyntaxNodeAction);
internal const string RegisterSymbolActionName = nameof(AnalysisContext.RegisterSymbolAction);
internal const string RegisterCodeBlockStartActionName = nameof(AnalysisContext.RegisterCodeBlockStartAction);
internal const string RegisterCodeBlockEndActionName = nameof(CodeBlockStartAnalysisContext<int>.RegisterCodeBlockEndAction);
internal const string RegisterCodeBlockActionName = nameof(AnalysisContext.RegisterCodeBlockAction);
internal const string RegisterCompilationStartActionName = nameof(AnalysisContext.RegisterCompilationStartAction);
internal const string RegisterCompilationEndActionName = nameof(CompilationStartAnalysisContext.RegisterCompilationEndAction);
internal const string RegisterCompilationActionName = nameof(AnalysisContext.RegisterCompilationAction);
internal const string ReportDiagnosticName = nameof(CompilationAnalysisContext.ReportDiagnostic);
internal const string SupportedDiagnosticsName = nameof(SupportedDiagnostics);
internal const string TLanguageKindEnumName = @"TLanguageKindEnum";
public override void Initialize(AnalysisContext context)
{
context.RegisterCompilationStartAction(compilationContext =>
{
var diagnosticAnalyzer = compilationContext.Compilation.GetTypeByMetadataName(DiagnosticAnalyzerTypeFullName);
var diagnosticAnalyzerAttribute = compilationContext.Compilation.GetTypeByMetadataName(DiagnosticAnalyzerAttributeFullName);
if (diagnosticAnalyzer == null || diagnosticAnalyzerAttribute == null)
{
// We don't need to check assemblies unless they're referencing Microsoft.CodeAnalysis which defines DiagnosticAnalyzer.
return;
}
var analyzer = GetDiagnosticAnalyzerSymbolAnalyzer(compilationContext, diagnosticAnalyzer, diagnosticAnalyzerAttribute);
if (analyzer != null)
{
compilationContext.RegisterSymbolAction(c => analyzer.AnalyzeSymbol(c), SymbolKind.NamedType);
}
});
}
protected abstract DiagnosticAnalyzerSymbolAnalyzer GetDiagnosticAnalyzerSymbolAnalyzer(CompilationStartAnalysisContext compilationContext, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
{
public abstract class DiagnosticAnalyzerFieldsAnalyzer<TClassDeclarationSyntax, TFieldDeclarationSyntax, TTypeSyntax, TVariableTypeDeclarationSyntax> : DiagnosticAnalyzerCorrectnessAnalyzer
where TClassDeclarationSyntax : SyntaxNode
where TFieldDeclarationSyntax : SyntaxNode
where TTypeSyntax : SyntaxNode
where TVariableTypeDeclarationSyntax : SyntaxNode
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.DoNotStorePerCompilationDataOntoFieldsTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.DoNotStorePerCompilationDataOntoFieldsMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.DoNotStorePerCompilationDataOntoFieldsDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources), nameof(AnalysisContext), DiagnosticAnalyzerCorrectnessAnalyzer.RegisterCompilationStartActionName);
private static readonly string s_compilationTypeFullName = typeof(Compilation).FullName;
private static readonly string s_symbolTypeFullName = typeof(ISymbol).FullName;
public static DiagnosticDescriptor DoNotStorePerCompilationDataOntoFieldsRule = new DiagnosticDescriptor(
DiagnosticIds.DoNotStorePerCompilationDataOntoFieldsRuleId,
s_localizableTitle,
s_localizableMessage,
DiagnosticCategory.AnalyzerPerformance,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: s_localizableDescription,
customTags: WellKnownDiagnosticTags.Telemetry);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(DoNotStorePerCompilationDataOntoFieldsRule);
}
}
protected override DiagnosticAnalyzerSymbolAnalyzer GetDiagnosticAnalyzerSymbolAnalyzer(CompilationStartAnalysisContext compilationContext, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
{
var compilation = compilationContext.Compilation;
var compilationType = compilation.GetTypeByMetadataName(s_compilationTypeFullName);
if (compilationType == null)
{
return null;
}
var symbolType = compilation.GetTypeByMetadataName(s_symbolTypeFullName);
if (symbolType == null)
{
return null;
}
return new FieldsAnalyzer(compilationType, symbolType, diagnosticAnalyzer, diagnosticAnalyzerAttribute);
}
private sealed class FieldsAnalyzer : SyntaxNodeWithinAnalyzerTypeCompilationAnalyzer<TClassDeclarationSyntax, TFieldDeclarationSyntax>
{
private readonly INamedTypeSymbol _compilationType;
private readonly INamedTypeSymbol _symbolType;
public FieldsAnalyzer(INamedTypeSymbol compilationType, INamedTypeSymbol symbolType, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
: base(diagnosticAnalyzer, diagnosticAnalyzerAttribute)
{
_compilationType = compilationType;
_symbolType = symbolType;
}
protected override void AnalyzeDiagnosticAnalyzer(SymbolAnalysisContext symbolContext)
{
var namedType = (INamedTypeSymbol)symbolContext.Symbol;
if (!HasDiagnosticAnalyzerAttribute(namedType))
{
// We are interested only in DiagnosticAnalyzer types with DiagnosticAnalyzerAttribute.
return;
}
base.AnalyzeDiagnosticAnalyzer(symbolContext);
}
protected override void AnalyzeNode(SymbolAnalysisContext symbolContext, TFieldDeclarationSyntax syntaxNode, SemanticModel semanticModel)
{
// Get all the type syntax nodes within the topmost type declaration nodes for field declarations.
var variableTypeDeclarations = syntaxNode.DescendantNodesAndSelf().OfType<TVariableTypeDeclarationSyntax>();
var topMostTypeNodes = variableTypeDeclarations.SelectMany(typeDecl => typeDecl.ChildNodes().OfType<TTypeSyntax>());
var typeNodes = topMostTypeNodes.SelectMany(t => t.DescendantNodesAndSelf().OfType<TTypeSyntax>());
foreach (var typeNode in typeNodes)
{
var type = semanticModel.GetTypeInfo(typeNode, symbolContext.CancellationToken).Type;
if (type != null)
{
foreach (var innerType in type.GetBaseTypesAndThis())
{
if (innerType.Equals(_compilationType))
{
ReportDiagnostic(type, typeNode, symbolContext);
return;
}
}
foreach (var iface in type.AllInterfaces)
{
if (iface.Equals(_symbolType))
{
ReportDiagnostic(type, typeNode, symbolContext);
return;
}
}
}
}
}
private static void ReportDiagnostic(ITypeSymbol type, TTypeSyntax typeSyntax, SymbolAnalysisContext context)
{
var diagnostic = Diagnostic.Create(DoNotStorePerCompilationDataOntoFieldsRule, typeSyntax.GetLocation(), type.ToDisplayString());
context.ReportDiagnostic(diagnostic);
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
{
public abstract class DiagnosticDescriptorCreationAnalyzer<TClassDeclarationSyntax, TObjectCreationExpressionSyntax, TLanguageKindEnum> : DiagnosticAnalyzer
where TClassDeclarationSyntax : SyntaxNode
where TObjectCreationExpressionSyntax : SyntaxNode
where TLanguageKindEnum : struct
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.UseLocalizableStringsInDescriptorTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.UseLocalizableStringsInDescriptorMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.UseLocalizableStringsInDescriptorDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
public static DiagnosticDescriptor UseLocalizableStringsInDescriptorRule = new DiagnosticDescriptor(
DiagnosticIds.UseLocalizableStringsInDescriptorRuleId,
s_localizableTitle,
s_localizableMessage,
DiagnosticCategory.AnalyzerLocalization,
DiagnosticSeverity.Warning,
isEnabledByDefault: false,
description: s_localizableDescription,
customTags: WellKnownDiagnosticTags.Telemetry);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(UseLocalizableStringsInDescriptorRule);
}
}
protected abstract ImmutableArray<TLanguageKindEnum> SyntaxKindsOfInterest { get; }
public override void Initialize(AnalysisContext context)
{
context.RegisterCompilationStartAction(compilationContext =>
{
var diagnosticDescriptorType = compilationContext.Compilation.GetTypeByMetadataName(DiagnosticAnalyzerCorrectnessAnalyzer.DiagnosticDescriptorFullName);
if (diagnosticDescriptorType == null)
{
return;
}
var analyzer = GetAnalyzer(compilationContext.Compilation, diagnosticDescriptorType);
if (analyzer == null)
{
return;
}
compilationContext.RegisterSyntaxNodeAction(c => analyzer.AnalyzeObjectCreation(c), SyntaxKindsOfInterest);
});
}
protected abstract CompilationAnalyzer GetAnalyzer(Compilation compilation, INamedTypeSymbol diagnosticDescriptorType);
protected abstract class CompilationAnalyzer
{
private readonly INamedTypeSymbol _diagnosticDescriptorType;
protected CompilationAnalyzer(INamedTypeSymbol diagnosticDescriptorType)
{
_diagnosticDescriptorType = diagnosticDescriptorType;
}
protected abstract SyntaxNode GetObjectCreationType(TObjectCreationExpressionSyntax objectCreation);
public void AnalyzeObjectCreation(SyntaxNodeAnalysisContext context)
{
var objectCreation = (TObjectCreationExpressionSyntax)context.Node;
var symbol = context.SemanticModel.GetSymbolInfo(objectCreation).Symbol;
if (symbol == null ||
symbol.Kind != SymbolKind.Method ||
!_diagnosticDescriptorType.Equals(symbol.ContainingType) ||
!_diagnosticDescriptorType.InstanceConstructors.Any(c => c.Equals(symbol)))
{
return;
}
var method = (IMethodSymbol)symbol;
var title = method.Parameters.Where(p => p.Name == "title").FirstOrDefault();
if (title != null &&
title.Type != null &&
title.Type.SpecialType == SpecialType.System_String)
{
var typeName = GetObjectCreationType(objectCreation);
var diagnostic = Diagnostic.Create(UseLocalizableStringsInDescriptorRule, typeName.GetLocation(), DiagnosticAnalyzerCorrectnessAnalyzer.LocalizableStringFullName);
context.ReportDiagnostic(diagnostic);
}
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Editing;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.CodeFixes
{
public abstract class ApplyDiagnosticAnalyzerAttributeFix : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(DiagnosticIds.MissingDiagnosticAnalyzerAttributeRuleId); }
}
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var token = root.FindToken(context.Span.Start);
if (!token.Span.IntersectsWith(context.Span))
{
return;
}
var generator = SyntaxGenerator.GetGenerator(context.Document);
var classDecl = generator.GetDeclaration(token.Parent);
if (classDecl == null)
{
return;
}
// Register fixes.
// 1) Apply C# DiagnosticAnalyzerAttribute.
var title = string.Format(CodeAnalysisDiagnosticsResources.ApplyDiagnosticAnalyzerAttribute_1, LanguageNames.CSharp);
AddFix(title, context, root, classDecl, generator, LanguageNames.CSharp);
// 2) Apply VB DiagnosticAnalyzerAttribute.
title = string.Format(CodeAnalysisDiagnosticsResources.ApplyDiagnosticAnalyzerAttribute_1, LanguageNames.VisualBasic);
AddFix(title, context, root, classDecl, generator, LanguageNames.VisualBasic);
// 3) Apply both C# and VB DiagnosticAnalyzerAttributes.
title = string.Format(CodeAnalysisDiagnosticsResources.ApplyDiagnosticAnalyzerAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic);
AddFix(title, context, root, classDecl, generator, LanguageNames.CSharp, LanguageNames.VisualBasic);
}
protected abstract SyntaxNode ParseExpression(string expression);
private void AddFix(string codeFixTitle, CodeFixContext context, SyntaxNode root, SyntaxNode classDecl, SyntaxGenerator generator, params string[] languages)
{
var fix = new MyCodeAction(
codeFixTitle,
c => GetFix(context.Document, root, classDecl, generator, languages));
context.RegisterCodeFix(fix, context.Diagnostics);
}
private Task<Document> GetFix(Document document, SyntaxNode root, SyntaxNode classDecl, SyntaxGenerator generator, params string[] languages)
{
var languageNamesFullName = typeof(LanguageNames).FullName;
var arguments = new SyntaxNode[languages.Length];
for (int i = 0; i < languages.Length; i++)
{
var language = languages[i] == LanguageNames.CSharp ? nameof(LanguageNames.CSharp) : nameof(LanguageNames.VisualBasic);
var expressionToParse = languageNamesFullName + "." + language;
var parsedExpression = ParseExpression(expressionToParse);
arguments[i] = generator.AttributeArgument(parsedExpression);
}
SyntaxNode attribute = generator.Attribute(DiagnosticAnalyzerCorrectnessAnalyzer.DiagnosticAnalyzerAttributeFullName, arguments);
var newClassDecl = generator.AddAttributes(classDecl, attribute);
var newRoot = root.ReplaceNode(classDecl, newClassDecl);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}
public sealed override FixAllProvider GetFixAllProvider()
{
return WellKnownFixAllProviders.BatchFixer;
}
private class MyCodeAction : DocumentChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument)
: base(title, createChangedDocument)
{
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
{
public abstract class ReportDiagnosticAnalyzer<TClassDeclarationSyntax, TInvocationExpressionSyntax, TIdentifierNameSyntax, TVariableDeclaratorSyntax> : DiagnosticAnalyzerCorrectnessAnalyzer
where TClassDeclarationSyntax : SyntaxNode
where TInvocationExpressionSyntax : SyntaxNode
where TIdentifierNameSyntax : SyntaxNode
where TVariableDeclaratorSyntax : SyntaxNode
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.InvalidReportDiagnosticTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.InvalidReportDiagnosticMessage), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
private static readonly LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.InvalidReportDiagnosticDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources));
public static DiagnosticDescriptor InvalidReportDiagnosticRule = new DiagnosticDescriptor(
DiagnosticIds.InvalidReportDiagnosticRuleId,
s_localizableTitle,
s_localizableMessage,
DiagnosticCategory.AnalyzerCorrectness,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: s_localizableDescription,
customTags: WellKnownDiagnosticTags.Telemetry);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(InvalidReportDiagnosticRule);
}
}
protected override DiagnosticAnalyzerSymbolAnalyzer GetDiagnosticAnalyzerSymbolAnalyzer(CompilationStartAnalysisContext compilationContext, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
{
var compilation = compilationContext.Compilation;
var compilationEndAnalysisContext = compilation.GetTypeByMetadataName(CompilationEndAnalysisContextFullName);
if (compilationEndAnalysisContext == null)
{
return null;
}
var codeBlockEndAnalysisContext = compilation.GetTypeByMetadataName(CodeBlockEndAnalysisContextFullName);
if (codeBlockEndAnalysisContext == null)
{
return null;
}
var semanticModelAnalysisContext = compilation.GetTypeByMetadataName(SemanticModelAnalysisContextFullName);
if (semanticModelAnalysisContext == null)
{
return null;
}
var symbolAnalysisContext = compilation.GetTypeByMetadataName(SymbolAnalysisContextFullName);
if (symbolAnalysisContext == null)
{
return null;
}
var syntaxNodeAnalysisContext = compilation.GetTypeByMetadataName(SyntaxNodeAnalysisContextFullName);
if (syntaxNodeAnalysisContext == null)
{
return null;
}
var syntaxTreeAnalysisContext = compilation.GetTypeByMetadataName(SyntaxTreeAnalysisContextFullName);
if (syntaxTreeAnalysisContext == null)
{
return null;
}
var diagnosticType = compilation.GetTypeByMetadataName(DiagnosticFullName);
if (diagnosticType == null)
{
return null;
}
var diagnosticDescriptorType = compilation.GetTypeByMetadataName(DiagnosticDescriptorFullName);
if (diagnosticDescriptorType == null)
{
return null;
}
var contextTypes = ImmutableHashSet.Create(compilationEndAnalysisContext, codeBlockEndAnalysisContext,
semanticModelAnalysisContext, symbolAnalysisContext, syntaxNodeAnalysisContext, syntaxTreeAnalysisContext);
return GetAnalyzer(contextTypes, diagnosticType, diagnosticDescriptorType, diagnosticAnalyzer, diagnosticAnalyzerAttribute);
}
protected abstract ReportDiagnosticCompilationAnalyzer GetAnalyzer(ImmutableHashSet<INamedTypeSymbol> contextTypes, INamedTypeSymbol diagnosticType, INamedTypeSymbol diagnosticDescriptorType, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute);
protected abstract class ReportDiagnosticCompilationAnalyzer : SyntaxNodeWithinAnalyzerTypeCompilationAnalyzer<TClassDeclarationSyntax, TInvocationExpressionSyntax>
{
private readonly ImmutableHashSet<INamedTypeSymbol> _contextTypes;
private readonly INamedTypeSymbol _diagnosticType;
private readonly INamedTypeSymbol _diagnosticDescriptorType;
private ImmutableDictionary<INamedTypeSymbol, ImmutableArray<IFieldSymbol>> _supportedDescriptorFieldsMap;
public ReportDiagnosticCompilationAnalyzer(ImmutableHashSet<INamedTypeSymbol> contextTypes, INamedTypeSymbol diagnosticType, INamedTypeSymbol diagnosticDescriptorType, INamedTypeSymbol diagnosticAnalyzer, INamedTypeSymbol diagnosticAnalyzerAttribute)
: base(diagnosticAnalyzer, diagnosticAnalyzerAttribute)
{
_contextTypes = contextTypes;
_diagnosticType = diagnosticType;
_diagnosticDescriptorType = diagnosticDescriptorType;
_supportedDescriptorFieldsMap = ImmutableDictionary<INamedTypeSymbol, ImmutableArray<IFieldSymbol>>.Empty;
}
protected abstract IEnumerable<SyntaxNode> GetArgumentExpressions(TInvocationExpressionSyntax invocation);
protected virtual SyntaxNode GetPropertyGetterBlockSyntax(SyntaxNode declaringSyntaxRefNode)
{
return declaringSyntaxRefNode;
}
protected override void AnalyzeDiagnosticAnalyzer(SymbolAnalysisContext symbolContext)
{
var descriptorFields = GetSupportedDescriptors(symbolContext.Compilation, (INamedTypeSymbol)symbolContext.Symbol, symbolContext.CancellationToken);
if (!descriptorFields.IsDefaultOrEmpty)
{
base.AnalyzeDiagnosticAnalyzer(symbolContext);
}
}
private ImmutableArray<IFieldSymbol> GetSupportedDescriptors(Compilation compilation, INamedTypeSymbol analyzer, CancellationToken cancellationToken)
{
ImmutableArray<IFieldSymbol> descriptorFields;
if (_supportedDescriptorFieldsMap.TryGetValue(analyzer, out descriptorFields))
{
return descriptorFields;
}
descriptorFields = default(ImmutableArray<IFieldSymbol>);
var supportedDiagnosticBaseProperty = this.DiagnosticAnalyzer.GetMembers(SupportedDiagnosticsName).FirstOrDefault() as IPropertySymbol;
if (supportedDiagnosticBaseProperty != null)
{
var supportedDiagnosticsProperty = analyzer.GetMembers()
.OfType<IPropertySymbol>()
.FirstOrDefault(p => p.OverriddenProperty != null &&
p.OverriddenProperty.Equals(supportedDiagnosticBaseProperty));
if (supportedDiagnosticsProperty != null && supportedDiagnosticsProperty.GetMethod != null)
{
var syntaxRef = supportedDiagnosticsProperty.GetMethod.DeclaringSyntaxReferences.FirstOrDefault();
if (syntaxRef != null)
{
var syntax = syntaxRef.GetSyntax(cancellationToken);
syntax = GetPropertyGetterBlockSyntax(syntax);
if (syntax != null)
{
var semanticModel = compilation.GetSemanticModel(syntax.SyntaxTree);
descriptorFields = GetReferencedDescriptorFields(syntax, semanticModel);
}
}
}
}
return ImmutableInterlocked.GetOrAdd(ref _supportedDescriptorFieldsMap, analyzer, descriptorFields);
}
private ImmutableArray<IFieldSymbol> GetReferencedDescriptorFields(SyntaxNode syntax, SemanticModel semanticModel)
{
var builder = ImmutableArray.CreateBuilder<IFieldSymbol>();
foreach (var identifier in syntax.DescendantNodes().OfType<TIdentifierNameSyntax>())
{
var symbol = semanticModel.GetSymbolInfo(identifier).Symbol;
if (symbol != null && symbol.Kind == SymbolKind.Field)
{
var field = (IFieldSymbol)symbol;
var fieldType = field.Type as INamedTypeSymbol;
if (fieldType != null && fieldType.GetBaseTypesAndThis().Contains(_diagnosticDescriptorType))
{
builder.Add((IFieldSymbol)symbol);
}
}
}
return builder.ToImmutable();
}
protected override void AnalyzeNode(SymbolAnalysisContext symbolContext, TInvocationExpressionSyntax invocation, SemanticModel semanticModel)
{
var symbol = semanticModel.GetSymbolInfo(invocation, symbolContext.CancellationToken).Symbol;
if (symbol == null ||
symbol.Kind != SymbolKind.Method ||
!symbol.Name.Equals(ReportDiagnosticName, StringComparison.OrdinalIgnoreCase) ||
!_contextTypes.Contains(symbol.ContainingType))
{
return;
}
var arguments = GetArgumentExpressions(invocation);
if (arguments.Count() == 1)
{
var argument = arguments.First();
var type = semanticModel.GetTypeInfo(argument, symbolContext.CancellationToken).ConvertedType;
if (type != null && type.Equals(_diagnosticType))
{
var argSymbol = semanticModel.GetSymbolInfo(argument, symbolContext.CancellationToken).Symbol;
if (argSymbol != null)
{
SyntaxNode diagnosticInitializerOpt = null;
var local = argSymbol as ILocalSymbol;
if (local != null)
{
var syntaxRef = local.DeclaringSyntaxReferences.FirstOrDefault();
if (syntaxRef != null)
{
diagnosticInitializerOpt = syntaxRef.GetSyntax(symbolContext.CancellationToken).FirstAncestorOrSelf<TVariableDeclaratorSyntax>();
}
}
else
{
var method = argSymbol as IMethodSymbol;
if (method != null &&
method.ContainingType.Equals(_diagnosticType) &&
method.Name.Equals(nameof(Diagnostic.Create), StringComparison.OrdinalIgnoreCase))
{
diagnosticInitializerOpt = argument;
}
}
if (diagnosticInitializerOpt != null)
{
var descriptorFields = GetReferencedDescriptorFields(diagnosticInitializerOpt, semanticModel);
if (descriptorFields.Length == 1 &&
!_supportedDescriptorFieldsMap[(INamedTypeSymbol)symbolContext.Symbol].Contains(descriptorFields[0]))
{
var diagnostic = Diagnostic.Create(InvalidReportDiagnosticRule, invocation.GetLocation(), descriptorFields[0].Name);
symbolContext.ReportDiagnostic(diagnostic);
}
}
}
}
}
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Resources;
[assembly: NeutralResourcesLanguage("en-US")]
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
</packages>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="Settings">
<Import Project="..\..\..\..\build\Targets\VSL.Settings.targets" />
</ImportGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{54F6AE18-B0CD-4799-9DF0-9B1AAD6A78AF}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.Analyzers.Setup</RootNamespace>
<AssemblyName>Microsoft.CodeAnalysis.Analyzers.Setup</AssemblyName>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<VSSDKTargetPlatformRegRootSuffix>RoslynDev</VSSDKTargetPlatformRegRootSuffix>
<IncludeAssemblyInVSIXContainer>false</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<ImportVSSDKTargets>true</ImportVSSDKTargets>
<MinimumVisualStudioVersion>$(VisualStudioVersion)</MinimumVisualStudioVersion>
<SolutionDir Condition="'$(SolutionDir)' == '' OR '$(SolutionDir)' == '*Undefined*'">..\..\..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix RoslynDev /log</StartArguments>
</PropertyGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\CodeAnalysisDiagnosticAnalyzers.csproj">
<Project>{d8762a0a-3832-47be-bcf6-8b1060be6b28}</Project>
<Name>CodeAnalysisDiagnosticAnalyzers</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup</IncludeOutputGroupsInVSIXLocalOnly>
<ForceIncludeInVSIX>true</ForceIncludeInVSIX>
</ProjectReference>
<ProjectReference Include="..\CSharp\CSharpCodeAnalysisDiagnosticAnalyzers.csproj">
<Project>{921b412a-5551-4853-82b4-46ad5a05a03e}</Project>
<Name>CSharpCodeAnalysisDiagnosticAnalyzers</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup</IncludeOutputGroupsInVSIXLocalOnly>
<ForceIncludeInVSIX>true</ForceIncludeInVSIX>
</ProjectReference>
<ProjectReference Include="..\VisualBasic\BasicCodeAnalysisDiagnosticAnalyzers.vbproj">
<Project>{b1a6a74b-e484-48fb-8745-7a30a06db631}</Project>
<Name>BasicCodeAnalysisDiagnosticAnalyzers</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup</IncludeOutputGroupsInVSIXLocalOnly>
<ForceIncludeInVSIX>true</ForceIncludeInVSIX>
</ProjectReference>
</ItemGroup>
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="41880BF7-B087-402F-AE29-18A367E9DF9B" Version="|%CurrentProject%;GetBuildVersion|" Language="en-US" Publisher="Microsoft" />
<DisplayName>.NET Compiler Platform (Roslyn) Analyzers</DisplayName>
<Description xml:space="preserve">Analyzers for .NET Compiler Platform (Roslyn) APIs.</Description>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[12.0,]" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.Analyzer" Path="|CodeAnalysisDiagnosticAnalyzers|" />
<Asset Type="Microsoft.VisualStudio.Analyzer" Path="|BasicCodeAnalysisDiagnosticAnalyzers|" />
<Asset Type="Microsoft.VisualStudio.Analyzer" Path="|CSharpCodeAnalysisDiagnosticAnalyzers|" />
</Assets>
</PackageManifest>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="Settings">
<Import Project="..\..\..\..\build\Targets\VSL.Settings.targets" />
</ImportGroup>
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<ProjectGuid>{0C2925AD-CD97-46FA-A686-E2C1AD19DAD8}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.UnitTests</RootNamespace>
<AssemblyName>Roslyn.CodeAnalysis.Analyzers.UnitTests</AssemblyName>
<Nonshipping>true</Nonshipping>
<SolutionDir Condition="'$(SolutionDir)' == '' OR '$(SolutionDir)' == '*Undefined*'">..\..\..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\CodeAnalysis.csproj">
<Project>{1EE8CAD3-55F9-4D91-96B2-084641DA9A6C}</Project>
<Name>CodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj">
<Project>{B501A547-C911-4A05-AC6E-274A50DFF30E}</Project>
<Name>CSharpCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\BasicCodeAnalysis.vbproj">
<Project>{2523D0E6-DF32-4A3E-8AE0-A19BFFAE2EF6}</Project>
<Name>BasicCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Test\Utilities\Desktop\TestUtilities.Desktop.csproj">
<Project>{76C6F005-C89D-4348-BB4A-391898DBEB52}</Project>
<Name>TestUtilities.Desktop</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Workspaces\CSharp\Portable\CSharpWorkspace.csproj">
<Project>{21B239D0-D144-430F-A394-C066D58EE267}</Project>
<Name>CSharpWorkspace</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Workspaces\VisualBasic\Portable\BasicWorkspace.vbproj">
<Project>{57CA988D-F010-4BF2-9A2E-07D6DCD2FF2C}</Project>
<Name>BasicWorkspace</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Workspaces.csproj">
<Project>{5F8D2414-064A-4B3A-9B42-8E2A04246BE5}</Project>
<Name>Workspaces</Name>
</ProjectReference>
<ProjectReference Include="..\..\Test\Utilities\DiagnosticsTestUtilities.csproj">
<Project>{0A0621F2-D1DC-47FF-B643-C6646557505E}</Project>
<Name>DiagnosticsTestUtilities</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Compilers\Test\Resources\Core\CompilerTestResources.csproj">
<Project>{7FE6B002-89D8-4298-9B1B-0B5C247DD1FD}</Project>
<Name>CompilerTestResources</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\Core\CodeAnalysisDiagnosticAnalyzers.csproj">
<Project>{d8762a0a-3832-47be-bcf6-8b1060be6b28}</Project>
<Name>CodeAnalysisDiagnosticAnalyzers</Name>
</ProjectReference>
<ProjectReference Include="..\CSharp\CSharpCodeAnalysisDiagnosticAnalyzers.csproj">
<Project>{921b412a-5551-4853-82b4-46ad5a05a03e}</Project>
<Name>CSharpCodeAnalysisDiagnosticAnalyzers</Name>
</ProjectReference>
<ProjectReference Include="..\VisualBasic\BasicCodeAnalysisDiagnosticAnalyzers.vbproj">
<Project>{b1a6a74b-e484-48fb-8745-7a30a06db631}</Project>
<Name>BasicCodeAnalysisDiagnosticAnalyzers</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\System.Collections.Immutable.$(SystemCollectionsImmutableVersion)\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="xunit">
<HintPath>..\..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Compile Include="FixAnalyzers\FixerWithFixAllAnalyzerTests.cs" />
<Compile Include="InternalImplementationOnlyTests.cs" />
<Compile Include="MetaAnalyzers\DoNotStorePerCompilationDataOntoFieldsRuleTests.cs" />
<Compile Include="MetaAnalyzers\InvalidReportDiagnosticRuleTests.cs" />
<Compile Include="MetaAnalyzers\StartActionWithOnlyEndActionRuleTests.cs" />
<Compile Include="MetaAnalyzers\StartActionWithNoRegisteredActionsRuleTests.cs" />
<Compile Include="MetaAnalyzers\InvalidSyntaxKindTypeArgumentRuleTests.cs" />
<Compile Include="MetaAnalyzers\UnsupportedSymbolKindArgumentRuleTests.cs" />
<Compile Include="MetaAnalyzers\MissingKindArgumentToRegisterActionRuleTests.cs" />
<Compile Include="MetaAnalyzers\UseLocalizableStringsInDescriptorTests.cs" />
<Compile Include="MetaAnalyzers\AddLanguageSupportToAnalyzerRuleTests.cs" />
<Compile Include="MetaAnalyzers\MissingDiagnosticAnalyzerAttributeRuleTests.cs" />
</ItemGroup>
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
<Import Project="..\..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.Analyzers;
using Microsoft.CodeAnalysis.Diagnostics;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests.Analyzers
{
public class InternalImplementationOnlyTests : DiagnosticAnalyzerTestBase
{
private const string AttributeStringCSharp = @"
namespace System.Runtime.CompilerServices
{
internal class InternalImplementationOnlyAttribute : System.Attribute {}
}
";
[Fact]
public void CSharp_VerifySameAssembly()
{
var source = AttributeStringCSharp + @"
[System.Runtime.CompilerServices.InternalImplementationOnly]
public interface IFoo { }
class Foo : IFoo { }
";
// Verify no diagnostic since interface is in the same assembly.
VerifyCSharp(source, addLanguageSpecificCodeAnalysisReference: false);
}
[Fact]
public void CSharp_VerifyDifferentAssembly()
{
var source1 = AttributeStringCSharp + @"
[System.Runtime.CompilerServices.InternalImplementationOnly]
public interface IFoo { }
public interface IBar : IFoo { }
";
var source2 = @"
class Foo : IFoo { }
class Boo : IBar { }";
var expected = new[] { GetCSharpExpectedDiagnostic(2, 7, "Foo", "IFoo"), GetCSharpExpectedDiagnostic(4, 7, "Boo", "IFoo") };
// Verify errors since interface is not in a friend assembly.
VerifyCSharpAcrossTwoAssemblies(source1, source2, expected);
}
[Fact]
public void CSharp_VerifyDifferentFriendAssembly()
{
var source1 = @"
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""TestProject"")]
" + AttributeStringCSharp + @"
[System.Runtime.CompilerServices.InternalImplementationOnly]
public interface IFoo { }
public interface IBar : IFoo { }
";
var source2 = @"
class Foo : IFoo { }
class Boo : IBar { }";
// Verify no diagnostic since interface is in a friend assembly.
VerifyCSharpAcrossTwoAssemblies(source1, source2);
}
[Fact]
public void CSharp_VerifyISymbol()
{
var source = @"
class Foo : Microsoft.CodeAnalysis.ISymbol { }
class Bar : Microsoft.CodeAnalysis.IAssemblySymbol { }
";
var expected = new[] { GetCSharpExpectedDiagnostic(2, 7, "Foo", "ISymbol"), GetCSharpExpectedDiagnostic(3, 7, "Bar", "ISymbol") };
// Verify that ISymbol is not implementable.
VerifyCSharp(source, addLanguageSpecificCodeAnalysisReference: true, expected: expected);
}
private const string AttributeStringBasic = @"
Namespace System.Runtime.CompilerServices
Friend Class InternalImplementationOnlyAttribute
Inherits System.Attribute
End Class
End Namespace
";
[Fact]
public void Basic_VerifySameAssembly()
{
var source = AttributeStringBasic + @"
<System.Runtime.CompilerServices.InternalImplementationOnly>
Public Interface IFoo
End Interface
Class Foo
Implements IFoo
End Class
";
// Verify no diagnostic since interface is in the same assembly.
VerifyBasic(source, addLanguageSpecificCodeAnalysisReference: false);
}
[Fact]
public void Basic_VerifyDifferentAssembly()
{
var source1 = AttributeStringBasic + @"
<System.Runtime.CompilerServices.InternalImplementationOnly>
Public Interface IFoo
End Interface
Public Interface IBar
Inherits IFoo
End Interface
";
var source2 = @"
Class Foo
Implements IFoo
End Class
Class Bar
Implements IBar
End Class
";
var expected = new[] { GetBasicExpectedDiagnostic(2, 7, "Foo", "IFoo"), GetBasicExpectedDiagnostic(6, 7, "Bar", "IFoo") };
// Verify errors since interface is not in a friend assembly.
VerifyBasicAcrossTwoAssemblies(source1, source2, expected);
}
[Fact]
public void Basic_VerifyDifferentFriendAssembly()
{
var source1 = @"
<Assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""TestProject"")>
" + AttributeStringBasic + @"
<System.Runtime.CompilerServices.InternalImplementationOnly>
Public Interface IFoo
End Interface
Public Interface IBar
Inherits IFoo
End Interface
";
var source2 = @"
Class Foo
Implements IFoo
End Class
Class Bar
Implements IBar
End Class
";
// Verify no diagnostic since interface is in a friend assembly.
VerifyBasicAcrossTwoAssemblies(source1, source2);
}
[Fact]
public void Basic_VerifyISymbol()
{
var source = @"
Class Foo
Implements Microsoft.CodeAnalysis.ISymbol
End Class
Class Bar
Implements Microsoft.CodeAnalysis.IAssemblySymbol
End Class
";
var expected = new[] { GetBasicExpectedDiagnostic(2, 7, "Foo", "ISymbol"), GetBasicExpectedDiagnostic(5, 7, "Bar", "ISymbol") };
// Verify that ISymbol is not implementable.
VerifyBasic(source, addLanguageSpecificCodeAnalysisReference: true, expected: expected);
}
private void VerifyAcrossTwoAssemblies(string source1, string source2, string language, params DiagnosticResult[] expected)
{
Debug.Assert(language == LanguageNames.CSharp || language == LanguageNames.VisualBasic);
var project1 = CreateProject(new string[] { source1 }, language: language, addLanguageSpecificCodeAnalysisReference: false);
var project2 = CreateProject(new string[] { source2 }, language: language, addLanguageSpecificCodeAnalysisReference: false, addToSolution: project1.Solution)
.AddProjectReference(new ProjectReference(project1.Id));
var analyzer = language == LanguageNames.CSharp ? GetCSharpDiagnosticAnalyzer() : GetBasicDiagnosticAnalyzer();
GetSortedDiagnostics(analyzer, project2.Documents.ToArray()).Verify(analyzer, expected);
}
private void VerifyCSharpAcrossTwoAssemblies(string source1, string source2, params DiagnosticResult[] expected)
{
VerifyAcrossTwoAssemblies(source1, source2, LanguageNames.CSharp, expected);
}
private void VerifyBasicAcrossTwoAssemblies(string source1, string source2, params DiagnosticResult[] expected)
{
VerifyAcrossTwoAssemblies(source1, source2, LanguageNames.VisualBasic, expected);
}
protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
{
return new InternalImplementationOnlyAnalyzer();
}
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new InternalImplementationOnlyAnalyzer();
}
private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, string typeName, string interfaceName)
{
return GetExpectedDiagnostic(LanguageNames.CSharp, line, column, typeName, interfaceName);
}
private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string typeName, string interfaceName)
{
return GetExpectedDiagnostic(LanguageNames.VisualBasic, line, column, typeName, interfaceName);
}
private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string typeName, string interfaceName)
{
var fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";
return new DiagnosticResult
{
Id = DiagnosticIds.InternalImplementationOnlyRuleId,
Message = string.Format(CodeAnalysisDiagnosticsResources.InternalImplementationOnlyMessage, typeName, interfaceName),
Severity = DiagnosticSeverity.Error,
Locations = new[]
{
new DiagnosticResultLocation(fileName, line, column)
}
};
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Analyzers;
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests.Analyzers.MetaAnalyzers
{
public class AddLanguageSupportToAnalyzerRuleTests : CodeFixTestBase
{
[Fact]
public void CSharp_VerifyDiagnostic()
{
var source = @"
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
[DiagnosticAnalyzer(LanguageNames.CSharp, ""MyLanguage"")]
class MyAnalyzer : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
throw new NotImplementedException();
}
}
public override void Initialize(AnalysisContext context)
{
}
}";
var expected = GetCSharpExpectedDiagnostic(7, 2, "MyAnalyzer", missingLanguageName: LanguageNames.VisualBasic);
// Verify diagnostic if analyzer assembly doesn't reference C# code analysis assembly.
VerifyCSharp(source, addLanguageSpecificCodeAnalysisReference: false, expected: expected);
// Verify no diagnostic if analyzer assembly references C# code analysis assembly.
VerifyCSharp(source, addLanguageSpecificCodeAnalysisReference: true);
}
[Fact]
public void VisualBasic_VerifyDiagnostic()
{
var source = @"
Imports System
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Diagnostics
<DiagnosticAnalyzer(LanguageNames.VisualBasic, ""MyLanguage"")>
Class MyAnalyzer
Inherits DiagnosticAnalyzer
Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Throw New NotImplementedException()
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
End Sub
End Class
";
var expected = GetBasicExpectedDiagnostic(7, 2, "MyAnalyzer", missingLanguageName: LanguageNames.CSharp);
// Verify diagnostic if analyzer assembly doesn't reference VB code analysis assembly.
VerifyBasic(source, addLanguageSpecificCodeAnalysisReference: false, expected: expected);
// Verify no diagnostic if analyzer assembly references VB code analysis assembly.
VerifyBasic(source, addLanguageSpecificCodeAnalysisReference: true);
}
[Fact]
public void CSharp_NoDiagnosticCases()
{
var source = @"
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
[DiagnosticAnalyzer(""MyLanguage"")]
class MyAnalyzerWithCustomLanguageAttribute : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
throw new NotImplementedException();
}
}
public override void Initialize(AnalysisContext context)
{
}
}
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
class MyAnalyzerWithBothLanguages : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
throw new NotImplementedException();
}
}
public override void Initialize(AnalysisContext context)
{
}
}
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public abstract class MyAbstractAnalyzer : DiagnosticAnalyzer
{
}
";
VerifyCSharp(source, addLanguageSpecificCodeAnalysisReference: false);
VerifyCSharp(source, addLanguageSpecificCodeAnalysisReference: true);
}
[Fact]
public void VisualBasic_NoDiagnosticCases()
{
var source = @"
Imports System
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Diagnostics
<DiagnosticAnalyzer(""MyLanguage"")>
Class MyAnalyzerWithCustomLanguageAttribute
Inherits DiagnosticAnalyzer
Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Throw New NotImplementedException()
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
End Sub
End Class
<DiagnosticAnalyzer(LanguageNames.VisualBasic, LanguageNames.CSharp)>
Class MyAnalyzerWithBothLanguages
Inherits DiagnosticAnalyzer
Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Throw New NotImplementedException()
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
End Sub
End Class
<DiagnosticAnalyzer(LanguageNames.VisualBasic)>
Public MustInherit Class MyAbstractAnalyzer
Inherits DiagnosticAnalyzer
End Class
";
VerifyBasic(source, addLanguageSpecificCodeAnalysisReference: false);
VerifyBasic(source, addLanguageSpecificCodeAnalysisReference: true);
}
protected override CodeFixProvider GetCSharpCodeFixProvider()
{
return null;
}
protected override CodeFixProvider GetBasicCodeFixProvider()
{
return null;
}
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new DiagnosticAnalyzerAttributeAnalyzer();
}
protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
{
return new DiagnosticAnalyzerAttributeAnalyzer();
}
private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, string analyzerTypeName, string missingLanguageName)
{
return GetExpectedDiagnostic(LanguageNames.CSharp, line, column, analyzerTypeName, missingLanguageName);
}
private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string analyzerTypeName, string missingLanguageName)
{
return GetExpectedDiagnostic(LanguageNames.VisualBasic, line, column, analyzerTypeName, missingLanguageName);
}
private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string analyzerTypeName, string missingLanguageName)
{
var fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";
return new DiagnosticResult
{
Id = DiagnosticIds.AddLanguageSupportToAnalyzerRuleId,
Message = string.Format(CodeAnalysisDiagnosticsResources.AddLanguageSupportToAnalyzerMessage, analyzerTypeName, missingLanguageName),
Severity = DiagnosticSeverity.Warning,
Locations = new[]
{
new DiagnosticResultLocation(fileName, line, column)
}
};
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Analyzers;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.VisualBasic;
using Microsoft.CodeAnalysis.VisualBasic.Analyzers.MetaAnalyzers;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests.Analyzers.MetaAnalyzers
{
public class DoNotStorePerCompilationDataOntoFieldsRuleTests : CodeFixTestBase
{
[Fact]
public void CSharp_VerifyDiagnostic()
{
var source = @"
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using MyNamedType = Microsoft.CodeAnalysis.INamedTypeSymbol;
class MyCompilation : Compilation
{
}
[DiagnosticAnalyzer(LanguageNames.CSharp)]
class MyAnalyzer : DiagnosticAnalyzer
{
private static readonly ITypeSymbol x1;
public static readonly CSharpCompilation x2;
private readonly List<MyNamedType> x3;
private static Dictionary<MyCompilation, MyNamedType> x4;
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
throw new NotImplementedException();
}
}
public override void Initialize(AnalysisContext context)
{
}
}";
var expected = new[]
{
GetCSharpExpectedDiagnostic(17, 29, violatingTypeName: typeof(ITypeSymbol).FullName),
GetCSharpExpectedDiagnostic(18, 28, violatingTypeName: typeof(CSharpCompilation).FullName),
GetCSharpExpectedDiagnostic(19, 27, violatingTypeName: typeof(INamedTypeSymbol).FullName),
GetCSharpExpectedDiagnostic(20, 31, violatingTypeName: "MyCompilation")
};
VerifyCSharp(source, expected);
}
[Fact]
public void VisualBasic_VerifyDiagnostic()
{
var source = @"
Imports System
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.VisualBasic
Imports MyNamedType = Microsoft.CodeAnalysis.INamedTypeSymbol
Class MyCompilation
Inherits Compilation
End Class
<DiagnosticAnalyzer(LanguageNames.VisualBasic)>
Class MyAnalyzer
Inherits DiagnosticAnalyzer
Private Shared ReadOnly x1 As ITypeSymbol
Public Shared ReadOnly x2 As VisualBasicCompilation
Private ReadOnly x3 As List(Of MyNamedType)
Private Shared x4 As Dictionary(Of MyCompilation, MyNamedType)
Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Throw New NotImplementedException
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
End Sub
End Class
";
var expected = new[]
{
GetBasicExpectedDiagnostic(17, 35, violatingTypeName: typeof(ITypeSymbol).FullName),
GetBasicExpectedDiagnostic(18, 34, violatingTypeName: typeof(VisualBasicCompilation).FullName),
GetBasicExpectedDiagnostic(19, 36, violatingTypeName: typeof(INamedTypeSymbol).FullName),
GetBasicExpectedDiagnostic(20, 40, violatingTypeName: "MyCompilation")
};
VerifyBasic(source, expected);
}
[Fact]
public void CSharp_NoDiagnosticCases()
{
var source = @"
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using MyNamedType = Microsoft.CodeAnalysis.INamedTypeSymbol;
class MyCompilation : Compilation
{
}
[DiagnosticAnalyzer(LanguageNames.CSharp)]
class MyAnalyzer : DiagnosticAnalyzer
{
private static readonly DiagnosticDescriptor x1;
private readonly List<LocalizableResourceString> x2;
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
throw new NotImplementedException();
}
}
public override void Initialize(AnalysisContext context)
{
var analyzer = new NestedCompilationAnalyzer();
context.RegisterCompilationStartAction(analyzer.StartCompilation);
}
private class NestedCompilationAnalyzer
{
// Ok to store per-compilation data here.
private readonly Dictionary<MyCompilation, MyNamedType> x;
internal void StartCompilation(CompilationStartAnalysisContext context)
{
}
}
}
class MyAnalyzerWithoutAttribute : DiagnosticAnalyzer
{
// Ok to store per-compilation data here.
private static ITypeSymbol x;
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
throw new NotImplementedException();
}
}
public override void Initialize(AnalysisContext context)
{
throw new NotImplementedException();
}
}";
VerifyCSharp(source);
}
[Fact]
public void VisualBasic_NoDiagnosticCases()
{
var source = @"
Imports System
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.VisualBasic
Imports MyNamedType = Microsoft.CodeAnalysis.INamedTypeSymbol
Class MyCompilation
Inherits Compilation
End Class
<DiagnosticAnalyzer(LanguageNames.VisualBasic)>
Class MyAnalyzer
Inherits DiagnosticAnalyzer
Private Shared ReadOnly x1 As DiagnosticDescriptor
Private ReadOnly x2 As List(Of LocalizableResourceString)
Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Throw New NotImplementedException
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
Dim compilationAnalyzer = New NestedCompilationAnalyzer
context.RegisterCompilationStartAction(AddressOf compilationAnalyzer.StartCompilation)
End Sub
Class NestedCompilationAnalyzer
' Ok to store per-compilation data here.
Private ReadOnly x As Dictionary(Of MyCompilation, MyNamedType)
Friend Sub StartCompilation(context As CompilationStartAnalysisContext)
End Sub
End Class
End Class
Class MyAnalyzerWithoutAttribute
Inherits DiagnosticAnalyzer
' Ok to store per-compilation data here.
Private Shared x As ITypeSymbol
Public Overrides ReadOnly Property SupportedDiagnostics As ImmutableArray(Of DiagnosticDescriptor)
Get
Throw New NotImplementedException()
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
Throw New NotImplementedException()
End Sub
End Class
";
VerifyBasic(source);
}
protected override CodeFixProvider GetCSharpCodeFixProvider()
{
return null;
}
protected override CodeFixProvider GetBasicCodeFixProvider()
{
return null;
}
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new CSharpDiagnosticAnalyzerFieldsAnalyzer();
}
protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
{
return new BasicDiagnosticAnalyzerFieldsAnalyzer();
}
private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, string violatingTypeName)
{
return GetExpectedDiagnostic(LanguageNames.CSharp, line, column, violatingTypeName);
}
private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string violatingTypeName)
{
return GetExpectedDiagnostic(LanguageNames.VisualBasic, line, column, violatingTypeName);
}
private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string violatingTypeName)
{
var fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";
return new DiagnosticResult
{
Id = DiagnosticIds.DoNotStorePerCompilationDataOntoFieldsRuleId,
Message = string.Format(CodeAnalysisDiagnosticsResources.DoNotStorePerCompilationDataOntoFieldsMessage, violatingTypeName),
Severity = DiagnosticSeverity.Warning,
Locations = new[]
{
new DiagnosticResultLocation(fileName, line, column)
}
};
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Analyzers;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.VisualBasic.Analyzers.MetaAnalyzers;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests.Analyzers.MetaAnalyzers
{
public class InvalidReportDiagnosticRuleTests : CodeFixTestBase
{
[Fact]
public void CSharp_VerifyDiagnostic()
{
var source = @"
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
class MyAnalyzer : DiagnosticAnalyzer
{
private static readonly DiagnosticDescriptor descriptor = new TriggerDiagnosticDescriptor(""MyDiagnosticId"");
private static readonly DiagnosticDescriptor descriptor2 = new TriggerDiagnosticDescriptor(""MyDiagnosticId2"");
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(descriptor);
}
}
public override void Initialize(AnalysisContext context)
{
}
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None));
var diag = Diagnostic.Create(descriptor2, Location.None);
context.ReportDiagnostic(diag);
}
private static void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
{
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None));
Diagnostic diag = Diagnostic.Create(descriptor2, Location.None), diag2 = Diagnostic.Create(descriptor2, Location.None);
context.ReportDiagnostic(diag);
}
}";
var expected = new[]
{
GetCSharpExpectedDiagnostic(27, 9, unsupportedDescriptorName: "descriptor2"),
GetCSharpExpectedDiagnostic(30, 9, unsupportedDescriptorName: "descriptor2"),
GetCSharpExpectedDiagnostic(35, 9, unsupportedDescriptorName: "descriptor2"),
GetCSharpExpectedDiagnostic(38, 9, unsupportedDescriptorName: "descriptor2")
};
VerifyCSharp(source, expected);
}
[Fact]
public void VisualBasic_VerifyDiagnostic()
{
var source = @"
Imports System
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Diagnostics
<DiagnosticAnalyzer(LanguageNames.CSharp)>
Class MyAnalyzer
Inherits DiagnosticAnalyzer
Private Shared ReadOnly descriptor1 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor(""MyDiagnosticId"")
Private Shared ReadOnly descriptor2 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor(""MyDiagnosticId2"")
Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Return ImmutableArray.Create(descriptor1)
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
End Sub
Private Shared Sub AnalyzeSymbol(context As SymbolAnalysisContext)
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None))
Dim diag = Diagnostic.Create(descriptor2, Location.None)
context.ReportDiagnostic(diag)
End Sub
Private Shared Sub AnalyzeSyntax(context As SyntaxNodeAnalysisContext)
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None))
Dim diag = Diagnostic.Create(descriptor2, Location.None), diag2 = Diagnostic.Create(descriptor2, Location.None)
context.ReportDiagnostic(diag)
End Sub
End Class
";
var expected = new[]
{
GetBasicExpectedDiagnostic(24, 9, unsupportedDescriptorName: "descriptor2"),
GetBasicExpectedDiagnostic(27, 9, unsupportedDescriptorName: "descriptor2"),
GetBasicExpectedDiagnostic(31, 9, unsupportedDescriptorName: "descriptor2"),
GetBasicExpectedDiagnostic(34, 9, unsupportedDescriptorName: "descriptor2")
};
VerifyBasic(source, expected);
}
[Fact]
public void CSharp_NoDiagnosticCases()
{
var source = @"
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
class MyAnalyzer : DiagnosticAnalyzer
{
private static readonly DiagnosticDescriptor descriptor = new TriggerDiagnosticDescriptor(""MyDiagnosticId"");
private static readonly DiagnosticDescriptor descriptor2 = new TriggerDiagnosticDescriptor(""MyDiagnosticId2"");
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(descriptor);
}
}
public override void Initialize(AnalysisContext context)
{
}
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
// Overload resolution failures
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None), null);
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None, null));
context.ReportDiagnostic(diag);
// Needs flow analysis
var diag = Diagnostic.Create(descriptor2, Location.None);
var diag2 = diag;
context.ReportDiagnostic(diag2);
}
}";
VerifyCSharp(source);
}
[Fact]
public void VisualBasic_NoDiagnosticCases()
{
var source = @"
Imports System
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Diagnostics
<DiagnosticAnalyzer(LanguageNames.CSharp)>
Class MyAnalyzer
Inherits DiagnosticAnalyzer
Private Shared ReadOnly descriptor1 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor(""MyDiagnosticId"")
Private Shared ReadOnly descriptor2 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor(""MyDiagnosticId2"")
Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Return ImmutableArray.Create(descriptor1)
End Get
End Property
Public Overrides Sub Initialize(context As AnalysisContext)
End Sub
Private Shared Sub AnalyzeSymbol(context As SymbolAnalysisContext)
' Overload resolution failures
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None), Nothing)
context.ReportDiagnostic(Diagnostic.Create(descriptor2, Location.None, Nothing))
context.ReportDiagnostic(diag)
' Needs flow analysis
Dim diag = Diagnostic.Create(descriptor2, Location.None)
Dim diag2 = diag
context.ReportDiagnostic(diag2)
End Sub
End Class
";
VerifyBasic(source);
}
protected override CodeFixProvider GetCSharpCodeFixProvider()
{
return null;
}
protected override CodeFixProvider GetBasicCodeFixProvider()
{
return null;
}
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new CSharpReportDiagnosticAnalyzer();
}
protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
{
return new BasicReportDiagnosticAnalyzer();
}
private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, string unsupportedDescriptorName)
{
return GetExpectedDiagnostic(LanguageNames.CSharp, line, column, unsupportedDescriptorName);
}
private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string unsupportedDescriptorName)
{
return GetExpectedDiagnostic(LanguageNames.VisualBasic, line, column, unsupportedDescriptorName);
}
private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string unsupportedDescriptorName)
{
var fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";
return new DiagnosticResult
{
Id = DiagnosticIds.InvalidReportDiagnosticRuleId,
Message = string.Format(CodeAnalysisDiagnosticsResources.InvalidReportDiagnosticMessage, unsupportedDescriptorName),
Severity = DiagnosticSeverity.Warning,
Locations = new[]
{
new DiagnosticResultLocation(fileName, line, column)
}
};
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="1.9.2" targetFramework="net45" />
</packages>
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.Analyzers.MetaAnalyzers
<DiagnosticAnalyzer(LanguageNames.VisualBasic)>
Public Class BasicDiagnosticAnalyzerFieldsAnalyzer
Inherits DiagnosticAnalyzerFieldsAnalyzer(Of ClassBlockSyntax, FieldDeclarationSyntax, TypeSyntax, SimpleAsClauseSyntax)
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Simplification
Namespace Microsoft.CodeAnalysis.VisualBasic.Analyzers.MetaAnalyzers.CodeFixes
<ExportCodeFixProviderAttribute(LanguageNames.VisualBasic, Name:=NameOf(BasicApplyDiagnosticAnalyzerAttributeFix)), [Shared]>
Public Class BasicApplyDiagnosticAnalyzerAttributeFix
Inherits ApplyDiagnosticAnalyzerAttributeFix
Protected Overrides Function ParseExpression(expression As String) As SyntaxNode
Return SyntaxFactory.ParseExpression(expression).WithAdditionalAnnotations(Simplifier.Annotation)
End Function
End Class
End Namespace
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
</packages>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册