Browse Source

Add TypeGraphNode to NRefactory; and move AbiComparer from NR.CSharp.Analysis to NR.Analysis

pull/45/merge
Daniel Grunwald 12 years ago
parent
commit
149dea7412
  1. 1
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  2. 2
      ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs
  3. 7
      ICSharpCode.NRefactory.Tests/Analysis/AbiComparerTests.cs
  4. 6
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  5. 2
      ICSharpCode.NRefactory/Analysis/AbiComparer.cs
  6. 85
      ICSharpCode.NRefactory/Analysis/TypeGraphNode.cs
  7. 4
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  8. 79
      ICSharpCode.NRefactory/TypeSystem/AssemblyQualifiedTypeName.cs

1
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -516,7 +516,6 @@
<Compile Include="Resolver\ReducedExtensionMethod.cs" /> <Compile Include="Resolver\ReducedExtensionMethod.cs" />
<Compile Include="Refactoring\CodeIssues\SimplifyAnonymousMethodToDelegateIssue.cs" /> <Compile Include="Refactoring\CodeIssues\SimplifyAnonymousMethodToDelegateIssue.cs" />
<Compile Include="Refactoring\CodeIssues\CompilerErrors\CS0127ReturnMustNotBeFollowedByAnyExpression.cs" /> <Compile Include="Refactoring\CodeIssues\CompilerErrors\CS0127ReturnMustNotBeFollowedByAnyExpression.cs" />
<Compile Include="Analysis\AbiComparer.cs" />
<Compile Include="Refactoring\CreateChangedEvent.cs" /> <Compile Include="Refactoring\CreateChangedEvent.cs" />
<Compile Include="Refactoring\CodeActions\SimplifyIfFlowAction.cs" /> <Compile Include="Refactoring\CodeActions\SimplifyIfFlowAction.cs" />
<Compile Include="Refactoring\CodeActions\SimplifyIfInLoopsFlowAction.cs" /> <Compile Include="Refactoring\CodeActions\SimplifyIfInLoopsFlowAction.cs" />

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

@ -72,6 +72,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// </summary> /// </summary>
public bool WholeVirtualSlot { get; set; } public bool WholeVirtualSlot { get; set; }
//public bool FindAllOverloads { get; set; }
/// <summary> /// <summary>
/// Specifies whether to look for references in documentation comments. /// Specifies whether to look for references in documentation comments.
/// This will find entity references in <c>cref</c> attributes and /// This will find entity references in <c>cref</c> attributes and

7
ICSharpCode.NRefactory.Tests/CSharp/Analysis/AbiComparerTests.cs → ICSharpCode.NRefactory.Tests/Analysis/AbiComparerTests.cs

@ -25,16 +25,13 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using NUnit.Framework; using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.CodeCompletion; using ICSharpCode.NRefactory.CSharp.CodeCompletion;
namespace ICSharpCode.NRefactory.CSharp.Analysis namespace ICSharpCode.NRefactory.Analysis
{ {
[TestFixture] [TestFixture]
public class AbiComparerTests public class AbiComparerTests

6
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -93,6 +93,7 @@
<Compile Include="..\ICSharpCode.NRefactory\Properties\GlobalAssemblyInfo.cs"> <Compile Include="..\ICSharpCode.NRefactory\Properties\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link> <Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Analysis\AbiComparerTests.cs" />
<Compile Include="CSharp\Analysis\DefiniteAssignmentTests.cs" /> <Compile Include="CSharp\Analysis\DefiniteAssignmentTests.cs" />
<Compile Include="CSharp\AstStructureTests.cs" /> <Compile Include="CSharp\AstStructureTests.cs" />
<Compile Include="CSharp\CodeActions\AddUsing\AddUsingActionAlphabeticalTests.cs" /> <Compile Include="CSharp\CodeActions\AddUsing\AddUsingActionAlphabeticalTests.cs" />
@ -396,7 +397,6 @@
<Compile Include="CSharp\CodeIssues\SimplifyAnonymousMethodToDelegateIssueTests.cs" /> <Compile Include="CSharp\CodeIssues\SimplifyAnonymousMethodToDelegateIssueTests.cs" />
<Compile Include="CSharp\CodeIssues\CS0127ReturnMustNotBeFollowedByAnyExpressionTests.cs" /> <Compile Include="CSharp\CodeIssues\CS0127ReturnMustNotBeFollowedByAnyExpressionTests.cs" />
<Compile Include="CSharp\Analysis\SemanticHighlightingTests.cs" /> <Compile Include="CSharp\Analysis\SemanticHighlightingTests.cs" />
<Compile Include="CSharp\Analysis\AbiComparerTests.cs" />
<Compile Include="CSharp\CodeActions\CreateChangedEventTests.cs" /> <Compile Include="CSharp\CodeActions\CreateChangedEventTests.cs" />
<Compile Include="CSharp\CodeActions\SimplifyIfFlowTests.cs" /> <Compile Include="CSharp\CodeActions\SimplifyIfFlowTests.cs" />
<Compile Include="CSharp\CodeActions\SimplifyIfFlowInLoopsTests.cs" /> <Compile Include="CSharp\CodeActions\SimplifyIfFlowInLoopsTests.cs" />
@ -439,7 +439,9 @@
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<Folder Include="Analysis" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>
<MonoDevelop> <MonoDevelop>

2
ICSharpCode.NRefactory.CSharp/Analysis/AbiComparer.cs → ICSharpCode.NRefactory/Analysis/AbiComparer.cs

@ -28,7 +28,7 @@ using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.Analysis
{ {
/// <summary> /// <summary>
/// Used to check the compatibility state of two compilations. /// Used to check the compatibility state of two compilations.

85
ICSharpCode.NRefactory/Analysis/TypeGraphNode.cs

@ -0,0 +1,85 @@
// Copyright (c) 2013 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.TypeSystem;
namespace ICSharpCode.NRefactory.Analysis
{
public sealed class TypeGraphNode
{
readonly ITypeDefinition typeDef;
readonly List<TypeGraphNode> baseTypes = new List<TypeGraphNode>();
readonly List<TypeGraphNode> derivedTypes = new List<TypeGraphNode>();
/// <summary>
/// Creates a new unconnected type graph node.
/// </summary>
public TypeGraphNode(ITypeDefinition typeDef)
{
this.typeDef = typeDef;
}
public ITypeDefinition TypeDefinition {
get { return typeDef; }
}
public IList<TypeGraphNode> DerivedTypes {
get { return derivedTypes; }
}
public IList<TypeGraphNode> BaseTypes {
get { return baseTypes; }
}
/// <summary>
/// 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>
public static Dictionary<AssemblyQualifiedTypeName, TypeGraphNode> BuildTypeInheritanceGraph(IEnumerable<ICompilation> compilations)
{
if (compilations == null)
throw new ArgumentNullException("compilations");
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 AssemblyQualifiedTypeName(typeDef)] = new TypeGraphNode(typeDef);
}
}
foreach (ICompilation compilation in compilations) {
foreach (ITypeDefinition typeDef in compilation.MainAssembly.GetAllTypeDefinitions()) {
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 AssemblyQualifiedTypeName(baseTypeDef), out baseTypeNode)) {
typeNode.BaseTypes.Add(baseTypeNode);
baseTypeNode.DerivedTypes.Add(typeNode);
}
}
}
}
}
return dict;
}
}
}

4
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -82,6 +82,8 @@
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Analysis\AbiComparer.cs" />
<Compile Include="Analysis\TypeGraphNode.cs" />
<Compile Include="Documentation\DocumentationComment.cs" /> <Compile Include="Documentation\DocumentationComment.cs" />
<Compile Include="Documentation\GetPotentiallyNestedClassTypeReference.cs" /> <Compile Include="Documentation\GetPotentiallyNestedClassTypeReference.cs" />
<Compile Include="Documentation\IDocumentationProvider.cs" /> <Compile Include="Documentation\IDocumentationProvider.cs" />
@ -137,6 +139,7 @@
<Compile Include="TypeSystem\Accessibility.cs" /> <Compile Include="TypeSystem\Accessibility.cs" />
<Compile Include="TypeSystem\AnonymousType.cs" /> <Compile Include="TypeSystem\AnonymousType.cs" />
<Compile Include="TypeSystem\ArrayType.cs" /> <Compile Include="TypeSystem\ArrayType.cs" />
<Compile Include="TypeSystem\AssemblyQualifiedTypeName.cs" />
<Compile Include="TypeSystem\ByReferenceType.cs" /> <Compile Include="TypeSystem\ByReferenceType.cs" />
<Compile Include="TypeSystem\CecilLoader.cs" /> <Compile Include="TypeSystem\CecilLoader.cs" />
<Compile Include="TypeSystem\ComHelper.cs" /> <Compile Include="TypeSystem\ComHelper.cs" />
@ -277,6 +280,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Completion\" /> <Folder Include="Completion\" />
<Folder Include="Analysis" />
<Folder Include="TypeSystem\" /> <Folder Include="TypeSystem\" />
<Folder Include="Utils\CompositeFormatStringParser\" /> <Folder Include="Utils\CompositeFormatStringParser\" />
<Folder Include="Refactoring\" /> <Folder Include="Refactoring\" />

79
ICSharpCode.NRefactory/TypeSystem/AssemblyQualifiedTypeName.cs

@ -0,0 +1,79 @@
// Copyright (c) 2013 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;
namespace ICSharpCode.NRefactory.TypeSystem
{
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);
}
}
}
Loading…
Cancel
Save