当前位置: 首页>>代码示例>>C#>>正文


C# RefactoringOptions.GetTextEditorData方法代码示例

本文整理汇总了C#中MonoDevelop.Refactoring.RefactoringOptions.GetTextEditorData方法的典型用法代码示例。如果您正苦于以下问题:C# RefactoringOptions.GetTextEditorData方法的具体用法?C# RefactoringOptions.GetTextEditorData怎么用?C# RefactoringOptions.GetTextEditorData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonoDevelop.Refactoring.RefactoringOptions的用法示例。


在下文中一共展示了RefactoringOptions.GetTextEditorData方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AnalyzeTargetExpression

		bool AnalyzeTargetExpression (RefactoringOptions options, MonoDevelop.CSharp.Ast.CompilationUnit unit)
		{
			var data = options.GetTextEditorData ();
			var target = unit.GetNodeAt (data.Caret.Line, data.Caret.Column);
			if (target == null)
				return false;
			if (target.Parent is MemberReferenceExpression && ((MemberReferenceExpression)target.Parent).GetChildByRole (MemberReferenceExpression.Roles.Identifier) == target) {
				var memberReference = (MemberReferenceExpression)target.Parent;
				target = memberReference.Target;
				var targetResult = options.GetResolver ().Resolve (new ExpressionResult (data.GetTextBetween (target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column)), resolvePosition);
				if (targetResult.StaticResolve)
					modifiers = MonoDevelop.Projects.Dom.Modifiers.Static;
				declaringType = options.Dom.GetType (targetResult.ResolvedType);
				methodName = memberReference.MemberName;
			} else if (target is Identifier) {
				declaringType = options.ResolveResult.CallingType;
				methodName = data.GetTextBetween (target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column);
			}
			
			if (declaringType != null && !HasCompatibleMethod (declaringType, methodName, invocation)) {
				if (declaringType.HasParts)
					declaringType = declaringType.Parts.FirstOrDefault (t => t.CompilationUnit.FileName == options.Document.FileName) ?? declaringType;
				var doc = ProjectDomService.GetParsedDocument (declaringType.SourceProjectDom, declaringType.CompilationUnit.FileName);
				declaringType = doc.CompilationUnit.GetTypeAt (declaringType.Location) ?? declaringType;
				return true;
			}
			return false;
		}
开发者ID:okrmartin,项目名称:monodevelop,代码行数:28,代码来源:CreateMethodCodeGenerator.cs

示例2: Run

		protected override void Run (RefactoringOptions options)
		{
			Gtk.Menu menu = new Gtk.Menu ();
			
			bool resolveDirect;
			List<string> namespaces = GetResolveableNamespaces (options, out resolveDirect);
			
			foreach (string ns in namespaces) {
				// remove used namespaces for conflict resolving.
				if (options.Document.CompilationUnit.IsNamespaceUsedAt (ns, options.ResolveResult.ResolvedExpression.Region.Start))
					continue;
				Gtk.MenuItem menuItem = new Gtk.MenuItem (string.Format (GettextCatalog.GetString ("Add using '{0}'"), ns));
				CurrentRefactoryOperationsHandler.ResolveNameOperation resolveNameOperation = new CurrentRefactoryOperationsHandler.ResolveNameOperation (options.Dom, options.Document, options.ResolveResult, ns);
				menuItem.Activated += delegate {
					resolveNameOperation.AddImport ();
				};
				menu.Add (menuItem);
			}
			if (resolveDirect) {
				foreach (string ns in namespaces) {
					Gtk.MenuItem menuItem = new Gtk.MenuItem (string.Format (GettextCatalog.GetString ("Add '{0}'"), ns));
					CurrentRefactoryOperationsHandler.ResolveNameOperation resolveNameOperation = new CurrentRefactoryOperationsHandler.ResolveNameOperation (options.Dom, options.Document, options.ResolveResult, ns);
					menuItem.Activated += delegate {
						resolveNameOperation.ResolveName ();
					};
					menu.Add (menuItem);
				}
			}
			
			if (menu.Children != null && menu.Children.Length > 0) {
				menu.ShowAll ();
				
				ICompletionWidget widget = options.Document.GetContent<ICompletionWidget> ();
				CodeCompletionContext codeCompletionContext = widget.CreateCodeCompletionContext (options.GetTextEditorData ().Caret.Offset);

				menu.Popup (null, null, delegate (Gtk.Menu menu2, out int x, out int y, out bool pushIn) {
					x = codeCompletionContext.TriggerXCoord; 
					y = codeCompletionContext.TriggerYCoord; 
					pushIn = false;
				}, 0, Gtk.Global.CurrentEventTime);
				menu.SelectFirst (true);
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:43,代码来源:QuickFixHandler.cs

示例3: AnalyzeTargetExpression

		bool AnalyzeTargetExpression (RefactoringOptions options, MonoDevelop.CSharp.Dom.CompilationUnit unit)
		{
			var data = options.GetTextEditorData ();
			var target = unit.GetNodeAt (data.Caret.Line, data.Caret.Column);
			if (target == null)
				return false;
			if (target.Parent is MemberReferenceExpression && ((MemberReferenceExpression)target.Parent).Identifier == target) {
				var memberReference = (MemberReferenceExpression)target.Parent;
				target = memberReference.Target;
				var targetResult = options.GetResolver ().Resolve (new ExpressionResult (data.GetTextBetween (target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column)), resolvePosition);
				if (targetResult.StaticResolve)
					modifiers = MonoDevelop.Projects.Dom.Modifiers.Static;
				declaringType = options.Dom.GetType (targetResult.ResolvedType);
				methodName = memberReference.Identifier.Name;
			} else if (target is Identifier) {
				declaringType = options.ResolveResult.CallingType;
				methodName = data.GetTextBetween (target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column);
			}
			return declaringType != null && !HasCompatibleMethod (declaringType, methodName, invocation);
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:20,代码来源:CreateMethodCodeGenerator.cs

示例4: GetDelegateType

		IType GetDelegateType (RefactoringOptions options, MonoDevelop.CSharp.Dom.CompilationUnit unit)
		{
			var data = options.GetTextEditorData ();
			var containingNode = unit.GetNodeAt (data.Caret.Line, data.Caret.Column);
			var parent = containingNode.Parent;
			
			while (parent != null) {
				if (parent is AssignmentExpression) {
					AssignmentExpression assignment = (AssignmentExpression)parent;
					if (assignment.AssignmentOperatorType != AssignmentOperatorType.Add && assignment.AssignmentOperatorType != AssignmentOperatorType.Subtract && assignment.AssignmentOperatorType != AssignmentOperatorType.Assign)
						return null;
					
					var resolveResult = ResolveAssignment (options, assignment);
					if (resolveResult == null)
						return null;
					IType type = options.Dom.GetType (resolveResult.ResolvedType);
					if (type == null || type.ClassType != ClassType.Delegate)
						return null;
					return type;
				}
				parent = parent.Parent;
			}
			return null;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:24,代码来源:CreateMethodCodeGenerator.cs

示例5: PerformChanges

		public override List<Change> PerformChanges (RefactoringOptions options, object prop)
		{
			List<Change> result = new List<Change> ();
			TextReplaceChange insertNewMethod = new TextReplaceChange ();
			insertNewMethod.FileName = fileName;
			insertNewMethod.RemovedChars = insertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : insertionPoint.Location.Column;
			var data = options.GetTextEditorData ();
			int insertionOffset = data.Document.LocationToOffset (insertionPoint.Location);
			insertNewMethod.Offset = insertionOffset - insertNewMethod.RemovedChars;
			
			StringBuilder sb = new StringBuilder ();
			sb.AppendLine ();
			switch (insertionPoint.LineBefore) {
			case NewLineInsertion.Eol:
				sb.AppendLine ();
				break;
			case NewLineInsertion.BlankLine:
				sb.AppendLine ();
				sb.Append (indent);
				sb.AppendLine ();
				break;
			}

			var generator = options.Document.CreateCodeGenerator ();
			sb.Append (generator.CreateMemberImplementation (declaringType, ConstructMethod (options), false).Code);
			
			switch (insertionPoint.LineAfter) {
			case NewLineInsertion.Eol:
				sb.AppendLine ();
				break;
			case NewLineInsertion.BlankLine:
				sb.AppendLine ();
				sb.AppendLine ();
				sb.Append (indent);
				break;
			}
			
			insertNewMethod.InsertedText = sb.ToString ();
			result.Add (insertNewMethod);
			selectionStart = selectionEnd = insertNewMethod.Offset;
			int idx = insertNewMethod.InsertedText.IndexOf ("throw");
			if (idx >= 0) {
				selectionStart = insertNewMethod.Offset + idx;
				selectionEnd   = insertNewMethod.Offset + insertNewMethod.InsertedText.IndexOf (';', idx) + 1;
			} else {
				selectionStart = selectionEnd = insertNewMethod.Offset;
			}
			return result;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:49,代码来源:CreateMethodCodeGenerator.cs

示例6: ConstructMethodFromInvocation

		IMethod ConstructMethodFromInvocation (RefactoringOptions options)
		{
			var resolver = options.GetResolver ();
			var data = options.GetTextEditorData ();
			
			DomMethod result = new DomMethod (methodName, modifiers, MethodModifier.None, DomLocation.Empty, DomRegion.Empty, returnType);
			result.DeclaringType = new DomType ("GeneratedType") { ClassType = declaringType.ClassType };
			int i = 1;
			foreach (var curArg in invocation.Arguments) {
				var argument = curArg;
				DomParameter arg = new DomParameter ();
				if (argument is DirectionExpression) {
					var de = (DirectionExpression)argument;
					arg.ParameterModifiers = de.FieldDirection == FieldDirection.Out ? ParameterModifiers.Out : ParameterModifiers.Ref; 
					argument = de.Expression;
				}
				
				string argExpression = data.GetTextBetween (argument.StartLocation.Line, argument.StartLocation.Column, argument.EndLocation.Line, argument.EndLocation.Column);
				var resolveResult = resolver.Resolve (new ExpressionResult (argExpression), resolvePosition);
				
				if (argument is MemberReferenceExpression) {
					arg.Name = ((MemberReferenceExpression)argument).Identifier.Name;
				} else if (argument is IdentifierExpression) {
					arg.Name = ((IdentifierExpression)argument).Identifier;
					int idx = arg.Name.LastIndexOf ('.');
					if (idx >= 0)
						arg.Name = arg.Name.Substring (idx + 1);
				} else {
					arg.Name = "par" + i++;
				}
				
				arg.Name = char.ToLower (arg.Name[0]) + arg.Name.Substring (1);
				
				if (resolveResult != null) {
					arg.ReturnType = resolveResult.ResolvedType;
				} else {
					arg.ReturnType = DomReturnType.Object;
				}
				
				result.Add (arg);
			}
			return result;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:43,代码来源:CreateMethodCodeGenerator.cs

示例7: Run

		public override void Run (RefactoringOptions options)
		{
			TextEditorData data = options.GetTextEditorData ();
			
			fileName = declaringType.CompilationUnit.FileName;
			
			var openDocument = IdeApp.Workbench.OpenDocument (fileName);
			if (openDocument == null) {
				MessageService.ShowError (string.Format (GettextCatalog.GetString ("Can't open file {0}."), fileName));
				return;
			}
			data = openDocument.Editor;
			if (data == null)
				return;
			
			if (data == null)
				throw new InvalidOperationException ("Can't open file:" + modifiers);
			try {
				indent = data.Document.GetLine (declaringType.Location.Line).GetIndentation (data.Document) ?? "";
			} catch (Exception) {
				indent = "";
			}
			indent += "\t";
			
			InsertionCursorEditMode mode = new InsertionCursorEditMode (data.Parent, MonoDevelop.Refactoring.HelperMethods.GetInsertionPoints (options.Document, declaringType));
			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) {
					SetInsertionPoint (args.InsertionPoint);
					BaseRun (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);
					}
				}
			};
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:62,代码来源:CreateMethodCodeGenerator.cs

示例8: Analyze

		public bool Analyze (RefactoringOptions options)
		{
			var data = options.GetTextEditorData ();
			if (data.Document.MimeType != CSharpFormatter.MimeType)
				return false;
			var parser = new CSharpParser ();
			var unit = parser.Parse (data);
			if (unit == null)
				return false;
			resolvePosition = new DomLocation (data.Caret.Line, data.Caret.Column);
			
			if (!AnalyzeTargetExpression (options, unit))
				return false;
			
			invocation = GetInvocation (unit, data);
			if (invocation != null) 
				return AnalyzeInvocation (options);
			delegateType = GetDelegateType (options, unit);
			return delegateType != null;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:20,代码来源:CreateMethodCodeGenerator.cs

示例9: GuessReturnType

		IReturnType GuessReturnType (RefactoringOptions options)
		{
			var resolver = options.GetResolver ();
			var data = options.GetTextEditorData ();
			DomNode node = invocation;
			while (node != null) {
				if (node.Parent is VariableInitializer) {
					var initializer = (VariableInitializer)node.Parent;
					var resolveResult = resolver.Resolve (new ExpressionResult (initializer.Name), resolvePosition);
					return resolveResult.ResolvedType;
				}
				if (node.Parent is AssignmentExpression) {
					var resolveResult = ResolveAssignment (options, (AssignmentExpression)node.Parent);
					if (resolveResult != null)
						return resolveResult.ResolvedType;
				}
				if (node.Parent is InvocationExpression) {
					var parentInvocation = (InvocationExpression)node.Parent;
					int idx = 0;
					foreach (var arg in parentInvocation.Arguments) {
						if (arg == node)
							break;
						idx++;
					}
					var resolveResult = resolver.Resolve (new ExpressionResult (data.GetTextBetween (parentInvocation.StartLocation.Line, parentInvocation.StartLocation.Column, parentInvocation.EndLocation.Line, parentInvocation.EndLocation.Column)), resolvePosition) as MethodResolveResult;
					if (resolveResult != null) {
						if (idx < resolveResult.MostLikelyMethod.Parameters.Count)
							return resolveResult.MostLikelyMethod.Parameters[idx].ReturnType;
					}
					return DomReturnType.Object;
				}
				
				node = node.Parent;
			}
			return DomReturnType.Void;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:36,代码来源:CreateMethodCodeGenerator.cs

示例10: ResolveAssignment

		ResolveResult ResolveAssignment (RefactoringOptions options, AssignmentExpression assignment)
		{
			var resolver = options.GetResolver ();
			var data = options.GetTextEditorData ();
			string expression;
			if (assignment.Left is IdentifierExpression) {
				expression = ((IdentifierExpression)assignment.Left).Identifier;
			} else {
				var left = assignment.Left;
				expression = data.GetTextBetween (left.StartLocation.Line, left.StartLocation.Column, left.EndLocation.Line, left.EndLocation.Column);
			}
			return resolver.Resolve (new ExpressionResult (expression), resolvePosition);
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:13,代码来源:CreateMethodCodeGenerator.cs

示例11: PerformChanges

		public override List<Change> PerformChanges (RefactoringOptions options, object prop)
		{
			List<Change> result = new List<Change> ();
			ExtractMethodParameters param = (ExtractMethodParameters)prop;
			var data = options.GetTextEditorData ();
		//	IResolver resolver = options.GetResolver ();
			
			TextReplaceChange replacement = new TextReplaceChange ();
			replacement.Description = string.Format (GettextCatalog.GetString ("Substitute selected statement(s) with call to {0}"), param.Name);
			replacement.FileName = options.Document.FileName;
			replacement.Offset = param.StartOffset;
			replacement.RemovedChars = param.EndOffset - param.StartOffset;
			replacement.MoveCaretToReplace = true;
			replacement.InsertedText = GenerateMethodCall (options, param);
			result.Add (replacement);
			
			TextReplaceChange insertNewMethod = new TextReplaceChange ();
			insertNewMethod.FileName = options.Document.FileName;
			insertNewMethod.Description = string.Format (GettextCatalog.GetString ("Create new method {0} from selected statement(s)"), param.Name);
			var insertionPoint = param.InsertionPoint;
			if (insertionPoint == null) {
				var points = CodeGenerationService.GetInsertionPoints (options.Document, param.DeclaringMember.DeclaringType);
				insertionPoint = points.LastOrDefault (p => p.Location.Line < param.DeclaringMember.Location.Line);
				if (insertionPoint == null)
					insertionPoint = points.FirstOrDefault ();
			}
			
			insertNewMethod.RemovedChars = 0; //insertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : insertionPoint.Location.Column - 1;
			insertNewMethod.Offset = data.Document.LocationToOffset (insertionPoint.Location) - insertNewMethod.RemovedChars;
			insertNewMethod.InsertedText = GenerateMethodDeclaration (options, param);
			result.Add (insertNewMethod);
			/*
			
			ExtractMethodAstTransformer transformer = new ExtractMethodAstTransformer (param.VariablesToGenerate);
			node.AcceptVisitor (transformer, null);
			if (!param.OneChangedVariable && node is Expression) {
				ResolveResult resolveResult = resolver.Resolve (new ExpressionResult ("(" + provider.OutputNode (options.Dom, node) + ")"), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column));
				if (resolveResult.ResolvedType != null)
					returnType = options.ShortenTypeName (resolveResult.ResolvedType).ConvertToTypeReference ();
			}
			
			MethodDeclaration methodDecl = new MethodDeclaration ();
			methodDecl.Name = param.Name;
			methodDecl.Modifier = param.Modifiers;
			methodDecl.TypeReference = returnType;
			
			
			if (node is BlockStatement) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new EmptyStatement ());
				if (param.OneChangedVariable)
					methodDecl.Body.AddChild (new ReturnStatement (new IdentifierExpression (param.ChangedVariables.First ())));
			} else if (node is Expression) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new ReturnStatement (node as Expression));
			}
			
			foreach (VariableDescriptor var in param.VariablesToDefine) {
				BlockStatement block = methodDecl.Body;
				LocalVariableDeclaration varDecl = new LocalVariableDeclaration (options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ());
				varDecl.Variables.Add (new VariableDeclaration (var.Name));
				block.Children.Insert (0, varDecl);
			}
			
			
			
			string indent = options.GetIndent (param.DeclaringMember);
			StringBuilder methodText = new StringBuilder ();
			switch (param.InsertionPoint.LineBefore) {
			case NewLineInsertion.Eol:
				methodText.AppendLine ();
				break;
			case NewLineInsertion.BlankLine:
				methodText.Append (indent);
				methodText.AppendLine ();
				break;
			}
			if (param.GenerateComment) {
				methodText.Append (indent);
				methodText.AppendLine ("/// <summary>");
				methodText.Append (indent);
				methodText.AppendLine ("/// TODO: write a comment.");
				methodText.Append (indent);
				methodText.AppendLine ("/// </summary>");
				Ambience ambience = AmbienceService.GetAmbienceForFile (options.Document.FileName);
				foreach (ParameterDeclarationExpression pde in methodDecl.Parameters) {
					methodText.Append (indent);
					methodText.Append ("/// <param name=\"");
					methodText.Append (pde.ParameterName);
					methodText.Append ("\"> A ");
					methodText.Append (ambience.GetString (pde.TypeReference.ConvertToReturnType (), OutputFlags.IncludeGenerics | OutputFlags.UseFullName));
					methodText.Append (" </param>");
					methodText.AppendLine ();
				}
				if (methodDecl.TypeReference.Type != "System.Void") {
					methodText.Append (indent);
					methodText.AppendLine ("/// <returns>");
					methodText.Append (indent);
					methodText.Append ("/// A ");
					methodText.AppendLine (ambience.GetString (methodDecl.TypeReference.ConvertToReturnType (), OutputFlags.IncludeGenerics | OutputFlags.UseFullName));
//.........这里部分代码省略.........
开发者ID:yayanyang,项目名称:monodevelop,代码行数:101,代码来源:ExtractMethodRefactoring.cs

示例12: Analyze

		bool Analyze (RefactoringOptions options, ExtractMethodParameters param, bool fillParameter)
		{
			var data = options.GetTextEditorData ();
			var parser = new CSharpParser ();
			var unit = parser.Parse (data);
			var resolver = options.GetResolver ();
			if (unit == null)
				return false;
			var selectionRange = data.SelectionRange;
			var startOffset = selectionRange.Offset;
			while (startOffset + 1 < data.Length && char.IsWhiteSpace (data.GetCharAt (startOffset + 1)))
				startOffset++;
			var endOffset = selectionRange.EndOffset;
			while (startOffset < endOffset && endOffset - 1 > 0 && char.IsWhiteSpace (data.GetCharAt (endOffset - 1)))
				endOffset--;
			if (startOffset >= endOffset)
				return false;
			
			var endLocation = data.OffsetToLocation (endOffset);
			var startLocation = data.OffsetToLocation (startOffset);
			param.StartOffset = startOffset;
			param.EndOffset = endOffset;
			param.Nodes = new List<AstNode> (unit.GetNodesBetween (startLocation.Line, startLocation.Column, endLocation.Line, endLocation.Column));
			string text = options.Document.Editor.GetTextBetween (startLocation, endLocation);
			
			param.Text = RemoveIndent (text, GetIndent (data.GetTextBetween (data.GetLine (startLocation.Line).Offset, data.GetLine (endLocation.Line).EndOffset))).TrimEnd ('\n', '\r');
			VariableLookupVisitor visitor = new VariableLookupVisitor (resolver, param.Location);
			visitor.MemberLocation = param.DeclaringMember.Location;
			visitor.CutRegion = new DomRegion (startLocation.Line, startLocation.Column, endLocation.Line, endLocation.Column);
			if (fillParameter) {
				unit.AcceptVisitor (visitor, null);
				if (param.Nodes != null && (param.Nodes.Count == 1 && param.Nodes [0].NodeType == NodeType.Expression)) {
					ResolveResult resolveResult = resolver.Resolve (new ExpressionResult ("(" + text + ")"), param.Location);
					if (resolveResult != null && resolveResult.ResolvedType != null)
						param.ExpressionType = resolveResult.ResolvedType;
				}
				
				foreach (VariableDescriptor varDescr in visitor.VariableList.Where (v => !v.IsDefinedInsideCutRegion && (v.UsedInCutRegion || v.IsChangedInsideCutRegion || v.UsedAfterCutRegion && v.IsDefinedInsideCutRegion))) {
					param.Parameters.Add (varDescr);
				}
			
				param.Variables = new List<VariableDescriptor> (visitor.Variables.Values);
				param.ReferencesMember = visitor.ReferencesMember;
				
				param.OneChangedVariable = param.Variables.Count (p => p.IsDefinedInsideCutRegion && p.UsedAfterCutRegion) == 1;
				if (param.OneChangedVariable)
					param.ExpressionType = param.Variables.First (p => p.IsDefinedInsideCutRegion && p.UsedAfterCutRegion).ReturnType;
				/*
					foreach (VariableDescriptor varDescr in visitor.VariableList.Where (v => !v.IsDefined && param.Variables.Contains (v))) {
					if (param.Parameters.Contains (varDescr))
						continue;
					if (startLocation <= varDescr.Location && varDescr.Location < endLocation)
						continue;
					param.Parameters.Add (varDescr);
				}
				
				
				param.ChangedVariables = new HashSet<string> (visitor.Variables.Values.Where (v => v.GetsChanged).Select (v => v.Name));
				*/
				// analyze the variables outside of the selected text
				IMember member = param.DeclaringMember;
			
				int bodyStartOffset = data.Document.LocationToOffset (member.BodyRegion.Start.Line, member.BodyRegion.Start.Column);
				int bodyEndOffset = data.Document.LocationToOffset (member.BodyRegion.End.Line, member.BodyRegion.End.Column);
				if (startOffset < bodyStartOffset || bodyEndOffset < endOffset)
					return false;
				text = data.Document.GetTextBetween (bodyStartOffset, startOffset) + data.Document.GetTextBetween (endOffset, bodyEndOffset);
				//				ICSharpCode.OldNRefactory.Ast.INode parsedNode = provider.ParseText (text);
				//				visitor = new VariableLookupVisitor (resolver, param.Location);
				//				visitor.CutRegion = new DomRegion (data.MainSelection.MinLine, data.MainSelection.MaxLine);
				//				visitor.MemberLocation = new Location (param.DeclaringMember.Location.Column, param.DeclaringMember.Location.Line);
				//				if (parsedNode != null)
				//					parsedNode.AcceptVisitor (visitor, null);
				
				
				/*	
				param.VariablesOutside = new Dictionary<string, VariableDescriptor> ();
				foreach (var pair in visitor.Variables) {
					if (startLocation < pair.Value.Location || endLocation >= pair.Value.Location) {
						param.VariablesOutside.Add (pair.Key, pair.Value);
					}
				}
				param.OutsideVariableList = new List<VariableDescriptor> ();
				foreach (var v in visitor.VariableList) {
					if (startLocation < v.Location || endLocation >= v.Location)
						param.OutsideVariableList.Add (v);
				}
				
				param.ChangedVariablesUsedOutside = new List<VariableDescriptor> (param.Variables.Where (v => v.GetsChanged && param.VariablesOutside.ContainsKey (v.Name)));
				param.OneChangedVariable = param.Nodes.Count == 1 && param.Nodes[0] is BlockStatement;
				if (param.OneChangedVariable) 
					param.OneChangedVariable = param.ChangedVariablesUsedOutside.Count == 1;
				
				param.VariablesToGenerate = new List<VariableDescriptor> (param.ChangedVariablesUsedOutside.Where (v => v.IsDefined));
				foreach (VariableDescriptor var in param.VariablesToGenerate) {
					param.Parameters.Add (var);
				}
				if (param.OneChangedVariable) {
					param.VariablesToDefine = new List<VariableDescriptor> (param.Parameters.Where (var => !var.InitialValueUsed));
					param.VariablesToDefine.ForEach (var => param.Parameters.Remove (var));
//.........这里部分代码省略.........
开发者ID:yayanyang,项目名称:monodevelop,代码行数:101,代码来源:ExtractMethodRefactoring.cs

示例13: GenerateMethodCall

		static string GenerateMethodCall (RefactoringOptions options, ExtractMethodParameters param)
		{
			var data = options.GetTextEditorData ();
			StringBuilder sb = new StringBuilder ();
			
	/*		LineSegment line = data.Document.GetLine (Math.Max (0, data.Document.OffsetToLineNumber (data.SelectionRange.Offset) - 1));
			if (param.VariablesToGenerate != null && param.VariablesToGenerate.Count > 0) {
				string indent = options.GetWhitespaces (line.Offset);
				sb.Append (Environment.NewLine + indent);
				foreach (VariableDescriptor var in param.VariablesToGenerate) {
					var returnType = options.ShortenTypeName (var.ReturnType);
					sb.Append (returnType.ToInvariantString ());
					sb.Append (" ");
					sb.Append (var.Name);
					sb.AppendLine (";");
					sb.Append (indent);
				}
			}*/
			if (param.OneChangedVariable) {
				sb.Append (param.Parameters.First (p => p.UsedAfterCutRegion).Name);
				sb.Append (" = ");
			}
			sb.Append (param.Name);
			sb.Append (" "); // TODO: respect formatting
			sb.Append ("(");
			bool first = true;
			foreach (VariableDescriptor var in param.Parameters) {
				if (param.OneChangedVariable && var.UsedAfterCutRegion && !var.UsedInCutRegion)
					continue;
				if (first) {
					first = false;
				} else {
					sb.Append (", "); // TODO: respect formatting
				}
				if (!param.OneChangedVariable) {
					if (var.UsedAfterCutRegion)
						sb.Append (var.UsedBeforeCutRegion ? "ref " : "out ");
				}
				sb.Append (var.Name);
			}
			sb.Append (")");
			if (param.Nodes != null && (param.Nodes.Count > 1 || param.Nodes.Count == 1 && param.Nodes[0].NodeType != NodeType.Expression)) 
				sb.Append (";");
			return sb.ToString ();
		}
开发者ID:silk,项目名称:monodevelop,代码行数:45,代码来源:ExtractMethodRefactoring.cs


注:本文中的MonoDevelop.Refactoring.RefactoringOptions.GetTextEditorData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。