Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit c1ded89

Browse files
committed
Add solution created by project template
1 parent ac46425 commit c1ded89

23 files changed

+1775
-0
lines changed

AsyncUsageAnalyzers.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.22823.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncUsageAnalyzers", "AsyncUsageAnalyzers\AsyncUsageAnalyzers\AsyncUsageAnalyzers.csproj", "{4E32037D-3EE0-419A-BC68-7D28FCD453A0}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncUsageAnalyzers.Test", "AsyncUsageAnalyzers\AsyncUsageAnalyzers.Test\AsyncUsageAnalyzers.Test.csproj", "{658C2A87-E2A9-494D-93D7-CB60EFE3D02B}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncUsageAnalyzers.Vsix", "AsyncUsageAnalyzers\AsyncUsageAnalyzers.Vsix\AsyncUsageAnalyzers.Vsix.csproj", "{8ABF883C-450A-4D0E-8D50-BF8A07C82C1B}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{4E32037D-3EE0-419A-BC68-7D28FCD453A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{4E32037D-3EE0-419A-BC68-7D28FCD453A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{4E32037D-3EE0-419A-BC68-7D28FCD453A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{4E32037D-3EE0-419A-BC68-7D28FCD453A0}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{658C2A87-E2A9-494D-93D7-CB60EFE3D02B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{658C2A87-E2A9-494D-93D7-CB60EFE3D02B}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{658C2A87-E2A9-494D-93D7-CB60EFE3D02B}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{658C2A87-E2A9-494D-93D7-CB60EFE3D02B}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{8ABF883C-450A-4D0E-8D50-BF8A07C82C1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{8ABF883C-450A-4D0E-8D50-BF8A07C82C1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{8ABF883C-450A-4D0E-8D50-BF8A07C82C1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{8ABF883C-450A-4D0E-8D50-BF8A07C82C1B}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
EndGlobal
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{658C2A87-E2A9-494D-93D7-CB60EFE3D02B}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>AsyncUsageAnalyzers.Test</RootNamespace>
12+
<AssemblyName>AsyncUsageAnalyzers.Test</AssemblyName>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
<Prefer32Bit>false</Prefer32Bit>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
<Prefer32Bit>false</Prefer32Bit>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
38+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
43+
<Private>True</Private>
44+
</Reference>
45+
<Reference Include="Microsoft.CodeAnalysis.CSharp.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll</HintPath>
47+
<Private>True</Private>
48+
</Reference>
49+
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
50+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
51+
<Private>True</Private>
52+
</Reference>
53+
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
57+
<Reference Include="Microsoft.CodeAnalysis.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
61+
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
62+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
63+
<Private>True</Private>
64+
</Reference>
65+
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66+
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
67+
<Private>True</Private>
68+
</Reference>
69+
<Reference Include="System" />
70+
<Reference Include="System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
71+
<HintPath>..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
72+
<Private>True</Private>
73+
</Reference>
74+
<Reference Include="System.Composition.AttributedModel, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
75+
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
76+
<Private>True</Private>
77+
</Reference>
78+
<Reference Include="System.Composition.Convention, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
79+
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll</HintPath>
80+
<Private>True</Private>
81+
</Reference>
82+
<Reference Include="System.Composition.Hosting, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
83+
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll</HintPath>
84+
<Private>True</Private>
85+
</Reference>
86+
<Reference Include="System.Composition.Runtime, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
87+
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll</HintPath>
88+
<Private>True</Private>
89+
</Reference>
90+
<Reference Include="System.Composition.TypedParts, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
91+
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll</HintPath>
92+
<Private>True</Private>
93+
</Reference>
94+
<Reference Include="System.Core" />
95+
<Reference Include="System.Reflection.Metadata, Version=1.0.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
96+
<HintPath>..\..\packages\System.Reflection.Metadata.1.0.18-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
97+
<Private>True</Private>
98+
</Reference>
99+
<Reference Include="System.Xml.Linq" />
100+
<Reference Include="System.Data.DataSetExtensions" />
101+
<Reference Include="Microsoft.CSharp" />
102+
<Reference Include="System.Data" />
103+
<Reference Include="System.Xml" />
104+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
105+
</ItemGroup>
106+
<ItemGroup>
107+
<Compile Include="Verifiers\CodeFixVerifier.cs" />
108+
<Compile Include="Verifiers\DiagnosticVerifier.cs" />
109+
<Compile Include="Helpers\CodeFixVerifier.Helper.cs" />
110+
<Compile Include="Helpers\DiagnosticResult.cs" />
111+
<Compile Include="Helpers\DiagnosticVerifier.Helper.cs" />
112+
<Compile Include="UnitTests.cs" />
113+
<Compile Include="Properties\AssemblyInfo.cs" />
114+
</ItemGroup>
115+
<ItemGroup>
116+
<None Include="packages.config" />
117+
</ItemGroup>
118+
<ItemGroup>
119+
<ProjectReference Include="..\AsyncUsageAnalyzers\AsyncUsageAnalyzers.csproj">
120+
<Project>{4E32037D-3EE0-419A-BC68-7D28FCD453A0}</Project>
121+
<Name>AsyncUsageAnalyzers</Name>
122+
</ProjectReference>
123+
</ItemGroup>
124+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
125+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
126+
Other similar extension points exist, see Microsoft.Common.targets.
127+
<Target Name="BeforeBuild">
128+
</Target>
129+
<Target Name="AfterBuild">
130+
</Target>
131+
-->
132+
</Project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.CodeActions;
3+
using Microsoft.CodeAnalysis.Formatting;
4+
using Microsoft.CodeAnalysis.Simplification;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading;
8+
9+
namespace TestHelper
10+
{
11+
/// <summary>
12+
/// Diagnostic Producer class with extra methods dealing with applying codefixes
13+
/// All methods are static
14+
/// </summary>
15+
public abstract partial class CodeFixVerifier : DiagnosticVerifier
16+
{
17+
/// <summary>
18+
/// Apply the inputted CodeAction to the inputted document.
19+
/// Meant to be used to apply codefixes.
20+
/// </summary>
21+
/// <param name="document">The Document to apply the fix on</param>
22+
/// <param name="codeAction">A CodeAction that will be applied to the Document.</param>
23+
/// <returns>A Document with the changes from the CodeAction</returns>
24+
private static Document ApplyFix(Document document, CodeAction codeAction)
25+
{
26+
var operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;
27+
var solution = operations.OfType<ApplyChangesOperation>().Single().ChangedSolution;
28+
return solution.GetDocument(document.Id);
29+
}
30+
31+
/// <summary>
32+
/// Compare two collections of Diagnostics,and return a list of any new diagnostics that appear only in the second collection.
33+
/// Note: Considers Diagnostics to be the same if they have the same Ids. In the case of multiple diagnostics with the same Id in a row,
34+
/// this method may not necessarily return the new one.
35+
/// </summary>
36+
/// <param name="diagnostics">The Diagnostics that existed in the code before the CodeFix was applied</param>
37+
/// <param name="newDiagnostics">The Diagnostics that exist in the code after the CodeFix was applied</param>
38+
/// <returns>A list of Diagnostics that only surfaced in the code after the CodeFix was applied</returns>
39+
private static IEnumerable<Diagnostic> GetNewDiagnostics(IEnumerable<Diagnostic> diagnostics, IEnumerable<Diagnostic> newDiagnostics)
40+
{
41+
var oldArray = diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
42+
var newArray = newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
43+
44+
int oldIndex = 0;
45+
int newIndex = 0;
46+
47+
while (newIndex < newArray.Length)
48+
{
49+
if (oldIndex < oldArray.Length && oldArray[oldIndex].Id == newArray[newIndex].Id)
50+
{
51+
++oldIndex;
52+
++newIndex;
53+
}
54+
else
55+
{
56+
yield return newArray[newIndex++];
57+
}
58+
}
59+
}
60+
61+
/// <summary>
62+
/// Get the existing compiler diagnostics on the inputted document.
63+
/// </summary>
64+
/// <param name="document">The Document to run the compiler diagnostic analyzers on</param>
65+
/// <returns>The compiler diagnostics that were found in the code</returns>
66+
private static IEnumerable<Diagnostic> GetCompilerDiagnostics(Document document)
67+
{
68+
return document.GetSemanticModelAsync().Result.GetDiagnostics();
69+
}
70+
71+
/// <summary>
72+
/// Given a document, turn it into a string based on the syntax root
73+
/// </summary>
74+
/// <param name="document">The Document to be converted to a string</param>
75+
/// <returns>A string containing the syntax of the Document after formatting</returns>
76+
private static string GetStringFromDocument(Document document)
77+
{
78+
var simplifiedDoc = Simplifier.ReduceAsync(document, Simplifier.Annotation).Result;
79+
var root = simplifiedDoc.GetSyntaxRootAsync().Result;
80+
root = Formatter.Format(root, Formatter.Annotation, simplifiedDoc.Project.Solution.Workspace);
81+
return root.GetText().ToString();
82+
}
83+
}
84+
}
85+
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using Microsoft.CodeAnalysis;
2+
using System;
3+
4+
namespace TestHelper
5+
{
6+
/// <summary>
7+
/// Location where the diagnostic appears, as determined by path, line number, and column number.
8+
/// </summary>
9+
public struct DiagnosticResultLocation
10+
{
11+
public DiagnosticResultLocation(string path, int line, int column)
12+
{
13+
if (line < 0 && column < 0)
14+
{
15+
throw new ArgumentOutOfRangeException("At least one of line and column must be > 0");
16+
}
17+
if (line < -1 || column < -1)
18+
{
19+
throw new ArgumentOutOfRangeException("Both line and column must be >= -1");
20+
}
21+
22+
this.Path = path;
23+
this.Line = line;
24+
this.Column = column;
25+
}
26+
27+
public string Path;
28+
public int Line;
29+
public int Column;
30+
}
31+
32+
/// <summary>
33+
/// Struct that stores information about a Diagnostic appearing in a source
34+
/// </summary>
35+
public struct DiagnosticResult
36+
{
37+
private DiagnosticResultLocation[] locations;
38+
39+
public DiagnosticResultLocation[] Locations
40+
{
41+
get
42+
{
43+
if (this.locations == null)
44+
{
45+
this.locations = new DiagnosticResultLocation[] { };
46+
}
47+
return this.locations;
48+
}
49+
50+
set
51+
{
52+
this.locations = value;
53+
}
54+
}
55+
56+
public DiagnosticSeverity Severity
57+
{
58+
get; set;
59+
}
60+
61+
public string Id
62+
{
63+
get; set;
64+
}
65+
66+
public string Message
67+
{
68+
get; set;
69+
}
70+
71+
public string Path
72+
{
73+
get
74+
{
75+
return this.Locations.Length > 0 ? this.Locations[0].Path : "";
76+
}
77+
}
78+
79+
public int Line
80+
{
81+
get
82+
{
83+
return this.Locations.Length > 0 ? this.Locations[0].Line : -1;
84+
}
85+
}
86+
87+
public int Column
88+
{
89+
get
90+
{
91+
return this.Locations.Length > 0 ? this.Locations[0].Column : -1;
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)