Ejemplo n.º 1
0
        private bool IsHandlerExists(Lifetime lifetime, int projectId, string className, string methodName)
        {
            var indicator = NullProgressIndicator.CreateCancellable(lifetime);

            using (TryReadLockCookie.Create(indicator, _locks,
                                            () => !lifetime.IsAlive || _locks.ContentModelLocks.IsWriteLockRequested))
            {
                var project = _projectModelViewHost.GetItemById <IProject>(projectId);
                Assertion.AssertNotNull(project, "project instance should not be null");
                _logger.Verbose($"Searching handler with name '{className}.{methodName}' in the project {project}...");

                var psiModules = project.GetPsiModules();
                foreach (var psiModule in psiModules)
                {
                    using (CompilationContextCookie.OverrideOrCreate(psiModule.GetContextFromModule()))
                    {
                        var scope = _symbolCache.GetSymbolScope(psiModule, false, true);

                        var typeElements = scope.GetElementsByQualifiedName(className).OfType <IClass>();
                        foreach (var typeElement in typeElements)
                        {
                            InterruptableActivityCookie.CheckAndThrow(indicator);
                            foreach (var method in typeElement.Methods)
                            {
                                if (method.ShortName != methodName)
                                {
                                    continue;
                                }
                                if (!LambdaFinder.IsSuitableLambdaMethod(method))
                                {
                                    continue;
                                }

                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }