Browse Source

Implement interface (explicit) context action.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6382 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Martin Koníček 15 years ago
parent
commit
f762d24d46
  1. 6
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs
  2. 8
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs
  3. 6
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs
  4. 36
      src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

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

@ -28,11 +28,7 @@ namespace SharpRefactoring.ContextActions @@ -28,11 +28,7 @@ namespace SharpRefactoring.ContextActions
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().Where(c => c.ClassType == ClassType.Class)) {
foreach (var implementAction in RefactoringService.GetImplementAbstractClassActions(targetClass)) {
var implementActionCopy = implementAction;
yield return new DelegateAction {
Title = string.Format("Implement abstract class {0}", ambience.Convert(implementActionCopy.ClassToImplement)),
ExecuteAction = implementActionCopy.Execute
};
yield return implementAction;
}
}
}

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

@ -34,12 +34,8 @@ namespace SharpRefactoring.ContextActions @@ -34,12 +34,8 @@ namespace SharpRefactoring.ContextActions
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().
Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)) {
foreach (var implementAction in RefactoringService.GetImplementInterfaceActions(targetClass, false)) {
var implementActionCopy = implementAction;
yield return new DelegateAction {
Title = string.Format("Implement interface {0}", ambience.Convert(implementActionCopy.ClassToImplement)),
ExecuteAction = implementActionCopy.Execute
};
foreach (var implementAction in RefactoringService.GetImplementInterfaceActions(targetClass)) {
yield return implementAction;
}
}
}

6
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs

@ -67,7 +67,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -67,7 +67,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
}
this.CurrentExpression = GetExpressionAtCaret(editor);
this.CurrentSymbol = ResolveExpression(editor);
this.CurrentSymbol = ResolveExpression(CurrentExpression, editor, CaretLine, CaretColumn);
this.CurrentLine = editor.Document.GetLine(CaretLine);
this.CurrentLineAST = GetCurrentLineAst(this.CurrentLine, editor);
@ -201,9 +201,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -201,9 +201,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
// }
// }
ResolveResult ResolveExpression(ITextEditor editor)
ResolveResult ResolveExpression(ExpressionResult expression, ITextEditor editor, int caretLine, int caretColumn)
{
return ParserService.Resolve(this.CurrentExpression, CaretLine, CaretColumn, editor.FileName, editor.Document.Text);
return ParserService.Resolve(expression, caretLine, caretColumn, editor.FileName, editor.Document.Text);
}
ExpressionResult GetExpressionAtCaret(ITextEditor editor)

36
src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

@ -477,7 +477,29 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -477,7 +477,29 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// <summary>
/// Gets actions which can add implementation of interface to given class.
/// </summary>
public static IEnumerable<ImplementInterfaceAction> GetImplementInterfaceActions(IClass c, bool isExplicitImpl, bool returnMissingInterfacesOnly = true)
public static IEnumerable<ImplementInterfaceAction> GetImplementInterfaceActions(IClass c, bool returnMissingInterfacesOnly = true)
{
var interfacesToImplement = GetInterfacesToImplement(c, returnMissingInterfacesOnly).ToList();
if (c.ProjectContent.Language.SupportsImplicitInterfaceImplementation) {
return MakeImplementActions(c, interfacesToImplement, false, "Implement interface {0}").Concat(
MakeImplementActions(c, interfacesToImplement, true, "Implement interface {0} (explicit)"));
} else {
return MakeImplementActions(c, interfacesToImplement, true, "Implement interface {0}");
}
}
static IEnumerable<ImplementInterfaceAction> MakeImplementActions(IClass c, IEnumerable<IReturnType> interfaces, bool isExplit, string format)
{
var ambience = AmbienceService.GetCurrentAmbience();
foreach (var iface in interfaces) {
yield return new ImplementInterfaceAction(iface, c, isExplit) {
Title = string.Format(format, ambience.Convert(iface))
};
}
}
static IEnumerable<IReturnType> GetInterfacesToImplement(IClass c, bool returnMissingInterfacesOnly = true)
{
foreach (IReturnType rt in c.BaseTypes) {
IClass interf = rt.GetUnderlyingClass();
@ -486,16 +508,17 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -486,16 +508,17 @@ namespace ICSharpCode.SharpDevelop.Refactoring
// this interface is already implemented
continue;
}
IReturnType rtCopy = rt;
yield return new ImplementInterfaceAction(rtCopy, c, isExplicitImpl);
yield return rt;
}
}
}
/// <summary>
/// Gets actions which can add implementation of abstract class to given class.
/// </summary>
public static IEnumerable<ImplementAbstractClassAction> GetImplementAbstractClassActions(IClass c, bool returnMissingClassesOnly = true)
{
var ambience = AmbienceService.GetCurrentAmbience();
foreach (IReturnType rt in c.BaseTypes) {
IClass abstractClass = rt.GetUnderlyingClass();
if (abstractClass != null && abstractClass.ClassType == ClassType.Class && abstractClass.IsAbstract) {
@ -504,7 +527,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -504,7 +527,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring
continue;
}
IReturnType rtCopy = rt;
yield return new ImplementAbstractClassAction(rtCopy, c);
yield return new ImplementAbstractClassAction(rtCopy, c) {
Title = string.Format("Implement abstract class {0}", ambience.Convert(rtCopy)) };
}
}
}
@ -512,11 +536,13 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -512,11 +536,13 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// <summary>
/// Action describing how to add implementation of an abstract class to a class.
/// </summary>
public class ImplementAbstractClassAction
public class ImplementAbstractClassAction : IContextAction
{
public IReturnType ClassToImplement { get; private set; }
public IClass TargetClass { get; private set; }
public string Title { get; set; }
public virtual void Execute()
{
var d = FindReferencesAndRenameHelper.GetDocument(TargetClass);

Loading…
Cancel
Save