diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 513d9a91ea..7e0b24f088 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -484,7 +484,7 @@ - + diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/AssemblyQualifiedTypeName.cs b/src/Main/Base/Project/Src/Services/RefactoringService/AssemblyQualifiedTypeName.cs new file mode 100644 index 0000000000..ca232574b1 --- /dev/null +++ b/src/Main/Base/Project/Src/Services/RefactoringService/AssemblyQualifiedTypeName.cs @@ -0,0 +1,73 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using ICSharpCode.Core; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem.Implementation; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.Parser; +using ICSharpCode.SharpDevelop.Project; + +namespace ICSharpCode.SharpDevelop.Refactoring +{ + public struct AssemblyQualifiedTypeName : IEquatable + { + public readonly string AssemblyName; + public readonly FullTypeName TypeName; + + public AssemblyQualifiedTypeName(FullTypeName typeName, string assemblyName) + { + this.AssemblyName = assemblyName; + this.TypeName = typeName; + } + + public AssemblyQualifiedTypeName(ITypeDefinition typeDefinition) + { + this.AssemblyName = typeDefinition.ParentAssembly.AssemblyName; + this.TypeName = typeDefinition.FullTypeName; + } + + public override string ToString() + { + if (string.IsNullOrEmpty(AssemblyName)) + return TypeName.ToString(); + else + return TypeName.ToString() + ", " + AssemblyName; + } + + public override bool Equals(object obj) + { + return (obj is AssemblyQualifiedTypeName) && Equals((AssemblyQualifiedTypeName)obj); + } + + public bool Equals(AssemblyQualifiedTypeName other) + { + return this.AssemblyName == other.AssemblyName && this.TypeName == other.TypeName; + } + + public override int GetHashCode() + { + int hashCode = 0; + unchecked { + if (AssemblyName != null) + hashCode += 1000000007 * AssemblyName.GetHashCode(); + hashCode += TypeName.GetHashCode(); + } + return hashCode; + } + + public static bool operator ==(AssemblyQualifiedTypeName lhs, AssemblyQualifiedTypeName rhs) + { + return lhs.Equals(rhs); + } + + public static bool operator !=(AssemblyQualifiedTypeName lhs, AssemblyQualifiedTypeName rhs) + { + return !lhs.Equals(rhs); + } + } +} \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs b/src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs index 4289fadc4f..73896526f4 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs @@ -172,7 +172,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring var compilations = GetProjectsThatCouldReferenceEntity(baseType).Select(p => solutionSnapshot.GetCompilation(p)); var graph = BuildTypeInheritanceGraph(compilations); TypeGraphNode node; - if (graph.TryGetValue(new TypeName(baseType), out node)) { + if (graph.TryGetValue(new AssemblyQualifiedTypeName(baseType), out node)) { node.BaseTypes.Clear(); // only derived types were requested, so don't return the base types return node; } else { @@ -184,26 +184,26 @@ namespace ICSharpCode.SharpDevelop.Refactoring /// Builds a graph of all type definitions in the specified set of project contents. /// /// The resulting graph may be cyclic if there are cyclic type definitions. - static Dictionary BuildTypeInheritanceGraph(IEnumerable compilations) + static Dictionary BuildTypeInheritanceGraph(IEnumerable compilations) { if (compilations == null) throw new ArgumentNullException("projectContents"); - Dictionary dict = new Dictionary(); + Dictionary dict = new Dictionary(); foreach (ICompilation compilation in compilations) { foreach (ITypeDefinition typeDef in compilation.MainAssembly.GetAllTypeDefinitions()) { // Overwrite previous entry - duplicates can occur if there are multiple versions of the // same project loaded in the solution (e.g. separate .csprojs for separate target frameworks) - dict[new TypeName(typeDef)] = new TypeGraphNode(typeDef); + dict[new AssemblyQualifiedTypeName(typeDef)] = new TypeGraphNode(typeDef); } } foreach (ICompilation compilation in compilations) { foreach (ITypeDefinition typeDef in compilation.MainAssembly.GetAllTypeDefinitions()) { - TypeGraphNode typeNode = dict[new TypeName(typeDef)]; + TypeGraphNode typeNode = dict[new AssemblyQualifiedTypeName(typeDef)]; foreach (IType baseType in typeDef.DirectBaseTypes) { ITypeDefinition baseTypeDef = baseType.GetDefinition(); if (baseTypeDef != null) { TypeGraphNode baseTypeNode; - if (dict.TryGetValue(new TypeName(baseTypeDef), out baseTypeNode)) { + if (dict.TryGetValue(new AssemblyQualifiedTypeName(baseTypeDef), out baseTypeNode)) { typeNode.BaseTypes.Add(baseTypeNode); baseTypeNode.DerivedTypes.Add(typeNode); } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/TypeName.cs b/src/Main/Base/Project/Src/Services/RefactoringService/TypeName.cs deleted file mode 100644 index b5736b5f33..0000000000 --- a/src/Main/Base/Project/Src/Services/RefactoringService/TypeName.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using ICSharpCode.Core; -using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem.Implementation; -using ICSharpCode.SharpDevelop.Gui; -using ICSharpCode.SharpDevelop.Parser; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.SharpDevelop.Refactoring -{ - public struct TypeName : IEquatable - { - public readonly string AssemblyName; - public readonly string Namespace; - public readonly string Name; - public readonly int TypeParameterCount; - - public TypeName(string assemblyName, string @namespace, string name, int typeParameterCount) - { - this.AssemblyName = assemblyName; - this.Namespace = @namespace; - this.Name = name; - this.TypeParameterCount = typeParameterCount; - } - - public TypeName(ITypeDefinition typeDefinition) - { - this.AssemblyName = typeDefinition.ParentAssembly.AssemblyName; - this.Namespace = typeDefinition.Namespace; - this.Name = typeDefinition.Name; - for (ITypeDefinition parent = typeDefinition.DeclaringTypeDefinition; parent != null; parent = parent.DeclaringTypeDefinition) { - this.Name = parent.Name + "." + this.Name; - } - this.TypeParameterCount = typeDefinition.TypeParameterCount; - } - - public override string ToString() - { - string fullName; - if (string.IsNullOrEmpty(Namespace)) - fullName = Name; - else - fullName = Namespace + "." + Name; - if (TypeParameterCount > 0) - fullName = fullName + "`" + TypeParameterCount.ToString(); - if (string.IsNullOrEmpty(AssemblyName)) - return fullName; - else - return fullName + ", " + AssemblyName; - } - - public override bool Equals(object obj) - { - return (obj is TypeName) && Equals((TypeName)obj); - } - - public bool Equals(TypeName other) - { - return this.AssemblyName == other.AssemblyName && this.Namespace == other.Namespace && this.Name == other.Name && this.TypeParameterCount == other.TypeParameterCount; - } - - public override int GetHashCode() - { - int hashCode = 0; - unchecked { - if (AssemblyName != null) - hashCode += 1000000007 * AssemblyName.GetHashCode(); - if (Namespace != null) - hashCode += 1000000009 * Namespace.GetHashCode(); - if (Name != null) - hashCode += 1000000021 * Name.GetHashCode(); - hashCode += TypeParameterCount; - } - return hashCode; - } - - public static bool operator ==(TypeName lhs, TypeName rhs) - { - return lhs.Equals(rhs); - } - - public static bool operator !=(TypeName lhs, TypeName rhs) - { - return !lhs.Equals(rhs); - } - } -} \ No newline at end of file