diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/InconsistentNamingIssue.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/InconsistentNamingIssue.cs index b39f677805..8cf6944695 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/InconsistentNamingIssue.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/InconsistentNamingIssue.cs @@ -147,11 +147,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring if (resolveResult is MemberResolveResult) { script.Rename(((MemberResolveResult)resolveResult).Member, n); } else if (resolveResult is TypeResolveResult) { - var def = ((TypeResolveResult)resolveResult).Type.GetDefinition(); + var def = resolveResult.Type.GetDefinition(); if (def != null) { script.Rename(def, n); - } else { - script.RenameTypeParameter(((TypeResolveResult)resolveResult).Type, n); + } else if (resolveResult.Type.Kind == TypeKind.TypeParameter) { + script.Rename((ITypeParameter)resolveResult.Type, n); } } else if (resolveResult is LocalResolveResult) { script.Rename(((LocalResolveResult)resolveResult).Variable, n); @@ -169,11 +169,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring if (resolveResult is MemberResolveResult) { script.Rename(((MemberResolveResult)resolveResult).Member); } else if (resolveResult is TypeResolveResult) { - var def = ((TypeResolveResult)resolveResult).Type.GetDefinition(); + var def = resolveResult.Type.GetDefinition(); if (def != null) { script.Rename(def); - } else { - script.RenameTypeParameter(((TypeResolveResult)resolveResult).Type); + } else if (resolveResult.Type.Kind == TypeKind.TypeParameter) { + script.Rename((ITypeParameter)resolveResult.Type); } } else if (resolveResult is LocalResolveResult) { script.Rename(((LocalResolveResult)resolveResult).Variable); diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/TypeParameterNotUsedIssue.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/TypeParameterNotUsedIssue.cs index 85e6e88a49..ee980ddd92 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/TypeParameterNotUsedIssue.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/TypeParameterNotUsedIssue.cs @@ -52,13 +52,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring } protected static bool FindUsage (BaseRefactoringContext context, SyntaxTree unit, - ITypeParameter typaParameter, AstNode declaration) + ITypeParameter typeParameter, AstNode declaration) { var found = false; - refFinder.FindTypeParameterReferences (typaParameter, context.UnresolvedFile, unit, context.Compilation, + var searchScopes = refFinder.GetSearchScopes(typeParameter); + refFinder.FindReferencesInFile(searchScopes, context.Resolver, (node, resolveResult) => { - found = found || node != declaration; + if (node != declaration) + found = true; }, context.CancellationToken); return found; } diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs index 3c9015958a..b133b22287 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs @@ -346,55 +346,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring } /// - /// Renames the specified entity. + /// Renames the specified symbol. /// - /// - /// The Entity to rename + /// + /// The symbol to rename /// /// /// The new name, if null the user is prompted for a new name. /// - public virtual void Rename(IEntity entity, string name = null) + public virtual void Rename(ISymbol symbol, string name = null) { } - /// - /// Renames the specified entity. - /// - /// - /// The Entity to rename - /// - /// - /// The new name, if null the user is prompted for a new name. - /// - public virtual void RenameTypeParameter (IType type, string name = null) - { - } - - /// - /// Renames the specified variable. - /// - /// - /// The Variable to rename - /// - /// - /// The new name, if null the user is prompted for a new name. - /// - public virtual void Rename(IVariable variable, string name = null) - { - } - - /// - /// Renames the specified namespace. - /// - /// The namespace - /// - /// The new name, if null the user is prompted for a new name. - /// - public virtual void Rename(INamespace ns, string name = null) - { - } - public virtual void DoGlobalOperationOn(IEntity entity, Action callback, string operationDescripton = null) { } diff --git a/ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs b/ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs index a291036f54..1f0afa1037 100644 --- a/ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs +++ b/ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs @@ -396,7 +396,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver /// /// Finds all references in the given file. /// - /// The search scopes for which to look. + /// The search scopes for which to look. /// AST resolver for the file to search in. /// Callback used to report the references that were found. /// CancellationToken that may be used to cancel the operation. @@ -530,7 +530,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver public void RenameReferencesInFile(IList searchScopes, string newName, CSharpAstResolver resolver, Action callback, Action errorCallback, CancellationToken cancellationToken = default (CancellationToken)) { - WholeVirtualSlot = true; FindReferencesInFile( searchScopes, resolver, diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs index 388458ceda..5a0e9f346b 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs @@ -165,17 +165,21 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions Replace (node, new IdentifierExpression (newName)); } - public override void Rename (IEntity entity, string name) + public override void Rename (ISymbol symbol, string name) { + if (symbol.SymbolKind == SymbolKind.Variable || symbol.SymbolKind == SymbolKind.Parameter) { + Rename(symbol as IVariable, name); + return; + } FindReferences refFinder = new FindReferences (); - refFinder.FindReferencesInFile (refFinder.GetSearchScopes (entity), + refFinder.FindReferencesInFile (refFinder.GetSearchScopes (symbol), context.UnresolvedFile, context.RootNode as SyntaxTree, context.Compilation, (n, r) => Rename (n, name), context.CancellationToken); } - public override void Rename (IVariable variable, string name) + void Rename (IVariable variable, string name) { FindReferences refFinder = new FindReferences (); refFinder.FindLocalReferences (variable, @@ -185,16 +189,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions context.CancellationToken); } - public override void RenameTypeParameter (IType type, string name = null) - { - FindReferences refFinder = new FindReferences (); - refFinder.FindTypeParameterReferences (type, - context.UnresolvedFile, - context.RootNode as SyntaxTree, - context.Compilation, (n, r) => Rename (n, name), - context.CancellationToken); - } - public override void CreateNewType (AstNode newType, NewTypeContext context) { var output = OutputNode (0, newType, true); diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Resolver/FindReferencesTest.cs b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/FindReferencesTest.cs index f71d0a9f65..033acf7fc1 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Resolver/FindReferencesTest.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/FindReferencesTest.cs @@ -442,6 +442,7 @@ namespace Foo sb.Append(ch); } Init(sb.ToString ()); + findReferences.WholeVirtualSlot = true; var doc = new ReadOnlyDocument(sb.ToString ()); var result = Rename(symbolName, "x", false); Assert.AreEqual(offsets.Count, result.Count);