Exemplo n.º 1
0
        public override ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            // todo: type abbreviations
            if (declaredElement is IFSharpLocalDeclaration localDeclaration)
            {
                return(mySearchDomainFactory.CreateSearchDomain(localDeclaration.GetSourceFile()));
            }

            if (declaredElement is IFSharpSymbolElement fsSymbolElement)
            {
                var fsSymbol = fsSymbolElement.Symbol;
                if (!(fsSymbol is FSharpActivePatternCase activePatternCase))
                {
                    return(EmptySearchDomain.Instance);
                }

                if (fsSymbolElement is ResolvedFSharpSymbolElement)
                {
                    var patternEntity = activePatternCase.Group.DeclaringEntity?.Value;
                    if (patternEntity != null)
                    {
                        var patternTypeElement = FSharpElementsUtil.GetDeclaredElement(patternEntity, fsSymbolElement.Module);
                        return(patternTypeElement != null
              ? myClrSearchFactory.GetDeclaredElementSearchDomain(patternTypeElement)
              : EmptySearchDomain.Instance);
                    }
                }
            }

            if (declaredElement is TopActivePatternCase activePatternCaseElement)
            {
                var declaration = activePatternCaseElement.GetDeclaration();
                if (declaration?.GetContainingNode <IFSharpLocalDeclaration>() != null)
                {
                    return(mySearchDomainFactory.CreateSearchDomain(declaration.GetSourceFile()));
                }

                var containingMemberDeclaration = declaration?.GetContainingNode <ITypeMemberDeclaration>();
                var containingMember            = containingMemberDeclaration?.DeclaredElement;
                if (containingMember != null)
                {
                    return(myClrSearchFactory.GetDeclaredElementSearchDomain(containingMember));
                }
            }

            if (declaredElement is CompiledActivePatternCase compiledActivePatternCase)
            {
                return(myClrSearchFactory.GetDeclaredElementSearchDomain(compiledActivePatternCase.Origin));
            }

            if (declaredElement is IFSharpAnonRecordFieldProperty fieldProperty)
            {
                return(mySearchDomainFactory.CreateSearchDomain(fieldProperty.Module));
            }

            return(EmptySearchDomain.Instance);
        }
        public ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            HybridCollection <IPsiSourceFile> files = declaredElement.GetSourceFiles();

            if (!(declaredElement is RuleDeclaration))
            {
                if (files.Count > 0)
                {
                    return(mySearchDomainFactory.CreateSearchDomain(files[0]));
                }
            }
            return(mySearchDomainFactory.CreateSearchDomain(declaredElement.GetSolution(), false));
        }
Exemplo n.º 3
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);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void ProcessBehaviorContainer(IDeclaredElement element)
        {
            var solution = element.GetSolution();

            var finder       = solution.GetPsiServices().Finder;
            var searchDomain = _searchDomainFactory.CreateSearchDomain(solution, false);
            var consumer     = new SearchResultsConsumer();
            var progress     = NullProgressIndicator.Create();

            finder.Find(new[] { element }, searchDomain, consumer, SearchPattern.FIND_USAGES, progress);

            var contexts = consumer.GetOccurrences()
                           .OfType <ReferenceOccurrence>()
                           .Select(x => x.GetTypeElement().GetValidDeclaredElement())
                           .OfType <IClass>()
                           .Where(x => x.IsContext());

            foreach (var context in contexts)
            {
                var type        = context.AsTypeInfo();
                var declaration = context.GetDeclarations().FirstOrDefault();

                if (declaration != null)
                {
                    ProcessContext(type, declaration, false);

                    foreach (var field in type.GetFields())
                    {
                        ProcessField(declaration.GetProject(), field);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            if (declaredElement is NitraDeclaredElement)
            {
                return(mySearchDomainFactory.CreateSearchDomain(declaredElement.GetSolution(), false));
            }

            return(EmptySearchDomain.Instance);
        }
Exemplo n.º 6
0
        private void DoSearch(IStructuralMatcher matcher, FindResultConsumer <IStructuralMatchResult> consumer)
        {
#if SDK70
            ISolution solution = Shell.Instance.GetComponent <SolutionsManager>().Solution;
#else
            ISolution solution = Shell.Instance.GetComponent <ISolutionManager>().CurrentSolution;
#endif

            var searchDomain    = searchDomainFactory.CreateSearchDomain(solution, false);
            var documentManager = solution.GetComponent <DocumentManager>();

            // todo add support for VB (eventually)
            var structuralSearcher   = new StructuralSearcher(documentManager, CSharpLanguage.Instance, matcher);
            var searchDomainSearcher = new StructuralSearchDomainSearcher <IStructuralMatchResult>(
                NarrowSearchDomain(solution, matcher.Words, matcher.GetExtendedWords(solution), searchDomain),
                structuralSearcher, consumer, NullProgressIndicator.Instance, true);
            searchDomainSearcher.Run();
        }
Exemplo n.º 7
0
        public ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            if (!(declaredElement is IShaderLabDeclaredElement))
            {
                return(EmptySearchDomain.Instance);
            }

            return(mySearchDomainFactory.CreateSearchDomain(declaredElement.GetSourceFiles()));
        }
 public UnityEditorFindUsageResultCreator(Lifetime lifetime, ISolution solution, SearchDomainFactory searchDomainFactory, IShellLocks locks,
                                          UnitySceneDataLocalCache sceneDataCache, UnityHost unityHost, UnityExternalFilesModuleFactory externalFilesModuleFactory, [CanBeNull] RiderBackgroundTaskHost backgroundTaskHost = null)
 {
     myLifetime = lifetime;
     mySolution = solution;
     myLocks    = locks;
     myUnitySceneDataLocalCache = sceneDataCache;
     myBackgroundTaskHost       = backgroundTaskHost;
     myYamlSearchDomain         = searchDomainFactory.CreateSearchDomain(externalFilesModuleFactory.PsiModule);
     myUnityHost             = unityHost;
     mySolutionDirectoryPath = solution.SolutionDirectory;
 }
Exemplo n.º 9
0
        public IEnumerable <RegistrationInfo> Analyze([NotNull] IPsiSourceFile sourceFile)
        {
            IContainerInfo matchingContainer = GetMatchingContainer(sourceFile);

            if (matchingContainer == null)
            {
                return(EmptyList <RegistrationInfo> .InstanceList);
            }

            ISearchDomain searchDomain = searchDomainFactory.CreateSearchDomain(sourceFile);

            return(ScanRegistrations(matchingContainer, searchDomain));
        }
        public override ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            if (IsInterestingElement(declaredElement))
            {
                var moduleFactory = declaredElement.GetSolution().TryGetComponent <UnityExternalFilesModuleFactory>();
                if (moduleFactory != null)
                {
                    return(mySearchDomainFactory.CreateSearchDomain(moduleFactory.PsiModule));
                }
            }

            return(EmptySearchDomain.Instance);
        }
        private void MarkModulesAsUsed([CanBeNull] CollectUsagesStageProcess usagesStageProcess)
        {
            if (usagesStageProcess != null)
            {
                IEnumerable <IClass> nancyModules = NancyUtil.GetAvailableModules(DaemonProcess.PsiModule,
                                                                                  searchDomainFactory.CreateSearchDomain(DaemonProcess.SourceFile),
                                                                                  DaemonProcess.SourceFile.ResolveContext, true, null).SelectMany(_ => _.Value);

                foreach (IClass @class in nancyModules)
                {
                    InterruptableActivityCookie.CheckAndThrow();
                    collectUsagesStageProcess.SetElementState(@class, UsageState.ACCESSED | UsageState.TYPEOF);
                }
            }
        }
Exemplo n.º 12
0
        public override ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            // todo: type abbreviations
            if (declaredElement is IFSharpLocalDeclaration localDeclaration)
            {
                return(mySearchDomainFactory.CreateSearchDomain(localDeclaration.GetSourceFile()));
            }

            if (declaredElement is TopActivePatternCase activePatternCaseElement)
            {
                var declaration = activePatternCaseElement.GetDeclaration();
                if (declaration?.GetContainingNode <IFSharpLocalDeclaration>() != null)
                {
                    return(mySearchDomainFactory.CreateSearchDomain(declaration.GetSourceFile()));
                }

                var containingMemberDeclaration = declaration?.GetContainingNode <ITypeMemberDeclaration>();
                var containingMember            = containingMemberDeclaration?.DeclaredElement;
                if (containingMember != null)
                {
                    return(myClrSearchFactory.GetDeclaredElementSearchDomain(containingMember));
                }
            }

            if (declaredElement is CompiledActivePatternCase compiledActivePatternCase)
            {
                return(myClrSearchFactory.GetDeclaredElementSearchDomain(compiledActivePatternCase.Origin));
            }

            if (declaredElement is IFSharpAnonRecordFieldProperty fieldProperty)
            {
                return(mySearchDomainFactory.CreateSearchDomain(fieldProperty.Module));
            }

            return(EmptySearchDomain.Instance);
        }
 public UnityEditorFindUsageResultCreator(Lifetime lifetime, ISolution solution, SearchDomainFactory searchDomainFactory, IShellLocks locks,
                                          AssetHierarchyProcessor assetHierarchyProcessor, UnityHost unityHost, UnityExternalFilesModuleFactory externalFilesModuleFactory,
                                          UnityEditorProtocol editorProtocol, IPersistentIndexManager persistentIndexManager,
                                          [CanBeNull] RiderBackgroundTaskHost backgroundTaskHost = null)
 {
     myLifetime = lifetime;
     mySolution = solution;
     myLocks    = locks;
     myAssetHierarchyProcessor = assetHierarchyProcessor;
     myBackgroundTaskHost      = backgroundTaskHost;
     myYamlSearchDomain        = searchDomainFactory.CreateSearchDomain(externalFilesModuleFactory.PsiModule);
     myUnityHost              = unityHost;
     myEditorProtocol         = editorProtocol;
     myPersistentIndexManager = persistentIndexManager;
     mySolutionDirectoryPath  = solution.SolutionDirectory;
 }
        public override ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            // todo: type abbreviations
            if (declaredElement is ILocalDeclaration localDeclaration)
            {
                return(mySearchDomainFactory.CreateSearchDomain(localDeclaration.GetSourceFile()));
            }

            if (declaredElement is IFSharpSymbolElement fsSymbolElement)
            {
                var fsSymbol = fsSymbolElement.Symbol;
                if (!(fsSymbol is FSharpActivePatternCase activePatternCase))
                {
                    return(EmptySearchDomain.Instance);
                }

                if (fsSymbolElement is ResolvedFSharpSymbolElement)
                {
                    var patternEntity = activePatternCase.Group.DeclaringEntity?.Value;
                    if (patternEntity != null)
                    {
                        var patternTypeElement = FSharpElementsUtil.GetDeclaredElement(patternEntity, fsSymbolElement.Module);
                        if (patternTypeElement == null)
                        {
                            return(EmptySearchDomain.Instance);
                        }

                        return(myClrSearchFactory.GetDeclaredElementSearchDomain(patternTypeElement));
                    }
                }

                if (fsSymbolElement is ActivePatternCase activePatternCaseElement)
                {
                    var declaration    = activePatternCaseElement.GetDeclaration();
                    var containingType = ((ITypeDeclaration)declaration?.GetContainingTypeDeclaration())?.DeclaredElement;
                    if (containingType != null)
                    {
                        return(myClrSearchFactory.GetDeclaredElementSearchDomain(containingType));
                    }
                }
            }

            return(EmptySearchDomain.Instance);
        }
Exemplo n.º 15
0
        private IUnitTestElement ProcessAbstractTestClass(IClass testClass)
        {
            var typeInfo = testClass.AsTypeInfo();

            if (!TypeUtility.ContainsTestMethods(typeInfo))
            {
                return(null);
            }

            var solution           = testClass.GetSolution();
            var inheritorsConsumer = new InheritorsConsumer();

            solution.GetPsiServices().Finder.FindInheritors(testClass, searchDomainFactory.CreateSearchDomain(solution, true),
                                                            inheritorsConsumer, NullProgressIndicator.Instance);

            var elements = new List <XunitTestClassElement>();

            foreach (var element in inheritorsConsumer.FoundElements)
            {
                var declaration = element.GetDeclarations().FirstOrDefault();
                if (declaration != null)
                {
                    var elementProject      = declaration.GetProject();
                    var elementAssemblyPath = assemblyPath;
                    if (!Equals(project, elementProject))
                    {
                        elementAssemblyPath = elementProject.GetOutputFilePath().FullPath;
                    }

                    var classElement = unitTestElementFactory.GetOrCreateTestClass(elementProject, element.GetClrName().GetPersistent(), elementAssemblyPath, typeInfo.GetTraits());
                    AppendTests(classElement, typeInfo, element.GetAllSuperTypes());

                    elements.Add(classElement);
                }
            }

            derivedTestClassElements[testClass] = elements;

            return(null);
        }
 public UnityEditorFindUsageResultCreator(Lifetime lifetime, ISolution solution,
                                          SearchDomainFactory searchDomainFactory, IShellLocks locks,
                                          AssetHierarchyProcessor assetHierarchyProcessor,
                                          BackendUnityHost backendUnityHost,
                                          FrontendBackendHost frontendBackendHost,
                                          UnityExternalFilesModuleFactory externalFilesModuleFactory,
                                          IPersistentIndexManager persistentIndexManager,
                                          [NotNull] AnimatorScriptUsagesElementContainer animatorContainer,
                                          [CanBeNull] RiderBackgroundTaskHost backgroundTaskHost = null)
 {
     myLifetime = lifetime;
     mySolution = solution;
     myLocks    = locks;
     myAssetHierarchyProcessor = assetHierarchyProcessor;
     myBackendUnityHost        = backendUnityHost;
     myBackgroundTaskHost      = backgroundTaskHost;
     myYamlSearchDomain        = searchDomainFactory.CreateSearchDomain(externalFilesModuleFactory.PsiModule);
     myFrontendBackendHost     = frontendBackendHost;
     myAnimatorContainer       = animatorContainer;
     myPersistentIndexManager  = persistentIndexManager;
     mySolutionDirectoryPath   = solution.SolutionDirectory;
 }
        public override ISearchDomain GetSearchDomain(SearchDomainFactory factory)
        {
            var solution = SourceFile.GetSolution();

            return(factory.CreateSearchDomain(solution, false));
        }
 public ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
 {
     return(_searchDomainFactory.CreateSearchDomain(declaredElement.GetPsiServices().Solution, false));
 }
Exemplo n.º 19
0
        public IEnumerable <RegistrationInfo> Analyze()
        {
            ISearchDomain searchDomain = searchDomainFactory.CreateSearchDomain(solution, false);

            return(knownContainers.SelectMany(info => ScanRegistrations(info, searchDomain)));
        }
Exemplo n.º 20
0
        /// <summary>
        /// This code changes PSI documents. It is executed usder PSI transaction, Command cookies, Reentrancy guard ets.
        /// All documents are committed (PSI is valid).
        /// </summary>
        public override bool Execute(IProgressIndicator pi)
        {
            pi.Start(6);

            //check if data stored in workflow is valid...
            Method    = Workflow.MethodPointer.FindDeclaredElement();
            Parameter = Workflow.ParameterPointer.FindDeclaredElement();

            if (Method == null || Parameter == null)
            {
                return(false);
            }

            IPsiServices services = Parameter.GetPsiServices();

            IReference[] referencesToParameter;
            IReference[] referencesToRootOverrides;

            // search for method overrides (OverridesFinder is util class that
            // allows to find all overrides and problems with quasi implementations)
            OverridesFinder overridesFinder = OverridesFinder.CreateInstance(Method);

            using (var subPi = new SubProgressIndicator(pi, 1))
                overridesFinder.Find(subPi);

            JetHashSet <HierarchyMember> hierarchyMembers = overridesFinder.Overrides;

            List <IMethod>    methods    = ScanHierarchyConflicts(hierarchyMembers).ToList();
            List <IParameter> parameters = GetAllParameters(methods).ToList();

            // find parameters and methods usages...
            using (var subPi = new SubProgressIndicator(pi, 1))
            {
                subPi.TaskName = "Searching parameter usages:";
                IEnumerable <IPsiSourceFile> projectFiles = from param in parameters
                                                            let projectFilesOfOneParameter = param.GetSourceFiles()
                                                                                             from projectFile in projectFilesOfOneParameter
                                                                                             select projectFile;
                ISearchDomain searchDomain = mySearchDomainFactory.CreateSearchDomain(projectFiles.ToList());
                referencesToParameter = services.Finder.FindReferences(parameters, searchDomain, subPi);
            }

            using (var subPi = new SubProgressIndicator(pi, 1))
            {
                subPi.TaskName            = "Searching method usages:";
                referencesToRootOverrides = services.Finder.FindReferences(methods,
                                                                           mySearchDomainFactory.CreateSearchDomain(Solution,
                                                                                                                    false), subPi);
            }

            // this step processes method usages, removes argument and stores reference specific data to the 'MethodInvocation'.
            List <MethodInvocation> usages;

            using (var subPi = new SubProgressIndicator(pi, 1))
                usages = PreProcessMethodUsages(referencesToRootOverrides, subPi).ToList();

            // replace usages of parameters with typeof(TNewTypeParameter) expression.
            using (var subPi = new SubProgressIndicator(pi, 1))
                ProcessParameterUsages(referencesToParameter, subPi);

            // Remove parameters from method declarations and insert new type parmeter. Map contains method -> new type parameter relation.
            Dictionary <IMethod, ITypeParameter> map = UpdateDeclarations(methods);

            // We have changed declarations. cashes should be updated)
            PsiManager.GetInstance(Solution).UpdateCaches();

            // Process method usages one more time to insert correct type arguments to the call.
            using (var subPi = new SubProgressIndicator(pi, 1))
                BindUsages(usages, map, subPi);

            return(true);
        }