| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis; | ||
|
|
||
| namespace Roslyn.Diagnostics.Analyzers.Reliability | ||
| { | ||
| 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(INamedTypeSymbol symbol, INamedTypeSymbol candidateBaseType) | ||
| { | ||
| while (symbol != null) | ||
| { | ||
| if (symbol.Equals(candidateBaseType)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| symbol = symbol.BaseType; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
|
|
||
| namespace Roslyn.Diagnostics.Analyzers.Reliability | ||
| { | ||
| [DiagnosticAnalyzer] | ||
| public class MissingSharedAttributeAnalyzer : DiagnosticAnalyzer | ||
| { | ||
| public static DiagnosticDescriptor Rule = new DiagnosticDescriptor( | ||
| RoslynDiagnosticIds.MissingSharedAttributeRuleId, | ||
| RoslynDiagnosticsResources.MissingSharedAttributeDescription, | ||
| RoslynDiagnosticsResources.MissingSharedAttributeMessage, | ||
| "Reliability", | ||
| DiagnosticSeverity.Error, | ||
| isEnabledByDefault: true, | ||
| customTags: WellKnownDiagnosticTags.Telemetry); | ||
|
|
||
| public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics | ||
| { | ||
| get | ||
| { | ||
| return ImmutableArray.Create(Rule); | ||
| } | ||
| } | ||
|
|
||
| public override void Initialize(AnalysisContext context) | ||
| { | ||
| context.RegisterCompilationStartAction(compilationContext => | ||
| { | ||
| var exportAttribute = compilationContext.Compilation.GetTypeByMetadataName("System.Composition.ExportAttribute"); | ||
| if (exportAttribute == null) | ||
| { | ||
| // We don't need to check assemblies unless they're referencing both MEFv2, so we're done | ||
| return; | ||
| } | ||
| compilationContext.RegisterSymbolAction(c => AnalyzeSymbol(c, exportAttribute), SymbolKind.NamedType); | ||
| }); | ||
| } | ||
|
|
||
| private void AnalyzeSymbol(SymbolAnalysisContext symbolContext, INamedTypeSymbol exportAttribute) | ||
| { | ||
| var namedType = (INamedTypeSymbol)symbolContext.Symbol; | ||
| var namedTypeAttributes = AttributeHelpers.GetApplicableAttributes(namedType); | ||
|
|
||
| var exportAttributeApplication = namedTypeAttributes.FirstOrDefault(ad => AttributeHelpers.DerivesFrom(ad.AttributeClass, exportAttribute)); | ||
|
|
||
| if (exportAttributeApplication != null) | ||
| { | ||
| if (!namedTypeAttributes.Any(ad => ad.AttributeClass.Name == "SharedAttribute" && | ||
| ad.AttributeClass.ContainingNamespace.Equals(exportAttribute.ContainingNamespace))) | ||
| { | ||
| symbolContext.ReportDiagnostic(Diagnostic.Create(Rule, exportAttributeApplication.ApplicationSyntaxReference.GetSyntax().GetLocation())); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
|
|
||
| namespace Roslyn.Diagnostics.Analyzers.Reliability | ||
| { | ||
| [DiagnosticAnalyzer] | ||
| public class MixedVersionsOfMefAttributesAnalyzer : DiagnosticAnalyzer | ||
| { | ||
| private static readonly string[] MefNamespaces = new[] { "System.ComponentModel.Composition", "System.Composition" }; | ||
|
|
||
| public static DiagnosticDescriptor Rule = new DiagnosticDescriptor( | ||
| RoslynDiagnosticIds.MixedVersionsOfMefAttributesRuleId, | ||
| RoslynDiagnosticsResources.MixedVersionsOfMefAttributesDescription, | ||
| RoslynDiagnosticsResources.MixedVersionsOfMefAttributesMessage, | ||
| "Reliability", | ||
| DiagnosticSeverity.Error, | ||
| isEnabledByDefault: true, | ||
| customTags: WellKnownDiagnosticTags.Telemetry); | ||
|
|
||
| public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics | ||
| { | ||
| get | ||
| { | ||
| return ImmutableArray.Create(Rule); | ||
| } | ||
| } | ||
|
|
||
| public override void Initialize(AnalysisContext context) | ||
| { | ||
| context.RegisterCompilationStartAction(compilationContext => | ||
| { | ||
| var exportAttributes = new List<INamedTypeSymbol>(); | ||
| foreach (var mefNamespace in MefNamespaces) | ||
| { | ||
| var exportAttribute = compilationContext.Compilation.GetTypeByMetadataName(mefNamespace + ".ExportAttribute"); | ||
| if (exportAttribute == null) | ||
| { | ||
| // We don't need to check assemblies unless they're referencing both versions of MEF, so we're done | ||
| return; | ||
| } | ||
| exportAttributes.Add(exportAttribute); | ||
| } | ||
| compilationContext.RegisterSymbolAction(c => AnalyzeSymbol(c, exportAttributes), SymbolKind.NamedType); | ||
| }); | ||
| } | ||
|
|
||
| private void AnalyzeSymbol(SymbolAnalysisContext symbolContext, IEnumerable<INamedTypeSymbol> exportAttributes) | ||
| { | ||
| var namedType = (INamedTypeSymbol)symbolContext.Symbol; | ||
| var namedTypeAttributes = AttributeHelpers.GetApplicableAttributes(namedType); | ||
|
|
||
| // Figure out which export attributes are being used here | ||
| var appliedExportAttributes = exportAttributes.Where(e => namedTypeAttributes.Any(ad => AttributeHelpers.DerivesFrom(ad.AttributeClass, e))).ToList(); | ||
|
|
||
| // If we have no exports we're done | ||
| if (appliedExportAttributes.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var badNamespaces = exportAttributes.Except(appliedExportAttributes).Select(s => s.ContainingNamespace).ToList(); | ||
|
|
||
| // Now look at all attributes and see if any are metadata attributes | ||
| foreach (var namedTypeAttribute in namedTypeAttributes) | ||
| { | ||
| if (AttributeHelpers.GetApplicableAttributes(namedTypeAttribute.AttributeClass).Any(ad => badNamespaces.Contains(ad.AttributeClass.ContainingNamespace) && | ||
| ad.AttributeClass.Name == "MetadataAttributeAttribute")) | ||
| { | ||
| ReportDiagnostic(symbolContext, namedType, namedTypeAttribute); | ||
| } | ||
| } | ||
|
|
||
| // Also look through all members and their attributes, and see if any are using from bad places | ||
| foreach (var member in namedType.GetMembers()) | ||
| { | ||
| foreach (var attribute in member.GetAttributes()) | ||
| { | ||
| if (badNamespaces.Contains(attribute.AttributeClass.ContainingNamespace)) | ||
| { | ||
| ReportDiagnostic(symbolContext, namedType, attribute); | ||
| } | ||
| } | ||
|
|
||
| // if it's a constructor, we should also check parameters since they may have [ImportMany] | ||
| var methodSymbol = member as IMethodSymbol; | ||
|
|
||
| if (methodSymbol != null && methodSymbol.MethodKind == MethodKind.Constructor) | ||
| { | ||
| foreach (var parameter in methodSymbol.Parameters) | ||
| { | ||
| foreach (var attribute in parameter.GetAttributes()) | ||
| { | ||
| if (badNamespaces.Contains(attribute.AttributeClass.ContainingNamespace)) | ||
| { | ||
| ReportDiagnostic(symbolContext, namedType, attribute); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void ReportDiagnostic(SymbolAnalysisContext symbolContext, INamedTypeSymbol exportedType, AttributeData problematicAttribute) | ||
| { | ||
| var metadataSyntax = problematicAttribute.ApplicationSyntaxReference; | ||
| var displayStringOfAttribute = problematicAttribute.AttributeClass.ToMinimalDisplayString(symbolContext.Compilation.GetSemanticModel(metadataSyntax.SyntaxTree), | ||
| metadataSyntax.Span.Start, | ||
| GetSymbolDisplayFormat(exportedType, minimal: true)); | ||
|
|
||
| var displayStringOfExport = exportedType.ToDisplayString(GetSymbolDisplayFormat(exportedType, minimal: false)); | ||
|
|
||
| symbolContext.ReportDiagnostic(Diagnostic.Create(Rule, metadataSyntax.GetSyntax().GetLocation(), displayStringOfAttribute, displayStringOfExport)); | ||
| } | ||
|
|
||
| private static SymbolDisplayFormat GetSymbolDisplayFormat(ISymbol symbol, bool minimal) | ||
| { | ||
| if (symbol.Language == LanguageNames.CSharp) | ||
| { | ||
| return minimal ? SymbolDisplayFormat.CSharpShortErrorMessageFormat : SymbolDisplayFormat.CSharpErrorMessageFormat; | ||
| } | ||
| else | ||
| { | ||
| return minimal ? SymbolDisplayFormat.VisualBasicShortErrorMessageFormat : SymbolDisplayFormat.VisualBasicErrorMessageFormat; | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| // General Information about an assembly is controlled through the following | ||
| // set of attributes. Change these attribute values to modify the information | ||
| // associated with an assembly. | ||
| [assembly: AssemblyTitle("FxCopRulesSetup")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyProduct("FxCopRulesSetup")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- Copyright (c) Microsoft Open Technologies, Inc. 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"> | ||
| <Import Project="..\..\..\..\packages\Microsoft.Net.ToolsetCompilers.0.7.4092303-beta\build\Microsoft.Net.ToolsetCompilers.props" Condition="Exists('..\..\..\..\packages\Microsoft.Net.ToolsetCompilers.0.7.4092303-beta\build\Microsoft.Net.ToolsetCompilers.props')" /> | ||
| <ImportGroup Label="Settings"> | ||
| <Import Project="..\..\..\Tools\Microsoft.CodeAnalysis.Toolset.Open\Targets\VSL.Settings.targets" /> | ||
| </ImportGroup> | ||
| <PropertyGroup> | ||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
| <OutDir>..\..\..\..\Binaries\$(Configuration)\</OutDir> | ||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
| <SchemaVersion>2.0</SchemaVersion> | ||
| <ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
| <ProjectGuid>{DEC6D219-A523-422C-AA36-D17662722C0B}</ProjectGuid> | ||
| <OutputType>Library</OutputType> | ||
| <RootNamespace>Roslyn.Diagnostics.Setup</RootNamespace> | ||
| <AssemblyName>Roslyn.Diagnostics.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> | ||
| </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> | ||
| <Compile Include="Properties\AssemblyInfo.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="packages.config" /> | ||
| <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\RoslynDiagnosticAnalyzers.csproj"> | ||
| <Project>{dcc1f13b-f51c-445b-bdae-92135bd58364}</Project> | ||
| <Name>RoslynDiagnosticAnalyzers</Name> | ||
| </ProjectReference> | ||
| <ProjectReference Include="..\CSharp\CSharpRoslynDiagnosticAnalyzers.csproj"> | ||
| <Project>{b82f1c54-2d3e-497b-8c31-4ab16d6508fa}</Project> | ||
| <Name>CSharpRoslynDiagnosticAnalyzers</Name> | ||
| </ProjectReference> | ||
| <ProjectReference Include="..\VisualBasicCodeAnalysis\BasicCodeAnalysisRoslynDiagnosticAnalyzers\BasicCodeAnalysisRoslynDiagnosticAnalyzers.vbproj"> | ||
| <Project>{f4408506-462d-45b1-b801-fe760b92610f}</Project> | ||
| <Name>BasicCodeAnalysisRoslynDiagnosticAnalyzers</Name> | ||
| </ProjectReference> | ||
| <ProjectReference Include="..\VisualBasic\BasicRoslynDiagnosticAnalyzers.vbproj"> | ||
| <Project>{640b92e8-ed8a-44ac-85c6-50b53837db91}</Project> | ||
| <Name>BasicRoslynDiagnosticAnalyzers</Name> | ||
| </ProjectReference> | ||
| </ItemGroup> | ||
| <ImportGroup Label="Targets"> | ||
| <Import Project="..\..\..\Tools\Microsoft.CodeAnalysis.Toolset.Open\Targets\VSL.Imports.targets" /> | ||
| <Import Project="..\..\..\..\packages\StyleCop.MSBuild.4.7.48.2\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\..\..\packages\StyleCop.MSBuild.4.7.48.2\build\StyleCop.MSBuild.Targets')" /> | ||
| <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> | ||
| </ImportGroup> | ||
| <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
| <PropertyGroup> | ||
| <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
| </PropertyGroup> | ||
| <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> | ||
| <Error Condition="!Exists('..\..\..\..\packages\Microsoft.Net.ToolsetCompilers.0.7.4092303-beta\build\Microsoft.Net.ToolsetCompilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Net.ToolsetCompilers.0.7.4092303-beta\build\Microsoft.Net.ToolsetCompilers.props'))" /> | ||
| </Target> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- Copyright (c) Microsoft Open Technologies, Inc. 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="b3d2dbbd-311e-47ee-b4ff-679c4505b3de" Version="|%CurrentProject%;GetBuildVersion|" Language="en-US" Publisher="Microsoft" /> | ||
| <DisplayName>Roslyn Diagnostics</DisplayName> | ||
| <Description xml:space="preserve">Diagnostics for the Roslyn codebase.</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="|RoslynDiagnosticAnalyzers|" /> | ||
| <Asset Type="Microsoft.VisualStudio.Analyzer" Path="|BasicRoslynDiagnosticAnalyzers|" /> | ||
| <Asset Type="Microsoft.VisualStudio.Analyzer" Path="|CSharpRoslynDiagnosticAnalyzers|" /> | ||
| </Assets> | ||
| </PackageManifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| <package id="StyleCop.MSBuild" version="4.7.48.2" targetFramework="net45" developmentDependency="true" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" /> | ||
| <package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" /> | ||
| <package id="Microsoft.Net.ToolsetCompilers" version="0.7.4092303-beta" targetFramework="net45" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.Composition; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using Roslyn.Compilers; | ||
| using Roslyn.Compilers.Common; | ||
| using Roslyn.Compilers.CSharp; | ||
| using Roslyn.Services.Shared.Extensions; | ||
| using Roslyn.Utilities; | ||
|
|
||
| namespace Roslyn.Services.CSharp.Classification.Classifiers | ||
| { | ||
| internal class TypeParameterConstraintClauseSyntaxClassifier : AbstractSyntaxClassifier | ||
| { | ||
| public override IEnumerable<ClassifiedSpan> ClassifyNode( | ||
| IDocument document, | ||
| CommonSyntaxNode syntax, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| if (syntax is TypeParameterConstraintClauseSyntax) | ||
| { | ||
| return ClassifyTypeParameterConstraintClause(document, (TypeParameterConstraintClauseSyntax)syntax, cancellationToken); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| public override IEnumerable<System.Type> SyntaxNodeTypes | ||
| { | ||
| get | ||
| { | ||
| yield return typeof(TypeParameterConstraintClauseSyntax); | ||
| } | ||
| } | ||
|
|
||
| private IEnumerable<ClassifiedSpan> ClassifyTypeParameterConstraintClause( | ||
| IDocument document, | ||
| TypeParameterConstraintClauseSyntax constraintClause, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var semanticModel = document.GetSemanticModel(cancellationToken); | ||
| var identifier = constraintClause.Identifier; | ||
| var symbol = semanticModel.GetSymbolInfo(identifier, cancellationToken).GetAllSymbols().OfType<ITypeSymbol>().FirstOrDefault(); | ||
|
|
||
| if (symbol != null) | ||
| { | ||
| var classification = GetClassificationForType(symbol); | ||
| if (classification != null) | ||
| { | ||
| return SpecializedCollections.SingletonEnumerable(new ClassifiedSpan(identifier.Span, classification)); | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
| } |