Example #1
0
        public void Execute(Action <DaemonStageResult> committer)
        {
            IPsiSourceFile sourceFile  = DaemonProcess.SourceFile;
            IPsiServices   psiServices = sourceFile.GetPsiServices();
            ISymbolScope   symbolScope = psiServices.Symbols.GetSymbolScope(LibrarySymbolScope.FULL, false, sourceFile.ResolveContext);

            ITypeElement typeElement = symbolScope.GetTypeElementByCLRName("TestStack.BDDfy.BDDfyExtensions");

            if (typeElement == null)
            {
                return;
            }

            IEnumerable <IMethod> bddfyMethods = typeElement.Methods.Where(method => method.ShortName == "BDDfy" || method.ShortName == "LazyBDDfy");
            ISearchDomain         searchDomain = searchDomainFactory.CreateSearchDomain(sourceFile);

            IReference[] references = bddfyMethods.SelectMany(method => psiServices.Finder.FindReferences(method, searchDomain, NullProgressIndicator.Instance)).ToArray();
            foreach (IReference reference in references)
            {
                var node = reference.GetTreeNode() as ICSharpTreeNode;
                if (node != null)
                {
                    var classDeclaration = node.GetContainingTypeDeclaration() as IClassDeclaration;
                    if (classDeclaration != null)
                    {
                        SetClassAndMembersUsed(classDeclaration);
                    }
                }
            }
        }
Example #2
0
        private IEnumerable <IClrDeclaredElement> FindReferencesWithinAssociatedAssembly(IDataContext context,
                                                                                         ISolution solution, ITextControl textControl, IClrTypeName clrTypeClassName,
                                                                                         IEnumerable <TestCopProjectItem> targetProjects)
        {
            if (clrTypeClassName == null)
            {
                ResharperHelper.AppendLineToOutputWindow(solution.Locks,
                                                         "FindReferencesWithinAssociatedAssembly() - clrTypeClassName was null");
                return(new List <IClrDeclaredElement>());
            }

            IPsiServices services = solution.GetPsiServices();

            ISearchDomain searchDomain;

            if (this.Settings.FindAnyUsageInTestAssembly)
            {
                searchDomain = PsiShared.GetComponent <SearchDomainFactory>().CreateSearchDomain(
                    targetProjects.SelectMany(proj => proj.Project.GetAllProjectFiles().Select(p => p.GetPsiModule())));
            }
            else
            {
                // look for similar named files that also have references to this code
                List <ProjectFileFinder.Match> items = new List <ProjectFileFinder.Match>();

                foreach (TestCopProjectItem projectItem in targetProjects)
                {
                    projectItem.Project.Accept(new ProjectFileFinder(items, projectItem.FilePattern));
                }

                searchDomain = PsiShared.GetComponent <SearchDomainFactory>()
                               .CreateSearchDomain(items.Select(p => p.ProjectFile.ToSourceFile()));
            }

            ISymbolScope declarationsCache = solution.GetPsiServices().Symbols
                                             .GetSymbolScope(LibrarySymbolScope.NONE, false); //, currentProject.GetResolveContext());

            ITypeElement declaredElement = declarationsCache.GetTypeElementByCLRName(clrTypeClassName);

            IReference[] findReferences =
                services.Finder.FindReferences(declaredElement, searchDomain, new ProgressIndicator(textControl.Lifetime));

            List <IClassDeclaration> findReferencesWithinAssociatedAssembly =
                findReferences.Select(p => p.GetTreeNode().GetContainingNode <IClassDeclaration>(true)).ToList();

            return(findReferencesWithinAssociatedAssembly
                   .Select(p => p.DeclaredElement).ToList()
                   .Select(p => p as IClrDeclaredElement).ToList());
        }