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


C# RefactoringOptions.GetTextEditorData方法代码示例

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


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

示例1: Run

		public override void Run (RefactoringOptions options)
		{
			DocumentLocation location = options.GetTextEditorData ().Caret.Location;
			IType interfaceType = options.Dom.GetType (options.ResolveResult.ResolvedType);
			IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line, location.Column);
			
			var editor = options.GetTextEditorData ().Parent;
			
			InsertionCursorEditMode mode = new InsertionCursorEditMode (editor, HelperMethods.GetInsertionPoints (editor.Document, declaringType));
			ModeHelpWindow helpWindow = new ModeHelpWindow ();
			helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
			helpWindow.TitleText = GettextCatalog.GetString ("<b>Implement Interface -- 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 interface implementation</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.CurIndex = mode.InsertionPoints.Count - 1;
			mode.StartMode ();
			mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
				if (args.Success) {
					CodeGenerator generator = options.Document.CreateCodeGenerator ();
					args.InsertionPoint.Insert (editor, generator.CreateInterfaceImplementation (declaringType, interfaceType, false));
				}
			};
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:27,代码来源:ImplementImplicit.cs

示例2: IsValid

		public override bool IsValid (RefactoringOptions options)
		{
			if (options.ResolveResult == null)
				return false;
			
			IType type = options.Dom.GetType (options.ResolveResult.ResolvedType);
			if (type == null || type.ClassType != MonoDevelop.Projects.Dom.ClassType.Interface)
				return false;
			if (!CodeGenerator.HasGenerator (options.GetTextEditorData ().Document.MimeType))
				return false;
			DocumentLocation location = options.GetTextEditorData ().Caret.Location;
			IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line, location.Column);
			return declaringType != null && options.ResolveResult.ResolvedExpression.IsInInheritableTypeContext;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:14,代码来源:ImplementImplicit.cs

示例3: IsValid

		public override bool IsValid (RefactoringOptions options)
		{
			IResolver resolver = options.GetResolver ();
			INRefactoryASTProvider provider = options.GetASTProvider ();
			if (resolver == null || provider == null)
				return false;
			TextEditorData data = options.GetTextEditorData ();
			if (data == null)
				return false;
			ResolveResult resolveResult;
			if (data.IsSomethingSelected) {
				ExpressionResult expressionResult = new ExpressionResult (data.SelectedText.Trim ());
				if (expressionResult.Expression.Contains (" ") || expressionResult.Expression.Contains ("\t"))
					expressionResult.Expression = "(" + expressionResult.Expression + ")";
				resolveResult = resolver.Resolve (expressionResult, new DomLocation (data.Caret.Line, data.Caret.Column));
				if (resolveResult == null)
					return false;
				return true;
			}
			LineSegment lineSegment = data.Document.GetLine (data.Caret.Line);
			string line = data.Document.GetTextAt (lineSegment);
			Expression expression = provider.ParseExpression (line);
			BlockStatement block = provider.ParseText (line) as BlockStatement;
			if (expression == null || (block != null && block.Children[0] is LocalVariableDeclaration))
				return false;
			
			resolveResult = resolver.Resolve (new ExpressionResult (line), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column));
			return resolveResult.ResolvedType != null && !string.IsNullOrEmpty (resolveResult.ResolvedType.FullName) && resolveResult.ResolvedType.FullName != DomReturnType.Void.FullName;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:29,代码来源:DeclareLocalCodeGenerator.cs

示例4: IsValid

		public override bool IsValid (RefactoringOptions options)
		{
			MemberResolveResult resolveResult = options.ResolveResult as MemberResolveResult;
			if (resolveResult == null)
				return false;
			IProperty property = resolveResult.ResolvedMember as IProperty;
			if (property == null || resolveResult.CallingMember == null || resolveResult.CallingMember.FullName != property.FullName || !property.HasGet || property.DeclaringType == null)
				return false;
			
			TextEditorData data = options.GetTextEditorData ();
			if (property.HasGet && data.Document.GetCharAt (data.Document.LocationToOffset (property.GetRegion.End.Line, property.GetRegion.End.Column - 1)) == ';')
				return false;
			if (property.HasSet && data.Document.GetCharAt (data.Document.LocationToOffset (property.SetRegion.End.Line, property.SetRegion.End.Column - 1)) == ';')
				return false;
			INRefactoryASTProvider astProvider = options.GetASTProvider ();
			string backingStoreName = RetrieveBackingStore (options, astProvider, property);
			if (string.IsNullOrEmpty (backingStoreName))
				return false;
			
			// look if there is a valid backing store field that doesn't have any attributes.
			int backinStoreStart;
			int backinStoreEnd;
			IField backingStore = GetBackingStoreField (options, backingStoreName, out backinStoreStart, out backinStoreEnd);
			if (backingStore == null || backingStore.Attributes.Any ())
				return false;
			return true;
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:27,代码来源:RemoveBackingStore.cs

示例5: Run

		public override void Run (RefactoringOptions options)
		{
			base.Run (options);
			
			TextEditorData data = options.GetTextEditorData ();
			Mono.TextEditor.TextEditor editor = data.Parent;
			
			List<TextLink> links = new List<TextLink> ();
			TextLink link = new TextLink ("name");
			int referenceCount = 1;
			MemberResolveResult resolveResult = options.ResolveResult as MemberResolveResult;
			IProperty property = resolveResult.ResolvedMember as IProperty;
			if (property.HasGet)
				referenceCount++;
			if (property.HasSet)
				referenceCount++;
			for (int i = refactoringStartOffset; i < data.Document.Length - backingStoreName.Length; i++) {
				if (data.Document.GetTextAt (i, backingStoreName.Length) == backingStoreName) {
					link.AddLink (new Segment (i - refactoringStartOffset, backingStoreName.Length));
					if (link.Count == referenceCount)
						break;
				}
			}
			
			links.Add (link);
			TextLinkEditMode tle = new TextLinkEditMode (editor, refactoringStartOffset, links);
			tle.SetCaretPosition = false;
			if (tle.ShouldStartTextLinkMode) {
				tle.OldMode = data.CurrentMode;
				tle.StartMode ();
				data.CurrentMode = tle;
			}
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:33,代码来源:CreateBackingStore.cs

示例6: IsValid

		public override bool IsValid (RefactoringOptions options)
		{
			TextEditorData data = options.GetTextEditorData ();
			LineSegment line = data.Document.GetLine (data.Caret.Line);
			if (!data.IsSomethingSelected && line != null) {
				var stack = line.StartSpan.Clone ();
				Mono.TextEditor.Highlighting.SyntaxModeService.ScanSpans (data.Document, data.Document.SyntaxMode, data.Document.SyntaxMode, stack, line.Offset, data.Caret.Offset);
				foreach (Span span in stack) {
					if (span.Color == "string.single" || span.Color == "string.double")
						return options.Document.CompilationUnit.GetMemberAt (data.Caret.Line, data.Caret.Column) != null;
				}
			}

			INRefactoryASTProvider provider = options.GetASTProvider ();
			if (provider == null)
				return false;
			string expressionText = null;
			if (options.ResolveResult != null && options.ResolveResult.ResolvedExpression != null)
				expressionText = options.ResolveResult.ResolvedExpression.Expression;

			if (string.IsNullOrEmpty (expressionText)) {
				int start, end;
				expressionText = SearchNumber (data, out start, out end);
			}

			Expression expression = provider.ParseExpression (expressionText);
			return expression is PrimitiveExpression;
		}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:28,代码来源:IntroduceConstantRefactoring.cs

示例7: Run

		public override void Run (RefactoringOptions options)
		{
			DocumentLocation location = options.GetTextEditorData ().Caret.Location;
			IType interfaceType = options.Dom.GetType (options.ResolveResult.ResolvedType);
			IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line, location.Column);
			options.Document.Editor.Document.BeginAtomicUndo ();
			
			var missingAbstractMembers = interfaceType.Members.Where (member => member.IsAbstract && !declaringType.Members.Any (m => member.Name == m.Name));
			CodeGenerationService.AddNewMembers (declaringType, missingAbstractMembers, "implemented abstract members of " + interfaceType.FullName);
			options.Document.Editor.Document.EndAtomicUndo ();
		}
开发者ID:okrmartin,项目名称:monodevelop,代码行数:11,代码来源:ImplementAbstractMembers.cs

示例8: Run

		public override void Run (RefactoringOptions options)
		{
			if (options.SelectedItem is LocalVariable || options.SelectedItem is IParameter) {
				var col = ReferenceFinder.FindReferences (options.SelectedItem);
				if (col == null)
					return;
				TextEditorData data = options.GetTextEditorData ();
				Mono.TextEditor.TextEditor editor = data.Parent;
				if (editor == null) {
					MessageService.ShowCustomDialog (new RenameItemDialog (options, this));
					return;
				}
				
				List<TextLink> links = new List<TextLink> ();
				TextLink link = new TextLink ("name");
				int baseOffset = Int32.MaxValue;
				foreach (MemberReference r in col) {
					baseOffset = Math.Min (baseOffset, data.Document.LocationToOffset (r.Line, r.Column));
				}
				foreach (MemberReference r in col) {
					Segment segment = new Segment (data.Document.LocationToOffset (r.Line, r.Column) - baseOffset, r.Name.Length);
					if (segment.Offset <= data.Caret.Offset - baseOffset && data.Caret.Offset - baseOffset <= segment.EndOffset) {
						link.Links.Insert (0, segment); 
					} else {
						link.AddLink (segment);
					}
				}
				
				links.Add (link);
				if (editor.CurrentMode is TextLinkEditMode)
					((TextLinkEditMode)editor.CurrentMode).ExitTextLinkMode ();
				TextLinkEditMode tle = new TextLinkEditMode (editor, baseOffset, links);
				tle.SetCaretPosition = false;
				tle.SelectPrimaryLink = true;
				if (tle.ShouldStartTextLinkMode) {
					ModeHelpWindow helpWindow = new ModeHelpWindow ();
					helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
					helpWindow.TitleText = options.SelectedItem is LocalVariable ? GettextCatalog.GetString ("<b>Local Variable -- Renaming</b>") : GettextCatalog.GetString ("<b>Parameter -- Renaming</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>Return</b>"), GettextCatalog.GetString ("<b>Accept</b> this refactoring.")));
					helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring.")));
					tle.HelpWindow = helpWindow;
					tle.Cancel += delegate {
						if (tle.HasChangedText)
							editor.Document.Undo ();
					};
					tle.OldMode = data.CurrentMode;
					tle.StartMode ();
					data.CurrentMode = tle;
				}
			} else {
				MessageService.ShowCustomDialog (new RenameItemDialog (options, this));
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:54,代码来源:RenameRefactoring.cs

示例9: PerformChanges

		public override List<Change> PerformChanges (RefactoringOptions options, object properties)
		{
			List<Change> result = new List<Change> ();
			ICSharpCode.NRefactory.Ast.CompilationUnit unit = options.GetASTProvider ().ParseFile (options.Document.Editor.Text);
			FindTypeReferencesVisitor visitor = new FindTypeReferencesVisitor (options.GetTextEditorData (), options.GetResolver ());
			visitor.VisitCompilationUnit (unit, null);

			ProjectDom dom = options.Dom;
			
			ICompilationUnit compilationUnit = options.ParseDocument ().CompilationUnit;
			HashSet<string> usedUsings = new HashSet<string> ();
			foreach (TypeReference r in visitor.PossibleTypeReferences) {
				if (r.IsKeyword)
					continue;
				IType type = dom.SearchType (compilationUnit, compilationUnit, r.ConvertToReturnType ());
				if (type != null) {
					usedUsings.Add (type.Namespace);
				}
			}
			
			Mono.TextEditor.TextEditorData textEditorData = options.GetTextEditorData ();
			HashSet<string> currentUsings = new HashSet<string> ();
			foreach (IUsing u in compilationUnit.Usings) {
				if (u.IsFromNamespace)
					continue;
				if (!u.Aliases.Any () && u.Namespaces.All (name => currentUsings.Contains (name) || !usedUsings.Contains (name)) ) {
					TextReplaceChange change = new TextReplaceChange ();
					change.FileName = options.Document.FileName;
					change.Offset = textEditorData.Document.LocationToOffset (u.Region.Start.Line, u.Region.Start.Column);
					change.RemovedChars = textEditorData.Document.LocationToOffset (u.Region.End.Line, u.Region.End.Column) - change.Offset;
					Mono.TextEditor.LineSegment line = textEditorData.Document.GetLineByOffset (change.Offset);
					if (line != null && line.EditableLength == change.RemovedChars)
						change.RemovedChars += line.DelimiterLength;
					result.Add (change);
				}
				foreach (string nspace in u.Namespaces)
					currentUsings.Add (nspace);
			}
			
			return result;
		}
开发者ID:sandyarmstrong,项目名称:monodevelop,代码行数:41,代码来源:RemoveUnusedImportsRefactoring.cs

示例10: IsValid

		public override bool IsValid (RefactoringOptions options)
		{
			MemberResolveResult resolveResult = options.ResolveResult as MemberResolveResult;
			if (resolveResult == null)
				return false;
			IProperty property = resolveResult.ResolvedMember as IProperty;
			if (property == null || resolveResult.CallingMember == null || resolveResult.CallingMember.FullName != property.FullName || !property.HasGet || property.DeclaringType == null)
				return false;
			TextEditorData data = options.GetTextEditorData ();
			if (property.HasGet && data.Document.GetCharAt (data.Document.LocationToOffset (property.GetRegion.End.Line - 1, property.GetRegion.End.Column - 2)) != ';')
				return false;
			if (property.HasSet && data.Document.GetCharAt (data.Document.LocationToOffset (property.SetRegion.End.Line - 1, property.SetRegion.End.Column - 2)) != ';')
				return false;
			return true;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:15,代码来源:CreateBackingStore.cs

示例11: Run

		public override void Run (RefactoringOptions options)
		{
			DocumentLocation location = options.GetTextEditorData ().Caret.Location;
			IType interfaceType = options.Dom.GetType (options.ResolveResult.ResolvedType);
			IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line + 1, location.Column + 1);
			options.Document.TextEditor.BeginAtomicUndo ();
			CodeRefactorer refactorer = IdeApp.Workspace.GetCodeRefactorer (IdeApp.ProjectOperations.CurrentSelectedSolution);
			refactorer.ImplementInterface (options.Document.CompilationUnit,
			                               declaringType,
			                               interfaceType, 
			                               true, 
			                               interfaceType, 
			                               options.ResolveResult.ResolvedType);
			options.Document.TextEditor.EndAtomicUndo ();
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:15,代码来源:ImplementExplicit.cs

示例12: IsValid

		public override bool IsValid (RefactoringOptions options)
		{
			if (options.ResolveResult == null)
				return false;
			
			IType type = options.Dom.GetType (options.ResolveResult.ResolvedType);
			if (type == null || type.ClassType != MonoDevelop.Projects.Dom.ClassType.Class)
				return false;
			if (!CurrentRefactoryOperationsHandler.ContainsAbstractMembers (type))
				return false;
			DocumentLocation location = options.GetTextEditorData ().Caret.Location;
			IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line, location.Column);
			var missingAbstractMembers = type.Members.Where (member => member.IsAbstract && !member.IsSpecialName && !declaringType.Members.Any (m => member.Name == m.Name));
			return missingAbstractMembers.Any ();
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:15,代码来源:ImplementAbstractMembers.cs

示例13: PerformChanges

		public override List<Change> PerformChanges (RefactoringOptions options, object properties)
		{
			List<Change> result = new List<Change> ();
			ICompilationUnit compilationUnit = options.ParseDocument ().CompilationUnit;
			Mono.TextEditor.TextEditorData textEditorData = options.GetTextEditorData ();
			int minOffset = int.MaxValue;
			foreach (IUsing u in compilationUnit.Usings) {
				if (u.IsFromNamespace)
					continue;
				int offset = textEditorData.Document.LocationToOffset (u.Region.Start.Line, u.Region.Start.Column);
				TextReplaceChange change = new TextReplaceChange () {
					FileName = options.Document.FileName,
					Offset = offset,
					RemovedChars = textEditorData.Document.LocationToOffset (u.Region.End.Line, u.Region.End.Column) - offset
				};
				Mono.TextEditor.LineSegment line = textEditorData.Document.GetLineByOffset (change.Offset);
				if (line != null && line.EditableLength == change.RemovedChars)
					change.RemovedChars += line.DelimiterLength;
				result.Add (change);
				minOffset = Math.Min (minOffset, offset);
			}
			StringBuilder output = new StringBuilder ();
			List<IUsing> usings = new List<IUsing> (compilationUnit.Usings);
			usings.Sort (UsingComparer);
			INRefactoryASTProvider astProvider = options.GetASTProvider ();
			foreach (IUsing u in usings) {
				AstNode declaration;
				if (u.IsFromNamespace)
					continue;
				if (u.Aliases.Any ()) {
					KeyValuePair<string, IReturnType> alias = u.Aliases.First ();
					declaration = new UsingAliasDeclaration (alias.Key, alias.Value.ConvertToTypeReference ());
				} else {
					declaration = new UsingDeclaration (u.Namespaces.First ());
				}
				output.Append (astProvider.OutputNode (options.Dom, declaration));
			}
			TextReplaceChange insertSortedUsings = new TextReplaceChange () {
				FileName = options.Document.FileName,
				Offset = minOffset,
				InsertedText = output.ToString ()
			};
			result.Add (insertSortedUsings);
			return result;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:45,代码来源:SortImportsRefactoring.cs

示例14: Run

		public override void Run (RefactoringOptions options)
		{
			DocumentLocation location = options.GetTextEditorData ().Caret.Location;
			IType interfaceType = options.Dom.GetType (options.ResolveResult.ResolvedType);
			IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line + 1, location.Column + 1);
			options.Document.TextEditor.BeginAtomicUndo ();
			CodeRefactorer refactorer = IdeApp.Workspace.GetCodeRefactorer (IdeApp.ProjectOperations.CurrentSelectedSolution);
			
			List<KeyValuePair<IMember,IReturnType>> members = new List<KeyValuePair<IMember, IReturnType>> ();
			foreach (IMember member in interfaceType.Members) {
				if (member.IsAbstract && !declaringType.Members.Any (m => member.Name == m.Name)) {
					members.Add (new KeyValuePair<IMember,IReturnType> (member, null));
				}
			}
			refactorer.ImplementMembers (declaringType, members, "implemented abstract members of " + interfaceType.FullName);
			
			options.Document.TextEditor.EndAtomicUndo ();
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:18,代码来源:ImplementAbstractMembers.cs

示例15: IsValid

		public override bool IsValid (RefactoringOptions options)
		{
			TextEditorData data = options.GetTextEditorData ();
			LineSegment line = data.Document.GetLine (data.Caret.Line);
			if (data.IsSomethingSelected && line != null) {
				Stack<Span> stack = line.StartSpan != null ? new Stack<Span> (line.StartSpan) : new Stack<Span> ();
				Mono.TextEditor.Highlighting.SyntaxModeService.ScanSpans (data.Document, data.Document.SyntaxMode, data.Document.SyntaxMode, stack, line.Offset, data.Caret.Offset);
				foreach (Span span in stack) {
					if (span.Color == "string.double") {
						int start, end;
						string str = MonoDevelop.Refactoring.IntroduceConstant.IntroduceConstantRefactoring.SearchString (data, '"', out start, out end);
						end = System.Math.Min (end, line.Offset + line.EditableLength);
						return str.StartsWith ("\"") && str.EndsWith ("\"") && data.SelectionRange.Offset < end;
					}
				}
			}
			return false;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:18,代码来源:IntroduceFormatItemRefactoring.cs


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