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


C# CSharpAstResolver.ApplyNavigator方法代码示例

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


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

示例1: RunTest

		public static void RunTest(CSharpFile file)
		{
			CSharpAstResolver resolver = new CSharpAstResolver(file.Project.Compilation, file.SyntaxTree, file.UnresolvedTypeSystemForFile);
			var navigator = new ValidatingResolveAllNavigator(file.FileName);
			resolver.ApplyNavigator(navigator, CancellationToken.None);
			navigator.Validate(resolver, file.SyntaxTree);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:7,代码来源:ResolverTest.cs

示例2: RunTest

		public static void RunTest(CSharpFile file)
		{
			CSharpAstResolver resolver = new CSharpAstResolver(file.Project.Compilation, file.CompilationUnit, file.ParsedFile);
			var navigator = new ValidatingResolveAllNavigator(file.FileName);
			resolver.ApplyNavigator(navigator, CancellationToken.None);
			navigator.Validate(file.CompilationUnit);
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:7,代码来源:ResolverTest.cs

示例3: GetSharedResolver

		/// <summary>
		/// Returns a full C# syntax tree resolver which is shared between semantic highlighting, source analysis and refactoring.
		/// For code analysis tasks this should be used instead of generating an own resolver. Only exception is if a local resolving is done using a 
		/// resolve navigator.
		/// Note: The shared resolver is fully resolved.
		/// </summary>
		public static Task<CSharpAstResolver> GetSharedResolver (this Document document)
		{
			var parsedDocument = document.ParsedDocument;
			if (parsedDocument == null)
				return null;
			
			var unit       = parsedDocument.GetAst<SyntaxTree> ();
			var parsedFile = parsedDocument.ParsedFile as CSharpUnresolvedFile;
			if (unit == null || parsedFile == null)
				return null;
			
			var resolverAnnotation = document.Annotation<ResolverAnnotation> ();

			if (resolverAnnotation != null) {
				if (resolverAnnotation.ParsedFile == parsedFile)
					return resolverAnnotation.Task;
				document.RemoveAnnotations<ResolverAnnotation> ();
			}

			var resolveTask = Task.Factory.StartNew (delegate {
				var result = new CSharpAstResolver (document.Compilation, unit, parsedFile);
				result.ApplyNavigator (new ConstantModeResolveVisitorNavigator (ResolveVisitorNavigationMode.Resolve, null));
				return result;
			});
			document.AddAnnotation (new ResolverAnnotation {
				Task = resolveTask,
				ParsedFile = parsedFile
			});
			return resolveTask;
		}
开发者ID:segaman,项目名称:monodevelop,代码行数:36,代码来源:ExtensionMethods.cs

示例4: FindSemanticErrors

        public SemanticErrorsResponse FindSemanticErrors(Request request)
        {
            var clientFilename = request.FileName.ApplyPathReplacementsForClient();
            var project = _solution.ProjectContainingFile(request.FileName);
            project.UpdateFile(request.FileName, request.Buffer);
            var solutionSnapshot = new DefaultSolutionSnapshot(_solution.Projects.Select(i => i.ProjectContent));
            SyntaxTree syntaxTree;
            if(project.CompilerSettings!=null){
            	syntaxTree = new CSharpParser(project.CompilerSettings).Parse(request.Buffer, request.FileName);
            }else{
            	syntaxTree = new CSharpParser().Parse(request.Buffer, request.FileName);
            }
            var resolver = new CSharpAstResolver(solutionSnapshot.GetCompilation(project.ProjectContent), syntaxTree);
            var navigator = new SemanticErrorsNavigator();
            resolver.ApplyNavigator(navigator);
            var errors = navigator.GetErrors()
                .Where(e => ShouldIncludeIssue(e.Message))
                .Select(i => new Error
            {
                FileName = clientFilename,
                Message = i.Message,
                Line = i.StartLocation.Line,
                Column = i.EndLocation.Column,
                EndLine = i.EndLocation.Line,
                EndColumn = i.EndLocation.Column
            });

            return new SemanticErrorsResponse
            {
                Errors = errors,
            };
        }
开发者ID:Reese-D,项目名称:my_emacs,代码行数:32,代码来源:SemanticErrorsHandler.cs

示例5: GetSharedResolver

		/// <summary>
		/// Returns a full C# syntax tree resolver which is shared between semantic highlighting, source analysis and refactoring.
		/// For code analysis tasks this should be used instead of generating an own resolver. Only exception is if a local resolving is done using a 
		/// resolve navigator.
		/// Note: The shared resolver is fully resolved.
		/// </summary>
		public static Task<CSharpAstResolver> GetSharedResolver (this Document document)
		{
			var parsedDocument = document.ParsedDocument;
			if (parsedDocument == null || document.IsProjectContextInUpdate || document.Project != null && !(document.Project is DotNetProject))
				return null;

			var unit       = parsedDocument.GetAst<SyntaxTree> ();
			var parsedFile = parsedDocument.ParsedFile as CSharpUnresolvedFile;
			if (unit == null || parsedFile == null)
				return null;
			var compilation = document.Compilation;

			var resolverAnnotation = document.Annotation<ResolverAnnotation> ();

			if (resolverAnnotation != null) {
				if (resolverAnnotation.ParsedFile == parsedFile)
					return resolverAnnotation.Task;
				if (resolverAnnotation.SharedTokenSource != null)
					resolverAnnotation.SharedTokenSource.Cancel ();
				document.RemoveAnnotations<ResolverAnnotation> ();
			}

			var tokenSource = new CancellationTokenSource ();
			var token = tokenSource.Token;
			var resolveTask = Task.Factory.StartNew (delegate {
				try {
					using (var timer = ResolveCounter.BeginTiming ()) {
						var result = new CSharpAstResolver (compilation, unit, parsedFile);
						result.ApplyNavigator (new ConstantModeResolveVisitorNavigator (ResolveVisitorNavigationMode.Resolve, null), token);
						return result;
					}
				} catch (OperationCanceledException) {
					return null;
				} catch (Exception e) {
					LoggingService.LogError ("Error while creating the resolver.", e);
					return null;
				}
			}, token);

			var wrapper = resolveTask.ContinueWith (t => {
				if (t.IsCanceled)
					return null;
				if (t.IsFaulted) {
					var ex = t.Exception.Flatten ().InnerException;
					if (!(ex is TaskCanceledException))
						LoggingService.LogWarning ("Exception while getting shared AST resolver.", ex);
					return null;
				}
				return t.Result;
			}, TaskContinuationOptions.ExecuteSynchronously);

			document.AddAnnotation (new ResolverAnnotation {
				Task = wrapper,
				ParsedFile = parsedFile,
				SharedTokenSource = tokenSource
			});

			return wrapper;
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:65,代码来源:ExtensionMethods.cs

示例6: 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

示例7: Run

		public void Run()
		{
			using (new Timer("Finding referenced entities... ")) {
				foreach (var file in solution.AllFiles) {
					var navigator = new FindReferencedEntities(
						delegate (AstNode node, IEntity entity) {
							if (node == null)
								throw new ArgumentNullException("node");
							if (entity == null)
								throw new ArgumentNullException("entity");
							
							if (!IgnoreEntity(entity)) {
								HashSet<AstNode> list;
								if (!referenceDict.TryGetValue(entity, out list)) {
									list = new HashSet<AstNode>();
									referenceDict.Add(entity, list);
								}
								list.Add(node);
							}
						}
					);
					var resolver = new CSharpAstResolver(file.Project.Compilation, file.CompilationUnit, file.ParsedFile);
					resolver.ApplyNavigator(navigator);
				}
			}
			Console.WriteLine("For each entity, find all references...");
			Stopwatch w = Stopwatch.StartNew();
			foreach (var project in solution.Projects) {
				foreach (var type in project.Compilation.MainAssembly.GetAllTypeDefinitions()) {
					TestFindReferences(type);
					foreach (IMember m in type.Members) {
						TestFindReferences(m);
					}
					Console.Write('.');
				}
			}
			w.Stop();
			Console.WriteLine("FindReferencesConsistencyCheck is done ({0}).", w.Elapsed);
			PrintTimingsPerEntityType();
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:40,代码来源:FindReferencesConsistencyCheck.cs

示例8: FindSemanticErrors

 public SemanticErrorsResponse FindSemanticErrors(Request request)
 {
     var clientFilename = request.FileName.ApplyPathReplacementsForClient();
     var project = _solution.ProjectContainingFile(request.FileName);
     project.UpdateFile(request.FileName, request.Buffer);
     var solutionSnapshot = new DefaultSolutionSnapshot(_solution.Projects.Select(i => i.ProjectContent));
     var syntaxTree = new CSharpParser().Parse(request.Buffer, request.FileName);
     var resolver = new CSharpAstResolver(solutionSnapshot.GetCompilation(project.ProjectContent), syntaxTree);
     var navigator = new SemanticErrorsNavigator();
     resolver.ApplyNavigator(navigator);
     var errors = navigator.GetErrors().Select(i => new Error
     {
         FileName = clientFilename,
         Message = i.Message,
         Line = i.TextLocation.Line,
         Column = i.TextLocation.Column,
     });
     return new SemanticErrorsResponse
     {
         Errors = errors,
     };
 }
开发者ID:gamwang,项目名称:vimrc,代码行数:22,代码来源:SemanticErrorsHandler.cs

示例9: GetItem

		public TooltipItem GetItem (Mono.TextEditor.TextEditor editor, int offset)
		{
			var doc = IdeApp.Workbench.ActiveDocument;
			if (doc == null || doc.ParsedDocument == null)
				return null;
			var unit = doc.ParsedDocument.GetAst<SyntaxTree> ();
			if (unit == null)
				return null;

			var file = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile;
			if (file == null)
				return null;
			
			ResolveResult result;
			AstNode node;
			var loc = editor.OffsetToLocation (offset);
			if (!doc.TryResolveAt (loc, out result, out node))
				return null;
			var resolver = new CSharpAstResolver (doc.Compilation, unit, file);
			resolver.ApplyNavigator (new NodeListResolveVisitorNavigator (node), CancellationToken.None);

			int startOffset = offset;
			int endOffset = offset;
			return new TooltipItem (new ToolTipData (unit, result, node, resolver), startOffset, endOffset - startOffset);
		}
开发者ID:kthguru,项目名称:monodevelop,代码行数:25,代码来源:LanguageItemTooltipProvider.cs

示例10: Resolve

		public static ResolveResult Resolve(Func<ICompilation> compilation, CSharpParsedFile parsedFile, CompilationUnit cu, TextLocation location, out AstNode node,
		                                    CancellationToken cancellationToken = default(CancellationToken))
		{
			node = cu.GetNodeAt(location);
			if (node == null)
				return null;
			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) {
				// we also need to resolve the invocation
				parentInvocation = node.Parent as InvocationExpression;
			}
			
			CSharpAstResolver resolver = new CSharpAstResolver(compilation(), cu, parsedFile);
			resolver.ApplyNavigator(new NodeListResolveVisitorNavigator(node), cancellationToken);
			ResolveResult rr = resolver.Resolve(node, cancellationToken);
			if (rr is MethodGroupResolveResult && parentInvocation != null)
				return resolver.Resolve(parentInvocation);
			else
				return rr;
		}
开发者ID:dodev,项目名称:monodevelop,代码行数:55,代码来源:ResolveAtLocation.cs

示例11: FindReferencesInFile

        /// <summary>
        /// Finds all references in the given file.
        /// </summary>
        /// <param name="searchScopes">The search scopes for which to look.</param>
        /// <param name="unresolvedFile">The type system representation of the file being searched.</param>
        /// <param name="syntaxTree">The syntax tree of the file being searched.</param>
        /// <param name="compilation">The compilation for the project that contains the file.</param>
        /// <param name="callback">Callback used to report the references that were found.</param>
        /// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
        public void FindReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree,
		                                 ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
        {
            if (searchScopes == null)
                throw new ArgumentNullException("searchScopes");
            if (syntaxTree == null)
                throw new ArgumentNullException("syntaxTree");
            if (compilation == null)
                throw new ArgumentNullException("compilation");
            if (callback == null)
                throw new ArgumentNullException("callback");

            if (searchScopes.Count == 0)
                return;
            var navigators = new IResolveVisitorNavigator[searchScopes.Count];
            for (int i = 0; i < navigators.Length; i++) {
                navigators[i] = searchScopes[i].GetNavigator(compilation, callback);
            }
            IResolveVisitorNavigator combinedNavigator;
            if (searchScopes.Count == 1) {
                combinedNavigator = navigators[0];
            } else {
                combinedNavigator = new CompositeResolveVisitorNavigator(navigators);
            }

            cancellationToken.ThrowIfCancellationRequested();
            combinedNavigator = new DetectSkippableNodesNavigator(combinedNavigator, syntaxTree);
            cancellationToken.ThrowIfCancellationRequested();
            CSharpAstResolver resolver = new CSharpAstResolver(compilation, syntaxTree, unresolvedFile);
            resolver.ApplyNavigator(combinedNavigator, cancellationToken);
            foreach (var n in navigators) {
                var frn = n as FindReferenceNavigator;
                if (frn != null)
                    frn.NavigatorDone(resolver, cancellationToken);
            }
        }
开发者ID:artifexor,项目名称:NRefactory,代码行数:45,代码来源:FindReferences.cs

示例12: GetLanguageItem

		public ResolveResult GetLanguageItem (MonoDevelop.Ide.Gui.Document doc, int offset, string expression)
		{
			if (offset < 0) {
				return null;
			}

			var parsedDocument = doc.ParsedDocument;
			if (parsedDocument == null)
				return null;
			var data = doc.Editor;
			var loc = data.OffsetToLocation (offset);

			var unit = parsedDocument.GetAst<CompilationUnit> ();
			var parsedFile = parsedDocument.ParsedFile as CSharpParsedFile;
			
			if (unit == null || parsedFile == null) {
				return null;
			}
			var node = unit.GetNodeAt (loc);
			if (node == null) {
				return null;
			}
			
			var resolver = new CSharpAstResolver (doc.Compilation, unit, parsedFile);
			resolver.ApplyNavigator (new NodeListResolveVisitorNavigator (node), CancellationToken.None);
			var state = resolver.GetResolverStateBefore (node, CancellationToken.None);
			return state.LookupSimpleNameOrTypeName (expression, new List<IType> (), NameLookupMode.Expression);
		}
开发者ID:vac0,项目名称:monodevelop,代码行数:28,代码来源:TextEditorResolverProvider.cs

示例13: AnalyzeFile

		void AnalyzeFile (JobSlice item, IEnumerable<BaseCodeIssueProvider> codeIssueProviders)
		{
			var file = item.File;

			if (file.BuildAction != BuildAction.Compile)
				return;

			if (!(file.Project is DotNetProject))
				return;

			TextEditorData editor;
			try {
				editor = TextFileProvider.Instance.GetReadOnlyTextEditorData (file.FilePath);
			} catch (FileNotFoundException) {
				// Swallow exception and ignore this file
				return;
			}
			var document = TypeSystemService.ParseFile (file.Project, editor);
			if (document == null)
				return;

			var content = TypeSystemService.GetProjectContext (file.Project);
			var compilation = content.AddOrUpdateFiles (document.ParsedFile).CreateCompilation ();

			CSharpAstResolver resolver;
			using (var timer = ExtensionMethods.ResolveCounter.BeginTiming ()) {
				resolver = new CSharpAstResolver (compilation, document.GetAst<SyntaxTree> (), document.ParsedFile as ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpUnresolvedFile);
				try {
					resolver.ApplyNavigator (new ExtensionMethods.ConstantModeResolveVisitorNavigator (ResolveVisitorNavigationMode.Resolve, null));
				} catch (Exception e) {
					LoggingService.LogError ("Error while applying navigator", e);
				}
			}
			var context = document.CreateRefactoringContextWithEditor (editor, resolver, CancellationToken.None);

			foreach (var provider in codeIssueProviders) {
				if (item.CancellationToken.IsCancellationRequested)
					break;
				IList<IAnalysisJob> jobs;
				lock (_lock)
					jobs = item.GetJobs ().ToList ();
				var jobsForProvider = jobs.Where (j => j.GetIssueProviders (file).Contains (provider)).ToList();
				try {
					var issues = provider.GetIssues (context, CancellationToken.None).ToList ();
					foreach (var job in jobsForProvider) {
						// Call AddResult even if issues.Count == 0, to enable a job implementation to keep
						// track of progress information.
						job.AddResult (file, provider, issues);
					}
				} catch (OperationCanceledException) {
					// The operation was cancelled, no-op as the user-visible parts are
					// handled elsewhere
				} catch (Exception e) {
					foreach (var job in jobsForProvider) {
						job.AddError (file, provider);
					}
				}
			}
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:59,代码来源:CodeAnalysisBatchRunner.cs

示例14: FindReferencesInFile

		/// <summary>
		/// Finds all references in the given file.
		/// </summary>
		/// <param name="searchScopes">The search scopes for which to look.</param>
		/// <param name="parsedFile">The type system representation of the file being searched.</param>
		/// <param name="compilationUnit">The compilation unit of the file being searched.</param>
		/// <param name="compilation">The compilation for the project that contains the file.</param>
		/// <param name="callback">Callback used to report the references that were found.</param>
		/// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
		public void FindReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
		                                 ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
		{
			if (searchScopes == null)
				throw new ArgumentNullException("searchScopes");
			if (parsedFile == null)
				throw new ArgumentNullException("parsedFile");
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			if (callback == null)
				throw new ArgumentNullException("callback");
			
			if (searchScopes.Count == 0)
				return;
			IResolveVisitorNavigator navigator;
			if (searchScopes.Count == 1) {
				navigator = searchScopes[0].GetNavigator(compilation, callback);
			} else {
				IResolveVisitorNavigator[] navigators = new IResolveVisitorNavigator[searchScopes.Count];
				for (int i = 0; i < navigators.Length; i++) {
					navigators[i] = searchScopes[i].GetNavigator(compilation, callback);
				}
				navigator = new CompositeResolveVisitorNavigator(navigators);
			}
			
			cancellationToken.ThrowIfCancellationRequested();
			navigator = new DetectSkippableNodesNavigator(navigator, compilationUnit);
			cancellationToken.ThrowIfCancellationRequested();
			CSharpAstResolver resolver = new CSharpAstResolver(compilation, compilationUnit, parsedFile);
			resolver.ApplyNavigator(navigator, cancellationToken);
		}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:42,代码来源:FindReferences.cs

示例15: GetLanguageItem

		public ResolveResult GetLanguageItem (MonoDevelop.Ide.Gui.Document doc, int offset, string expression)
		{
			if (offset < 0) {
				return null;
			}

			var parsedDocument = doc.ParsedDocument;
			if (parsedDocument == null)
				return null;
			var data = doc.Editor;
			var loc = data.OffsetToLocation (offset);

			var unit = parsedDocument.GetAst<SyntaxTree> ();
			var parsedFile = parsedDocument.ParsedFile as CSharpUnresolvedFile;
			
			if (unit == null || parsedFile == null) {
				return null;
			}
			var node = unit.GetNodeAt (loc);
			if (node == null) {
				return null;
			}
			
			var resolver = new CSharpAstResolver (doc.Compilation, unit, parsedFile);
			resolver.ApplyNavigator (new NodeListResolveVisitorNavigator (node), CancellationToken.None);
			var state = resolver.GetResolverStateBefore (node, CancellationToken.None);

			var list = new List<IType> ();
			int indexOf = expression.IndexOf ('`');
			if (indexOf != -1) {
				var intType = new PrimitiveType ("int").ToTypeReference ().Resolve (doc.Compilation);
				var num = expression.Substring (indexOf + 1);
				int number = int.Parse (num);
				for (int i = 0; i < number; i++)
					list.Add (intType);
				expression = expression.Remove (indexOf);
			}
			return state.LookupSimpleNameOrTypeName (expression, list, NameLookupMode.Expression);
		}
开发者ID:nerzhulart,项目名称:monodevelop,代码行数:39,代码来源:TextEditorResolverProvider.cs


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