Browse Source

Rename TypeName to AssemblyQualifiedTypeName.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
85f8ff0e8e
  1. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 73
      src/Main/Base/Project/Src/Services/RefactoringService/AssemblyQualifiedTypeName.cs
  3. 12
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs
  4. 93
      src/Main/Base/Project/Src/Services/RefactoringService/TypeName.cs

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -484,7 +484,7 @@ @@ -484,7 +484,7 @@
<Compile Include="Src\Services\RefactoringService\ExtractInterfaceOptions.cs" />
<Compile Include="Src\Services\RefactoringService\FindReferenceService.cs" />
<Compile Include="Src\Services\RefactoringService\TypeGraphNode.cs" />
<Compile Include="Src\Services\RefactoringService\TypeName.cs" />
<Compile Include="Src\Services\RefactoringService\AssemblyQualifiedTypeName.cs" />
<Compile Include="Src\Services\Tasks\ErrorPainter.cs" />
<Compile Include="Src\Services\Tasks\TagComment.cs" />
<Compile Include="Src\Services\Tasks\Task.cs" />

73
src/Main/Base/Project/Src/Services/RefactoringService/AssemblyQualifiedTypeName.cs

@ -0,0 +1,73 @@ @@ -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<AssemblyQualifiedTypeName>
{
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);
}
}
}

12
src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs

@ -172,7 +172,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -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 @@ -184,26 +184,26 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// Builds a graph of all type definitions in the specified set of project contents.
/// </summary>
/// <remarks>The resulting graph may be cyclic if there are cyclic type definitions.</remarks>
static Dictionary<TypeName, TypeGraphNode> BuildTypeInheritanceGraph(IEnumerable<ICompilation> compilations)
static Dictionary<AssemblyQualifiedTypeName, TypeGraphNode> BuildTypeInheritanceGraph(IEnumerable<ICompilation> compilations)
{
if (compilations == null)
throw new ArgumentNullException("projectContents");
Dictionary<TypeName, TypeGraphNode> dict = new Dictionary<TypeName, TypeGraphNode>();
Dictionary<AssemblyQualifiedTypeName, TypeGraphNode> dict = new Dictionary<AssemblyQualifiedTypeName, TypeGraphNode>();
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);
}

93
src/Main/Base/Project/Src/Services/RefactoringService/TypeName.cs

@ -1,93 +0,0 @@ @@ -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<TypeName>
{
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);
}
}
}
Loading…
Cancel
Save