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


C# NRefactoryResolver.Resolve方法代码示例

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


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

示例1: OnToolTipRequest

        private void OnToolTipRequest(object sender, ToolTipRequestEventArgs e)
        {
            if (e.InDocument && !e.ToolTipShown)
            {
                IExpressionFinder expressionFinder;
                if (MainForm.IsVisualBasic)
                {
                    expressionFinder = new VBExpressionFinder();
                }
                else
                {
                    expressionFinder = new CSharpExpressionFinder(mainForm.parseInformation);
                }
                ExpressionResult expression = expressionFinder.FindFullExpression(
                    editor.Text,
                    editor.Document.PositionToOffset(e.LogicalPosition));
                if (expression.Region.IsEmpty)
                {
                    expression.Region = new DomRegion(e.LogicalPosition.Line + 1, e.LogicalPosition.Column + 1);
                }

                TextArea textArea = editor.ActiveTextAreaControl.TextArea;
                NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent.Language);
                ResolveResult rr = resolver.Resolve(expression,
                                                    mainForm.parseInformation,
                                                    textArea.MotherTextEditorControl.Text);
                string toolTipText = GetText(rr);
                if (toolTipText != null)
                {
                    e.ShowToolTip(toolTipText);
                }
            }
        }
开发者ID:ExRam,项目名称:DotSpatial-PCL,代码行数:33,代码来源:ToolTipProvider.cs

示例2: OnToolTipRequest

		private void OnToolTipRequest(object sender, TextEditor.ToolTipRequestEventArgs e)
		{
			if (!e.InDocument || e.ToolTipShown)
				return;

			IExpressionFinder expressionFinder;
			if (IntellisenseForm.SupportedLanguage == SupportedLanguage.VisualBasic)
			{
				expressionFinder = new VBExpressionFinder();
			}
			else
			{
				expressionFinder = new CSharpExpressionFinder(_iForm.ParseInformation);
			}

			var expression = expressionFinder.FindFullExpression(
				_editor.Text,
				_editor.Document.PositionToOffset(e.LogicalPosition));
			if (expression.Region.IsEmpty)
			{
				expression.Region = new DomRegion(e.LogicalPosition.Line + 1, e.LogicalPosition.Column + 1);
			}

			var textArea = _editor.ActiveTextAreaControl.TextArea;
			var resolver = new NRefactoryResolver(_iForm.ProjectContent.Language);
			var rr = resolver.Resolve(expression,
				_iForm.ParseInformation,
				textArea.MotherTextEditorControl.Text);

			var toolTipText = GetText(rr);
			if (toolTipText != null)
			{
				e.ShowToolTip(toolTipText);
			}
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:35,代码来源:ToolTipProvider.cs

示例3: GenerateCompletionData

        public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            // We can return code-completion items like this:

            //			return new ICompletionData[] {
            //				new DefaultCompletionData("Text", "Description", 1)
            //			};

            NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent);
            Dom.ResolveResult rr = resolver.Resolve(FindExpression(textArea),
                                                    textArea.Caret.Line,
                                                    textArea.Caret.Column,
                                                    fileName,
                                                    textArea.MotherTextEditorControl.Text);
            List<ICompletionData> resultList = new List<ICompletionData>();
            if (rr != null) {
                ArrayList completionData = rr.GetCompletionData(mainForm.myProjectContent);
                if (completionData != null) {
                    AddCompletionData(resultList, completionData);
                }
            }

            //textArea.MotherTextEditorControl.Text = backup;

            return resultList.ToArray();
        }
开发者ID:cleciusjm,项目名称:db4oanalyzer,代码行数:26,代码来源:CodeCompletionProvider.cs

示例4: NRefactoryTemplateParameterDataProvider

		public NRefactoryTemplateParameterDataProvider (TextEditorData editor, NRefactoryResolver resolver, IEnumerable<string> namespaces, ExpressionResult expressionResult, DomLocation loc)
		{
//			this.editor = editor;
			ResolveResult plainResolveResult = resolver.Resolve (expressionResult, loc);
			MethodResolveResult resolveResult = plainResolveResult as MethodResolveResult;
			if (resolveResult != null) {
				foreach (IMethod method in resolveResult.Methods) {
					if (method.TypeParameters.Count > 0)
						this.types.Add (method);
				}
			} else {
				string typeName = expressionResult.Expression.Trim ();
				foreach (string ns in namespaces) {
					string prefix = ns + (ns.Length > 0 ? "." : "") + typeName + "`";
					for (int i = 1; i < 99; i++) {
						IType possibleType = resolver.Dom.GetType (prefix + i);
						if (possibleType != null)
							this.types.Add (possibleType);
					}
				}
				IType resolvedType = plainResolveResult != null ? resolver.Dom.GetType (plainResolveResult.ResolvedType) : null;
				if (resolvedType == null) {
					int idx = expressionResult.Expression.LastIndexOf (".");
					if (idx < 0)
						return;
					typeName = expressionResult.Expression.Substring (idx + 1);
					expressionResult.Expression = expressionResult.Expression.Substring (0, idx);
					plainResolveResult = resolver.Resolve (expressionResult, loc);
					resolvedType = resolver.Dom.GetType (plainResolveResult.ResolvedType);
				}
				if (resolvedType == null)
					return;
				foreach (IType innerType in resolvedType.InnerTypes) {
					this.types.Add (innerType);
				}
			}
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:37,代码来源:NRefactoryTemplateParameterDataProvider.cs

示例5: GenerateCompletionData

        public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            // We can return code-completion items like this:
            
            //return new ICompletionData[] {
            //	new DefaultCompletionData("Text", "Description", 1)
            //};
            string targetText;
            if (CodeCompleteCaretLocationOffset.Line == 0)
            {

                targetText = textArea.get_Text(); // textArea.MotherTextEditorControl.Text;                
            }
            else
            {
                var firstMethodOffset = calculateFirstMethodOffset();
                targetText = getAdjustedSnippetText(textArea, firstMethodOffset);
            }

            var resolver = new NRefactoryResolver(myProjectContent.Language);
            //ResolveResult rr = resolver.Resolve(FindExpression(textArea),
            var rr = resolver.Resolve(currentExpression, parseInformation, targetText);
            var resultList = new List<ICompletionData>();
            if (rr.notNull())// && ) 
            {                
                ArrayList completionData = rr.GetCompletionData(this.myProjectContent);
                /*"[CodeComplete] expression '{0}' was resolved into type: {1} with {2} results".info(currentExpression.Expression, 
                                                                                                    rr.ResolvedType.FullyQualifiedName,
                                                                                                    completionData.isNull() ? -1 
                                                                                                                            : completionData.Count);*/
                "[CodeComplete] expression '{0}' was resolved into: {1} with {2} results".info(currentExpression.Expression,
                                                                                               rr.ResolvedType.notNull() 
                                                                                                    ? rr.ResolvedType.FullyQualifiedName
                                                                                                    : rr.prop("Name").str(),
                                                                                               completionData.isNull() 
                                                                                                    ? -1 
                                                                                                    : completionData.Count);
                if (completionData != null) {
                    AddCompletionData(resultList, completionData);
                }
            }
            else
                "[CodeComplete] expression '{0}' could not be resolved".error(currentExpression.Expression);
           // "In generate completion Data, There were {0} results found".format(resultList.Count).debug();
            return resultList.ToArray();
        }        
开发者ID:modulexcite,项目名称:FluentSharp_Fork.SharpDevelopEditor,代码行数:46,代码来源:O2CodeCompletion.cs

示例6: resolveLocation

        private ResolveResult resolveLocation(TextLocation logicalPosition)
        {
           var textArea = TextEditor.ActiveTextAreaControl.TextArea;
            string targetText;
            int targetOffset;
            if (CodeCompleteCaretLocationOffset.Line == 0)
            {
                targetText = TextEditor.get_Text();//.Text;
                targetOffset = TextEditor.Document.PositionToOffset(logicalPosition);
            }
            else
            {
                var firstMethodOffset = calculateFirstMethodOffset();
                targetText = getAdjustedSnippetText(textArea, firstMethodOffset);
                targetOffset = firstMethodOffset + textArea.Caret.Offset;
            }

            //getExpressionFromTextArea(textArea);
            var expressionFinder = new CSharpExpressionFinder(parseInformation);
            var expression = expressionFinder.FindFullExpression(targetText,targetOffset);              

            /*IExpressionFinder expressionFinder;
            expressionFinder = new CSharpExpressionFinder(this.parseInformation);
            ExpressionResult expression = expressionFinder.FindFullExpression(
                textEditor.Text,
                textEditor.Document.PositionToOffset(logicalPosition));
             */
            if (expression.Region.IsEmpty)
            {
                expression.Region = new DomRegion(logicalPosition.Line + 1, logicalPosition.Column + 1);
            }
            
            var resolver = new NRefactoryResolver(this.myProjectContent.Language);
            var rr = resolver.Resolve(expression, parseInformation, targetText);                                                

            return rr;
        }        
开发者ID:modulexcite,项目名称:FluentSharp_Fork.SharpDevelopEditor,代码行数:37,代码来源:O2CodeCompletion.cs

示例7: FindExactContextForAsCompletion

		public ExpressionContext FindExactContextForAsCompletion (TextEditorData editor, ICompilationUnit unit, string fileName, IType callingType)
		{
			// find expression on left hand side of the assignment
			int caretOffset = editor.Caret.Offset;
			int pos = -1;
			for (int i = caretOffset - 1; i >= 0; i--) {
				char ch = editor.GetCharAt (i);
				if (Char.IsWhiteSpace (ch))
					continue;
				if (ch == '=') {
					pos = i;
					break;
				}
				if (!(Char.IsLetterOrDigit (ch) || ch == '_'))
					return null;
				
			}
			
			if (pos <= 0)
				return null;
			
			int lastWs = pos - 1;
			while (lastWs > 0 && Char.IsWhiteSpace (editor.GetCharAt (lastWs)))
				lastWs--;
			while (lastWs > 0 && !Char.IsWhiteSpace (editor.GetCharAt (lastWs)))
				lastWs--;
			ExpressionResult firstExprs = FindExpression (editor, lastWs);
			if (firstExprs.Expression != null) {
				IReturnType unresolvedReturnType = NRefactoryResolver.ParseReturnType (firstExprs);
				if (unresolvedReturnType != null) {
					IType resolvedType = projectContent.SearchType (unit, (INode)callingType ?? unit, unresolvedReturnType);
					return ExpressionContext.TypeDerivingFrom (resolvedType != null ? new DomReturnType (resolvedType) : null, unresolvedReturnType, true);
				}
				
			}
			
			ExpressionResult lhsExpr = FindExpression (editor, pos);
			if (lhsExpr.Expression != null) {
				NRefactoryResolver resolver = new NRefactoryResolver (projectContent, unit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, editor, fileName);
				
				ResolveResult rr = resolver.Resolve (lhsExpr, new DomLocation (editor.Caret.Line, editor.Caret.Column));
				//ResolveResult rr = ParserService.Resolve (lhsExpr, currentLine.LineNumber, pos, editor.FileName, editor.Text);
				
				if (rr != null && rr.ResolvedType != null) {
					ExpressionContext context;
					IType c;
					/*					if (rr.ResolvedType.IsArrayReturnType) {
						// when creating an array, all classes deriving from the array's element type are allowed
						IReturnType elementType = rr.ResolvedType.CastToArrayReturnType().ArrayElementType;
						c = elementType != null ? dom.GetType (elementType) : null;
						context = ExpressionContext.TypeDerivingFrom(elementType, false);
					} else */					{
						// when creating a normal instance, all non-abstract classes deriving from the type
						// are allowed
						c = projectContent.GetType (rr.ResolvedType);
						context = ExpressionContext.TypeDerivingFrom (rr.ResolvedType, null, true);
					}
					if (c != null && !context.FilterEntry (c)) {
						// Try to suggest an entry (List<int> a = new => suggest List<int>).
						
						string suggestedClassName = null;
						/*LanguageProperties.CSharp.CodeGenerator.GenerateCode(
							CodeGenerator.ConvertType(
								rr.ResolvedType,
								new ClassFinder(ParserService.GetParseInformation(editor.FileName), editor.ActiveTextAreaControl.Caret.Line, editor.ActiveTextAreaControl.Caret.Column)
							), "");*/						if (suggestedClassName != c.Name) {
							// create an IType instance that includes the type arguments in its name
							//context.DefaultItem = new RenamedClass (c, suggestedClassName);
						} else {
							context.DefaultItem = c;
						}
					}
					return context;
				}
			}
			return null;
		}
开发者ID:famousthom,项目名称:monodevelop,代码行数:77,代码来源:NewCSharpExpressionFinder.cs

示例8: FindExactContextForNewCompletion

		public ExpressionContext FindExactContextForNewCompletion (TextEditorData editor, ICompilationUnit unit, string fileName, IType callingType, int cursorPos)
		{
			// find expression on left hand side of the assignment
			int caretOffset = editor.Caret.Offset;
			int pos = -1;
			for (int i = caretOffset - 1; i >= 0; i--) {
				if (editor.GetCharAt (i) == '=') {
					if (i > 0 && (editor.GetCharAt (i - 1) == '+' || editor.GetCharAt (i - 1) == '-'))
						i--;
					pos = i;
					break;
				}
			}
			if (pos <= 0)
				return null;
			
			// check if new +=/-=/= is right before "new"
			for (int i = pos; i < cursorPos; i++) {
				char ch = editor.GetCharAt (i);
				if (Char.IsWhiteSpace (ch))
					continue;
				if (ch != '=' && ch != '+' && ch != '-' && ch != 'n' && ch != 'e' && ch != 'w')
					return null;
			}
			int lastWs = pos - 1;
			while (lastWs > 0 && char.IsWhiteSpace (editor.GetCharAt (lastWs)))
				lastWs--;
			
			int varTypePos = lastWs;
			while (varTypePos > 0 && !char.IsWhiteSpace (editor.GetCharAt (varTypePos)))
				varTypePos--;
			while (varTypePos > 0 && char.IsWhiteSpace (editor.GetCharAt (varTypePos)))
				varTypePos--;
			
			ExpressionResult possibleTypeExpression = FindFullExpression (editor, varTypePos);
			if (possibleTypeExpression.Expression != null) {
				if (possibleTypeExpression.Expression == "var")
					return ExpressionContext.TypeDerivingFrom (DomReturnType.Object, DomReturnType.Object, true);
				IReturnType unresolvedReturnType = NRefactoryResolver.ParseReturnType (possibleTypeExpression);
				if (unresolvedReturnType != null) {
					IType resolvedType = projectContent.SearchType (unit, callingType, new DomLocation (editor.Caret.Line, editor.Caret.Column), unresolvedReturnType);
					if (resolvedType != null)
						return ExpressionContext.TypeDerivingFrom (new DomReturnType (resolvedType), unresolvedReturnType, true);
				}
			}
			
			ExpressionResult lhsExpr = FindFullExpression (editor, lastWs);
			if (lhsExpr.Expression != null) {
				NRefactoryResolver resolver = new NRefactoryResolver (projectContent, unit, ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, editor, fileName);
				
				ResolveResult rr = resolver.Resolve (lhsExpr, new DomLocation (editor.Caret.Line, editor.Caret.Column));
				//ResolveResult rr = ParserService.Resolve (lhsExpr, currentLine.LineNumber, pos, editor.FileName, editor.Text);
				if (rr != null && rr.ResolvedType != null) {
					ExpressionContext context;
					IType c;
					/*					if (rr.ResolvedType.IsArrayReturnType) {
						// when creating an array, all classes deriving from the array's element type are allowed
						IReturnType elementType = rr.ResolvedType.CastToArrayReturnType().ArrayElementType;
						c = elementType != null ? dom.GetType (elementType) : null;
						context = ExpressionContext.TypeDerivingFrom(elementType, false);
					} else */					{
						// when creating a normal instance, all non-abstract classes deriving from the type
						// are allowed
						c = projectContent.GetType (rr.ResolvedType);
						context = ExpressionContext.TypeDerivingFrom (rr.ResolvedType, null, true);
					}
					if (c != null && !context.FilterEntry (c)) {
						// Try to suggest an entry (List<int> a = new => suggest List<int>).
						
						string suggestedClassName = null;
						/*LanguageProperties.CSharp.CodeGenerator.GenerateCode(
							CodeGenerator.ConvertType(
								rr.ResolvedType,
								new ClassFinder(ParserService.GetParseInformation(editor.FileName), editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1)
							), "");*/						if (suggestedClassName != c.Name) {
							// create an IType instance that includes the type arguments in its name
							//context.DefaultItem = new RenamedClass (c, suggestedClassName);
						} else {
							context.DefaultItem = c;
						}
					}
					return context;
				}
			}
		
			return null;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:87,代码来源:NewCSharpExpressionFinder.cs

示例9: SetupDataProvider

		public void SetupDataProvider(string fileName)
		{
			IExpressionFinder expressionFinder;
			if (IntellisenseForm.SupportedLanguage == SupportedLanguage.VisualBasic)
			{
				expressionFinder = new VBExpressionFinder();
			}
			else
			{
				expressionFinder = new CSharpExpressionFinder(_iForm.ParseInformation);
			}

			//TextLocation position = _textArea.Caret.Position;
			//ExpressionResult expression = expressionFinder.FindFullExpression(_textArea.MotherTextEditorControl.Text, _textArea.Document.PositionToOffset(position));
			//if (expression.Region.IsEmpty)
			//{
			//    expression.Region = new DomRegion(position.Line + 1, position.Column + 1);
			//}
			var expression = expressionFinder.FindFullExpression(
				_textArea.MotherTextEditorControl.Text,
				_textArea.MotherTextEditorControl.Document.PositionToOffset(_textArea.Caret.Position) - 1);
			if (expression.Region.IsEmpty)
			{
				expression.Region = new DomRegion(_textArea.Caret.Position.Line + 1, _textArea.Caret.Position.Column + 1);
			}


			var resolver = new NRefactoryResolver(_iForm.ProjectContent.Language);
			var rr = resolver.Resolve(expression, _iForm.ParseInformation, _textArea.MotherTextEditorControl.Text);

			var lines = new List<string>();
			if (rr is MethodGroupResolveResult)
			{
				var mrr = rr as MethodGroupResolveResult;
				var ambience = IntellisenseForm.SupportedLanguage == SupportedLanguage.VisualBasic
					? (IAmbience) new VBNetAmbience()
					: new CSharpAmbience();
				ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowAccessibility;

				lines.AddRange(mrr.Methods.SelectMany(methodgroup => methodgroup,
					(methodgroup, method) => ToolTipProvider.GetMemberText(ambience, method)));
			}

			_insighText = (lines.Count > 0) ? lines.ToArray() : null;
			ArgumentStartOffset = _textArea.Caret.Offset;
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:46,代码来源:MethodInsightDataProvider.cs

示例10: GenerateCompletionData

        public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            // We can return code-completion items like this:

            //return new ICompletionData[] {
            //	new DefaultCompletionData("Text", "Description", 1)
            //};
            var targetText = "";
            if (CodeCompleteCaretLocationOffset.Line == 0)
            {

                targetText = textArea.get_Text(); // textArea.MotherTextEditorControl.Text;
            }
            else
            {
                var firstMethodOffset = calculateFirstMethodOffset();
                targetText = getAdjustedSnippetText(textArea, firstMethodOffset);
            }

            NRefactoryResolver resolver = new NRefactoryResolver(this.myProjectContent.Language);
            //ResolveResult rr = resolver.Resolve(FindExpression(textArea),
            ResolveResult rr = resolver.Resolve(currentExpression,
                                                    this.parseInformation,
                                                    targetText);
            List<ICompletionData> resultList = new List<ICompletionData>();
            if (rr != null) {
                ArrayList completionData = rr.GetCompletionData(this.myProjectContent);
                if (completionData != null) {
                    AddCompletionData(resultList, completionData);
                }
            }
               // "In generate completion Data, There were {0} results found".format(resultList.Count).debug();
            return resultList.ToArray();
        }
开发者ID:pusp,项目名称:o2platform,代码行数:34,代码来源:O2CodeCompletion.cs

示例11: SetupDataProvider

        public void SetupDataProvider(string fileName)
        {
            IExpressionFinder expressionFinder;
            if (IntellisenseForm.SupportedLanguage == ESupportedLanguage.VisualBasic)
            {
                expressionFinder = new VBExpressionFinder();
            }
            else
            {
                expressionFinder = new CSharpExpressionFinder(iForm.ParseInformation);
            }

            //TextLocation position = m_textarea.Caret.Position;
            //ExpressionResult expression = expressionFinder.FindFullExpression(m_textarea.MotherTextEditorControl.Text, m_textarea.Document.PositionToOffset(position));
            //if (expression.Region.IsEmpty)
            //{
            //    expression.Region = new DomRegion(position.Line + 1, position.Column + 1);
            //}
            ExpressionResult expression = expressionFinder.FindFullExpression(
                    m_textarea.MotherTextEditorControl.Text,
                    m_textarea.MotherTextEditorControl.Document.PositionToOffset(m_textarea.Caret.Position)-1);
            if (expression.Region.IsEmpty)
            {
                expression.Region = new DomRegion(m_textarea.Caret.Position.Line + 1, m_textarea.Caret.Position.Column + 1);
            }



            NRefactoryResolver resolver = new NRefactoryResolver(iForm.ProjectContent.Language);
            ResolveResult rr = resolver.Resolve(expression, iForm.ParseInformation, m_textarea.MotherTextEditorControl.Text);

            List<string> lines = new List<string>();
            if (rr is MethodGroupResolveResult)
            {
                MethodGroupResolveResult mrr = rr as MethodGroupResolveResult;
                IAmbience ambience = IntellisenseForm.SupportedLanguage == ESupportedLanguage.VisualBasic ? (IAmbience)new VBNetAmbience() : new CSharpAmbience();
                ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowAccessibility;
                
                foreach (MethodGroup methodgroup in mrr.Methods)
                {
                    foreach (IMethod method in methodgroup)
                    {
                        lines.Add(ToolTipProvider.GetMemberText(ambience, method));
                    }
                }
            }

            m_insighttext = (lines.Count > 0) ? lines.ToArray() : null;
            m_argumentstartoffset = m_textarea.Caret.Offset;
        }
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:50,代码来源:MethodInsightDataProvider.cs

示例12: Resolve

			public override ResolveResult Resolve(ITextEditor editor, ExpressionResult expressionResult)
			{
				// bypass ParserService.Resolve and set resolver.LimitMethodExtractionUntilCaretLine
				ParseInformation parseInfo = ParserService.GetParseInformation(editor.FileName);
				NRefactoryResolver resolver = new NRefactoryResolver(LanguageProperties.CSharp);
				resolver.LimitMethodExtractionUntilLine = editor.Caret.Line;
				return resolver.Resolve(expressionResult, parseInfo, editor.Document.Text);
			}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:8,代码来源:CSharpCompletionBinding.cs

示例13: CreateRefactoringOptions

		internal static RefactoringOptions CreateRefactoringOptions (string text)
		{
			int cursorPosition = -1;
			int endPos = text.IndexOf ('$');
			if (endPos >= 0) {
				cursorPosition = endPos;
				text = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
			}
			
			int selectionStart = -1;
			int selectionEnd   = -1;
			int idx = text.IndexOf ("<-");
			if (idx >= 0) {
				selectionStart = idx;
				text = text.Substring (0, idx) + text.Substring (idx + 2);
				selectionEnd = idx = text.IndexOf ("->");
				
				text = text.Substring (0, idx) + text.Substring (idx + 2);
				if (cursorPosition < 0)
					cursorPosition = selectionEnd - 1;
			}
			
			TestWorkbenchWindow tww = new TestWorkbenchWindow ();
			TestViewContent sev = new TestViewContent ();
	//		return new RefactoringOptions ();
			
			DotNetProject project = new DotNetAssemblyProject ("C#");
			Solution solution = new Solution ();
			solution.RootFolder.Items.Add (project);
			project.FileName = GetTempFile (".csproj");
			string file = GetTempFile (".cs");
			project.AddFile (file);
			string parsedText = text;
			string editorText = text;
			ProjectDomService.Load (project);
			ProjectDom dom = ProjectDomService.GetProjectDom (project);
			dom.ForceUpdate (true);
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			
			sev.Project = project;
			sev.ContentName = file;
			sev.Text = editorText;
			sev.CursorPosition = cursorPosition;
			
			tww.ViewContent = sev;
			var doc = new MonoDevelop.Ide.Gui.Document (tww);
			doc.Editor.Document.MimeType = "text/x-csharp";
			doc.Editor.Document.FileName = file;
			doc.ParsedDocument = new McsParser ().Parse (null, sev.ContentName, parsedText);
			foreach (var e in doc.ParsedDocument.Errors)
				Console.WriteLine (e);
			if (cursorPosition >= 0)
				doc.Editor.Caret.Offset = cursorPosition;
			if (selectionStart >= 0) 
				doc.Editor.SetSelection (selectionStart, selectionEnd);
			
			NRefactoryResolver resolver = new NRefactoryResolver (dom, 
			                                                      doc.ParsedDocument.CompilationUnit, 
			                                                      sev.Data, 
			                                                      file);
			
			ExpressionResult expressionResult;
			if (selectionStart >= 0) {
				expressionResult = new ExpressionResult (editorText.Substring (selectionStart, selectionEnd - selectionStart).Trim ());
				endPos = selectionEnd;
			} else {
				expressionResult = new NewCSharpExpressionFinder (dom).FindFullExpression (doc.Editor, cursorPosition + 1);
			}
			ResolveResult resolveResult = endPos >= 0 ? resolver.Resolve (expressionResult, new DomLocation (doc.Editor.Caret.Line, doc.Editor.Caret.Column)) : null;
			
			RefactoringOptions result = new RefactoringOptions {
				Document = doc,
				Dom = dom,
				ResolveResult = resolveResult,
				SelectedItem = null
			};
			if (resolveResult is MemberResolveResult)
				result.SelectedItem = ((MemberResolveResult)resolveResult).ResolvedMember;
			if (resolveResult is LocalVariableResolveResult)
				result.SelectedItem = ((LocalVariableResolveResult)resolveResult).LocalVariable;
			if (resolveResult is ParameterResolveResult)
				result.SelectedItem = ((ParameterResolveResult)resolveResult).Parameter;
			result.TestFileProvider = new FileProvider (result);
			return result;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:86,代码来源:ExtractMethodTests.cs

示例14: Resolve

			protected override ResolveResult Resolve(ExpressionResult expressionResult, int caretLineNumber, int caretColumn, string fileName, string fileContent)
			{
				// bypass ParserService.Resolve and set resolver.LimitMethodExtractionUntilCaretLine
				ParseInformation parseInfo = ParserService.GetParseInformation(fileName);
				NRefactoryResolver resolver = new NRefactoryResolver(LanguageProperties.CSharp);
				resolver.LimitMethodExtractionUntilLine = caretLineNumber;
				return resolver.Resolve(expressionResult, parseInfo, fileContent);
			}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:8,代码来源:CSharpCompletionBinding.cs


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