10 changed files with 425 additions and 51 deletions
@ -0,0 +1,124 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel |
||||||
|
* Date: 10/6/2012 |
||||||
|
* Time: 17:51 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.NRefactory.CSharp; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||||
|
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.ConsistencyCheck |
||||||
|
{ |
||||||
|
// Adapters from SD to NR.ConsistencyCheck solution model
|
||||||
|
public class Solution |
||||||
|
{ |
||||||
|
public readonly List<CSharpProject> Projects = new List<CSharpProject>(); |
||||||
|
|
||||||
|
public Solution(ICSharpCode.SharpDevelop.Project.Solution solution) |
||||||
|
{ |
||||||
|
foreach (var p in solution.Projects.OfType<MSBuildBasedProject>()) { |
||||||
|
if (p.FileName.ToString().EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)) |
||||||
|
Projects.Add(new CSharpProject(p)); |
||||||
|
} |
||||||
|
var snapshot = SD.ParserService.GetCurrentSolutionSnapshot(); |
||||||
|
foreach (var p in Projects) { |
||||||
|
p.Compilation = snapshot.GetCompilation(p.IProject); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<CSharpFile> AllFiles { |
||||||
|
get { |
||||||
|
return Projects.SelectMany(p => p.Files); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class CSharpProject |
||||||
|
{ |
||||||
|
public readonly MSBuildBasedProject IProject; |
||||||
|
public readonly CompilerSettings CompilerSettings = new CompilerSettings(); |
||||||
|
public readonly List<CSharpFile> Files = new List<CSharpFile>(); |
||||||
|
public ICompilation Compilation; |
||||||
|
|
||||||
|
public CSharpProject(MSBuildBasedProject project) |
||||||
|
{ |
||||||
|
this.IProject = project; |
||||||
|
|
||||||
|
CompilerSettings.AllowUnsafeBlocks = GetBoolProperty("AllowUnsafeBlocks") ?? false; |
||||||
|
CompilerSettings.CheckForOverflow = GetBoolProperty("CheckForOverflowUnderflow") ?? false; |
||||||
|
string defineConstants = project.GetEvaluatedProperty("DefineConstants"); |
||||||
|
foreach (string symbol in defineConstants.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)) |
||||||
|
this.CompilerSettings.ConditionalSymbols.Add(symbol.Trim()); |
||||||
|
|
||||||
|
// Parse the C# code files
|
||||||
|
foreach (var item in project.GetItemsOfType(ItemType.Compile)) { |
||||||
|
var file = new CSharpFile(this, FileName.Create(item.FileName)); |
||||||
|
Files.Add(file); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool? GetBoolProperty(string propertyName) |
||||||
|
{ |
||||||
|
string val = IProject.GetEvaluatedProperty(propertyName); |
||||||
|
bool result; |
||||||
|
if (bool.TryParse(val, out result)) |
||||||
|
return result; |
||||||
|
else |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class CSharpFile |
||||||
|
{ |
||||||
|
public readonly CSharpProject Project; |
||||||
|
public readonly string FileName; |
||||||
|
public readonly string OriginalText; |
||||||
|
|
||||||
|
public SyntaxTree SyntaxTree; |
||||||
|
public CSharpUnresolvedFile UnresolvedTypeSystemForFile; |
||||||
|
|
||||||
|
public CSharpFile(CSharpProject project, FileName fileName) |
||||||
|
{ |
||||||
|
this.Project = project; |
||||||
|
this.FileName = fileName; |
||||||
|
this.OriginalText = File.ReadAllText(fileName); |
||||||
|
CSharpParser p = new CSharpParser(project.CompilerSettings); |
||||||
|
this.SyntaxTree = p.Parse(this.OriginalText, fileName); |
||||||
|
this.UnresolvedTypeSystemForFile = SD.ParserService.GetExistingUnresolvedFile(fileName, null, project.IProject) as CSharpUnresolvedFile; |
||||||
|
if (this.UnresolvedTypeSystemForFile == null) |
||||||
|
throw new InvalidOperationException("LoadSolutionProjectsThread not yet finished?"); |
||||||
|
} |
||||||
|
|
||||||
|
public CSharpAstResolver CreateResolver() |
||||||
|
{ |
||||||
|
return new CSharpAstResolver(Project.Compilation, SyntaxTree, UnresolvedTypeSystemForFile); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
sealed class Timer : IDisposable |
||||||
|
{ |
||||||
|
Stopwatch w = Stopwatch.StartNew(); |
||||||
|
|
||||||
|
public Timer(string title) |
||||||
|
{ |
||||||
|
Console.Write(title); |
||||||
|
} |
||||||
|
|
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
Console.WriteLine(w.Elapsed); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,67 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel |
||||||
|
* Date: 10/6/2012 |
||||||
|
* Time: 18:05 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.ConsistencyCheck |
||||||
|
{ |
||||||
|
public abstract class ConsistencyCheckCommand : SimpleCommand |
||||||
|
{ |
||||||
|
public sealed override void Execute(object parameter) |
||||||
|
{ |
||||||
|
Execute(parameter as Solution ?? new Solution(ProjectService.OpenSolution)); |
||||||
|
} |
||||||
|
|
||||||
|
public abstract void Execute(Solution solution); |
||||||
|
|
||||||
|
protected void RunTestOnAllFiles(Solution solution, Action<CSharpFile> runTest) |
||||||
|
{ |
||||||
|
using (new Timer(GetType().Name + "... ")) { |
||||||
|
foreach (var file in solution.AllFiles) { |
||||||
|
runTest(file); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class RunAllTestsCommand : ConsistencyCheckCommand |
||||||
|
{ |
||||||
|
public override void Execute(Solution solution) |
||||||
|
{ |
||||||
|
new ResolverTestCommand().Execute(solution); |
||||||
|
new ResolverTestWithoutUnresolvedFileCommand().Execute(solution); |
||||||
|
new ResolverTestRandomizedOrderCommand().Execute(solution); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class ResolverTestCommand : ConsistencyCheckCommand |
||||||
|
{ |
||||||
|
public override void Execute(Solution solution) |
||||||
|
{ |
||||||
|
RunTestOnAllFiles(solution, ResolverTest.RunTest); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class ResolverTestWithoutUnresolvedFileCommand : ConsistencyCheckCommand |
||||||
|
{ |
||||||
|
public override void Execute(Solution solution) |
||||||
|
{ |
||||||
|
RunTestOnAllFiles(solution, ResolverTest.RunTestWithoutUnresolvedFile); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class ResolverTestRandomizedOrderCommand : ConsistencyCheckCommand |
||||||
|
{ |
||||||
|
public override void Execute(Solution solution) |
||||||
|
{ |
||||||
|
RunTestOnAllFiles(solution, RandomizedOrderResolverTest.RunTest); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
#region Using directives
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Reflection; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// 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("StressTest")] |
||||||
|
[assembly: AssemblyDescription("")] |
||||||
|
[assembly: AssemblyConfiguration("")] |
||||||
|
[assembly: AssemblyCompany("")] |
||||||
|
[assembly: AssemblyProduct("StressTest")] |
||||||
|
[assembly: AssemblyCopyright("Copyright 2012 Daniel Grunwald")] |
||||||
|
[assembly: AssemblyTrademark("")] |
||||||
|
[assembly: AssemblyCulture("")] |
||||||
|
|
||||||
|
// This sets the default COM visibility of types in the assembly to invisible.
|
||||||
|
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||||
|
[assembly: ComVisible(false)] |
||||||
|
|
||||||
|
// The assembly version has following format :
|
||||||
|
//
|
||||||
|
// Major.Minor.Build.Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can use the default the Revision and
|
||||||
|
// Build Numbers by using the '*' as shown below:
|
||||||
|
[assembly: AssemblyVersion("1.0.*")] |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
<AddIn name = "NRConsistencyCheck" |
||||||
|
author = "Daniel Grunwald" |
||||||
|
url = "" |
||||||
|
description = "TODO: Put description here"> |
||||||
|
|
||||||
|
<Runtime> |
||||||
|
<Import assembly = "NRConsistencyCheckAddIn.dll"/> |
||||||
|
</Runtime> |
||||||
|
|
||||||
|
<Path name="/SharpDevelop/Workbench/Tools"> |
||||||
|
<MenuItem id="NR Consistency Check" |
||||||
|
type="Menu" |
||||||
|
label="NR Consistency Check"> |
||||||
|
<MenuItem label="Run all tests" class="ICSharpCode.NRefactory.ConsistencyCheck.RunAllTestsCommand" /> |
||||||
|
<MenuItem label="CSharpAstResolver test" class="ICSharpCode.NRefactory.ConsistencyCheck.ResolverTestCommand" /> |
||||||
|
<MenuItem label="CSharpAstResolver test (no unresolved file)" class="ICSharpCode.NRefactory.ConsistencyCheck.ResolverTestWithoutUnresolvedFileCommand" /> |
||||||
|
<MenuItem label="CSharpAstResolver test (randomized order)" class="ICSharpCode.NRefactory.ConsistencyCheck.ResolverTestRandomizedOrderCommand" /> |
||||||
|
</MenuItem> |
||||||
|
</Path> |
||||||
|
</AddIn> |
||||||
@ -0,0 +1,119 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||||
|
<PropertyGroup> |
||||||
|
<ProjectGuid>{30D10654-A5F5-4AC5-A370-E6DD4D0FAC50}</ProjectGuid> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
||||||
|
<OutputType>Library</OutputType> |
||||||
|
<RootNamespace>ICSharpCode.NRefactory.ConsistencyCheck</RootNamespace> |
||||||
|
<AssemblyName>NRConsistencyCheckAddIn</AssemblyName> |
||||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
||||||
|
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||||
|
<NoStdLib>False</NoStdLib> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||||
|
<TargetFrameworkProfile /> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget> |
||||||
|
<RegisterForComInterop>False</RegisterForComInterop> |
||||||
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||||
|
<BaseAddress>4194304</BaseAddress> |
||||||
|
<FileAlignment>4096</FileAlignment> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||||
|
<OutputPath>bin\Debug\</OutputPath> |
||||||
|
<DebugSymbols>true</DebugSymbols> |
||||||
|
<DebugType>Full</DebugType> |
||||||
|
<Optimize>False</Optimize> |
||||||
|
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||||
|
<StartAction>Program</StartAction> |
||||||
|
<StartProgram>..\..\..\bin\SharpDevelop.exe</StartProgram> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||||
|
<OutputPath>bin\Release\</OutputPath> |
||||||
|
<DebugSymbols>False</DebugSymbols> |
||||||
|
<DebugType>None</DebugType> |
||||||
|
<Optimize>True</Optimize> |
||||||
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||||
|
<DefineConstants>TRACE</DefineConstants> |
||||||
|
</PropertyGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="ICSharpCode.AvalonEdit"> |
||||||
|
<HintPath>..\..\..\bin\ICSharpCode.AvalonEdit.dll</HintPath> |
||||||
|
<Private>False</Private> |
||||||
|
</Reference> |
||||||
|
<Reference Include="ICSharpCode.Core"> |
||||||
|
<HintPath>..\..\..\bin\ICSharpCode.Core.dll</HintPath> |
||||||
|
<Private>False</Private> |
||||||
|
</Reference> |
||||||
|
<Reference Include="ICSharpCode.NRefactory"> |
||||||
|
<HintPath>..\..\..\bin\ICSharpCode.NRefactory.dll</HintPath> |
||||||
|
<Private>False</Private> |
||||||
|
</Reference> |
||||||
|
<Reference Include="ICSharpCode.NRefactory.CSharp"> |
||||||
|
<HintPath>..\..\..\bin\ICSharpCode.NRefactory.CSharp.dll</HintPath> |
||||||
|
<Private>False</Private> |
||||||
|
</Reference> |
||||||
|
<Reference Include="ICSharpCode.SharpDevelop"> |
||||||
|
<HintPath>..\..\..\bin\ICSharpCode.SharpDevelop.dll</HintPath> |
||||||
|
<Private>False</Private> |
||||||
|
</Reference> |
||||||
|
<Reference Include="PresentationCore"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="PresentationFramework"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System" /> |
||||||
|
<Reference Include="System.Core"> |
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System.Data" /> |
||||||
|
<Reference Include="System.Data.DataSetExtensions"> |
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System.Drawing" /> |
||||||
|
<Reference Include="System.Windows.Forms" /> |
||||||
|
<Reference Include="System.Xaml"> |
||||||
|
<RequiredTargetFramework>4.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System.Xml" /> |
||||||
|
<Reference Include="System.Xml.Linq"> |
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="WindowsBase"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<None Include="NRConsistencyCheckAddIn.addin"> |
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||||
|
</None> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="..\..\Libraries\NRefactory\ICSharpCode.NRefactory.ConsistencyCheck\FindReferencesConsistencyCheck.cs"> |
||||||
|
<Link>FindReferencesConsistencyCheck.cs</Link> |
||||||
|
</Compile> |
||||||
|
<Compile Include="..\..\Libraries\NRefactory\ICSharpCode.NRefactory.ConsistencyCheck\RandomizedOrderResolverTest.cs"> |
||||||
|
<Link>RandomizedOrderResolverTest.cs</Link> |
||||||
|
</Compile> |
||||||
|
<Compile Include="..\..\Libraries\NRefactory\ICSharpCode.NRefactory.ConsistencyCheck\ResolverTest.cs"> |
||||||
|
<Link>ResolverTest.cs</Link> |
||||||
|
</Compile> |
||||||
|
<Compile Include="..\..\Libraries\NRefactory\ICSharpCode.NRefactory.ConsistencyCheck\TypeSystemTests.cs"> |
||||||
|
<Link>TypeSystemTests.cs</Link> |
||||||
|
</Compile> |
||||||
|
<Compile Include="..\..\Libraries\NRefactory\ICSharpCode.NRefactory.ConsistencyCheck\VisitorBenchmark.cs"> |
||||||
|
<Link>VisitorBenchmark.cs</Link> |
||||||
|
</Compile> |
||||||
|
<Compile Include="Commands.cs" /> |
||||||
|
<Compile Include="Configuration\AssemblyInfo.cs" /> |
||||||
|
<Compile Include="Adapter.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
<PropertyGroup> |
||||||
|
<StartArguments>/addindir:"$(MsBuildProjectDirectory)\$(OutputPath)"</StartArguments> |
||||||
|
</PropertyGroup> |
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||||
|
</Project> |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 11.00 |
||||||
|
# Visual Studio 2010 |
||||||
|
# SharpDevelop 4.3 |
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRConsistencyCheckAddIn", "NRConsistencyCheckAddIn.csproj", "{30D10654-A5F5-4AC5-A370-E6DD4D0FAC50}" |
||||||
|
EndProject |
||||||
|
Global |
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||||
|
Debug|x86 = Debug|x86 |
||||||
|
Release|x86 = Release|x86 |
||||||
|
EndGlobalSection |
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||||
|
{30D10654-A5F5-4AC5-A370-E6DD4D0FAC50}.Debug|x86.Build.0 = Debug|x86 |
||||||
|
{30D10654-A5F5-4AC5-A370-E6DD4D0FAC50}.Debug|x86.ActiveCfg = Debug|x86 |
||||||
|
{30D10654-A5F5-4AC5-A370-E6DD4D0FAC50}.Release|x86.Build.0 = Release|x86 |
||||||
|
{30D10654-A5F5-4AC5-A370-E6DD4D0FAC50}.Release|x86.ActiveCfg = Release|x86 |
||||||
|
EndGlobalSection |
||||||
|
EndGlobal |
||||||
Loading…
Reference in new issue