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


C# RefactorerContext.GetFile方法代码示例

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


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

示例1: RenameClass

		public override IClass RenameClass (RefactorerContext ctx, IClass cls, string newName)
		{
			IEditableTextFile file = ctx.GetFile (cls.Region.FileName);
			if (file == null)
				return null;

			int pos1 = file.GetPositionFromLineColumn (cls.Region.BeginLine, cls.Region.BeginColumn);
			int pos2 = file.GetPositionFromLineColumn (cls.Region.EndLine, cls.Region.EndColumn);
			string txt = file.GetText (pos1, pos2);
			
			Regex targetExp = new Regex(@"\sclass\s*(" + cls.Name + @")\s", RegexOptions.Multiline);
			Match match = targetExp.Match (" " + txt + " ");
			if (!match.Success)
				return null;
			
			int pos = pos1 + match.Groups [1].Index - 1;
			file.DeleteText (pos, cls.Name.Length);
			file.InsertText (pos, newName);
			
			return GetGeneratedClass (ctx, file, cls);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:21,代码来源:CodeGeneration.cs

示例2: AddAttribute

		public virtual void AddAttribute (RefactorerContext ctx, IType cls, CodeAttributeDeclaration attr)
		{
			IEditableTextFile buffer = ctx.GetFile (cls.CompilationUnit.FileName);

			CodeTypeDeclaration type = new CodeTypeDeclaration ("temp");
			type.CustomAttributes.Add (attr);
			CodeDomProvider provider = GetCodeDomProvider ();
			StringWriter sw = new StringWriter ();
			provider.GenerateCodeFromType (type, sw, GetOptions (false));
			string code = sw.ToString ();
			int start = code.IndexOf ('[');
			int end = code.LastIndexOf (']');
			code = code.Substring (start, end-start+1) + Environment.NewLine;

			int line = cls.Location.Line;
			int col = cls.Location.Column;
			int pos = buffer.GetPositionFromLineColumn (line, col);

			code = Indent (code, GetLineIndent (buffer, line), false);
			buffer.InsertText (pos, code);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:21,代码来源:BaseRefactorer.cs

示例3: FindMemberReferences

		public override IEnumerable<MemberReference> FindMemberReferences (RefactorerContext ctx, string fileName, IType cls, IMember member, bool includeXmlComment)
		{
			var editor = ((Mono.TextEditor.ITextEditorDataProvider)ctx.GetFile (fileName)).GetTextEditorData ();
			
			var doc = ProjectDomService.GetParsedDocument (ctx.ParserContext, fileName);
			if (doc == null || doc.CompilationUnit == null)
				return null;
			NRefactoryResolver resolver = new NRefactoryResolver (ctx.ParserContext, doc.CompilationUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, editor, fileName);
			resolver.CallingMember = member;
			FindMemberAstVisitor visitor = new FindMemberAstVisitor (editor.Document, resolver, member);
			visitor.IncludeXmlDocumentation = includeXmlComment;
			visitor.RunVisitor ();
			SetContext (visitor.FoundReferences, ctx);
			return visitor.FoundReferences;
		}
开发者ID:sandyarmstrong,项目名称:monodevelop,代码行数:15,代码来源:CSharpRefactorer.cs

示例4: PerformChange

		public override void PerformChange (IProgressMonitor monitor, RefactorerContext rctx)
		{
			if (rctx == null)
				throw new InvalidOperationException ("Refactory context not available.");
			
			TextEditorData textEditorData = this.TextEditorData;
			if (textEditorData == null) {
				IEditableTextFile file = rctx.GetFile (FileName);
				if (file != null) {
					if (RemovedChars > 0)
						file.DeleteText (Offset, RemovedChars);
					if (!string.IsNullOrEmpty (InsertedText))
						file.InsertText (Offset, InsertedText);
					rctx.Save ();
				}
			} else if (textEditorData != null) {
				int charsInserted = textEditorData.Replace (Offset, RemovedChars, InsertedText);
				if (MoveCaretToReplace)
					textEditorData.Caret.Offset = Offset + charsInserted;
			}
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:21,代码来源:Change.cs

示例5: AddMember

		public virtual IMember AddMember (RefactorerContext ctx, IType cls, CodeTypeMember member)
		{
			IEditableTextFile buffer = ctx.GetFile (cls.CompilationUnit.FileName);
			
			int pos = GetNewMemberPosition (buffer, cls, member);
			string code = GenerateCodeFromMember (member).Trim ();
			
			int line, col;
			buffer.GetLineColumnFromPosition (pos, out line, out col);
			
			string indent = GetLineIndent (buffer, cls.Location.Line) + "\t";
			code = Indent (code, indent, false);
			buffer.InsertText (pos, code);
			
			return FindGeneratedMember (ctx, buffer, cls, member, line);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:16,代码来源:BaseRefactorer.cs

示例6: FindParameterReferences

		public override IEnumerable<MemberReference> FindParameterReferences (RefactorerContext ctx, string fileName, IParameter param, bool includeXmlComment)
		{
			NRefactoryResolver resolver = new NRefactoryResolver (ctx.ParserContext, param.DeclaringMember.DeclaringType.CompilationUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, null, fileName);
			
			resolver.CallingMember = param.DeclaringMember;
			
			FindMemberAstVisitor visitor = new FindMemberAstVisitor (resolver, ctx.GetFile (fileName), param);
			visitor.IncludeXmlDocumentation = includeXmlComment;
			visitor.RunVisitor ();
			SetContext (visitor.FoundReferences, ctx);
			return visitor.FoundReferences;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:12,代码来源:CodeGenerator.cs

示例7: FindMemberReferences

		public override IEnumerable<MemberReference> FindMemberReferences (RefactorerContext ctx, string fileName, IType cls, IMember member, bool includeXmlComment)
		{
			ParsedDocument parsedDocument = parser.Parse (cls.SourceProjectDom, fileName, ctx.GetFile (fileName).Text);
			
			NRefactoryResolver resolver = new NRefactoryResolver (ctx.ParserContext, parsedDocument.CompilationUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, null, fileName);
			resolver.SetupParsedCompilationUnit (parser.LastUnit);
			resolver.CallingMember = member;
			FindMemberAstVisitor visitor = new FindMemberAstVisitor (resolver, ctx.GetFile (fileName), member);
			visitor.IncludeXmlDocumentation = includeXmlComment;
			visitor.RunVisitor ();
			SetContext (visitor.FoundReferences, ctx);
			return visitor.FoundReferences;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:13,代码来源:CodeGenerator.cs

示例8: AddLocalNamespaceImport

		public override void AddLocalNamespaceImport (RefactorerContext ctx, string fileName, string nsName, DomLocation caretLocation)
		{
			IEditableTextFile file = ctx.GetFile (fileName);
			int pos = 0;
			ParsedDocument parsedDocument = parser.Parse (ctx.ParserContext, fileName, file.Text);
			StringBuilder text = new StringBuilder ();
			string indent = "";
			if (parsedDocument.CompilationUnit != null) {
				IUsing containingUsing = null;
				foreach (IUsing u in parsedDocument.CompilationUnit.Usings) {
					if (u.IsFromNamespace && u.Region.Contains (caretLocation)) {
						containingUsing = u;
					}
				}
				
				if (containingUsing != null) {
					indent = GetLineIndent (file, containingUsing.Region.Start.Line);
					
					IUsing lastUsing = null;
					foreach (IUsing u in parsedDocument.CompilationUnit.Usings) {
						if (u == containingUsing)
							continue;
						if (containingUsing.Region.Contains (u.Region)) {
							if (u.IsFromNamespace)
								break;
							lastUsing = u;
						}
					}
					
					if (lastUsing != null) {
						pos = file.GetPositionFromLineColumn (lastUsing.Region.End.Line, lastUsing.Region.End.Column);
					} else {
						pos = file.GetPositionFromLineColumn (containingUsing.ValidRegion.Start.Line, containingUsing.ValidRegion.Start.Column);
						// search line end
						while (pos < file.Length) {
							char ch = file.GetCharAt (pos);
							if (ch == '\n') {
								if (file.GetCharAt (pos + 1) == '\r')
									pos++;
								break;
							} else if (ch == '\r') {
								break;
							}
							pos++;
						}
					}
					
				} else {
					AddGlobalNamespaceImport (ctx, fileName, nsName);
					return;
				}
			}
			if (pos != 0)
				text.AppendLine ();
			text.Append (indent);
			text.Append ("\t");
			text.Append ("using ");
			text.Append (nsName);
			text.Append (";");
			if (pos == 0)
				text.AppendLine ();
			if (file is Mono.TextEditor.ITextEditorDataProvider) {
				Mono.TextEditor.TextEditorData data = ((Mono.TextEditor.ITextEditorDataProvider)file).GetTextEditorData ();
				int caretOffset = data.Caret.Offset;
				int insertedChars = data.Insert (pos, text.ToString ());
				if (pos < caretOffset) {
					data.Caret.Offset = caretOffset + insertedChars;
				}
			} else {
				file.InsertText (pos, text.ToString ());
			} 
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:72,代码来源:CodeGenerator.cs

示例9: CompleteStatement

		public override DomLocation CompleteStatement (RefactorerContext ctx, string fileName, DomLocation caretLocation)
		{
			IEditableTextFile file = ctx.GetFile (fileName);
			int pos = file.GetPositionFromLineColumn (caretLocation.Line + 1, 1);
			
			StringBuilder line = new StringBuilder ();
			int lineNr = caretLocation.Line + 1, column = 1, maxColumn = 1, lastPos = pos;
			
			while (lineNr == caretLocation.Line + 1) {
				maxColumn = column;
				lastPos = pos;
				line.Append (file.GetCharAt (pos));
				pos++;
				file.GetLineColumnFromPosition (pos, out lineNr, out column);
			}
			string trimmedline = line.ToString ().Trim ();
			string indent      = line.ToString ().Substring (0, line.Length - line.ToString ().TrimStart (' ', '\t').Length);
			if (trimmedline.EndsWith (";") || trimmedline.EndsWith ("{"))
				return caretLocation;
			if (trimmedline.StartsWith ("if") || 
			    trimmedline.StartsWith ("while") ||
			    trimmedline.StartsWith ("switch") ||
			    trimmedline.StartsWith ("for") ||
			    trimmedline.StartsWith ("foreach")) {
				if (!trimmedline.EndsWith (")")) {
					file.InsertText (lastPos, " () {" + Environment.NewLine + indent + TextEditorProperties.IndentString + Environment.NewLine + indent + "}");
					caretLocation.Column = maxColumn + 1;
				} else {
					file.InsertText (lastPos, " {" + Environment.NewLine + indent + TextEditorProperties.IndentString + Environment.NewLine + indent + "}");
					caretLocation.Column = indent.Length + 1;
					caretLocation.Line++;
				}
			} else if (trimmedline.StartsWith ("do")) {
				file.InsertText (lastPos, " {" + Environment.NewLine + indent + TextEditorProperties.IndentString + Environment.NewLine + indent + "} while ();");
				caretLocation.Column = indent.Length + 1;
				caretLocation.Line++;
			} else {
				file.InsertText (lastPos, ";" + Environment.NewLine + indent);
				caretLocation.Column = indent.Length;
				caretLocation.Line++;
			}
			return caretLocation;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:43,代码来源:CodeGenerator.cs

示例10: RenameMember

		public virtual IMember RenameMember (RefactorerContext ctx, IType cls, IMember member, string newName)
		{
			IEditableTextFile file = null;
			int pos = -1;
			
			foreach (IType part in cls.Parts) {
				if ((file = ctx.GetFile (part.CompilationUnit.FileName)) == null)
					continue;
				
				if ((pos = GetMemberNamePosition (file, member)) != -1)
					break;
			}
			
			if (pos == -1)
				return null;
			
			string name;
			if (member is IMethod && ((IMethod) member).IsConstructor)
				name = cls.Name;
			else
				name = member.Name;
			
			string txt = file.GetText (pos, pos + name.Length);
			if (txt != name)
				return null;
// Rename is done in CodeRefactorer.RenameMember. A simple text search & replace is NOT the way to rename things
// in source code.
//			file.DeleteText (pos, txt.Length);
//			file.InsertText (pos, newName);
			
			CodeTypeMember memberInfo;
			if (member is IField)
				memberInfo = new CodeMemberField ();
			else if (member is IMethod)
				memberInfo = new CodeMemberMethod ();
			else if (member is IProperty)
				memberInfo = new CodeMemberProperty ();
			else if (member is IEvent)
				memberInfo = new CodeMemberEvent ();
			else
				return null;
			
			memberInfo.Name = newName;
			return FindGeneratedMember (ctx, file, cls, memberInfo, member.Location.Line);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:45,代码来源:BaseRefactorer.cs

示例11: ReplaceMember

		public virtual IMember ReplaceMember (RefactorerContext ctx, IType cls, IMember oldMember, CodeTypeMember memberInfo)
		{
			IEditableTextFile buffer = null;
			int pos = -1;
			
			foreach (IType part in cls.Parts) {
				if ((buffer = ctx.GetFile (part.CompilationUnit.FileName)) == null)
					continue;
				
				if ((pos = GetMemberNamePosition (buffer, oldMember)) != -1)
					break;
			}
			
			if (pos == -1)
				return null;
			
			DomRegion reg = GetMemberBounds (buffer, oldMember);
			int sp = buffer.GetPositionFromLineColumn (reg.Start.Line, reg.Start.Column);
			int ep = buffer.GetPositionFromLineColumn (reg.End.Line, reg.End.Column);
			buffer.DeleteText (sp, ep - sp);
			
			string code = GenerateCodeFromMember (memberInfo);
			string indent = GetLineIndent (buffer, reg.Start.Line);
			code = Indent (code, indent, false);
			
			buffer.InsertText (sp, code);
			
			return FindGeneratedMember (ctx, buffer, cls, memberInfo, reg.Start.Line);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:29,代码来源:BaseRefactorer.cs

示例12: RemoveMember

		public virtual void RemoveMember (RefactorerContext ctx, IType cls, IMember member)
		{
			IEditableTextFile buffer = null;
			int pos = -1;
			foreach (IType part in cls.Parts) {
				if ((buffer = ctx.GetFile (part.CompilationUnit.FileName)) == null)
					continue;
				
				if ((pos = GetMemberNamePosition (buffer, member)) != -1)
					break;
			}
			
			if (pos == -1)
				return;
			
			DomRegion reg = GetMemberBounds (buffer, member);
			int sp = buffer.GetPositionFromLineColumn (reg.Start.Line, reg.Start.Column);
			int ep = buffer.GetPositionFromLineColumn (reg.End.Line, reg.End.Column);
			buffer.DeleteText (sp, ep - sp);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:20,代码来源:BaseRefactorer.cs

示例13: AddFoldingRegion

		public virtual int AddFoldingRegion (RefactorerContext ctx, IType cls, string regionName)
		{
			IEditableTextFile buffer = ctx.GetFile (cls.CompilationUnit.FileName);
			return GetNewMethodPosition (buffer, cls);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:5,代码来源:BaseRefactorer.cs

示例14: AddMembers

		public virtual void AddMembers (RefactorerContext ctx, IType cls, IEnumerable<CodeTypeMember> members, string foldingRegionName)
		{
			//no region name, so distribute them with like members
			if (string.IsNullOrEmpty (foldingRegionName)) {
				AddMembers (ctx, cls, members);
				return;
			}
			
			if (!members.Any ())
				return;
			
			IEditableTextFile buffer = ctx.GetFile (cls.CompilationUnit.FileName);
			int pos;
			
			// create/find the folding region, or if creation of regions isn't supported, put all the added
			// members in one place anyway
			if ((SupportedOperations & RefactorOperations.AddFoldingRegion) == 0) {
				pos = GetNewMethodPosition (buffer, cls);
			} else {
				pos = AddFoldingRegion (ctx, cls, foldingRegionName);
			}
			AddMembersAtPosition (ctx, cls, members, buffer, pos);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:23,代码来源:BaseRefactorer.cs

示例15: FindVariableReferences

		public override IEnumerable<MemberReference> FindVariableReferences (RefactorerContext ctx, string fileName, LocalVariable var)
		{
			var editor = ((Mono.TextEditor.ITextEditorDataProvider)ctx.GetFile (fileName)).GetTextEditorData ();
			
			NRefactoryResolver resolver = new NRefactoryResolver (ctx.ParserContext, var.CompilationUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, editor, fileName);
			resolver.CallingMember = var.DeclaringMember;
			
			FindMemberAstVisitor visitor = new FindMemberAstVisitor (editor.Document, resolver, var);
			visitor.RunVisitor ();
			SetContext (visitor.FoundReferences, ctx);
			return visitor.FoundReferences;
		}
开发者ID:sandyarmstrong,项目名称:monodevelop,代码行数:12,代码来源:CSharpRefactorer.cs


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