Skip to content

Commit f389f78

Browse files
committed
Add initial code from template
1 parent 754d505 commit f389f78

22 files changed

Lines changed: 1480 additions & 0 deletions

.nuget/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NuGet.CommandLine" version="2.8.2" />
4+
</packages>

OpenStackNetAnalyzers.sln

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.22512.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenStackNetAnalyzers", "OpenStackNetAnalyzers\OpenStackNetAnalyzers\OpenStackNetAnalyzers.csproj", "{AB7F7388-74A9-4497-8512-AC1E194D3B93}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9E9D25AB-EA1A-4511-8A6F-E5E352113F94}"
9+
ProjectSection(SolutionItems) = preProject
10+
.nuget\packages.config = .nuget\packages.config
11+
EndProjectSection
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenStackNetAnalyzers.Test", "OpenStackNetAnalyzers\OpenStackNetAnalyzers.Test\OpenStackNetAnalyzers.Test.csproj", "{D1E1094C-4679-4CAC-9626-0215EC3A06DF}"
14+
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenStackNetAnalyzers.Vsix", "OpenStackNetAnalyzers\OpenStackNetAnalyzers.Vsix\OpenStackNetAnalyzers.Vsix.csproj", "{7A301A1D-5CDF-4B13-AD32-4E391B1380F3}"
16+
EndProject
17+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FD988EF6-A3E8-47FB-B768-39DF7EE74BD5}"
18+
ProjectSection(SolutionItems) = preProject
19+
CONTRIBUTING.md = CONTRIBUTING.md
20+
LICENSE.md = LICENSE.md
21+
README.md = README.md
22+
EndProjectSection
23+
EndProject
24+
Global
25+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
26+
Debug|Any CPU = Debug|Any CPU
27+
Release|Any CPU = Release|Any CPU
28+
EndGlobalSection
29+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
30+
{AB7F7388-74A9-4497-8512-AC1E194D3B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{AB7F7388-74A9-4497-8512-AC1E194D3B93}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{AB7F7388-74A9-4497-8512-AC1E194D3B93}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{AB7F7388-74A9-4497-8512-AC1E194D3B93}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{D1E1094C-4679-4CAC-9626-0215EC3A06DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{D1E1094C-4679-4CAC-9626-0215EC3A06DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{D1E1094C-4679-4CAC-9626-0215EC3A06DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{D1E1094C-4679-4CAC-9626-0215EC3A06DF}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{7A301A1D-5CDF-4B13-AD32-4E391B1380F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{7A301A1D-5CDF-4B13-AD32-4E391B1380F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{7A301A1D-5CDF-4B13-AD32-4E391B1380F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{7A301A1D-5CDF-4B13-AD32-4E391B1380F3}.Release|Any CPU.Build.0 = Release|Any CPU
42+
EndGlobalSection
43+
GlobalSection(SolutionProperties) = preSolution
44+
HideSolutionNode = FALSE
45+
EndGlobalSection
46+
EndGlobal
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)