private void ProcessBindingsFromProjectItem(ProjectItem projectItem, IdeBindingSourceProcessor bindingSourceProcessor, List <ProjectItem> relatedProjectItems)
        {
            foreach (CodeClass codeClass in VsxHelper.GetClasses(projectItem))
            {
                CodeClass2 bindingClassIncludingParts = codeClass as CodeClass2;

                var parts = new List <CodeClass>();

                if (bindingClassIncludingParts == null)
                {
                    parts.Add(codeClass);
                }
                else
                {
                    parts.AddRange(bindingClassIncludingParts.Parts.OfType <CodeClass>());
                }


                var baseClass = GetBaseClass(codeClass);

                while (baseClass != null)
                {
                    tracer.Trace("Adding inherited bindings for class: " + baseClass.FullName, GetType().Name);
                    parts.Add(baseClass);
                    baseClass = GetBaseClass(baseClass);
                }

                // we need to use the class parts to grab class-related information (e.g. [Binding] attribute)
                // but we need to process the binding methods only from the current part, otherwise these
                // methods would be registered to multiple file paths, and the update tracking would not work

                relatedProjectItems.AddRange(parts.Select(SafeGetProjectItem).Where(pi => pi != null && pi != projectItem));
                ProcessCodeClass(codeClass, bindingSourceProcessor, parts.ToArray());
            }
        }
Example #2
0
        private void ProcessCodeClass(CodeClass codeClass, IdeBindingSourceProcessor bindingSourceProcessor)
        {
            var filteredAttributes = codeClass.Attributes.Cast <CodeAttribute2>().Where(attr => bindingSourceProcessor.CanProcessTypeAttribute(attr.FullName)).ToArray();

            if (!bindingSourceProcessor.PreFilterType(filteredAttributes.Select(attr => attr.FullName)))
            {
                return;
            }

            var bindingSourceType = bindingReflectionFactory.CreateBindingSourceType(codeClass, filteredAttributes);

            if (!bindingSourceProcessor.ProcessType(bindingSourceType))
            {
                return;
            }

            foreach (var codeFunction in codeClass.Children.OfType <CodeFunction>())
            {
                var bindingSourceMethod = CreateBindingSourceMethod(codeFunction, bindingSourceType, bindingSourceProcessor);
                if (bindingSourceMethod != null)
                {
                    bindingSourceProcessor.ProcessMethod(bindingSourceMethod);
                }
            }

            bindingSourceProcessor.ProcessTypeDone();
        }
Example #3
0
        public IEnumerable <IStepDefinitionBinding> GetBindingsFromProjectItem(ProjectItem projectItem)
        {
            var bindingProcessor = new IdeBindingSourceProcessor();

            ProcessBindingsFromProjectItem(projectItem, bindingProcessor);
            return(bindingProcessor.ReadStepDefinitionBindings());
        }
        public IEnumerable <IStepDefinitionBinding> GetBindingsFromProjectItem(ProjectItem projectItem, out List <ProjectItem> relatedProjectItems)
        {
            var bindingProcessor = new IdeBindingSourceProcessor(tracer);

            relatedProjectItems = new List <ProjectItem>();
            ProcessBindingsFromProjectItem(projectItem, bindingProcessor, relatedProjectItems);
            return(bindingProcessor.ReadStepDefinitionBindings());
        }
        private static bool CanProcessTypeAttribute(IdeBindingSourceProcessor bindingSourceProcessor, CodeAttribute2 attr)
        {
            string attributeTypeName;

            try
            {
                attributeTypeName = attr.FullName;
            }
            catch (Exception)
            {
                // invalid attribute - ignore
                return(false);
            }

            return(bindingSourceProcessor.CanProcessTypeAttribute(attributeTypeName));
        }
Example #6
0
 private void ProcessBindingsFromProjectItem(ProjectItem projectItem, IdeBindingSourceProcessor bindingSourceProcessor)
 {
     foreach (CodeClass codeClass in VsxHelper.GetClasses(projectItem))
     {
         CodeClass2 bindingClassIncludingParts = codeClass as CodeClass2;
         if (bindingClassIncludingParts == null)
         {
             ProcessCodeClass(codeClass, bindingSourceProcessor);
         }
         else
         {
             foreach (CodeClass2 partialClassParts in bindingClassIncludingParts.Parts)
             {
                 ProcessCodeClass(partialClassParts, bindingSourceProcessor);
             }
         }
     }
 }
Example #7
0
 private void ProcessBindingsFromProjectItem(ProjectItem projectItem, IdeBindingSourceProcessor bindingSourceProcessor, List <ProjectItem> relatedProjectItems)
 {
     foreach (CodeClass codeClass in VsxHelper.GetClasses(projectItem))
     {
         CodeClass2 bindingClassIncludingParts = codeClass as CodeClass2;
         if (bindingClassIncludingParts == null)
         {
             ProcessCodeClass(codeClass, bindingSourceProcessor, codeClass);
         }
         else
         {
             var parts = bindingClassIncludingParts.Parts.OfType <CodeClass>().ToArray();
             relatedProjectItems.AddRange(parts.Select(p => p.ProjectItem).Where(pi => pi != null && pi != projectItem));
             // we need to use the class parts to grab class-related information (e.g. [Binding] attribute)
             // but we need to process the binding methods only from the current part, otherwise these
             // methods would be registered to multiple file pathes, and the update tracking would not work
             ProcessCodeClass(codeClass, bindingSourceProcessor, parts.ToArray());
         }
     }
 }
Example #8
0
        private void ProcessCodeClass(CodeClass codeClass, IdeBindingSourceProcessor bindingSourceProcessor, params CodeClass[] classParts)
        {
            var filteredAttributes = classParts
                                     .SelectMany(cc => cc.Attributes.Cast <CodeAttribute2>().Where(attr => CanProcessTypeAttribute(bindingSourceProcessor, attr))).ToArray();

            if (!bindingSourceProcessor.PreFilterType(filteredAttributes.Select(attr => attr.FullName)))
            {
                return;
            }

            var bindingSourceType = bindingReflectionFactory.CreateBindingSourceType(classParts, filteredAttributes); //TODO: merge info from parts

            if (!bindingSourceProcessor.ProcessType(bindingSourceType))
            {
                return;
            }

            ProcessCodeFunctions(codeClass, bindingSourceType, bindingSourceProcessor);

            bindingSourceProcessor.ProcessTypeDone();
        }
 private BindingSourceMethod CreateBindingSourceMethod(CodeFunction codeFunction, BindingSourceType bindingSourceType, IdeBindingSourceProcessor bindingSourceProcessor)
 {
     try
     {
         var filteredAttributes = codeFunction.Attributes.Cast <CodeAttribute2>().Where(attr => bindingSourceProcessor.CanProcessTypeAttribute(attr.FullName)).ToArray();
         return(bindingReflectionFactory.CreateBindingSourceMethod(codeFunction, bindingSourceType, filteredAttributes));
     }
     catch (Exception ex)
     {
         tracer.Trace("CreateBindingSourceMethod error: {0}", this, ex);
         return(null);
     }
 }
 private void ProcessCodeFunctions(CodeClass codeClass, BindingSourceType bindingSourceType, IdeBindingSourceProcessor bindingSourceProcessor)
 {
     foreach (var codeFunction in codeClass.Children.OfType <CodeFunction>())
     {
         var bindingSourceMethod = CreateBindingSourceMethod(codeFunction, bindingSourceType, bindingSourceProcessor);
         if (bindingSourceMethod != null)
         {
             bindingSourceProcessor.ProcessMethod(bindingSourceMethod);
         }
     }
 }