Browse Source

Implemented "Introduce method" context action.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6258 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Martin Koníček 15 years ago
parent
commit
007996e7cd
  1. 10
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/GenerateMember.cs
  2. 30
      src/AddIns/Misc/SharpRefactoring/Project/Src/GenerateCode.cs
  3. 18
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs

10
src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/GenerateMember.cs

@ -17,13 +17,11 @@ namespace SharpRefactoring.ContextActions @@ -17,13 +17,11 @@ namespace SharpRefactoring.ContextActions
/// </summary>
public class GenerateMemberProvider : IContextActionsProvider
{
public IEnumerable<IContextAction> GetAvailableActions(EditorContext editorAST)
public IEnumerable<IContextAction> GetAvailableActions(EditorContext editorContext)
{
yield break;
var generateCodeAction = GenerateCode.GetContextAction(editorContext.SymbolUnderCaret, editorContext.Editor);
if (generateCodeAction != null)
yield return generateCodeAction;
}
}
public class GenerateMemberAction
{
}
}

30
src/AddIns/Misc/SharpRefactoring/Project/Src/GenerateCode.cs

@ -34,13 +34,13 @@ namespace SharpRefactoring @@ -34,13 +34,13 @@ namespace SharpRefactoring
{
if (symbol is UnknownMethodResolveResult) {
UnknownMethodResolveResult rr = symbol as UnknownMethodResolveResult;
Ast.Expression ex = GetExpressionInContext(rr, editor);
if (ex == null)
UnknownMethodResolveResult unknownMethodCall = symbol as UnknownMethodResolveResult;
Ast.Expression expression = GetExpressionInContext(unknownMethodCall, editor);
if (expression == null)
return null;
return new IntroduceMethodContextAction(rr, ex, editor) {
Title = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.IntroduceMethod}"), rr.CallName, rr.Target.FullyQualifiedName)
return new IntroduceMethodContextAction(unknownMethodCall, expression, editor) {
Title = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.IntroduceMethod}"), unknownMethodCall.CallName, unknownMethodCall.Target.FullyQualifiedName)
};
}
return null;
@ -53,6 +53,8 @@ namespace SharpRefactoring @@ -53,6 +53,8 @@ namespace SharpRefactoring
NRefactoryResolver resolver = Extensions.CreateResolverForContext(rr.CallingClass.ProjectContent.Language, editor);
Ast.INode node = resolver.ParseCurrentMember(editor.Document.Text);
if (node == null)
return null;
resolver.RunLookupTableVisitor(node);
InvocationExpressionLookupVisitor visitor = new InvocationExpressionLookupVisitor(editor);
@ -100,9 +102,9 @@ namespace SharpRefactoring @@ -100,9 +102,9 @@ namespace SharpRefactoring
#region Introduce method
public class IntroduceMethodContextAction : GenerateCodeContextAction
{
public UnknownMethodResolveResult rr { get; private set; }
public Ast.Expression ex { get; private set; }
public ITextEditor editor { get; private set; }
public UnknownMethodResolveResult UnknownMethodCall { get; private set; }
public Ast.Expression Expression { get; private set; }
public ITextEditor Editor { get; private set; }
public IntroduceMethodContextAction(UnknownMethodResolveResult symbol, Ast.Expression expression, ITextEditor editor)
{
@ -112,19 +114,19 @@ namespace SharpRefactoring @@ -112,19 +114,19 @@ namespace SharpRefactoring
throw new ArgumentNullException("ex");
if (editor == null)
throw new ArgumentNullException("editor");
this.rr = symbol;
this.ex = expression;
this.editor = editor;
this.UnknownMethodCall = symbol;
this.Expression = expression;
this.Editor = editor;
}
public override void Execute()
{
IClass targetClass = rr.Target.GetUnderlyingClass();
IClass targetClass = UnknownMethodCall.Target.GetUnderlyingClass();
bool isNew = false;
object result = null;
if (targetClass.BodyRegion.IsEmpty) {
IntroduceMethodDialog dialog = new IntroduceMethodDialog(rr.CallingClass);
IntroduceMethodDialog dialog = new IntroduceMethodDialog(UnknownMethodCall.CallingClass);
dialog.Owner = WorkbenchSingleton.MainWindow;
if (dialog.ShowDialog() != true)
@ -134,7 +136,7 @@ namespace SharpRefactoring @@ -134,7 +136,7 @@ namespace SharpRefactoring
result = dialog.Result;
}
ExecuteIntroduceMethod(rr, ex, editor, isNew, result);
ExecuteIntroduceMethod(UnknownMethodCall, Expression, Editor, isNew, result);
}
internal void ExecuteIntroduceMethod(UnknownMethodResolveResult rr, Ast.Expression expression, ITextEditor editor, bool isNew, object result)

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

@ -21,16 +21,16 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -21,16 +21,16 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public class EditorContext
{
public ITextEditor Editor { get; private set; }
public SnippetParser snippetParser { get; private set; }
public NRefactoryResolver resolver { get; private set; }
SnippetParser SnippetParser { get; set; }
NRefactoryResolver Resolver { get; set; }
public EditorContext(ITextEditor editor)
{
if (editor == null)
throw new ArgumentNullException("editor");
this.Editor = editor;
this.snippetParser = GetSnippetParser(editor);
this.resolver = GetResolver(editor);
this.SnippetParser = GetSnippetParser(editor);
this.Resolver = GetResolver(editor);
}
// TODO make all reference types cached ResolveResult? - implement own Nullable<T>
@ -74,10 +74,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -74,10 +74,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
if (currentLineAST != null)
return currentLineAST;
if (this.snippetParser == null || this.CurrentLine == null)
if (this.SnippetParser == null || this.CurrentLine == null)
return null;
try {
return (currentLineAST = snippetParser.Parse(this.CurrentLine.Text));
return (currentLineAST = SnippetParser.Parse(this.CurrentLine.Text));
}
catch {
return null;
@ -90,13 +90,13 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -90,13 +90,13 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
get
{
if (resolver == null)
if (Resolver == null)
return null;
if (currentMemberAST != null)
return currentMemberAST;
try {
resolver.Initialize(ParserService.GetParseInformation(Editor.FileName), Editor.Caret.Line, Editor.Caret.Column);
return (currentMemberAST = resolver.ParseCurrentMember(Editor.Document.Text));
Resolver.Initialize(ParserService.GetParseInformation(Editor.FileName), Editor.Caret.Line, Editor.Caret.Column);
return (currentMemberAST = Resolver.ParseCurrentMember(Editor.Document.Text));
}
catch {
return null;

Loading…
Cancel
Save