15 changed files with 368 additions and 118 deletions
@ -1,54 +1,56 @@
@@ -1,54 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{63D3B27A-D966-4902-90B3-30290E1692F1}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>ICSharpCode.NRefactory.Tests</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.Tests</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
</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> |
||||
</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="nunit.framework" /> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="MyClassTests.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{63D3B27A-D966-4902-90B3-30290E1692F1}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>ICSharpCode.NRefactory.Tests</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.Tests</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
</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> |
||||
</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="nunit.framework"> |
||||
<HintPath>..\lib\nunit.framework.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="MyClassTests.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
||||
@ -0,0 +1,183 @@
@@ -0,0 +1,183 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics.Contracts; |
||||
|
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem |
||||
{ |
||||
/// <summary>
|
||||
/// Project content that represents an already compiled assembly.
|
||||
/// </summary>
|
||||
public class CecilProjectContent : IProjectContent |
||||
{ |
||||
IList<IAttribute> assemblyAttributes; |
||||
|
||||
#region Constructor
|
||||
public CecilProjectContent(AssemblyDefinition assemblyDefinition) |
||||
{ |
||||
this.assemblyAttributes = ReadAttributes(assemblyDefinition, this); |
||||
} |
||||
#endregion
|
||||
|
||||
#region IProjectContent implementation
|
||||
public IList<IAttribute> AssemblyAttributes { |
||||
get { return assemblyAttributes; } |
||||
} |
||||
|
||||
public ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ISynchronizedTypeResolveContext Synchronize() |
||||
{ |
||||
// CecilProjectContent is immutable, so we don't need to synchronize
|
||||
return new DummySynchronizedTypeResolveContext(this); |
||||
} |
||||
|
||||
sealed class DummySynchronizedTypeResolveContext : ProxyTypeResolveContext, ISynchronizedTypeResolveContext |
||||
{ |
||||
public DummySynchronizedTypeResolveContext(ITypeResolveContext context) : base(context) |
||||
{ |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region Load Assembly From Disk
|
||||
public static CecilProjectContent LoadAssembly(string fileName) |
||||
{ |
||||
if (fileName == null) |
||||
throw new ArgumentNullException("fileName"); |
||||
AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, new ReaderParameters { AssemblyResolver = new DummyAssemblyResolver() }); |
||||
return new CecilProjectContent(asm); |
||||
} |
||||
|
||||
// used to prevent Cecil from loading referenced assemblies
|
||||
sealed class DummyAssemblyResolver : IAssemblyResolver |
||||
{ |
||||
public AssemblyDefinition Resolve(AssemblyNameReference name) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public AssemblyDefinition Resolve(string fullName) |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region Read Type Reference
|
||||
public static ITypeReference ReadTypeReference(TypeReference attributeType, ITypeResolveContext earlyBindContext) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Read Attributes
|
||||
public static IList<IAttribute> ReadAttributes(ICustomAttributeProvider attributeProvider, ITypeResolveContext earlyBindContext) |
||||
{ |
||||
Contract.Ensures(Contract.Result<IList<IAttribute>>() != null); |
||||
if (attributeProvider == null || !attributeProvider.HasCustomAttributes) |
||||
return EmptyList<IAttribute>.Instance; |
||||
var cecilAttributes = attributeProvider.CustomAttributes; |
||||
IAttribute[] attributes = new IAttribute[cecilAttributes.Count]; |
||||
for (int i = 0; i < attributes.Length; i++) { |
||||
attributes[i] = new CecilAttribute(cecilAttributes[i], earlyBindContext); |
||||
} |
||||
return Array.AsReadOnly(attributes); |
||||
} |
||||
|
||||
sealed class CecilAttribute : Immutable, IAttribute |
||||
{ |
||||
ITypeReference attributeType; |
||||
volatile CustomAttribute ca; |
||||
ITypeResolveContext earlyBindContext; |
||||
IList<IConstantValue> positionalArguments; |
||||
IList<KeyValuePair<string, IConstantValue>> namedArguments; |
||||
|
||||
public CecilAttribute(CustomAttribute ca, ITypeResolveContext earlyBindContext) |
||||
{ |
||||
this.attributeType = ReadTypeReference(ca.AttributeType, earlyBindContext); |
||||
this.ca = ca; |
||||
this.earlyBindContext = earlyBindContext; |
||||
} |
||||
|
||||
public DomRegion Region { |
||||
get { return DomRegion.Empty; } |
||||
} |
||||
|
||||
public ITypeReference AttributeType { |
||||
get { return attributeType; } |
||||
} |
||||
|
||||
public IList<IConstantValue> PositionalArguments { |
||||
get { |
||||
EnsureArguments(); |
||||
return positionalArguments; |
||||
} |
||||
} |
||||
|
||||
public IList<KeyValuePair<string, IConstantValue>> NamedArguments { |
||||
get { |
||||
EnsureArguments(); |
||||
return namedArguments; |
||||
} |
||||
} |
||||
|
||||
void EnsureArguments() |
||||
{ |
||||
CustomAttribute ca = this.ca; |
||||
if (ca != null) { |
||||
try { |
||||
if (ca.HasConstructorArguments) { |
||||
var posArgs = new List<IConstantValue>(); |
||||
foreach (var arg in ca.ConstructorArguments) { |
||||
posArgs.Add(ReadConstantValue(arg, earlyBindContext)); |
||||
} |
||||
this.positionalArguments = posArgs.AsReadOnly(); |
||||
} else { |
||||
this.positionalArguments = EmptyList<IConstantValue>.Instance; |
||||
} |
||||
} catch (InvalidOperationException) { |
||||
this.positionalArguments = EmptyList<IConstantValue>.Instance; |
||||
} |
||||
try { |
||||
if (ca.HasFields || ca.HasProperties) { |
||||
var namedArgs = new List<KeyValuePair<string, IConstantValue>>(); |
||||
foreach (var arg in ca.Fields) { |
||||
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument, earlyBindContext))); |
||||
} |
||||
foreach (var arg in ca.Properties) { |
||||
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument, earlyBindContext))); |
||||
} |
||||
this.namedArguments = namedArgs.AsReadOnly(); |
||||
} else { |
||||
this.namedArguments = EmptyList<KeyValuePair<string, IConstantValue>>.Instance; |
||||
} |
||||
} catch (InvalidOperationException) { |
||||
this.namedArguments = EmptyList<KeyValuePair<string, IConstantValue>>.Instance; |
||||
} |
||||
this.ca = null; |
||||
} |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region Read Constant Value
|
||||
public static IConstantValue ReadConstantValue(CustomAttributeArgument arg, ITypeResolveContext earlyBindContext) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics.Contracts; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem |
||||
{ |
||||
/// <summary>
|
||||
/// Context representing the set of assemblies in which a type is being searched.
|
||||
/// Guarantees that the list of types available in the context is not changed until Dispose() is called.
|
||||
/// The Dispose() method must be called from the same thread that create the
|
||||
/// <c>ISynchronizedTypeResolveContext</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A simple implementation might enter a ReaderWriterLock when the synchronized context
|
||||
/// is created, and releases the lock when Dispose() is called.
|
||||
/// However, implementations based on immutable data structures are also possible.
|
||||
/// </remarks>
|
||||
public interface ISynchronizedTypeResolveContext : ITypeResolveContext, IDisposable |
||||
{ |
||||
} |
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
||||
{ |
||||
/// <summary>
|
||||
/// Proxy that forwards calls to another TypeResolveContext.
|
||||
/// Useful as base class for decorators.
|
||||
/// </summary>
|
||||
public class ProxyTypeResolveContext : ITypeResolveContext |
||||
{ |
||||
ITypeResolveContext target; |
||||
|
||||
public ProxyTypeResolveContext(ITypeResolveContext target) |
||||
{ |
||||
if (target == null) |
||||
throw new ArgumentNullException("target"); |
||||
this.target = target; |
||||
} |
||||
|
||||
public virtual ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer) |
||||
{ |
||||
return target.GetClass(fullTypeName, typeParameterCount, nameComparer); |
||||
} |
||||
|
||||
public virtual ISynchronizedTypeResolveContext Synchronize() |
||||
{ |
||||
return target.Synchronize(); |
||||
} |
||||
} |
||||
} |
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Diagnostics.Contracts; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem |
||||
{ |
||||
/// <summary>
|
||||
/// Describes the properties of a language.
|
||||
/// </summary>
|
||||
public class LanguageProperties |
||||
{ |
||||
// TODO: is this class actually useful? consider removing it
|
||||
|
||||
public virtual StringComparer NameComparer { |
||||
get { |
||||
Contract.Ensures(Contract.Result<StringComparer>() != null); |
||||
Contract.Assume(StringComparer.Ordinal != null); |
||||
return StringComparer.Ordinal; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,24 +1,29 @@
@@ -1,24 +1,29 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00 |
||||
# Visual Studio 2010 |
||||
# SharpDevelop 4.0.0.6197 |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj", "{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.Tests", "ICSharpCode.NRefactory.Tests\ICSharpCode.NRefactory.Tests.csproj", "{63D3B27A-D966-4902-90B3-30290E1692F1}" |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
Debug|Any CPU = Debug|Any CPU |
||||
Release|Any CPU = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
EndGlobalSection |
||||
EndGlobal |
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00 |
||||
# Visual Studio 2010 |
||||
# SharpDevelop 4.0.0.6362 |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj", "{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.Tests", "ICSharpCode.NRefactory.Tests\ICSharpCode.NRefactory.Tests.csproj", "{63D3B27A-D966-4902-90B3-30290E1692F1}" |
||||
EndProject |
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DC98210E-1646-483B-819A-2BB8272461E4}" |
||||
ProjectSection(SolutionItems) = postProject |
||||
README = README |
||||
EndProjectSection |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
Debug|Any CPU = Debug|Any CPU |
||||
Release|Any CPU = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{63D3B27A-D966-4902-90B3-30290E1692F1}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
EndGlobalSection |
||||
EndGlobal |
||||
|
||||
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
Overview of the NRefactory library: |
||||
|
||||
ICSharpCode.NRefactory.TypeSystem: |
||||
Contains a language-independent representation of the .NET type system. |
||||
|
||||
ICSharpCode.NRefactory.TypeSystem.Implementation: |
||||
Contains base classes that help implementing the type system interfaces. |
||||
Loading…
Reference in new issue