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


C# CSharpAstResolver.Resolve方法代码示例

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


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

示例1: Resolve

        public static ResolveResult Resolve(Lazy<ICompilation> compilation, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree, TextLocation location, out AstNode node,
		                                    CancellationToken cancellationToken = default(CancellationToken))
        {
            node = syntaxTree.GetNodeAt(location);
            if (node == null || node is ArrayInitializerExpression)
                return null;
            if (node.Parent is UsingAliasDeclaration && node.Role == UsingAliasDeclaration.AliasRole) {
                var r = new CSharpAstResolver(compilation.Value, syntaxTree, unresolvedFile);
                return r.Resolve(((UsingAliasDeclaration)node.Parent).Import, cancellationToken);
            }
            if (CSharpAstResolver.IsUnresolvableNode(node)) {
                if (node is Identifier) {
                    node = node.Parent;
                } else if (node.NodeType == NodeType.Token) {
                    if (node.Parent is IndexerExpression || node.Parent is ConstructorInitializer) {
                        // There's no other place where one could hover to see the indexer's tooltip,
                        // so we need to resolve it when hovering over the '[' or ']'.
                        // For constructor initializer, the same applies to the 'base'/'this' token.
                        node = node.Parent;
                    } else {
                        return null;
                    }
                } else {
                    // don't resolve arbitrary nodes - we don't want to show tooltips for everything
                    return null;
                }
            } else {
                // It's a resolvable node.
                // However, we usually don't want to show the tooltip everywhere
                // For example, hovering with the mouse over an empty line between two methods causes
                // node==TypeDeclaration, but we don't want to show any tooltip.

                if (!node.GetChildByRole(Roles.Identifier).IsNull) {
                    // We'll suppress the tooltip for resolvable nodes if there is an identifier that
                    // could be hovered over instead:
                    return null;
                }
            }

            if (node == null)
                return null;

            if (node.Parent is ObjectCreateExpression && node.Role == Roles.Type) {
                node = node.Parent;
            }

            InvocationExpression parentInvocation = null;
            if ((node is IdentifierExpression || node is MemberReferenceExpression || node is PointerReferenceExpression) && node.Role != Roles.Argument) {
                // we also need to resolve the invocation
                parentInvocation = node.Parent as InvocationExpression;
            }

            // TODO: I think we should provide an overload so that an existing CSharpAstResolver can be reused
            CSharpAstResolver resolver = new CSharpAstResolver(compilation.Value, syntaxTree, unresolvedFile);
            ResolveResult rr = resolver.Resolve(node, cancellationToken);
            if (rr is MethodGroupResolveResult && parentInvocation != null)
                return resolver.Resolve(parentInvocation);
            else
                return rr;
        }
开发者ID:riviti,项目名称:NRefactory,代码行数:60,代码来源:ResolveAtLocation.cs

示例2: GetAllValidTypesFromInvocation

		static IEnumerable<IType> GetAllValidTypesFromInvocation(CSharpAstResolver resolver, InvocationExpression invoke, AstNode parameter)
		{
			int index = GetArgumentIndex(invoke.Arguments, parameter);
			if (index < 0)
				yield break;

			var targetResult = resolver.Resolve(invoke.Target) as MethodGroupResolveResult;
			if (targetResult != null) {
				foreach (var method in targetResult.Methods) {
					if (index < method.Parameters.Count) {
						if (method.Parameters [index].IsParams) {
							var arrayType = method.Parameters [index].Type as ArrayType;
							if (arrayType != null)
								yield return arrayType.ElementType;
						}

						yield return method.Parameters [index].Type;
					}
				}
				foreach (var extMethods in targetResult.GetExtensionMethods ()) {
					foreach (var extMethod in extMethods) {
						if (index + 1 < extMethod.Parameters.Count) {
							if (extMethod.Parameters [index + 1].IsParams) {
								var arrayType = extMethod.Parameters [index + 1].Type as ArrayType;
								if (arrayType != null)
									yield return arrayType.ElementType;
							}

							yield return extMethod.Parameters [index + 1].Type;
						}
					}
				}
			}
		}
开发者ID:RHE24,项目名称:SharpDevelop,代码行数:34,代码来源:TypeGuessing.cs

示例3: ResolveCref

		public override IEntity ResolveCref(string cref)
		{
			if (cref.Length > 2 && cref[1] == ':') {
				// resolve ID string
				return base.ResolveCref(cref);
			}
			var documentationReference = new CSharpParser().ParseDocumentationReference(cref);
			var csharpContext = context as CSharpTypeResolveContext;
			CSharpResolver resolver;
			if (csharpContext != null) {
				resolver = new CSharpResolver(csharpContext);
			} else {
				resolver = new CSharpResolver(context.Compilation);
			}
			var astResolver = new CSharpAstResolver(resolver, documentationReference);
			var rr = astResolver.Resolve(documentationReference);
			
			MemberResolveResult mrr = rr as MemberResolveResult;
			if (mrr != null)
				return mrr.Member;
			TypeResolveResult trr = rr as TypeResolveResult;
			if (trr != null)
				return trr.Type.GetDefinition();
			return null;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:25,代码来源:CSharpDocumentationComment.cs

示例4: RunTestWithoutUnresolvedFile

        public static void RunTestWithoutUnresolvedFile(CSharpFile file)
        {
            CSharpAstResolver resolver = new CSharpAstResolver(file.Project.Compilation, file.SyntaxTree);
            var navigator = new ValidatingResolveAllNavigator(file.FileName);
            resolver.ApplyNavigator(navigator, CancellationToken.None);
            navigator.Validate(resolver, file.SyntaxTree);

            CSharpAstResolver originalResolver = new CSharpAstResolver(file.Project.Compilation, file.SyntaxTree, file.UnresolvedTypeSystemForFile);
            foreach (var node in file.SyntaxTree.DescendantsAndSelf) {
                var originalResult = originalResolver.Resolve(node);
                var result = resolver.Resolve(node);
                if (!RandomizedOrderResolverTest.IsEqualResolveResult(result, originalResult)) {
                    Console.WriteLine("Got different without IUnresolvedFile at " + file.FileName + ":" + node.StartLocation);
                }
            }
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:16,代码来源:ResolverTest.cs

示例5: GetAllValidTypesFromObjectCreation

		static IEnumerable<IType> GetAllValidTypesFromObjectCreation(CSharpAstResolver resolver, ObjectCreateExpression invoke, AstNode parameter)
		{
			int index = GetArgumentIndex(invoke.Arguments, parameter);
			if (index < 0)
				yield break;

			var targetResult = resolver.Resolve(invoke.Type);
			if (targetResult is TypeResolveResult) {
				var type = ((TypeResolveResult)targetResult).Type;
				if (type.Kind == TypeKind.Delegate && index == 0) {
					yield return type;
					yield break;
				}
				foreach (var constructor in type.GetConstructors ()) {
					if (index < constructor.Parameters.Count)
						yield return constructor.Parameters [index].Type;
				}
			}
		}
开发者ID:qhta,项目名称:NRefactory,代码行数:19,代码来源:TypeGuessing.cs

示例6: GetAllValidTypesFromInvocation

		static IEnumerable<IType> GetAllValidTypesFromInvocation(CSharpAstResolver resolver, InvocationExpression invoke, AstNode parameter)
		{
			int index = GetArgumentIndex(invoke.Arguments, parameter);
			if (index < 0)
				yield break;

			var targetResult = resolver.Resolve(invoke.Target) as MethodGroupResolveResult;
			if (targetResult != null) {
				foreach (var method in targetResult.Methods) {
					if (index < method.Parameters.Count) {
						if (method.Parameters [index].IsParams) {
							var arrayType = method.Parameters [index].Type as ArrayType;
							if (arrayType != null)
								yield return arrayType.ElementType;
						}

						yield return method.Parameters [index].Type;
					}
				}
				foreach (var extMethods in targetResult.GetExtensionMethods ()) {
					foreach (var extMethod in extMethods) {
						IType[] inferredTypes;
						var m = extMethod;
						if (CSharpResolver.IsEligibleExtensionMethod(targetResult.TargetType, extMethod, true, out inferredTypes)) {
							if (inferredTypes != null)
								m = extMethod.Specialize(new TypeParameterSubstitution(null, inferredTypes));
						}

						int correctedIndex = index + 1;
						if (correctedIndex < m.Parameters.Count) {
							if (m.Parameters [correctedIndex].IsParams) {
								var arrayType = m.Parameters [correctedIndex].Type as ArrayType;
								if (arrayType != null)
									yield return arrayType.ElementType;
							}
							yield return m.Parameters [correctedIndex].Type;
						}
					}
				}
			}
		}
开发者ID:furesoft,项目名称:NRefactory,代码行数:41,代码来源:TypeGuessing.cs

示例7: FindReferencesButtonClick

		void FindReferencesButtonClick(object sender, EventArgs e)
		{
			if (csharpTreeView.SelectedNode == null)
				return;
			
			IProjectContent project = new CSharpProjectContent();
			var unresolvedFile = syntaxTree.ToTypeSystem();
			project = project.AddOrUpdateFiles(unresolvedFile);
			project = project.AddAssemblyReferences(builtInLibs.Value);
			
			ICompilation compilation = project.CreateCompilation();
			CSharpAstResolver resolver = new CSharpAstResolver(compilation, syntaxTree, unresolvedFile);
			
			AstNode node = (AstNode)csharpTreeView.SelectedNode.Tag;
			IEntity entity;
			MemberResolveResult mrr = resolver.Resolve(node) as MemberResolveResult;
			TypeResolveResult trr = resolver.Resolve(node) as TypeResolveResult;
			if (mrr != null) {
				entity = mrr.Member;
			} else if (trr != null) {
				entity = trr.Type.GetDefinition();
			} else {
				return;
			}
			
			FindReferences fr = new FindReferences();
			int referenceCount = 0;
			FoundReferenceCallback callback = delegate(AstNode matchNode, ResolveResult result) {
				Debug.WriteLine(matchNode.StartLocation + " - " + matchNode + " - " + result);
				referenceCount++;
			};
			
			var searchScopes = fr.GetSearchScopes(entity);
			Debug.WriteLine("Find references to " + entity.ReflectionName);
			fr.FindReferencesInFile(searchScopes, unresolvedFile, syntaxTree, compilation, callback, CancellationToken.None);
			
			MessageBox.Show("Found " + referenceCount + " references to " + entity.FullName);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:38,代码来源:CSDemo.cs

示例8: ResolveButtonClick

		void ResolveButtonClick(object sender, EventArgs e)
		{
			IProjectContent project = new CSharpProjectContent();
			var unresolvedFile = syntaxTree.ToTypeSystem();
			project = project.AddOrUpdateFiles(unresolvedFile);
			project = project.AddAssemblyReferences(builtInLibs.Value);
			
			ICompilation compilation = project.CreateCompilation();
			
			ResolveResult result;
			if (csharpTreeView.SelectedNode != null) {
				var selectedNode = (AstNode)csharpTreeView.SelectedNode.Tag;
				CSharpAstResolver resolver = new CSharpAstResolver(compilation, syntaxTree, unresolvedFile);
				result = resolver.Resolve(selectedNode);
				// CSharpAstResolver.Resolve() never returns null
			} else {
				TextLocation location = GetTextLocation(csharpCodeTextBox, csharpCodeTextBox.SelectionStart);
				result = ResolveAtLocation.Resolve(compilation, unresolvedFile, syntaxTree, location);
				if (result == null) {
					MessageBox.Show("Could not find a resolvable node at the caret location.");
					return;
				}
			}
			using (var dlg = new SemanticTreeDialog(result))
				dlg.ShowDialog();
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:26,代码来源:CSDemo.cs

示例9: GetAllUnresolvedNodes

        static IEnumerable<NodeResolved> GetAllUnresolvedNodes(AstNode tree, CSharpAstResolver resolver)
        {
            var nodes = tree.Descendants.OrderBy(n => n.StartLocation).Select(n => new NodeResolved
                {
                    Node = n,
                    ResolveResult = resolver.Resolve(n)
                });

            return nodes.Where(n => n.ResolveResult is UnknownIdentifierResolveResult ||
                n.ResolveResult is UnknownMemberResolveResult);
        }
开发者ID:Reese-D,项目名称:my_emacs,代码行数:11,代码来源:FixUsingsHandler.cs

示例10: MagicKeyCompletion

		IEnumerable<ICompletionData> MagicKeyCompletion(char completionChar, bool controlSpace)
		{
			Tuple<ResolveResult, CSharpResolver> resolveResult;
			switch (completionChar) {
			// Magic key completion
				case ':':
				case '.':
					if (IsInsideCommentStringOrDirective()) {
						return Enumerable.Empty<ICompletionData>();
					}
					return HandleMemberReferenceCompletion(GetExpressionBeforeCursor());
				case '#':
					if (!IsInPreprocessorDirective())
						return null;
					return GetDirectiveCompletionData();
			// XML doc completion
				case '<':
					if (IsInsideDocComment()) {
						return GetXmlDocumentationCompletionData();
					}
					if (controlSpace) {
						return DefaultControlSpaceItems();
					}
					return null;
				case '>':
					if (!IsInsideDocComment()) {
						return null;
					}
					string lineText = document.GetText(document.GetLineByNumber(location.Line));
					int startIndex = Math.Min(location.Column - 1, lineText.Length - 1);
				
					while (startIndex >= 0 && lineText [startIndex] != '<') {
						--startIndex;
						if (lineText [startIndex] == '/') {
							// already closed.
							startIndex = -1;
							break;
						}
					}
				
					if (startIndex >= 0) {
						int endIndex = startIndex;
						while (endIndex <= location.Column && endIndex < lineText.Length && !Char.IsWhiteSpace (lineText [endIndex])) {
							endIndex++;
						}
						string tag = endIndex - startIndex - 1 > 0 ? lineText.Substring(
							startIndex + 1,
							endIndex - startIndex - 2
						) : null;
						if (!string.IsNullOrEmpty(tag) && commentTags.IndexOf(tag) >= 0) {
							document.Insert(offset, "</" + tag + ">");
						}
					}
					return null;
			
			// Parameter completion
				case '(':
					if (IsInsideCommentStringOrDirective()) {
						return null;
					}
					var invoke = GetInvocationBeforeCursor(true);
					if (invoke == null) {
						if (controlSpace)
							return DefaultControlSpaceItems(invoke);
						return null;
					}
					if (invoke.Node is TypeOfExpression) {
						return CreateTypeList();
					}
					var invocationResult = ResolveExpression(invoke);
					if (invocationResult == null) {
						return null;
					}
					var methodGroup = invocationResult.Item1 as MethodGroupResolveResult;
					if (methodGroup != null) {
						return CreateParameterCompletion(
							methodGroup,
							invocationResult.Item2,
							invoke.Node,
							invoke.Unit,
							0,
							controlSpace
						);
					}
				
					if (controlSpace) {
						return DefaultControlSpaceItems(invoke);
					}
					return null;
				case '=':
					return controlSpace ? DefaultControlSpaceItems() : null;
				case ',':
					int cpos2;
					if (!GetParameterCompletionCommandOffset(out cpos2)) { 
						return null;
					}
			//	completionContext = CompletionWidget.CreateCodeCompletionContext (cpos2);
			//	int currentParameter2 = MethodParameterDataProvider.GetCurrentParameterIndex (CompletionWidget, completionContext) - 1;
//				return CreateParameterCompletion (CreateResolver (), location, ExpressionContext.MethodBody, provider.Methods, currentParameter);	
					break;
//.........这里部分代码省略.........
开发者ID:DavidS,项目名称:monodevelop,代码行数:101,代码来源:CSharpCompletionEngine.cs

示例11: GuessFromConstructorInitializer

 static IEnumerable<IType> GuessFromConstructorInitializer(CSharpAstResolver resolver, AstNode expr)
 {
     var init = expr.Parent as ConstructorInitializer;
     var rr = resolver.Resolve(expr.Parent);
     int index = GetArgumentIndex(init.Arguments, expr);
     if (index >= 0) {
         foreach (var constructor in rr.Type.GetConstructors()) {
             if (index < constructor.Parameters.Count) {
                 yield return constructor.Parameters[index].Type;
             }
         }
     }
 }
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:13,代码来源:TypeGuessing.cs

示例12: CodeGenerationOptions

		public CodeGenerationOptions ()
		{
			currentState = new Lazy<CSharpResolver> (() => {
				var parsedDocument = Document.ParsedDocument;
				if (parsedDocument == null)
					return null;
				var unit = parsedDocument.GetAst<SyntaxTree> ().Clone ();
				var file = parsedDocument.ParsedFile as CSharpUnresolvedFile;
				
				var resolvedNode = unit.GetNodeAt<BlockStatement> (Document.Editor.Caret.Location);
				if (resolvedNode == null)
					return null;
				
				var expr = new IdentifierExpression ("foo");
				resolvedNode.Add (expr);
				
				var ctx = file.GetTypeResolveContext (Document.Compilation, Document.Editor.Caret.Location);
				
				var resolver = new CSharpResolver (ctx);
				
				var astResolver = new CSharpAstResolver (resolver, unit, file);
				astResolver.ApplyNavigator (new NodeListResolveVisitorNavigator (expr), CancellationToken.None);
				astResolver.Resolve (expr);
				return astResolver.GetResolverStateBefore (expr);
			});
		}
开发者ID:telebovich,项目名称:monodevelop,代码行数:26,代码来源:CodeGenerationOptions.cs

示例13: Validate

			public virtual void Validate(CSharpAstResolver resolver, SyntaxTree syntaxTree)
			{
				foreach (AstNode node in syntaxTree.DescendantsAndSelf.Except(resolvedNodes.Keys)) {
					if (!CSharpAstResolver.IsUnresolvableNode(node)) {
						if (!node.Ancestors.Any(a => a is PreProcessorDirective)) {
							Console.WriteLine("Forgot to resolve " + node);
						}
					}
				}
				foreach (var pair in resolvedNodes) {
					if (resolver.Resolve(pair.Key) != pair.Value)
						throw new InvalidOperationException("Inconsistent result");
				}
			}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:14,代码来源:ResolverTest.cs

示例14: ResolveExpression

		protected Tuple<ResolveResult, CSharpResolver> ResolveExpression(AstNode expr, CompilationUnit unit)
		{
			if (expr == null) {
				return null;
			}
			AstNode resolveNode;
			if (expr is Expression || expr is AstType) {
				resolveNode = expr;
			} else if (expr is VariableDeclarationStatement) {
				resolveNode = ((VariableDeclarationStatement)expr).Type;
			} else {
				resolveNode = expr;
			}
			try {
				var ctx = CSharpParsedFile.GetResolver(Compilation, location);
				var root = expr.AncestorsAndSelf.FirstOrDefault(n => n is EntityDeclaration || n is CompilationUnit);
				if (root == null) {
					return null;
				}
				var csResolver = new CSharpAstResolver (ctx, root, CSharpParsedFile);
				var result = csResolver.Resolve(resolveNode);
				var state = csResolver.GetResolverStateBefore(resolveNode);
				return Tuple.Create(result, state);
			} catch (Exception e) {
				Console.WriteLine(e);
				return null;
			}
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:28,代码来源:CSharpCompletionEngineBase.cs

示例15: VisitVisibleNodes

		void VisitVisibleNodes(AstNode node, IResolveVisitorNavigator currentNavigator, CSharpAstResolver resolver, int start, int end)
		{
			if (!CSharpAstResolver.IsUnresolvableNode(node))
				currentNavigator.Resolved(node, resolver.Resolve(node, caretMovementTokenSource.Token));
			for (var child = node.FirstChild; child != null; child = child.NextSibling) {
				if (child.StartLocation.Line <= end && child.EndLocation.Line >= start)
					VisitVisibleNodes(child, currentNavigator, resolver, start, end);
			}
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:9,代码来源:CaretReferenceHighlightRenderer.cs


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