Browse Source

Worked on ITypeResolveContext API and on CecilLoader.

newNRvisualizers
Daniel Grunwald 16 years ago
parent
commit
1dd18c1215
  1. 9
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  2. 13
      ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs
  3. 12
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs
  4. 20
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  5. 4
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  6. 125
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  7. 67
      ICSharpCode.NRefactory/TypeSystem/ITypeResolveContext.cs
  8. 84
      ICSharpCode.NRefactory/TypeSystem/Implementation/MultiTypeResolveContext.cs
  9. 26
      ICSharpCode.NRefactory/TypeSystem/Implementation/ProxyTypeResolveContext.cs
  10. 124
      ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs

9
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.NRefactory.Tests</RootNamespace>
<RootNamespace>ICSharpCode.NRefactory</RootNamespace>
<AssemblyName>ICSharpCode.NRefactory.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
@ -48,8 +48,10 @@ @@ -48,8 +48,10 @@
<Compile Include="FormattingTests\TestSpacingVisitor.cs" />
<Compile Include="FormattingTests\TestStatementIndentation.cs" />
<Compile Include="FormattingTests\TestTypeLevelIndentation.cs" />
<Compile Include="MyClassTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TypeSystem\CecilLoaderTests.cs" />
<Compile Include="TypeSystem\TypeSystemTests.cs" />
<Compile Include="TypeSystem\TypeSystemTests.TestCase.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
@ -57,5 +59,8 @@ @@ -57,5 +59,8 @@
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="TypeSystem" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

13
ICSharpCode.NRefactory.Tests/MyClassTests.cs → ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs

@ -2,18 +2,17 @@ @@ -2,18 +2,17 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.Tests
namespace ICSharpCode.NRefactory.TypeSystem
{
[TestFixture]
public class MyClassTests
public class CecilLoaderTests : TypeSystemTests
{
[Test]
public void OK()
[TestFixtureSetUp]
public void SetUp()
{
//CecilProjectContent pc = new CecilProjectContent(
}
}
}
}

12
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
// 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;
namespace ICSharpCode.NRefactory.TypeSystem.TestCase
{
class SimpleInternalClass
{
public void Method() {}
}
}

20
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// 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 NUnit.Framework;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Base class for the type system tests.
/// Test fixtures for specific APIs (Cecil, C# Parser) derive from this class.
/// </summary>
public abstract class TypeSystemTests
{
[Test]
public void Test1()
{
}
}
}

4
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -141,7 +141,7 @@ @@ -141,7 +141,7 @@
<Compile Include="CSharp\Parser\mcs\roottypes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TypeSystem\Accessibility.cs" />
<Compile Include="TypeSystem\CecilProjectContent.cs" />
<Compile Include="TypeSystem\CecilLoader.cs" />
<Compile Include="TypeSystem\ClassType.cs" />
<Compile Include="TypeSystem\DomRegion.cs" />
<Compile Include="TypeSystem\EntityType.cs" />
@ -165,12 +165,14 @@ @@ -165,12 +165,14 @@
<Compile Include="TypeSystem\Implementation\DefaultParameter.cs" />
<Compile Include="TypeSystem\Implementation\DynamicType.cs" />
<Compile Include="TypeSystem\Implementation\GetClassTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\MultiTypeResolveContext.cs" />
<Compile Include="TypeSystem\Implementation\NestedTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\PointerType.cs" />
<Compile Include="TypeSystem\Implementation\ProxyTypeResolveContext.cs" />
<Compile Include="TypeSystem\Implementation\DefaultTypeDefinition.cs" />
<Compile Include="TypeSystem\Implementation\NullType.cs" />
<Compile Include="TypeSystem\Implementation\SimpleConstantValue.cs" />
<Compile Include="TypeSystem\Implementation\SimpleProjectContent.cs" />
<Compile Include="TypeSystem\Implementation\TypeWithElementType.cs" />
<Compile Include="TypeSystem\Implementation\UnknownType.cs" />
<Compile Include="TypeSystem\INamedElement.cs" />

125
ICSharpCode.NRefactory/TypeSystem/CecilProjectContent.cs → ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -12,18 +12,18 @@ using Mono.Cecil; @@ -12,18 +12,18 @@ using Mono.Cecil;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Project content that represents an already compiled assembly.
/// Static methods for loading an IProjectContent from an already compiled assembly.
/// </summary>
public class CecilProjectContent : IProjectContent
public static class CecilLoader
{
IList<IAttribute> assemblyAttributes;
#region Constructor
public CecilProjectContent(AssemblyDefinition assemblyDefinition)
#region Load From AssemblyDefinition
public static IProjectContent LoadAssembly(AssemblyDefinition assemblyDefinition)
{
this.assemblyAttributes = new List<IAttribute>();
ReadAttributes(assemblyDefinition, this.assemblyAttributes);
this.assemblyAttributes = new ReadOnlyCollection<IAttribute>(this.assemblyAttributes);
if (assemblyDefinition == null)
throw new ArgumentNullException("assemblyDefinition");
List<IAttribute> assemblyAttributes = new List<IAttribute>();
ReadAttributes(assemblyDefinition, assemblyAttributes, earlyBindContext: null);
CecilProjectContent pc = new CecilProjectContent(assemblyDefinition.Name.FullName, assemblyAttributes.AsReadOnly());
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>();
foreach (ModuleDefinition module in assemblyDefinition.Modules) {
foreach (TypeDefinition td in module.Types) {
@ -31,38 +31,72 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -31,38 +31,72 @@ namespace ICSharpCode.NRefactory.TypeSystem
string name = td.FullName;
if (name.Length == 0 || name[0] == '<')
continue;
types.Add(new CecilTypeDefinition(this, td));
types.Add(new CecilTypeDefinition(pc, td));
}
}
}
foreach (CecilTypeDefinition c in types) {
c.Init(this);
c.Init(pc);
pc.AddType(c);
}
pc.initialized = true;
return pc;
}
public CecilProjectContent(TypeDefinition typeDefinition)
/// <summary>
/// Loads a type from Cecil.
/// </summary>
/// <param name="typeDefinition">The Cecil TypeDefinition.</param>
/// <param name="projectContent">The project content used as parent for the new type.</param>
/// <returns>ITypeDefinition representing the Cecil type.</returns>
public static ITypeDefinition LoadType(TypeDefinition typeDefinition, IProjectContent projectContent)
{
this.assemblyAttributes = EmptyList<IAttribute>.Instance;
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>();
types.Add(new CecilTypeDefinition(this, typeDefinition));
types[0].Init(this);
if (typeDefinition == null)
throw new ArgumentNullException("typeDefinition");
if (projectContent == null)
throw new ArgumentNullException("projectContent");
var c = new CecilTypeDefinition(projectContent, typeDefinition);
c.Init(null);
return c;
}
#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()
sealed class CecilProjectContent : SimpleProjectContent
{
// CecilProjectContent is immutable, so we don't need to synchronize
return new DummySynchronizedTypeResolveContext(this);
readonly string assemblyName;
internal bool initialized;
public CecilProjectContent(string assemblyName, ReadOnlyCollection<IAttribute> assemblyAttributes)
{
this.assemblyName = assemblyName;
this.AssemblyAttributes = assemblyAttributes;
}
public override string ToString()
{
return "[CecilProjectContent " + assemblyName + "]";
}
public override void AddType(ITypeDefinition typeDefinition)
{
// ensure that CecilProjectContent stays immutable after it's initialized
if (initialized)
throw new NotSupportedException();
base.AddType(typeDefinition);
}
public override void RemoveType(ITypeDefinition typeDefinition)
{
// ensure that CecilProjectContent stays immutable after it's initialized
throw new NotSupportedException();
}
public override ISynchronizedTypeResolveContext Synchronize()
{
// CecilProjectContent is immutable, so we don't need to synchronize
return new DummySynchronizedTypeResolveContext(this);
}
}
sealed class DummySynchronizedTypeResolveContext : ProxyTypeResolveContext, ISynchronizedTypeResolveContext
@ -74,16 +108,21 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -74,16 +108,21 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void Dispose()
{
}
public override ISynchronizedTypeResolveContext Synchronize()
{
return this;
}
}
#endregion
#region Load Assembly From Disk
public static CecilProjectContent LoadAssembly(string fileName)
public static IProjectContent LoadAssembly(string fileName)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, new ReaderParameters { AssemblyResolver = new DummyAssemblyResolver() });
return new CecilProjectContent(asm);
return LoadAssembly(asm);
}
// used to prevent Cecil from loading referenced assemblies
@ -109,10 +148,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -109,10 +148,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// a type system type reference.</param>
/// <param name="typeAttributes">Attributes associated with the Cecil type reference.
/// This is used to support the 'dynamic' type.</param>
/// <param name="earlyBindContext">Early binding context - used to pre-resolve
/// type references where possible.</param>
/// <param name="entity">The entity that owns this type reference.
/// Used for generic type references.</param>
/// <param name="earlyBindContext">Early binding context - used to pre-resolve
/// type references where possible.</param>
public static ITypeReference ReadTypeReference(
TypeReference type,
ICustomAttributeProvider typeAttributes = null,
@ -262,10 +301,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -262,10 +301,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region Read Attributes
void ReadAttributes(ICustomAttributeProvider attributeProvider, IList<IAttribute> outputList)
static void ReadAttributes(ICustomAttributeProvider attributeProvider, IList<IAttribute> outputList, ITypeResolveContext earlyBindContext)
{
foreach (var cecilAttribute in attributeProvider.CustomAttributes) {
outputList.Add(new CecilAttribute(cecilAttribute, this));
outputList.Add(new CecilAttribute(cecilAttribute, earlyBindContext));
}
}
@ -356,9 +395,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -356,9 +395,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
this.typeDefinition = typeDefinition;
}
public void Init(CecilProjectContent pc)
public void Init(ITypeResolveContext earlyBindContext)
{
InitNestedTypes(pc);
InitNestedTypes(earlyBindContext);
InitModifiers();
if (typeDefinition.HasGenericParameters) {
@ -373,26 +412,26 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -373,26 +412,26 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
if (typeDefinition.HasCustomAttributes) {
pc.ReadAttributes(typeDefinition, this.Attributes);
ReadAttributes(typeDefinition, this.Attributes, earlyBindContext);
}
// set base classes
if (typeDefinition.BaseType != null) {
BaseTypes.Add(ReadTypeReference(typeDefinition.BaseType, entity: this, earlyBindContext: pc));
BaseTypes.Add(ReadTypeReference(typeDefinition.BaseType, entity: this, earlyBindContext: earlyBindContext));
}
if (typeDefinition.HasInterfaces) {
foreach (TypeReference iface in typeDefinition.Interfaces) {
BaseTypes.Add(ReadTypeReference(iface, entity: this, earlyBindContext: pc));
BaseTypes.Add(ReadTypeReference(iface, entity: this, earlyBindContext: earlyBindContext));
}
}
InitMembers(pc);
InitMembers(earlyBindContext);
this.typeDefinition = null;
Freeze(); // freeze after initialization
}
void InitNestedTypes(CecilProjectContent pc)
void InitNestedTypes(ITypeResolveContext earlyBindContext)
{
if (!typeDefinition.HasNestedTypes)
return;
@ -413,7 +452,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -413,7 +452,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
foreach (CecilTypeDefinition innerClass in this.InnerClasses) {
innerClass.Init(pc);
innerClass.Init(earlyBindContext);
}
}
@ -471,7 +510,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -471,7 +510,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
return false;
}
void InitMembers(CecilProjectContent pc)
void InitMembers(ITypeResolveContext earlyBindContext)
{
throw new NotImplementedException();
}

67
ICSharpCode.NRefactory/TypeSystem/ITypeResolveContext.cs

@ -13,8 +13,46 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -13,8 +13,46 @@ namespace ICSharpCode.NRefactory.TypeSystem
[ContractClass(typeof(ITypeResolveContextContract))]
public interface ITypeResolveContext
{
/// <summary>
/// Retrieves a class.
/// </summary>
/// <param name="fullTypeName">Full name of the class</param>
/// <param name="typeParameterCount">Number of type parameters</param>
/// <param name="nameComparer">Language-specific rules for how class names are compared</param>
/// <returns>The type definition for the class; or null if no such class exists.</returns>
/// <remarks>This method never returns inner classes; it can be used only with top-level classes.</remarks>
ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer);
/// <summary>
/// Retrieves all top-level classes.
/// </summary>
/// <remarks>
/// If this method is called within <c>using (pc.Synchronize())</c>, then the returned enumerable is valid
/// only until the end of the synchronize block.
/// </remarks>
IEnumerable<ITypeDefinition> GetClasses();
/// <summary>
/// Retrieves all classes in the specified namespace.
/// </summary>
/// <param name="nameSpace">Namespace in which classes are being retrieved. Use <c>string.Empty</c> for the root namespace.</param>
/// <param name="nameComparer">Language-specific rules for how namespace names are compared</param>
/// <returns>List of classes within that namespace.</returns>
/// <remarks>
/// If this method is called within <c>using (pc.Synchronize())</c>, then the returned enumerable is valid
/// only until the end of the synchronize block.
/// </remarks>
IEnumerable<ITypeDefinition> GetClasses(string nameSpace, StringComparer nameComparer);
/// <summary>
/// Retrieves all namespaces.
/// </summary>
/// <remarks>
/// If this method is called within <c>using (pc.Synchronize())</c>, then the returned enumerable is valid
/// only until the end of the synchronize block.
/// </remarks>
IEnumerable<string> GetNamespaces();
/// <summary>
/// Returns a <see cref="ISynchronizedTypeResolveContext"/> that
/// represents the same context as this instance, but cannot be modified
@ -22,6 +60,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -22,6 +60,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// The ISynchronizedTypeResolveContext must be disposed from the same thread
/// that called this method when it is no longer used.
/// </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>
ISynchronizedTypeResolveContext Synchronize();
}
@ -33,13 +76,33 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -33,13 +76,33 @@ namespace ICSharpCode.NRefactory.TypeSystem
Contract.Requires(fullTypeName != null);
Contract.Requires(typeParameterCount >= 0);
Contract.Requires(nameComparer != null);
return null;
throw new NotImplementedException();
}
ISynchronizedTypeResolveContext ITypeResolveContext.Synchronize()
{
Contract.Ensures(Contract.Result<ISynchronizedTypeResolveContext>() != null);
return null;
throw new NotImplementedException();
}
IEnumerable<ITypeDefinition> ITypeResolveContext.GetClasses()
{
Contract.Ensures(Contract.Result<IEnumerable<ITypeDefinition>>() != null);
throw new NotImplementedException();
}
IEnumerable<ITypeDefinition> ITypeResolveContext.GetClasses(string nameSpace, StringComparer nameComparer)
{
Contract.Requires(nameSpace != null);
Contract.Requires(nameComparer != null);
Contract.Ensures(Contract.Result<IEnumerable<ITypeDefinition>>() != null);
throw new NotImplementedException();
}
IEnumerable<string> ITypeResolveContext.GetNamespaces()
{
Contract.Ensures(Contract.Result<IEnumerable<ITypeDefinition>>() != null);
throw new NotImplementedException();
}
}
}

84
ICSharpCode.NRefactory/TypeSystem/Implementation/MultiTypeResolveContext.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
// 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.Linq;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Represents multiple type resolve contexts.
/// </summary>
public class MultiTypeResolveContext : ITypeResolveContext
{
readonly ITypeResolveContext[] contexts;
/// <summary>
/// Creates a new <see cref="MultiTypeResolveContext"/>
/// </summary>
public MultiTypeResolveContext(IEnumerable<ITypeResolveContext> contexts)
{
if (contexts == null)
throw new ArgumentNullException("contexts");
this.contexts = contexts.ToArray();
}
/// <inheritdoc/>
public ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
{
foreach (ITypeResolveContext context in contexts) {
ITypeDefinition d = context.GetClass(fullTypeName, typeParameterCount, nameComparer);
if (d != null)
return d;
}
return null;
}
/// <inheritdoc/>
public IEnumerable<ITypeDefinition> GetClasses()
{
return contexts.SelectMany(c => c.GetClasses());
}
/// <inheritdoc/>
public IEnumerable<ITypeDefinition> GetClasses(string nameSpace, StringComparer nameComparer)
{
return contexts.SelectMany(c => c.GetClasses(nameSpace, nameComparer));
}
/// <inheritdoc/>
public IEnumerable<string> GetNamespaces()
{
return contexts.SelectMany(c => c.GetNamespaces()).Distinct();
}
/// <inheritdoc/>
public ISynchronizedTypeResolveContext Synchronize()
{
ISynchronizedTypeResolveContext[] sync = new ISynchronizedTypeResolveContext[contexts.Length];
for (int i = 0; i < sync.Length; i++) {
sync[i] = contexts[i].Synchronize();
}
return new MultiSynchronizedTypeResolveContext(this, sync);
}
sealed class MultiSynchronizedTypeResolveContext : ProxyTypeResolveContext, ISynchronizedTypeResolveContext
{
readonly ISynchronizedTypeResolveContext[] sync;
public MultiSynchronizedTypeResolveContext(ITypeResolveContext target, ISynchronizedTypeResolveContext[] sync)
: base(target)
{
this.sync = sync;
}
public void Dispose()
{
foreach (var element in sync) {
element.Dispose();
}
}
}
}
}

26
ICSharpCode.NRefactory/TypeSystem/Implementation/ProxyTypeResolveContext.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
@ -11,8 +12,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -11,8 +12,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// </summary>
public class ProxyTypeResolveContext : ITypeResolveContext
{
ITypeResolveContext target;
readonly ITypeResolveContext target;
/// <summary>
/// Creates a new ProxyTypeResolveContext.
/// </summary>
public ProxyTypeResolveContext(ITypeResolveContext target)
{
if (target == null)
@ -20,11 +24,31 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -20,11 +24,31 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.target = target;
}
/// <inheritdoc/>
public virtual ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
{
return target.GetClass(fullTypeName, typeParameterCount, nameComparer);
}
/// <inheritdoc/>
public virtual IEnumerable<ITypeDefinition> GetClasses()
{
return target.GetClasses();
}
/// <inheritdoc/>
public virtual IEnumerable<ITypeDefinition> GetClasses(string nameSpace, StringComparer nameComparer)
{
return target.GetClasses(nameSpace, nameComparer);
}
/// <inheritdoc/>
public virtual IEnumerable<string> GetNamespaces()
{
return target.GetNamespaces();
}
/// <inheritdoc/>
public virtual ISynchronizedTypeResolveContext Synchronize()
{
return target.Synchronize();

124
ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs

@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
// 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.Threading;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Simple <see cref="IProjectContent"/> implementation that stores the list of classes/namespaces.
/// </summary>
public class SimpleProjectContent : IProjectContent
{
ReaderWriterLockSlim readWriteLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
#region AssemblyAttributes
IList<IAttribute> assemblyAttributes = new List<IAttribute>();
/// <inheritdoc/>
public IList<IAttribute> AssemblyAttributes {
get { return assemblyAttributes; }
protected set {
if (value == null)
throw new ArgumentNullException();
assemblyAttributes = value;
}
}
#endregion
#region ITypeResolveContext implementation
/// <inheritdoc/>
public ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
{
throw new NotImplementedException();
}
/// <inheritdoc/>
public IEnumerable<ITypeDefinition> GetClasses()
{
throw new NotImplementedException();
}
/// <inheritdoc/>
public IEnumerable<ITypeDefinition> GetClasses(string nameSpace, StringComparer nameComparer)
{
throw new NotImplementedException();
}
/// <inheritdoc/>
public IEnumerable<string> GetNamespaces()
{
throw new NotImplementedException();
}
#endregion
#region Synchronize
/// <inheritdoc/>
public virtual ISynchronizedTypeResolveContext Synchronize()
{
readWriteLock.EnterReadLock();
return new ReadWriteSynchronizedTypeResolveContext(this, readWriteLock);
}
sealed class ReadWriteSynchronizedTypeResolveContext : ProxyTypeResolveContext, ISynchronizedTypeResolveContext
{
readonly ReaderWriterLockSlim readWriteLock;
bool disposed;
public ReadWriteSynchronizedTypeResolveContext(ITypeResolveContext context, ReaderWriterLockSlim readWriteLock)
: base(context)
{
this.readWriteLock = readWriteLock;
}
public void Dispose()
{
if (!disposed) {
disposed = true;
readWriteLock.ExitReadLock();
}
}
}
#endregion
#region AddType
/// <summary>
/// Adds a type definition to this project content.
/// </summary>
public virtual void AddType(ITypeDefinition typeDefinition)
{
if (typeDefinition == null)
throw new ArgumentNullException("typeDefinition");
if (!typeDefinition.IsFrozen)
throw new ArgumentException("Type definition must be frozen before it can be added to a project content");
if (typeDefinition.ProjectContent != this)
throw new ArgumentException("Cannot add a type definition that belongs to another project content");
try {
readWriteLock.EnterWriteLock();
throw new NotImplementedException();
} finally {
readWriteLock.ExitWriteLock();
}
}
#endregion
#region RemoveType
/// <summary>
/// Removes a type definition from this project content.
/// </summary>
public virtual void RemoveType(ITypeDefinition typeDefinition)
{
if (typeDefinition == null)
throw new ArgumentNullException("typeDefinition");
try {
readWriteLock.EnterWriteLock();
throw new NotImplementedException();
} finally {
readWriteLock.ExitWriteLock();
}
}
#endregion
}
}
Loading…
Cancel
Save