Exemplo n.º 1
0
        /// <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;
            }
            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, compilationUnit);
            cancellationToken.ThrowIfCancellationRequested();
            CSharpAstResolver resolver = new CSharpAstResolver(compilation, compilationUnit, parsedFile);

            resolver.ApplyNavigator(combinedNavigator, cancellationToken);
            foreach (var n in navigators)
            {
                var frn = n as FindReferenceNavigator;
                if (frn != null)
                {
                    frn.NavigatorDone(resolver, cancellationToken);
                }
            }
        }
Exemplo n.º 2
0
 /// <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="context">The type resolve context to use for resolving the file.</param>
 /// <param name="callback">Callback used to report the references that were found.</param>
 public void FindReferencesInFile(IList <IFindReferenceSearchScope> searchScopes, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
                                  ITypeResolveContext context, FoundReferenceCallback callback)
 {
     if (searchScopes == null)
     {
         throw new ArgumentNullException("searchScopes");
     }
     if (parsedFile == null)
     {
         throw new ArgumentNullException("parsedFile");
     }
     if (compilationUnit == null)
     {
         throw new ArgumentNullException("compilationUnit");
     }
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     this.CancellationToken.ThrowIfCancellationRequested();
     if (searchScopes.Count == 0)
     {
         return;
     }
     using (var ctx = context.Synchronize()) {
         IResolveVisitorNavigator navigator;
         if (searchScopes.Count == 1)
         {
             navigator = searchScopes[0].GetNavigator(callback);
         }
         else
         {
             navigator = new CompositeResolveVisitorNavigator(searchScopes.Select(s => s.GetNavigator(callback)).ToArray());
         }
         navigator = new DetectSkippableNodesNavigator(navigator, compilationUnit);
         CSharpResolver resolver = new CSharpResolver(ctx, this.CancellationToken);
         ResolveVisitor v        = new ResolveVisitor(resolver, parsedFile, navigator);
         v.Scan(compilationUnit);
     }
 }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
		void FindReferencesButtonClick(object sender, EventArgs e)
		{
			if (csharpTreeView.SelectedNode == null)
				return;
			
			SimpleProjectContent project = new SimpleProjectContent();
			var parsedFile = new TypeSystemConvertVisitor(project, "dummy.cs").Convert(compilationUnit);
			project.UpdateProjectContent(null, parsedFile);
			
			List<ITypeResolveContext> projects = new List<ITypeResolveContext>();
			projects.Add(project);
			projects.AddRange(builtInLibs.Value);
			
			using (var context = new CompositeTypeResolveContext(projects).Synchronize()) {
				CSharpResolver resolver = new CSharpResolver(context);
				
				AstNode node = (AstNode)csharpTreeView.SelectedNode.Tag;
				IResolveVisitorNavigator navigator = new NodeListResolveVisitorNavigator(new[] { node });
				ResolveVisitor visitor = new ResolveVisitor(resolver, parsedFile, navigator);
				visitor.Scan(compilationUnit);
				IEntity entity;
				MemberResolveResult mrr = visitor.GetResolveResult(node) as MemberResolveResult;
				TypeResolveResult trr = visitor.GetResolveResult(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) {
					referenceCount++;
				};
				
				var searchScopes = fr.GetSearchScopes(entity);
				navigator = new CompositeResolveVisitorNavigator(searchScopes.Select(s => s.GetNavigator(callback)).ToArray());
				visitor = new ResolveVisitor(resolver, parsedFile, navigator);
				visitor.Scan(compilationUnit);
				
				csharpTreeView.BeginUpdate();
				ShowResolveResultsInTree(csharpTreeView.Nodes, visitor);
				csharpTreeView.EndUpdate();
				
				MessageBox.Show("Found " + referenceCount + " references to " + entity.FullName);
			}
		}
		IResolveVisitorNavigator InitNavigator(ICompilation compilation)
		{
			if (currentSymbolReference == null || compilation == null)
				return null;
			var symbol = currentSymbolReference.Resolve(compilation.TypeResolveContext);
			FindReferences findReferences = new FindReferences();
			if (symbol == null) return null;
			var searchScopes = findReferences.GetSearchScopes(symbol);
			if (searchScopes.Count == 0)
				return null;
			var navigators = new IResolveVisitorNavigator[searchScopes.Count];
			for (int i = 0; i < navigators.Length; i++) {
				navigators[i] = searchScopes[i].GetNavigator(compilation, ColorizeMatch);
			}
			IResolveVisitorNavigator combinedNavigator;
			if (searchScopes.Count == 1) {
				combinedNavigator = navigators[0];
			}
			else {
				combinedNavigator = new CompositeResolveVisitorNavigator(navigators);
			}
			return combinedNavigator;
		}
Exemplo n.º 6
0
		/// <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);
		}
Exemplo n.º 7
0
		/// <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="context">The type resolve context to use for resolving the file.</param>
		/// <param name="callback">Callback used to report the references that were found.</param>
		public void FindReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
		                                 ITypeResolveContext context, FoundReferenceCallback callback)
		{
			if (searchScopes == null)
				throw new ArgumentNullException("searchScopes");
			if (parsedFile == null)
				throw new ArgumentNullException("parsedFile");
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			if (context == null)
				throw new ArgumentNullException("context");
			this.CancellationToken.ThrowIfCancellationRequested();
			if (searchScopes.Count == 0)
				return;
			using (var ctx = context.Synchronize()) {
				IResolveVisitorNavigator navigator;
				if (searchScopes.Count == 1)
					navigator = searchScopes[0].GetNavigator(callback);
				else
					navigator = new CompositeResolveVisitorNavigator(searchScopes.Select(s => s.GetNavigator(callback)).ToArray());
				navigator = new DetectSkippableNodesNavigator(navigator, compilationUnit);
				CSharpResolver resolver = new CSharpResolver(ctx, this.CancellationToken);
				ResolveVisitor v = new ResolveVisitor(resolver, parsedFile, navigator);
				v.Scan(compilationUnit);
			}
		}