Browse Source

Add rename API (not implemented yet).

pull/45/merge
Daniel Grunwald 12 years ago
parent
commit
76d4845bbe
  1. 1
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  2. 88
      ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs
  3. 31
      ICSharpCode.NRefactory.CSharp/Resolver/RenameCallbackArguments.cs

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

@ -363,6 +363,7 @@ @@ -363,6 +363,7 @@
<Compile Include="Resolver\NodeListResolveVisitorNavigator.cs" />
<Compile Include="Resolver\OverloadResolution.cs" />
<Compile Include="Resolver\OverloadResolutionErrors.cs" />
<Compile Include="Resolver\RenameCallbackArguments.cs" />
<Compile Include="Resolver\ResolveAtLocation.cs" />
<Compile Include="Resolver\ResolveVisitor.cs" />
<Compile Include="Resolver\TypeInference.cs" />

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

@ -21,6 +21,7 @@ using System.Collections.Generic; @@ -21,6 +21,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Semantics;
@ -220,16 +221,24 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -220,16 +221,24 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
#endregion
#region GetSearchScopes
public IList<IFindReferenceSearchScope> GetSearchScopes(IEntity entity)
{
public IList<IFindReferenceSearchScope> GetSearchScopes(ISymbol symbol)
{
if (symbol == null)
throw new ArgumentNullException("symbol");
switch (symbol.SymbolKind) {
case SymbolKind.Namespace:
return new[] { GetSearchScopeForNamespace((INamespace)symbol) };
case SymbolKind.TypeParameter:
return new[] { GetSearchScopeForTypeParameter((ITypeParameter)symbol) };
// TODO: IVariable etc.
}
IEntity entity = symbol as IEntity;
if (entity == null)
throw new ArgumentNullException("entity");
throw new NotSupportedException("Unsupported symbol type");
if (entity is IMember)
entity = NormalizeMember((IMember)entity);
Accessibility effectiveAccessibility = GetEffectiveAccessibility(entity);
ITypeDefinition topLevelTypeDefinition = entity.DeclaringTypeDefinition;
while (topLevelTypeDefinition != null && topLevelTypeDefinition.DeclaringTypeDefinition != null)
topLevelTypeDefinition = topLevelTypeDefinition.DeclaringTypeDefinition;
var topLevelTypeDefinition = GetTopLevelTypeDefinition(entity);
SearchScope scope;
SearchScope additionalScope = null;
switch (entity.SymbolKind) {
@ -289,13 +298,22 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -289,13 +298,22 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
public IList<IFindReferenceSearchScope> GetSearchScopes(INamespace ns)
public IList<IFindReferenceSearchScope> GetSearchScopes(IEnumerable<ISymbol> symbols)
{
if (ns == null)
throw new ArgumentNullException("ns");
return new[] { GetSearchScopeForNamespace(ns) };
if (symbols == null)
throw new ArgumentNullException("symbols");
return symbols.SelectMany(GetSearchScopes).ToList();
}
static ITypeDefinition GetTopLevelTypeDefinition(IEntity entity)
{
if (entity == null)
return null;
ITypeDefinition topLevelTypeDefinition = entity.DeclaringTypeDefinition;
while (topLevelTypeDefinition != null && topLevelTypeDefinition.DeclaringTypeDefinition != null)
topLevelTypeDefinition = topLevelTypeDefinition.DeclaringTypeDefinition;
return topLevelTypeDefinition;
}
#endregion
#region GetInterestingFileNames
@ -360,6 +378,36 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -360,6 +378,36 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
#endregion
#region FindReferencesInFile
/// <summary>
/// Finds all references in the given file.
/// </summary>
/// <param name="searchScope">The search scope for which to look.</param>
/// <param name="resolver">AST resolver for the file to search in.</param>
/// <param name="callback">Callback used to report the references that were found.</param>
/// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
public void FindReferencesInFile(IFindReferenceSearchScope searchScope, CSharpAstResolver resolver,
FoundReferenceCallback callback, CancellationToken cancellationToken)
{
if (resolver == null)
throw new ArgumentNullException("resolver");
FindReferencesInFile(searchScope, resolver.UnresolvedFile, (SyntaxTree)resolver.RootNode, resolver.Compilation, callback, cancellationToken);
}
/// <summary>
/// Finds all references in the given file.
/// </summary>
/// <param name="searchScope">The search scopes for which to look.</param>
/// <param name="resolver">AST resolver for the file to search in.</param>
/// <param name="callback">Callback used to report the references that were found.</param>
/// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
public void FindReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, CSharpAstResolver resolver,
FoundReferenceCallback callback, CancellationToken cancellationToken)
{
if (resolver == null)
throw new ArgumentNullException("resolver");
FindReferencesInFile(searchScopes, resolver.UnresolvedFile, (SyntaxTree)resolver.RootNode, resolver.Compilation, callback, cancellationToken);
}
/// <summary>
/// Finds all references in the given file.
/// </summary>
@ -424,6 +472,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -424,6 +472,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
#endregion
#region RenameReferencesInFile
public void RenameReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, string newName, CSharpAstResolver resolver,
Action<RenameCallbackArguments> callback, Action<Error> errorCallback, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
#endregion
#region Find TypeDefinition References
SearchScope FindTypeDefinitionReferences(ITypeDefinition typeDefinition, bool findTypeReferencesEvenIfAliased, out SearchScope additionalScope)
{
@ -1282,6 +1338,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1282,6 +1338,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// <param name="compilation">The compilation.</param>
/// <param name="callback">Callback used to report the references that were found.</param>
/// <param name="cancellationToken">Cancellation token that may be used to cancel the operation.</param>
[Obsolete("Use GetSearchScopes(typeParameter) instead")]
public void FindTypeParameterReferences(IType typeParameter, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree,
ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
{
@ -1295,6 +1352,17 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1295,6 +1352,17 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
FindReferencesInFile(searchScope, unresolvedFile, syntaxTree, compilation, callback, cancellationToken);
}
SearchScope GetSearchScopeForTypeParameter(ITypeParameter tp)
{
var searchScope = new SearchScope(c => new FindTypeParameterReferencesNavigator(tp));
var compilationProvider = tp as ICompilationProvider;
if (compilationProvider != null)
searchScope.declarationCompilation = compilationProvider.Compilation;
searchScope.topLevelTypeDefinition = GetTopLevelTypeDefinition(tp.Owner);
searchScope.accessibility = Accessibility.Private;
return searchScope;
}
class FindTypeParameterReferencesNavigator : FindReferenceNavigator
{
readonly ITypeParameter typeParameter;

31
ICSharpCode.NRefactory.CSharp/Resolver/RenameCallbackArguments.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
/*
* Created by SharpDevelop.
* User: Daniel
* Date: 6/13/2013
* Time: 17:50
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace ICSharpCode.NRefactory.CSharp.Resolver
{
/// <summary>
/// Arguments for the callback of <see cref="FindReferences.RenameReferencesInFile"/>.
/// </summary>
public class RenameCallbackArguments
{
public AstNode NodeToReplace { get; private set; }
public AstNode NewNode { get; private set; }
public RenameCallbackArguments(AstNode nodeToReplace, AstNode newNode)
{
if (nodeToReplace == null)
throw new ArgumentNullException("nodeToReplace");
if (newNode == null)
throw new ArgumentNullException("newNode");
this.NodeToReplace = nodeToReplace;
this.NewNode = newNode;
}
}
}
Loading…
Cancel
Save