Browse Source

Implement * refactorings do now work properly with partial classes

pull/1/head
Siegfried Pammer 15 years ago
parent
commit
abef6e6f74
  1. 3
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs
  2. 6
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs
  3. 6
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs
  4. 15
      src/AddIns/Misc/SharpRefactoring/Project/Src/RefactoringHelpers.cs
  5. 3
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

3
src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs

@ -20,8 +20,7 @@ namespace SharpRefactoring.ContextActions @@ -20,8 +20,7 @@ namespace SharpRefactoring.ContextActions
{
public override IEnumerable<IContextAction> GetAvailableActions(EditorContext editorContext)
{
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().Where(c => c.ClassType == ClassType.Class)) {
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().Where(c => c.ClassType == ClassType.Class).Select(c2 => c2.GetCurrentClassPart(editorContext.Editor.FileName))) {
foreach (var implementAction in RefactoringService.GetImplementAbstractClassActions(targetClass)) {
yield return implementAction;
}

6
src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs

@ -26,9 +26,9 @@ namespace SharpRefactoring.ContextActions @@ -26,9 +26,9 @@ namespace SharpRefactoring.ContextActions
// Using CurrentLineAST is basically OK, but when the "class" keyword is on different line than class name,
// parsing only one line never tells us that we are looking at TypeDeclaration
// Alternative solution could be to try to resolve also IdentifierExpression to see if it is class declaration.
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().
Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)) {
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine()
.Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)
.Select(c2 => c2.GetCurrentClassPart(editorContext.Editor.FileName))) {
foreach (var implementAction in RefactoringService.GetImplementInterfaceActions(targetClass)) {
yield return implementAction;
}

6
src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs

@ -23,9 +23,9 @@ namespace SharpRefactoring.ContextActions @@ -23,9 +23,9 @@ namespace SharpRefactoring.ContextActions
{
public override IEnumerable<IContextAction> GetAvailableActions(EditorContext editorContext)
{
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().
Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)) {
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine()
.Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)
.Select(c2 => c2.GetCurrentClassPart(editorContext.Editor.FileName))) {
foreach (var implementAction in RefactoringService.GetImplementInterfaceActions(targetClass, true)) {
yield return implementAction;
}

15
src/AddIns/Misc/SharpRefactoring/Project/Src/RefactoringHelpers.cs

@ -5,11 +5,12 @@ using System; @@ -5,11 +5,12 @@ using System;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace SharpRefactoring
{
public class RefactoringHelpers
public static class RefactoringHelpers
{
/// <summary>
/// Renames file as well as files it is dependent upon.
@ -39,5 +40,17 @@ namespace SharpRefactoring @@ -39,5 +40,17 @@ namespace SharpRefactoring
}
}
}
public static IClass GetCurrentClassPart(this IClass c, string fileName)
{
if (c is CompoundClass) {
foreach (IClass part in ((CompoundClass)c).Parts) {
if (fileName.Equals(part.CompilationUnit.FileName, StringComparison.OrdinalIgnoreCase))
return part;
}
}
return c;
}
}
}

3
src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

@ -509,6 +509,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -509,6 +509,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public static IDocument GetDocument(IClass c)
{
if (c is CompoundClass)
throw new ArgumentException("Cannot get document from compound class - must pass a specific class part");
ITextEditorProvider tecp = FileService.OpenFile(c.CompilationUnit.FileName) as ITextEditorProvider;
if (tecp == null) return null;
return tecp.TextEditor.Document;

Loading…
Cancel
Save