Example #1
0
        ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility)
        {
            ModifierEnum r = (ModifierEnum)m;

            if ((r & ModifierEnum.VisibilityMask) == ModifierEnum.None)
            {
                return(r | defaultVisibility);
            }
            else
            {
                return(r);
            }
        }
Example #2
0
 ModifierEnum ConvertTypeModifier(AST.Modifiers m)
 {
     if (this.IsVisualBasic)
     {
         return(ConvertModifier(m, ModifierEnum.Public));
     }
     if (currentClass.Count > 0)
     {
         return(ConvertModifier(m, ModifierEnum.Private));
     }
     else
     {
         return(ConvertModifier(m, ModifierEnum.Internal));
     }
 }
Example #3
0
 ModifierEnum ConvertModifier(AST.Modifiers m)
 {
     if (this.IsVisualBasic)
     {
         return(ConvertModifier(m, ModifierEnum.Public));
     }
     else if (currentClass.Count > 0 && currentClass.Peek().ClassType == ClassType.Interface)
     {
         return(ConvertModifier(m, ModifierEnum.Public));
     }
     else
     {
         return(ConvertModifier(m, ModifierEnum.Private));
     }
 }
		public override void Run (RefactoringOptions options)
		{
			IResolver resolver = options.GetResolver ();
			INRefactoryASTProvider provider = options.GetASTProvider ();
			TextEditorData data = options.GetTextEditorData ();
			IType type = options.ResolveResult.CallingType;
			if (invoke.TargetObject is IdentifierExpression) {
				fileName = options.Document.FileName;
				newMethodName = ((IdentifierExpression)invoke.TargetObject).Identifier;
				indent = options.GetIndent (options.ResolveResult.CallingMember);
				if (options.ResolveResult.CallingMember.IsStatic)
					modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
			} else {
				newMethodName = ((MemberReferenceExpression)invoke.TargetObject).MemberName;
				string callingObject = provider.OutputNode (options.Dom, ((MemberReferenceExpression)invoke.TargetObject).TargetObject);
				ResolveResult resolveResult = resolver.Resolve (new ExpressionResult (callingObject), resolvePosition);
				type = options.Dom.GetType (resolveResult.ResolvedType);
				fileName = type.CompilationUnit.FileName;
				if (resolveResult.StaticResolve)
					modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
				
				if (fileName == options.Document.FileName) {
					indent = options.GetIndent (options.ResolveResult.CallingMember);
//					insertNewMethod.Offset = options.Document.TextEditor.GetPositionFromLineColumn (options.ResolveResult.CallingMember.BodyRegion.End.Line, options.ResolveResult.CallingMember.BodyRegion.End.Column);
				} else {
					var openDocument = IdeApp.Workbench.OpenDocument (fileName);
					data = openDocument.Editor;
					if (data == null)
						return;
					modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Public;
					bool isInInterface = type.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface;
					if (isInInterface) 
						modifiers = ICSharpCode.NRefactory.Ast.Modifiers.None;
					if (data == null)
						throw new InvalidOperationException ("Can't open file:" + modifiers);
					try {
						indent = data.Document.GetLine (type.Location.Line - 1).GetIndentation (data.Document) ?? "";
					} catch (Exception) {
						indent = "";
					}
					indent += "\t";
//					insertNewMethod.Offset = otherFile.Document.LocationToOffset (type.BodyRegion.End.Line - 1, 0);
				}
			}
			
			InsertionCursorEditMode mode = new InsertionCursorEditMode (data.Parent, HelperMethods.GetInsertionPoints (data.Document, type));
			if (fileName == options.Document.FileName) {
				for (int i = 0; i < mode.InsertionPoints.Count; i++) {
					var point = mode.InsertionPoints[i];
					if (point.Location < data.Caret.Location) {
						mode.CurIndex = i;
					} else {
						break;
					}
				}
			}
			
			ModeHelpWindow helpWindow = new ModeHelpWindow ();
			helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
			helpWindow.TitleText = GettextCatalog.GetString ("<b>Create Method -- Targeting</b>");
			helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Key</b>"), GettextCatalog.GetString ("<b>Behavior</b>")));
			helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Up</b>"), GettextCatalog.GetString ("Move to <b>previous</b> target point.")));
			helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Down</b>"), GettextCatalog.GetString ("Move to <b>next</b> target point.")));
			helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Enter</b>"), GettextCatalog.GetString ("<b>Declare new method</b> at target point.")));
			helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring.")));
			mode.HelpWindow = helpWindow;
			mode.StartMode ();
			mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
				if (args.Success) {
					insertionPoint = args.InsertionPoint;
					insertionOffset = data.Document.LocationToOffset (args.InsertionPoint.Location);
					base.Run (options);
					if (string.IsNullOrEmpty (fileName))
						return;
					MonoDevelop.Ide.Gui.Document document = IdeApp.Workbench.OpenDocument (fileName);
					TextEditorData docData = document.Editor;
					if (docData != null) {
						docData.ClearSelection ();
						docData.Caret.Offset = selectionEnd;
						docData.SetSelection (selectionStart, selectionEnd);
					}
				}
			};
		}
Example #5
0
        public override void Run(RefactoringOptions options)
        {
            IResolver resolver = options.GetResolver();
            INRefactoryASTProvider provider = options.GetASTProvider();
            TextEditorData         data     = options.GetTextEditorData();
            IType type = options.ResolveResult.CallingType;

            if (invoke.TargetObject is IdentifierExpression)
            {
                fileName      = options.Document.FileName;
                newMethodName = ((IdentifierExpression)invoke.TargetObject).Identifier;
                indent        = options.GetIndent(options.ResolveResult.CallingMember);
                if (options.ResolveResult.CallingMember.IsStatic)
                {
                    modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
                }
            }
            else
            {
                newMethodName = ((MemberReferenceExpression)invoke.TargetObject).MemberName;
                string        callingObject = provider.OutputNode(options.Dom, ((MemberReferenceExpression)invoke.TargetObject).TargetObject);
                ResolveResult resolveResult = resolver.Resolve(new ExpressionResult(callingObject), resolvePosition);
                type     = options.Dom.GetType(resolveResult.ResolvedType);
                fileName = type.CompilationUnit.FileName;
                if (resolveResult.StaticResolve)
                {
                    modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
                }

                if (fileName == options.Document.FileName)
                {
                    indent = options.GetIndent(options.ResolveResult.CallingMember);
//					insertNewMethod.Offset = options.Document.TextEditor.GetPositionFromLineColumn (options.ResolveResult.CallingMember.BodyRegion.End.Line, options.ResolveResult.CallingMember.BodyRegion.End.Column);
                }
                else
                {
                    var openDocument = IdeApp.Workbench.OpenDocument(fileName);
                    data = openDocument.TextEditorData;
                    if (data == null)
                    {
                        return;
                    }
                    modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Public;
                    bool isInInterface = type.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface;
                    if (isInInterface)
                    {
                        modifiers = ICSharpCode.NRefactory.Ast.Modifiers.None;
                    }
                    if (data == null)
                    {
                        throw new InvalidOperationException("Can't open file:" + modifiers);
                    }
                    try {
                        indent = data.Document.GetLine(type.Location.Line - 1).GetIndentation(data.Document) ?? "";
                    } catch (Exception) {
                        indent = "";
                    }
                    indent += "\t";
//					insertNewMethod.Offset = otherFile.Document.LocationToOffset (type.BodyRegion.End.Line - 1, 0);
                }
            }

            InsertionCursorEditMode mode = new InsertionCursorEditMode(data.Parent, HelperMethods.GetInsertionPoints(data.Document, type));

            if (fileName == options.Document.FileName)
            {
                for (int i = 0; i < mode.InsertionPoints.Count; i++)
                {
                    var point = mode.InsertionPoints[i];
                    if (point.Location < data.Caret.Location)
                    {
                        mode.CurIndex = i;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            ModeHelpWindow helpWindow = new ModeHelpWindow();

            helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
            helpWindow.TitleText    = GettextCatalog.GetString("<b>Create Method -- Targeting</b>");
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Key</b>"), GettextCatalog.GetString("<b>Behavior</b>")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Up</b>"), GettextCatalog.GetString("Move to <b>previous</b> target point.")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Down</b>"), GettextCatalog.GetString("Move to <b>next</b> target point.")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Enter</b>"), GettextCatalog.GetString("<b>Declare new method</b> at target point.")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Esc</b>"), GettextCatalog.GetString("<b>Cancel</b> this refactoring.")));
            mode.HelpWindow = helpWindow;
            mode.StartMode();
            mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
                if (args.Success)
                {
                    insertionPoint  = args.InsertionPoint;
                    insertionOffset = data.Document.LocationToOffset(args.InsertionPoint.Location);
                    base.Run(options);
                    if (string.IsNullOrEmpty(fileName))
                    {
                        return;
                    }
                    MonoDevelop.Ide.Gui.Document document = IdeApp.Workbench.OpenDocument(fileName);
                    TextEditorData docData = document.TextEditorData;
                    if (docData != null)
                    {
                        docData.ClearSelection();
                        docData.Caret.Offset = selectionEnd;
                        docData.SetSelection(selectionStart, selectionEnd);
                    }
                }
            };
        }