Example #1
0
        public IEnumerable <AvailableBindingClass> GetBindingTypes(IPsiModule module)
        {
            foreach (var(fullClassName, sourceFile) in _mergeData.SpecflowBindingTypes.SelectMany(e => e.Value.Select(v => (fullClassName: e.Key, sourceFile: v))))
            {
                if (!module.Equals(sourceFile.PsiModule) && !module.References(sourceFile.PsiModule))
                {
                    continue;
                }
                yield return(new AvailableBindingClass(sourceFile, fullClassName));
            }

            // Since we cannot know when cache are built if a partial class in a given file has an attribute or not.
            // This is due to the fact that `DeclaredElement` are resolved using cache and we cannot depends ond cache when building a cache.
            // The check need to be done at this time.
            foreach (var(fullClassName, sourceFile) in _mergeData.PotentialSpecflowBindingTypes.SelectMany(e => e.Value.Select(v => (fullClassName: e.Key, sourceFile: v))))
            {
                if (!module.Equals(sourceFile.PsiModule) && !module.References(sourceFile.PsiModule))
                {
                    continue;
                }
                var type = CSharpTypeFactory.CreateType(fullClassName, sourceFile.PsiModule);
                if (!(type is DeclaredTypeFromCLRName declaredTypeFromClrName))
                {
                    continue;
                }
                var resolveResult = declaredTypeFromClrName.Resolve();
                if (!resolveResult.IsValid())
                {
                    continue;
                }
                if (!(resolveResult.DeclaredElement is IClass @class))
                {
                    continue;
                }
                if (@class.GetAttributeInstances(AttributesSource.Self).All(x => x.GetAttributeType().GetClrName().FullName != "TechTalk.SpecFlow.BindingAttribute"))
                {
                    continue;
                }
                yield return(new AvailableBindingClass(sourceFile, fullClassName));
            }
        }