public Task FindReferencesAsync(SymbolSearchArgs args, Action <SearchedFile> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            var cancellationToken = args.ProgressMonitor.CancellationToken;

            return(Task.Run(
                       () => {
                for (int i = 0; i < searchScopes.Count; i++)
                {
                    IFindReferenceSearchScope searchScope = searchScopes[i];
                    object progressLock = new object();
                    Parallel.ForEach(
                        interestingFileNames[i],
                        new ParallelOptions {
                        MaxDegreeOfParallelism = Environment.ProcessorCount,
                        CancellationToken = cancellationToken
                    },
                        delegate(string fileName) {
                        try {
                            FindReferencesInFile(args, searchScope, FileName.Create(fileName), callback, cancellationToken);
                        } catch (OperationCanceledException) {
                            throw;
                        } catch (Exception ex) {
                            throw new ApplicationException("Error searching in file '" + fileName + "'", ex);
                        }
                        lock (progressLock)
                            args.ProgressMonitor.Progress += workAmountInverse;
                    });
                }
            }, cancellationToken
                       ));
        }
        public Task RenameAsync(SymbolRenameArgs args, Action <PatchedFile> callback, Action <Error> errorCallback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            var cancellationToken = args.ProgressMonitor.CancellationToken;

            return(Task.Run(
                       () => {
                bool isNameValid = Mono.CSharp.Tokenizer.IsValidIdentifier(args.NewName);
                for (int i = 0; i < searchScopes.Count; i++)
                {
                    IFindReferenceSearchScope searchScope = searchScopes[i];
                    object progressLock = new object();
                    Parallel.ForEach(
                        interestingFileNames[i],
                        new ParallelOptions {
                        MaxDegreeOfParallelism = Environment.ProcessorCount,
                        CancellationToken = cancellationToken
                    },
                        delegate(string fileName) {
                        RenameReferencesInFile(args, searchScope, FileName.Create(fileName), callback, errorCallback, isNameValid, cancellationToken);
                        lock (progressLock)
                            args.ProgressMonitor.Progress += workAmountInverse;
                    });
                }
            }, cancellationToken
                       ));
        }
Exemple #3
0
 /// <summary>
 /// Finds all references in the given file.
 /// </summary>
 /// <param name="searchScope">The search scope 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(IFindReferenceSearchScope searchScope, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
                                  ITypeResolveContext context, FoundReferenceCallback callback)
 {
     if (searchScope == null)
     {
         throw new ArgumentNullException("searchScope");
     }
     FindReferencesInFile(new[] { searchScope }, parsedFile, compilationUnit, context, callback);
 }
Exemple #4
0
 /// <summary>
 /// Finds all references in the given file.
 /// </summary>
 /// <param name="searchScope">The search scope 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(IFindReferenceSearchScope searchScope, CppParsedFile parsedFile, CompilationUnit compilationUnit,
                                  ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
 {
     if (searchScope == null)
     {
         throw new ArgumentNullException("searchScope");
     }
     FindReferencesInFile(new[] { searchScope }, parsedFile, compilationUnit, compilation, callback, cancellationToken);
 }
Exemple #5
0
        /// <summary>
        /// Gets the file names that possibly contain references to the element being searched for.
        /// </summary>
        public IList <string> GetInterestingFileNames(IFindReferenceSearchScope searchScope, IEnumerable <ITypeDefinition> allTypes)
        {
            IEnumerable <ITypeDefinition> interestingTypes;

            if (searchScope.TopLevelTypeDefinition != null)
            {
                switch (searchScope.Accessibility)
                {
                case Accessibility.None:
                case Accessibility.Private:
                    interestingTypes = new [] { searchScope.TopLevelTypeDefinition.GetDefinition() };
                    break;

                case Accessibility.Protected:
                    interestingTypes = GetInterestingTypesProtected(allTypes, searchScope.TopLevelTypeDefinition);
                    break;

                case Accessibility.Internal:
                    interestingTypes = GetInterestingTypesInternal(allTypes, searchScope.TopLevelTypeDefinition.ParentAssembly);
                    break;

                case Accessibility.ProtectedAndInternal:
                    interestingTypes = GetInterestingTypesProtected(allTypes, searchScope.TopLevelTypeDefinition)
                                       .Intersect(GetInterestingTypesInternal(allTypes, searchScope.TopLevelTypeDefinition.ParentAssembly));
                    break;

                case Accessibility.ProtectedOrInternal:
                    interestingTypes = GetInterestingTypesProtected(allTypes, searchScope.TopLevelTypeDefinition)
                                       .Union(GetInterestingTypesInternal(allTypes, searchScope.TopLevelTypeDefinition.ParentAssembly));
                    break;

                default:
                    interestingTypes = allTypes;
                    break;
                }
            }
            else
            {
                interestingTypes = allTypes;
            }
            return((from typeDef in interestingTypes
                    from part in typeDef.Parts
                    where part.ParsedFile != null
                    select part.ParsedFile.FileName
                    ).Distinct(Platform.FileNameComparer).ToList());
        }
 /// <summary>
 /// Gets the file names that possibly contain references to the element being searched for.
 /// </summary>
 public IEnumerable<CSharpUnresolvedFile> GetInterestingFiles(IFindReferenceSearchScope searchScope, ICompilation compilation)
 {
     if (searchScope == null)
         throw new ArgumentNullException("searchScope");
     if (compilation == null)
         throw new ArgumentNullException("compilation");
     var pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
     if (pc == null)
         throw new ArgumentException("Main assembly is not a project content");
     if (searchScope.TopLevelTypeDefinition != null) {
         ITypeDefinition topLevelTypeDef = compilation.Import(searchScope.TopLevelTypeDefinition);
         if (topLevelTypeDef == null) {
             // This compilation cannot have references to the target entity.
             return EmptyList<CSharpUnresolvedFile>.Instance;
         }
         switch (searchScope.Accessibility) {
             case Accessibility.None:
             case Accessibility.Private:
                 if (topLevelTypeDef.ParentAssembly == compilation.MainAssembly)
                     return topLevelTypeDef.Parts.Select(p => p.UnresolvedFile).OfType<CSharpUnresolvedFile>().Distinct();
                 else
                     return EmptyList<CSharpUnresolvedFile>.Instance;
             case Accessibility.Protected:
                 return GetInterestingFilesProtected(topLevelTypeDef);
             case Accessibility.Internal:
                 if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                     return pc.Files.OfType<CSharpUnresolvedFile>();
                 else
                     return EmptyList<CSharpUnresolvedFile>.Instance;
             case Accessibility.ProtectedAndInternal:
                 if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                     return GetInterestingFilesProtected(topLevelTypeDef);
                 else
                     return EmptyList<CSharpUnresolvedFile>.Instance;
             case Accessibility.ProtectedOrInternal:
                 if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                     return pc.Files.OfType<CSharpUnresolvedFile>();
                 else
                     return GetInterestingFilesProtected(topLevelTypeDef);
             default:
                 return pc.Files.OfType<CSharpUnresolvedFile>();
         }
     } else {
         return pc.Files.OfType<CSharpUnresolvedFile>();
     }
 }
        /// <summary>
        /// Finds all references in the given file.
        /// </summary>
        /// <param name="searchScope">The search scope 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(IFindReferenceSearchScope searchScope, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree,
		                                 ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
        {
            if (searchScope == null)
                throw new ArgumentNullException("searchScope");
            FindReferencesInFile(new[] { searchScope }, unresolvedFile, syntaxTree, compilation, callback, cancellationToken);
        }
        void RenameReferencesInFile(SymbolRenameArgs args, IFindReferenceSearchScope searchScope, FileName fileName, Action <PatchedFile> callback, Action <Error> errorCallback, bool isNameValid, CancellationToken cancellationToken)
        {
            ITextSource textSource = args.ParseableFileContentFinder.Create(fileName);

            if (textSource == null)
            {
                return;
            }
            if (searchScope.SearchTerm != null)
            {
                if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0)
                {
                    return;
                }
            }

            var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation;

            if (parseInfo == null)
            {
                return;
            }
            ReadOnlyDocument         document    = null;
            IHighlighter             highlighter = null;
            List <RenameResultMatch> results     = new List <RenameResultMatch>();

            // Grab the unresolved file matching the compilation version
            // (this may differ from the version created by re-parsing the project)
            CSharpUnresolvedFile unresolvedFile = null;
            IProjectContent      pc             = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;

            if (pc != null)
            {
                unresolvedFile = pc.GetFile(fileName) as CSharpUnresolvedFile;
            }

            CSharpAstResolver resolver = new CSharpAstResolver(compilation, parseInfo.SyntaxTree, unresolvedFile);

            fr.RenameReferencesInFile(
                new[] { searchScope }, args.NewName, resolver,
                delegate(RenameCallbackArguments callbackArgs) {
                var node       = callbackArgs.NodeToReplace;
                string newCode = callbackArgs.NewNode.ToString();
                if (document == null)
                {
                    document = new ReadOnlyDocument(textSource, fileName);

                    if (args.ProvideHighlightedLine)
                    {
                        highlighter = SD.EditorControlService.CreateHighlighter(document);
                        highlighter.BeginHighlighting();
                    }
                }
                var startLocation = node.StartLocation;
                var endLocation   = node.EndLocation;
                int offset        = document.GetOffset(startLocation);
                int length        = document.GetOffset(endLocation) - offset;
                if (args.ProvideHighlightedLine)
                {
                    var builder          = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
                    var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
                    results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode, builder, defaultTextColor));
                }
                else
                {
                    results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode));
                }
            },
                errorCallback, cancellationToken);
            if (highlighter != null)
            {
                highlighter.Dispose();
            }
            if (results.Count > 0)
            {
                if (!isNameValid)
                {
                    errorCallback(new Error(ErrorType.Error, string.Format("The name '{0}' is not valid in the current context!", args.NewName),
                                            new DomRegion(fileName, results[0].StartLocation)));
                    return;
                }
                IDocument changedDocument = new TextDocument(document);
                var       oldVersion      = changedDocument.Version;
                foreach (var result in results.OrderByDescending(m => m.StartOffset))
                {
                    changedDocument.Replace(result.StartOffset, result.Length, result.NewCode);
                }
                callback(new PatchedFile(fileName, results, oldVersion, changedDocument.Version));
            }
        }
        void FindReferencesInFile(SymbolSearchArgs args, IFindReferenceSearchScope searchScope, FileName fileName, Action <SearchedFile> callback, CancellationToken cancellationToken)
        {
            ITextSource textSource = args.ParseableFileContentFinder.Create(fileName);

            if (textSource == null)
            {
                return;
            }
            if (searchScope.SearchTerm != null)
            {
                if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0)
                {
                    return;
                }
            }

            var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation;

            if (parseInfo == null)
            {
                return;
            }
            ReadOnlyDocument         document    = null;
            IHighlighter             highlighter = null;
            List <SearchResultMatch> results     = new List <SearchResultMatch>();

            // Grab the unresolved file matching the compilation version
            // (this may differ from the version created by re-parsing the project)
            CSharpUnresolvedFile unresolvedFile = null;
            IProjectContent      pc             = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;

            if (pc != null)
            {
                unresolvedFile = pc.GetFile(fileName) as CSharpUnresolvedFile;
            }

            fr.FindReferencesInFile(
                searchScope, unresolvedFile, parseInfo.SyntaxTree, compilation,
                delegate(AstNode node, ResolveResult result) {
                if (document == null)
                {
                    document    = new ReadOnlyDocument(textSource, fileName);
                    highlighter = SD.EditorControlService.CreateHighlighter(document);
                    highlighter.BeginHighlighting();
                }
                Identifier identifier = node.GetChildByRole(Roles.Identifier);
                if (!identifier.IsNull)
                {
                    node = identifier;
                }
                var region           = new DomRegion(fileName, node.StartLocation, node.EndLocation);
                int offset           = document.GetOffset(node.StartLocation);
                int length           = document.GetOffset(node.EndLocation) - offset;
                var builder          = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
                var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
                results.Add(new SearchResultMatch(fileName, node.StartLocation, node.EndLocation, offset, length, builder, defaultTextColor));
            }, cancellationToken);
            if (highlighter != null)
            {
                highlighter.Dispose();
            }
            if (results.Count > 0)
            {
                callback(new SearchedFile(fileName, results));
            }
        }
		void FindReferencesInFile(SymbolSearchArgs args, IFindReferenceSearchScope searchScope, FileName fileName, Action<SearchedFile> callback, CancellationToken cancellationToken)
		{
			ITextSource textSource = args.ParseableFileContentFinder.Create(fileName);
			if (textSource == null)
				return;
			if (searchScope.SearchTerm != null) {
				if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0)
					return;
			}
			
			var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation;
			if (parseInfo == null)
				return;
			ReadOnlyDocument document = null;
			IHighlighter highlighter = null;
			List<SearchResultMatch> results = new List<SearchResultMatch>();
			
			// Grab the unresolved file matching the compilation version
			// (this may differ from the version created by re-parsing the project)
			CSharpUnresolvedFile unresolvedFile = null;
			IProjectContent pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
			if (pc != null) {
				unresolvedFile = pc.GetFile(fileName) as CSharpUnresolvedFile;
			}
			
			fr.FindReferencesInFile(
				searchScope, unresolvedFile, parseInfo.SyntaxTree, compilation,
				delegate (AstNode node, ResolveResult result) {
					if (document == null) {
						document = new ReadOnlyDocument(textSource, fileName);
						highlighter = SD.EditorControlService.CreateHighlighter(document);
						highlighter.BeginHighlighting();
					}
					Identifier identifier = node.GetChildByRole(Roles.Identifier);
					if (!identifier.IsNull)
						node = identifier;
					var region = new DomRegion(fileName, node.StartLocation, node.EndLocation);
					int offset = document.GetOffset(node.StartLocation);
					int length = document.GetOffset(node.EndLocation) - offset;
					var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
					var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
					results.Add(new SearchResultMatch(fileName, node.StartLocation, node.EndLocation, offset, length, builder, defaultTextColor));
				}, cancellationToken);
			if (highlighter != null) {
				highlighter.Dispose();
			}
			if (results.Count > 0)
				callback(new SearchedFile(fileName, results));
		}
		void RenameReferencesInFile(SymbolRenameArgs args, IFindReferenceSearchScope searchScope, FileName fileName, Action<PatchedFile> callback, Action<Error> errorCallback, bool isNameValid, CancellationToken cancellationToken)
		{
			ITextSource textSource = args.ParseableFileContentFinder.Create(fileName);
			if (textSource == null)
				return;
			if (searchScope.SearchTerm != null) {
				if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0)
					return;
			}
			
			var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation;
			if (parseInfo == null)
				return;
			ReadOnlyDocument document = null;
			IHighlighter highlighter = null;
			List<RenameResultMatch> results = new List<RenameResultMatch>();
			
			// Grab the unresolved file matching the compilation version
			// (this may differ from the version created by re-parsing the project)
			CSharpUnresolvedFile unresolvedFile = null;
			IProjectContent pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
			if (pc != null) {
				unresolvedFile = pc.GetFile(fileName) as CSharpUnresolvedFile;
			}
			
			CSharpAstResolver resolver = new CSharpAstResolver(compilation, parseInfo.SyntaxTree, unresolvedFile);
			
			fr.RenameReferencesInFile(
				new[] { searchScope }, args.NewName, resolver,
				delegate (RenameCallbackArguments callbackArgs) {
					var node = callbackArgs.NodeToReplace;
					string newCode = callbackArgs.NewNode.ToString();
					if (document == null) {
						document = new ReadOnlyDocument(textSource, fileName);
						
						if (args.ProvideHighlightedLine) {
							highlighter = SD.EditorControlService.CreateHighlighter(document);
							highlighter.BeginHighlighting();
						}
					}
					var startLocation = node.StartLocation;
					var endLocation = node.EndLocation;
					int offset = document.GetOffset(startLocation);
					int length = document.GetOffset(endLocation) - offset;
					if (args.ProvideHighlightedLine) {
						var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
						var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
						results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode, builder, defaultTextColor));
					} else {
						results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode));
					}
				},
				errorCallback, cancellationToken);
			if (highlighter != null) {
				highlighter.Dispose();
			}
			if (results.Count > 0) {
				if (!isNameValid) {
					errorCallback(new Error(ErrorType.Error, string.Format("The name '{0}' is not valid in the current context!", args.NewName),
					                        new DomRegion(fileName, results[0].StartLocation)));
					return;
				}
				IDocument changedDocument = new TextDocument(document);
				var oldVersion = changedDocument.Version;
				foreach (var result in results.OrderByDescending(m => m.StartOffset)) {
					changedDocument.Replace(result.StartOffset, result.Length, result.NewCode);
				}
				callback(new PatchedFile(fileName, results, oldVersion, changedDocument.Version));
			}
		}
Exemple #12
0
		/// <summary>
		/// Finds all references in the given file.
		/// </summary>
		/// <param name="searchScope">The search scope 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(IFindReferenceSearchScope searchScope, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
		                                 ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
		{
			if (searchScope == null)
				throw new ArgumentNullException("searchScope");
			FindReferencesInFile(new[] { searchScope }, parsedFile, compilationUnit, compilation, callback, cancellationToken);
		}
Exemple #13
0
        /// <summary>
        /// Gets the file names that possibly contain references to the element being searched for.
        /// </summary>
        public IEnumerable <CppParsedFile> GetInterestingFiles(IFindReferenceSearchScope searchScope, ICompilation compilation)
        {
            if (searchScope == null)
            {
                throw new ArgumentNullException("searchScope");
            }
            if (compilation == null)
            {
                throw new ArgumentNullException("compilation");
            }
            var pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;

            if (pc == null)
            {
                throw new ArgumentException("Main assembly is not a project content");
            }
            if (searchScope.TopLevelTypeDefinition != null)
            {
                ITypeDefinition topLevelTypeDef = compilation.Import(searchScope.TopLevelTypeDefinition);
                if (topLevelTypeDef == null)
                {
                    // This compilation cannot have references to the target entity.
                    return(EmptyList <CppParsedFile> .Instance);
                }
                switch (searchScope.Accessibility)
                {
                case Accessibility.None:
                case Accessibility.Private:
                    if (topLevelTypeDef.ParentAssembly == compilation.MainAssembly)
                    {
                        return(topLevelTypeDef.Parts.Select(p => p.ParsedFile).OfType <CppParsedFile>().Distinct());
                    }
                    else
                    {
                        return(EmptyList <CppParsedFile> .Instance);
                    }

                case Accessibility.Protected:
                    return(GetInterestingFilesProtected(topLevelTypeDef));

                case Accessibility.Internal:
                    if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                    {
                        return(pc.Files.OfType <CppParsedFile>());
                    }
                    else
                    {
                        return(EmptyList <CppParsedFile> .Instance);
                    }

                case Accessibility.ProtectedAndInternal:
                    if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                    {
                        return(GetInterestingFilesProtected(topLevelTypeDef));
                    }
                    else
                    {
                        return(EmptyList <CppParsedFile> .Instance);
                    }

                case Accessibility.ProtectedOrInternal:
                    if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                    {
                        return(pc.Files.OfType <CppParsedFile>());
                    }
                    else
                    {
                        return(GetInterestingFilesProtected(topLevelTypeDef));
                    }

                default:
                    return(pc.Files.OfType <CppParsedFile>());
                }
            }
            else
            {
                return(pc.Files.OfType <CppParsedFile>());
            }
        }
		/// <summary>
		/// Finds all references in the given file.
		/// </summary>
		/// <param name="searchScope">The search scope for which to look.</param>
		/// <param name="resolver">AST resolver for the file to search in.</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(IFindReferenceSearchScope searchScope, CSharpAstResolver resolver,
		                                 FoundReferenceCallback callback, CancellationToken cancellationToken)
		{
			if (resolver == null)
				throw new ArgumentNullException("resolver");
			FindReferencesInFile(searchScope, resolver.UnresolvedFile, (SyntaxTree)resolver.RootNode, resolver.Compilation, callback, cancellationToken);
		}
Exemple #15
0
		/// <summary>
		/// Gets the file names that possibly contain references to the element being searched for.
		/// </summary>
		public IList<string> GetInterestingFileNames(IFindReferenceSearchScope searchScope, IEnumerable<ITypeDefinition> allTypes)
		{
			IEnumerable<ITypeDefinition> interestingTypes;
			if (searchScope.TopLevelTypeDefinition != null) {
				switch (searchScope.Accessibility) {
					case Accessibility.None:
					case Accessibility.Private:
						interestingTypes = new [] { searchScope.TopLevelTypeDefinition.GetDefinition() };
						break;
					case Accessibility.Protected:
						interestingTypes = GetInterestingTypesProtected(allTypes, searchScope.TopLevelTypeDefinition);
						break;
					case Accessibility.Internal:
						interestingTypes = GetInterestingTypesInternal(allTypes, searchScope.TopLevelTypeDefinition.ParentAssembly);
						break;
					case Accessibility.ProtectedAndInternal:
						interestingTypes = GetInterestingTypesProtected(allTypes, searchScope.TopLevelTypeDefinition)
							.Intersect(GetInterestingTypesInternal(allTypes, searchScope.TopLevelTypeDefinition.ParentAssembly));
						break;
					case Accessibility.ProtectedOrInternal:
						interestingTypes = GetInterestingTypesProtected(allTypes, searchScope.TopLevelTypeDefinition)
							.Union(GetInterestingTypesInternal(allTypes, searchScope.TopLevelTypeDefinition.ParentAssembly));
						break;
					default:
						interestingTypes = allTypes;
						break;
				}
			} else {
				interestingTypes = allTypes;
			}
			return (from typeDef in interestingTypes
			        from part in typeDef.Parts
			        where part.ParsedFile != null
			        select part.ParsedFile.FileName
			       ).Distinct(Platform.FileNameComparer).ToList();
		}
Exemple #16
0
		/// <summary>
		/// Finds all references in the given file.
		/// </summary>
		/// <param name="searchScope">The search scope 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(IFindReferenceSearchScope searchScope, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
		                                 ITypeResolveContext context, FoundReferenceCallback callback)
		{
			if (searchScope == null)
				throw new ArgumentNullException("searchScope");
			FindReferencesInFile(new[] { searchScope }, parsedFile, compilationUnit, context, callback);
		}