Browse Source

Implement ICompilationProvider in a few more places where we have the compilation available.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
d01a22564a
  1. 2
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeOrNamespaceReference.cs
  2. 10
      ICSharpCode.NRefactory/TypeSystem/ArrayType.cs
  3. 4
      ICSharpCode.NRefactory/TypeSystem/ICompilation.cs
  4. 10
      ICSharpCode.NRefactory/TypeSystem/ITypeReference.cs
  5. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs
  6. 6
      ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs

2
ICSharpCode.NRefactory.CSharp/TypeSystem/TypeOrNamespaceReference.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
public abstract ResolveResult Resolve(CSharpResolver resolver);
/// <summary>
/// Returns the type that is referenced; or an <see cref="UnknownType"/> if the type isn't found.
/// Returns the type that is referenced; or an <c>UnknownType</c> if the type isn't found.
/// </summary>
public abstract IType ResolveType(CSharpResolver resolver);

10
ICSharpCode.NRefactory/TypeSystem/ArrayType.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents an array type.
/// </summary>
public sealed class ArrayType : TypeWithElementType
public sealed class ArrayType : TypeWithElementType, ICompilationProvider
{
readonly int dimensions;
readonly ICompilation compilation;
@ -38,12 +38,20 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -38,12 +38,20 @@ namespace ICSharpCode.NRefactory.TypeSystem
throw new ArgumentOutOfRangeException("dimensions", dimensions, "dimensions must be positive");
this.compilation = compilation;
this.dimensions = dimensions;
ICompilationProvider p = elementType as ICompilationProvider;
if (p != null && p.Compilation != compilation)
throw new InvalidOperationException("Cannot create an array type using a different compilation from the element type.");
}
public override TypeKind Kind {
get { return TypeKind.Array; }
}
public ICompilation Compilation {
get { return compilation; }
}
public int Dimensions {
get { return dimensions; }
}

4
ICSharpCode.NRefactory/TypeSystem/ICompilation.cs

@ -74,6 +74,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -74,6 +74,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
public interface ICompilationProvider
{
/// <summary>
/// Gets the parent compilation.
/// This property never returns null.
/// </summary>
ICompilation Compilation { get; }
}
}

10
ICSharpCode.NRefactory/TypeSystem/ITypeReference.cs

@ -43,20 +43,14 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -43,20 +43,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </param>
/// <returns>
/// Returns the resolved type.
/// In case of an error, returns <see cref="SpecialType.UnknownType"/>.
/// In case of an error, returns an unknown type (<see cref="TypeKind.Unknown"/>).
/// Never returns null.
/// </returns>
IType Resolve(ITypeResolveContext context);
}
public interface ITypeResolveContext
public interface ITypeResolveContext : ICompilationProvider
{
/// <summary>
/// Gets the parent compilation.
/// This property never returns null.
/// </summary>
ICompilation Compilation { get; }
/// <summary>
/// Gets the current assembly.
/// This property may return null if this context does not specify any assembly.

2
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs

@ -24,7 +24,7 @@ using ICSharpCode.NRefactory.Utils; @@ -24,7 +24,7 @@ using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
public abstract class AbstractTypeParameter : ITypeParameter
public abstract class AbstractTypeParameter : ITypeParameter, ICompilationProvider
{
readonly ICompilation compilation;
readonly EntityType ownerType;

6
ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// the type arguments.
/// </remarks>
[Serializable]
public sealed class ParameterizedType : IType
public sealed class ParameterizedType : IType, ICompilationProvider
{
readonly ITypeDefinition genericType;
readonly IType[] typeArguments;
@ -57,8 +57,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -57,8 +57,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
for (int i = 0; i < this.typeArguments.Length; i++) {
if (this.typeArguments[i] == null)
throw new ArgumentNullException("typeArguments[" + i + "]");
ICompilationProvider r = this.typeArguments[i] as ICompilationProvider;
if (r != null && r.Compilation != genericType.Compilation)
ICompilationProvider p = this.typeArguments[i] as ICompilationProvider;
if (p != null && p.Compilation != genericType.Compilation)
throw new InvalidOperationException("Cannot parameterize a type with type arguments from a different compilation.");
}
}

Loading…
Cancel
Save