Skip to content

Commit

Permalink
Merge pull request #488 from pdelvo/roslyn_1_0_0_rc
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Feb 26, 2015
2 parents 45d1f1b + 0da3896 commit 04f8fc7
Show file tree
Hide file tree
Showing 71 changed files with 227 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ protected static async Task<ImmutableArray<Diagnostic>> GetSortedDiagnosticsFrom
foreach (var project in projects)
{
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var driver = AnalyzerDriver.Create(compilation, ImmutableArray.Create(analyzer), null, out compilation, cancellationToken);
var discarded = compilation.GetDiagnostics(cancellationToken);
var diags = await driver.GetDiagnosticsAsync().ConfigureAwait(false);
var compilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create(analyzer), null, cancellationToken);
var diags = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().ConfigureAwait(false);
foreach (var diag in diags)
{
if (diag.Location == Location.None || diag.Location.IsInMetadata)
Expand Down Expand Up @@ -106,7 +105,7 @@ protected static async Task<ImmutableArray<Diagnostic>> GetSortedDiagnosticsFrom
/// <see cref="Diagnostic.Location"/>.</returns>
private static Diagnostic[] SortDistinctDiagnostics(IEnumerable<Diagnostic> diagnostics)
{
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).Distinct(default(DiagnosticEqualityComparer)).ToArray();
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
}

#endregion
Expand Down Expand Up @@ -170,7 +169,7 @@ private static Project CreateProject(string[] sources, string language = Languag

var projectId = ProjectId.CreateNewId(debugName: TestProjectName);

var solution = new CustomWorkspace()
var solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.AddMetadataReference(projectId, CorlibReference)
Expand All @@ -190,42 +189,6 @@ private static Project CreateProject(string[] sources, string language = Languag
return solution.GetProject(projectId);
}
#endregion

/// <summary>
/// A little helper to be able to use Enumerable.Distinct. Currently Roslyn does have a bug so that Diagnostic.GetHashCode()
/// is not implemented correctly. <see href="https://github.com/dotnet/roslyn/issues/57"/>.
/// </summary>
private struct DiagnosticEqualityComparer : IEqualityComparer<Diagnostic>
{
public bool Equals(Diagnostic x, Diagnostic y)
{
return (x == null && y == null)
|| x.Equals(y);
}

public int GetHashCode(Diagnostic obj)
{
return this.Combine(obj.Descriptor,
this.Combine(obj.Location.GetHashCode(),
this.Combine(obj.Severity.GetHashCode(), obj.WarningLevel)));
}

private int Combine<T>(T newKeyPart, int currentKey) where T : class
{
int hash = unchecked(currentKey * (int)0xA5555529);

if (newKeyPart != null)
{
return unchecked(hash + newKeyPart.GetHashCode());
}

return hash;
}
private int Combine(int newKey, int currentKey)
{
return unchecked((currentKey * (int)0xA5555529) + newKey);
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace StyleCop.Analyzers.Test.Helpers
{
/// <summary>
/// Indicates that a specific test is related to an open issue.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public sealed class OpenIssueAttribute : System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="OpenIssueAttribute"/> class.
/// </summary>
/// <param name="issue">A link to the open issue.</param>
public OpenIssueAttribute(string issue)
{
this.Issue = issue;
}

public string Issue { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
{
using System.Threading;
using System.Threading.Tasks;
using Analyzers.MaintainabilityRules;
using Helpers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StyleCop.Analyzers.MaintainabilityRules;
using TestHelper;

[TestClass]
Expand Down Expand Up @@ -487,37 +488,37 @@ public async Task TestInterfacePropertyDeclarationWithDirectivesAsync()

#region EventFieldDeclarationSyntax

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestEventFieldDeclarationAsync()
{
await this.TestNestedDeclarationAsync("private", "MemberName", "event EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestEventFieldDeclarationWithAttributesAsync()
{
await this.TestNestedDeclarationWithAttributesAsync("private", "MemberName", "event EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestEventFieldDeclarationWithDirectivesAsync()
{
await this.TestNestedDeclarationWithDirectivesAsync("private", "MemberName", "event EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestStaticEventFieldDeclarationAsync()
{
await this.TestNestedDeclarationAsync("private", "MemberName", "static event EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestStaticEventFieldDeclarationWithAttributesAsync()
{
await this.TestNestedDeclarationWithAttributesAsync("private", "MemberName", "static event EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestStaticEventFieldDeclarationWithDirectivesAsync()
{
await this.TestNestedDeclarationWithDirectivesAsync("private", "MemberName", "static event EventHandler MemberName", ", AnotherMemberName;");
Expand Down Expand Up @@ -545,37 +546,37 @@ public async Task TestInterfaceEventFieldDeclarationWithDirectivesAsync()

#region FieldDeclarationSyntax

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestFieldDeclarationAsync()
{
await this.TestNestedDeclarationAsync("private", "MemberName", "System.EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestFieldDeclarationWithAttributesAsync()
{
await this.TestNestedDeclarationWithAttributesAsync("private", "MemberName", "System.EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestFieldDeclarationWithDirectivesAsync()
{
await this.TestNestedDeclarationWithDirectivesAsync("private", "MemberName", "System.EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestStaticFieldDeclarationAsync()
{
await this.TestNestedDeclarationAsync("private", "MemberName", "static System.EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestStaticFieldDeclarationWithAttributesAsync()
{
await this.TestNestedDeclarationWithAttributesAsync("private", "MemberName", "static System.EventHandler MemberName", ", AnotherMemberName;");
}

[TestMethod]
[TestMethod, Ignore, OpenIssue("https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/496")]
public async Task TestStaticFieldDeclarationWithDirectivesAsync()
{
await this.TestNestedDeclarationWithDirectivesAsync("private", "MemberName", "static System.EventHandler MemberName", ", AnotherMemberName;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,40 @@
<ItemGroup>
<Reference Include="Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.1.32.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\System.Collections.Immutable.1.1.32-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Reference Include="System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Composition.AttributedModel">
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
Expand All @@ -94,8 +94,9 @@
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Reflection.Metadata">
<HintPath>..\..\packages\System.Reflection.Metadata.1.0.17-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
<Reference Include="System.Reflection.Metadata, Version=1.0.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Reflection.Metadata.1.0.18-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -119,6 +120,7 @@
<Compile Include="Helpers\CodeFixVerifier.Helper.cs" />
<Compile Include="Helpers\DiagnosticResult.cs" />
<Compile Include="Helpers\DiagnosticVerifier.Helper.cs" />
<Compile Include="Helpers\OpenIssueAttribute.cs" />
<Compile Include="MaintainabilityRules\DebugMessagesUnitTestsBase.cs" />
<Compile Include="MaintainabilityRules\FileMayOnlyContainTestBase.cs" />
<Compile Include="MaintainabilityRules\SA1119UnitTests.cs" />
Expand Down Expand Up @@ -169,6 +171,8 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0-rc1\tools\analyzers\C#\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0-rc1\tools\analyzers\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.0-alpha003\tools\analyzers\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private async Task VerifyFixAsync(string language, DiagnosticAnalyzer analyzer,
{
var actions = new List<CodeAction>();
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), cancellationToken);
await codeFixProvider.ComputeFixesAsync(context).ConfigureAwait(false);
await codeFixProvider.RegisterCodeFixesAsync(context).ConfigureAwait(false);

if (!actions.Any())
{
Expand Down
13 changes: 7 additions & 6 deletions StyleCop.Analyzers/StyleCop.Analyzers.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeAnalysis.Common" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.0.0-rc1" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Common" version="1.0.0-rc1" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp" version="1.0.0-rc1" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.0.0-rc1" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0-rc1" targetFramework="net45" />
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
<package id="StyleCop.Analyzers" version="1.0.0-alpha003" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.1.32-beta" targetFramework="net45" />
<package id="System.Reflection.Metadata" version="1.0.17-beta" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.1.33-beta" targetFramework="net45" />
<package id="System.Reflection.Metadata" version="1.0.18-beta" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public class SA1642SA1643CodeFixProvider : CodeFixProvider
ImmutableArray.Create(SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.DiagnosticId, SA1643DestructorSummaryDocumentationMustBeginWithStandardText.DiagnosticId);

/// <inheritdoc/>
public override ImmutableArray<string> GetFixableDiagnosticIds()
{
return FixableDiagnostics;
}
public override ImmutableArray<string> FixableDiagnosticIds => FixableDiagnostics;

/// <inheritdoc/>
public override FixAllProvider GetFixAllProvider()
Expand All @@ -40,7 +37,7 @@ public override FixAllProvider GetFixAllProvider()
}

/// <inheritdoc/>
public override async Task ComputeFixesAsync(CodeFixContext context)
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand Down Expand Up @@ -89,7 +86,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
var newRoot = root.ReplaceNode(node, newNode);

var newDocument = context.Document.WithSyntaxRoot(newRoot);
context.RegisterFix(CodeAction.Create("Add standard text.", newDocument), diagnostic);
context.RegisterCodeFix(CodeAction.Create("Add standard text.", token => Task.FromResult(newDocument)), diagnostic);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
/// }
/// </code>
/// </remarks>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine : DiagnosticAnalyzer
{
/// <summary>
Expand Down
Loading

0 comments on commit 04f8fc7

Please sign in to comment.