Browse Source

Add support for partial classes.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
69ae15aee3
  1. 2
      ICSharpCode.NRefactory/CSharp/Resolver/MemberTypeOrNamespaceReference.cs
  2. 2
      ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs
  3. 1
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  4. 71
      ICSharpCode.NRefactory/TypeSystem/IType.cs
  5. 9
      ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs
  6. 5
      ICSharpCode.NRefactory/TypeSystem/ITypeReference.cs
  7. 142
      ICSharpCode.NRefactory/TypeSystem/Implementation/CompoundTypeDefinition.cs
  8. 57
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  9. 23
      ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs
  10. 28
      ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs
  11. 3
      ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs
  12. 12
      ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs

2
ICSharpCode.NRefactory/CSharp/Resolver/MemberTypeOrNamespaceReference.cs

@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (targetRR.IsError)
return targetRR;
CSharpResolver r = new CSharpResolver(context);
r.CurrentTypeDefinition = parentTypeDefinition != null ? parentTypeDefinition.GetCompoundClass() : null;
r.CurrentTypeDefinition = parentTypeDefinition;
r.UsingScope = parentUsingScope;
IType[] typeArgs = new IType[typeArguments.Count];
for (int i = 0; i < typeArgs.Length; i++) {

2
ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public ResolveResult DoResolve(ITypeResolveContext context)
{
CSharpResolver r = new CSharpResolver(context);
r.CurrentTypeDefinition = parentTypeDefinition != null ? parentTypeDefinition.GetCompoundClass() : null;
r.CurrentTypeDefinition = parentTypeDefinition;
r.UsingScope = parentUsingScope;
IType[] typeArgs = new IType[typeArguments.Count];
for (int i = 0; i < typeArgs.Length; i++) {

1
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -235,6 +235,7 @@ @@ -235,6 +235,7 @@
<Compile Include="TypeSystem\Implementation\AbstractMember.cs" />
<Compile Include="TypeSystem\Implementation\AbstractType.cs" />
<Compile Include="TypeSystem\Implementation\BaseTypeCollector.cs" />
<Compile Include="TypeSystem\Implementation\CompoundTypeDefinition.cs" />
<Compile Include="TypeSystem\Implementation\DefaultAccessor.cs" />
<Compile Include="TypeSystem\Implementation\DefaultAttribute.cs" />
<Compile Include="TypeSystem\Implementation\DefaultEvent.cs" />

71
ICSharpCode.NRefactory/TypeSystem/IType.cs

@ -22,6 +22,32 @@ using System.Diagnostics.Contracts; @@ -22,6 +22,32 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// This interface represents a resolved type in the type system.
/// </summary>
/// <remarks>
/// <para>
/// A type is potentially
/// - a type definition (<see cref="ITypeDefiniton"/>, i.e. a class, struct, interface, delegate, or built-in primitive type)
/// - a parameterized type (<see cref="ParameterizedType"/>, e.g. List&lt;int>)
/// - a type parameter (<see cref="ITypeParameter"/>, e.g. T)
/// - an array (<see cref="ArrayType"/>)
/// - a pointer (<see cref="PointerType"/>)
/// - a managed reference (<see cref="ByReferenceType"/>)
/// - one of the special types (<see cref="SharedTypes.UnknownType"/>, <see cref="SharedTypes.Null"/>,
/// <see cref="SharedTypes.Dynamic"/>, <see cref="SharedTypes.UnboundTypeArgument"/>)
///
/// The <see cref="IType.Kind"/> property can be used to switch on the kind of a type.
/// </para>
/// <para>
/// IType uses the null object pattern: <see cref="SharedTypes.UnknownType"/> serves as the null object.
/// Methods or properties returning IType never return null unless documented otherwise.
/// </para>
/// <para>
/// Types should be compared for equality using the <see cref="IType.Equals(IType)"/> method.
/// Identical types do not necessarily use the same object reference.
/// </para>
/// </remarks>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeContract))]
#endif
@ -48,7 +74,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -48,7 +74,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Gets the underlying type definition.
/// Can return null for types which do not have a type definition (for example arrays, pointers, type parameters)
/// Can return null for types which do not have a type definition (for example arrays, pointers, type parameters).
///
/// For partial classes, this method always returns the <see cref="CompoundTypeDefinition"/>.
/// </summary>
ITypeDefinition GetDefinition();
@ -92,14 +120,17 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -92,14 +120,17 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <param name="filter">The filter used to select which types to return.
/// The filter is tested on the original type definitions (before parameterization).</param>
/// <remarks>
/// <para>
/// If the nested type is generic (and has more type parameters than the outer class),
/// this method will return a parameterized type,
/// where the additional type parameters are set to <see cref="SharedType.UnboundTypeArgument"/>.
///
/// </para>
/// <para>
/// Type parameters belonging to the outer class will have the value copied from the outer type
/// if it is a parameterized type. Otherwise, those existing type parameters will be self-parameterized,
/// and thus 'leaked' to the caller in the same way the GetMembers() method does not specialize members
/// from an <see cref="ITypeDefinition"/> and 'leaks' type parameters in member signatures.
/// </para>
/// </remarks>
/// <example>
/// <code>
@ -148,9 +179,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -148,9 +179,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <param name="filter">The filter used to select which constructors to return.
/// The filter is tested on the original method definitions (before specialization).</param>
/// <remarks>
/// This list does not include constructors in base classes or static constructors.
/// <para>The result does not include constructors in base classes or static constructors.</para>
/// <para>
/// For methods on parameterized types, type substitution will be performed on the method signature,
/// and the appropriate <see cref="SpecializedMethod"/> will be returned.
/// </para>
/// </remarks>
IEnumerable<IMethod> GetConstructors(ITypeResolveContext context, Predicate<IMethod> filter = null);
@ -161,22 +194,44 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -161,22 +194,44 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <param name="filter">The filter used to select which methods to return.
/// The filter is tested on the original method definitions (before specialization).</param>
/// <remarks>
/// The list does not include constructors.
/// <para>
/// The result does not include constructors.
/// </para>
/// <para>
/// For methods on parameterized types, type substitution will be performed on the method signature,
/// and the appropriate <see cref="SpecializedMethod"/> will be returned.
/// </para>
/// <para>
/// If the method being returned is generic, and this type is a parameterized type where the type
/// arguments involve another method's type parameters, the resulting specialized signature
/// will be ambiguous as to which method a type parameter belongs to.
/// For example, "List[[``0]].GetMethods()" will return "ConvertAll(Converter`2[[``0, ``0]])".
///
/// If possible, use the other GetMethods() overload to supply type arguments to the method,
/// so that both class and method type parameter can be substituted at the same time, so that
/// the ambiguity can be avoided.
/// </para>
/// </remarks>
IEnumerable<IMethod> GetMethods(ITypeResolveContext context, Predicate<IMethod> filter = null);
/// <summary>
/// Gets all generic methods that can be called on this type with the specified type arguments.
/// </summary>
/// <param name="typeArguments">The type arguments used for the call.</param>
/// <param name="typeArguments">The type arguments used for the method call.</param>
/// <param name="context">The context used for resolving type references</param>
/// <param name="filter">The filter used to select which methods to return.
/// The filter is tested on the original method definitions (before specialization).</param>
/// <remarks>
/// <para>The result does not include constructors.</para>
/// <para>
/// Type substitution will be performed on the method signature, creating a <see cref="SpecializedMethod"/>
/// with the specified type arguments.
/// </para>
/// <para>
/// When the list of type arguments is empty, this method acts like the GetMethods() overload without
/// the type arguments parameter - that is, it also returns generic methods,
/// and the other overload's remarks about ambiguous signatures apply here as well.
/// </para>
/// </remarks>
IEnumerable<IMethod> GetMethods(IList<IType> typeArguments, ITypeResolveContext context, Predicate<IMethod> filter = null);
@ -223,9 +278,15 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -223,9 +278,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <param name="filter">The filter used to select which members to return.
/// The filter is tested on the original member definitions (before specialization).</param>
/// <remarks>
/// <para>
/// The resulting list is the union of GetFields(), GetProperties(), GetMethods() and GetEvents().
/// It does not include constructors.
/// For parameterized types, type substitution will be performed.
/// </para>
/// <para>
/// For generic methods, the remarks about ambiguous signatures from the
/// <see cref="GetMethods(ITypeResolveContext, Predicate{IMethod})"/> method apply here as well.
/// </para>
/// </remarks>
IEnumerable<IMember> GetMembers(ITypeResolveContext context, Predicate<IMember> filter = null);
}

9
ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs

@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Represents a class, enum, interface, struct, delegate or VB module.
/// Also used to represent a part of a partial class.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeDefinitionContract))]
@ -33,14 +34,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -33,14 +34,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
IList<ITypeReference> BaseTypes { get; }
IList<ITypeParameter> TypeParameters { get; }
/// <summary>
/// If this is a partial class, gets the compound class containing information from all parts.
/// If this is not a partial class, a reference to this class is returned.
///
/// This method will always retrieve the latest version of the class, which might not contain this class as a part.
/// </summary>
ITypeDefinition GetCompoundClass();
/// <summary>
/// If this is a compound class (combination of class parts), this method retrieves all individual class parts.
/// Otherwise, a list containing <c>this</c> is returned.

5
ICSharpCode.NRefactory/TypeSystem/ITypeReference.cs

@ -40,6 +40,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -40,6 +40,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Resolves this type reference.
/// </summary>
/// <returns>
/// Returns the resolved type.
/// In case of an error, returns <see cref="SharedTypes.UnknownType"/>.
/// Never returns null.
/// </returns>
IType Resolve(ITypeResolveContext context);
}

142
ICSharpCode.NRefactory/TypeSystem/Implementation/CompoundTypeDefinition.cs

@ -0,0 +1,142 @@ @@ -0,0 +1,142 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Type definition that represents a partial class with multiple parts.
/// </summary>
public class CompoundTypeDefinition : DefaultTypeDefinition
{
IList<ITypeDefinition> parts;
private CompoundTypeDefinition(ITypeDefinition declaringTypeDefinition, string name)
: base(declaringTypeDefinition, name)
{
}
private CompoundTypeDefinition(IProjectContent projectContent, string ns, string name)
: base(projectContent, ns, name)
{
}
protected override void FreezeInternal()
{
parts = FreezeList(parts);
base.FreezeInternal();
}
public override IList<ITypeDefinition> GetParts()
{
return parts;
}
public override string Documentation {
get { return parts[0].Documentation; }
}
public static ITypeDefinition Create(IList<ITypeDefinition> parts)
{
if (parts == null || parts.Count == 0)
throw new ArgumentException("parts");
ITypeDefinition mainPart = parts[0];
for (int i = 1; i < parts.Count; i++) {
if (PreferAsMainPart(parts[i], mainPart))
mainPart = parts[i];
}
if (parts.Count == 1) {
((DefaultTypeDefinition)mainPart).SetCompoundTypeDefinition(mainPart);
return mainPart;
}
CompoundTypeDefinition compound;
if (mainPart.DeclaringTypeDefinition != null) {
throw new NotImplementedException("nested compound types not implemented");
} else {
compound = new CompoundTypeDefinition(mainPart.ProjectContent, mainPart.Namespace, mainPart.Name);
}
compound.parts = parts;
compound.Region = mainPart.Region;
compound.BodyRegion = mainPart.BodyRegion;
compound.TypeParameters.AddRange(mainPart.TypeParameters);
compound.IsSynthetic = mainPart.IsSynthetic;
compound.Accessibility = mainPart.Accessibility;
bool allPartsFrozen = true;
foreach (DefaultTypeDefinition part in parts) {
compound.BaseTypes.AddRange(part.BaseTypes);
compound.Attributes.AddRange(part.Attributes);
compound.NestedTypes.AddRange(part.NestedTypes);
compound.Methods.AddRange(part.Methods);
compound.Properties.AddRange(part.Properties);
compound.Events.AddRange(part.Events);
compound.Fields.AddRange(part.Fields);
if (part.IsAbstract)
compound.IsAbstract = true;
if (part.IsSealed)
compound.IsSealed = true;
if (part.IsShadowing)
compound.IsShadowing = true;
if (part.HasExtensionMethods)
compound.HasExtensionMethods = true;
if (part.AddDefaultConstructorIfRequired)
compound.AddDefaultConstructorIfRequired = true;
// internal is the default, so use another part's accessibility until we find a non-internal accessibility
if (compound.Accessibility == Accessibility.Internal)
compound.Accessibility = part.Accessibility;
allPartsFrozen &= part.IsFrozen;
}
if (allPartsFrozen) {
// If all parts are frozen, also freeze the compound typedef.
compound.Freeze();
}
// Publish the compound class via part.compoundTypeDefinition only after it has been frozen.
foreach (DefaultTypeDefinition part in parts) {
part.SetCompoundTypeDefinition(compound);
}
return compound;
}
/// <summary>
/// Gets whether part1 should be preferred as main part over part2.
/// </summary>
static bool PreferAsMainPart(ITypeDefinition part1, ITypeDefinition part2)
{
if (part1.IsSynthetic != part2.IsSynthetic)
return part2.IsSynthetic; // prefer non-synthetic part
string file1 = part1.Region.FileName;
string file2 = part2.Region.FileName;
if ((file1 != null) != (file2 != null))
return file1 != null; // prefer part with file name
if (file1 != null && file2 != null) {
return file1.Length < file2.Length; // prefer shorter file name (file without Designer suffix)
}
return false;
}
}
}

57
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs

@ -20,7 +20,7 @@ using System; @@ -20,7 +20,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@ -30,6 +30,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -30,6 +30,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
readonly IProjectContent projectContent;
readonly ITypeDefinition declaringTypeDefinition;
volatile ITypeDefinition compoundTypeDefinition;
string ns;
string name;
@ -79,6 +81,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -79,6 +81,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.declaringTypeDefinition = declaringTypeDefinition;
this.name = name;
this.ns = declaringTypeDefinition.Namespace;
this.compoundTypeDefinition = this;
}
public DefaultTypeDefinition(IProjectContent projectContent, string ns, string name)
@ -90,6 +94,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -90,6 +94,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.projectContent = projectContent;
this.ns = ns ?? string.Empty;
this.name = name;
this.compoundTypeDefinition = this;
}
public TypeKind Kind {
@ -371,6 +377,15 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -371,6 +377,15 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
public IEnumerable<IType> GetBaseTypes(ITypeResolveContext context)
{
ITypeDefinition compound = this.compoundTypeDefinition;
if (compound != this)
return compound.GetBaseTypes(context);
else
return GetBaseTypesImpl(context);
}
IEnumerable<IType> GetBaseTypesImpl(ITypeResolveContext context)
{
bool hasNonInterface = false;
if (baseTypes != null && kind != TypeKind.Enum) {
@ -382,31 +397,31 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -382,31 +397,31 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
if (!hasNonInterface && !(this.Name == "Object" && this.Namespace == "System" && this.TypeParameterCount == 0)) {
Type primitiveBaseType;
string primitiveBaseType;
switch (kind) {
case TypeKind.Enum:
primitiveBaseType = typeof(Enum);
primitiveBaseType = "Enum";
break;
case TypeKind.Struct:
case TypeKind.Void:
primitiveBaseType = typeof(ValueType);
primitiveBaseType = "ValueType";
break;
case TypeKind.Delegate:
primitiveBaseType = typeof(Delegate);
primitiveBaseType = "Delegate";
break;
default:
primitiveBaseType = typeof(object);
primitiveBaseType = "Object";
break;
}
IType t = context.GetTypeDefinition(primitiveBaseType);
IType t = context.GetTypeDefinition("System", primitiveBaseType, 0, StringComparer.Ordinal);
if (t != null)
yield return t;
}
}
public virtual ITypeDefinition GetCompoundClass()
internal void SetCompoundTypeDefinition(ITypeDefinition compoundTypeDefinition)
{
return this;
this.compoundTypeDefinition = compoundTypeDefinition;
}
public virtual IList<ITypeDefinition> GetParts()
@ -414,9 +429,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -414,9 +429,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
return new ITypeDefinition[] { this };
}
ITypeDefinition IType.GetDefinition()
public ITypeDefinition GetDefinition()
{
return this;
return compoundTypeDefinition;
}
IType ITypeReference.Resolve(ITypeResolveContext context)
@ -448,7 +463,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -448,7 +463,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public virtual IEnumerable<IMethod> GetConstructors(ITypeResolveContext context, Predicate<IMethod> filter = null)
{
ITypeDefinition compound = GetCompoundClass();
ITypeDefinition compound = this.compoundTypeDefinition;
if (compound != this)
return compound.GetConstructors(context, filter);
@ -492,11 +507,25 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -492,11 +507,25 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
return ParameterizedType.GetMembers(this, context, filter);
}
// we use reference equality
#region Equals / GetHashCode
bool IEquatable<IType>.Equals(IType other)
{
return this == other;
// Two ITypeDefinitions are considered to be equal if they have the same compound class.
ITypeDefinition typeDef = other as ITypeDefinition;
return typeDef != null && this.GetDefinition() == typeDef.GetDefinition();
}
public override bool Equals(object obj)
{
ITypeDefinition typeDef = obj as ITypeDefinition;
return typeDef != null && this.GetDefinition() == typeDef.GetDefinition();
}
public override int GetHashCode()
{
return RuntimeHelpers.GetHashCode(compoundTypeDefinition);
}
#endregion
public override string ToString()
{

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

@ -96,15 +96,32 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -96,15 +96,32 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
if (typeDefinition.ProjectContent != this)
throw new ArgumentException("Cannot add a type definition that belongs to another project content");
// TODO: handle partial classes
types.UpdateType(typeDefinition);
ITypeDefinition existingTypeDef = types.GetTypeDefinition(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount, StringComparer.Ordinal);
if (existingTypeDef != null) {
// Add a part to a compound class
var newParts = new List<ITypeDefinition>(existingTypeDef.GetParts());
newParts.Add(typeDefinition);
types.UpdateType(CompoundTypeDefinition.Create(newParts));
} else {
types.UpdateType(typeDefinition);
}
}
#endregion
#region RemoveType
void RemoveType(ITypeDefinition typeDefinition)
{
types.RemoveType (typeDefinition); // <- Daniel: Correct ?
var compoundTypeDef = typeDefinition.GetDefinition() as CompoundTypeDefinition;
if (compoundTypeDef != null) {
// Remove one part from a compound class
var newParts = new List<ITypeDefinition>(compoundTypeDef.GetParts());
if (newParts.Remove(typeDefinition)) {
((DefaultTypeDefinition)typeDefinition).SetCompoundTypeDefinition(typeDefinition);
}
types.UpdateType(CompoundTypeDefinition.Create(newParts));
} else {
types.RemoveType(typeDefinition);
}
}
#endregion

28
ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
@ -114,5 +115,32 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -114,5 +115,32 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public bool IsOperator {
get { return methodDefinition.IsOperator; }
}
public override string ToString()
{
StringBuilder b = new StringBuilder("[");
b.Append(GetType().Name);
b.Append(' ');
b.Append(this.DeclaringType.ToString());
b.Append('.');
b.Append(this.Name);
if (typeArguments != null && typeArguments.Count > 0) {
b.Append('[');
for (int i = 0; i < typeArguments.Count; i++) {
if (i > 0) b.Append(", ");
b.Append(typeArguments[i].ToString());
}
b.Append(']');
}
b.Append('(');
for (int i = 0; i < this.Parameters.Count; i++) {
if (i > 0) b.Append(", ");
b.Append(this.Parameters[i].ToString());
}
b.Append("):");
b.Append(this.ReturnType.ToString());
b.Append(']');
return b.ToString();
}
}
}

3
ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs

@ -295,7 +295,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -295,7 +295,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Removes a type definition from this project content.
/// </summary>
public void RemoveType(ITypeDefinition typeDefinition)
public bool RemoveType(ITypeDefinition typeDefinition)
{
if (typeDefinition == null)
throw new ArgumentNullException("typeDefinition");
@ -323,6 +323,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -323,6 +323,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
}
return wasRemoved;
}
void RemoveNamespaceIfPossible(Dictionary<string, NamespaceEntry> dict, NamespaceEntry ns)

12
ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs

@ -138,7 +138,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -138,7 +138,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
public ITypeDefinition GetDefinition()
{
return genericType;
return genericType.GetDefinition();
}
public IType Resolve(ITypeResolveContext context)
@ -205,7 +205,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -205,7 +205,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null)
yield break;
baseTypeDef = baseTypeDef.GetCompoundClass();
int outerTypeParameterCount = baseTypeDef.TypeParameterCount;
ParameterizedType pt = baseType as ParameterizedType;
foreach (ITypeDefinition nestedType in baseTypeDef.NestedTypes) {
@ -279,8 +279,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -279,8 +279,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null)
yield break;
baseTypeDef = baseTypeDef.GetCompoundClass();
ParameterizedType pt = baseType as ParameterizedType;
if (pt != null || (methodTypeArguments != null && methodTypeArguments.Count > 0)) {
@ -320,7 +318,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -320,7 +318,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null)
yield break;
baseTypeDef = baseTypeDef.GetCompoundClass();
ParameterizedType pt = baseType as ParameterizedType;
if (pt != null) {
TypeParameterSubstitution substitution = null;
@ -355,7 +353,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -355,7 +353,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null)
yield break;
baseTypeDef = baseTypeDef.GetCompoundClass();
ParameterizedType pt = baseType as ParameterizedType;
if (pt != null) {
TypeParameterSubstitution substitution = null;
@ -390,7 +388,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -390,7 +388,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null)
yield break;
baseTypeDef = baseTypeDef.GetCompoundClass();
ParameterizedType pt = baseType as ParameterizedType;
if (pt != null) {
TypeParameterSubstitution substitution = null;

Loading…
Cancel
Save