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
{ {
public override IEnumerable<IContextAction> GetAvailableActions(EditorContext editorContext) 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)) { foreach (var implementAction in RefactoringService.GetImplementAbstractClassActions(targetClass)) {
yield return implementAction; yield return implementAction;
} }

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

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

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

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

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

@ -5,11 +5,12 @@ using System;
using System.IO; using System.IO;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
namespace SharpRefactoring namespace SharpRefactoring
{ {
public class RefactoringHelpers public static class RefactoringHelpers
{ {
/// <summary> /// <summary>
/// Renames file as well as files it is dependent upon. /// Renames file as well as files it is dependent upon.
@ -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
public static IDocument GetDocument(IClass c) 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; ITextEditorProvider tecp = FileService.OpenFile(c.CompilationUnit.FileName) as ITextEditorProvider;
if (tecp == null) return null; if (tecp == null) return null;
return tecp.TextEditor.Document; return tecp.TextEditor.Document;

Loading…
Cancel
Save