<commit_before>using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Autodesk.Revit.UI;

namespace RevitLookup.Snoop.CollectorExts
{
    public class ElementMethodsStream : IElementStream
    {
        private readonly UIApplication application;
        private readonly ArrayList data;
        private readonly object elem;
        private readonly List<string> seenMethods = new List<string>();

        public ElementMethodsStream(UIApplication application, ArrayList data, object elem)
        {
            this.application = application;
            this.data = data;
            this.elem = elem;
        }

        public void Stream(Type type)
        {
            var methods = GetElementMethods(type);

            if (methods.Length > 0) data.Add(new Snoop.Data.MemberSeparatorWithOffset("Methods"));

            var currentTypeMethods = new List<string>();

            foreach (MethodInfo mi in methods)
            {
                if (seenMethods.Contains(mi.Name)) continue;

                currentTypeMethods.Add(mi.Name);
                AddMethodToData(mi);
            }

            seenMethods.AddRange(currentTypeMethods);
        }

        private MethodInfo[] GetElementMethods(Type type)
        {
            MethodInfo[] mInfo = type
                .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                .Where(x => !x.GetParameters().Any()
                            && x.ReturnType != typeof(void)
                            && !x.IsSpecialName)
                .OrderBy(x => x.Name)
                .ToArray();

            return mInfo;
        }

        private void AddMethodToData(MethodInfo mi)
        {
            Type methodType = mi.ReturnType;

            try
            {
                var returnValue = mi.Invoke(elem, new object[0]);<commit_msg>fix bug in getting Application.Documents when more than one document is opened. Close() method must not be called - it sucessfully closes non-active documents and fails to get information about it<commit_after>using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Autodesk.Revit.UI;

namespace RevitLookup.Snoop.CollectorExts
{
    public class ElementMethodsStream : IElementStream
    {
        private readonly UIApplication application;
        private readonly ArrayList data;
        private readonly object elem;
        private readonly List<string> seenMethods = new List<string>();
        
        public ElementMethodsStream(UIApplication application, ArrayList data, object elem)
        {
            this.application = application;
            this.data = data;
            this.elem = elem;
        }

        public void Stream(Type type)
        {
            var methods = GetElementMethods(type)
                .Where(x => IsValidMethod(type, x))
                .ToList();

            if (methods.Count > 0) data.Add(new Snoop.Data.MemberSeparatorWithOffset("Methods"));

            var currentTypeMethods = new List<string>();

            foreach (MethodInfo mi in methods)
            {
                if (seenMethods.Contains(mi.Name)) continue;

                currentTypeMethods.Add(mi.Name);
                AddMethodToData(mi);
            }

            seenMethods.AddRange(currentTypeMethods);
        }

        private MethodInfo[] GetElementMethods(Type type)
        {
            MethodInfo[] mInfo = type
                .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                .Where(x => !x.GetParameters().Any()
                            && x.ReturnType != typeof(void)
                            && !x.IsSpecialName)
                .OrderBy(x => x.Name)
                .ToArray();

            return mInfo;
        }

        private bool IsValidMethod(Type type, MethodInfo methodInfo)
        {
            var forbiddenMethods = new[]
                {
                    "Autodesk.Revit.DB.Document.Close"
                };

            var name = string.Format("{0}.{1}", type.FullName, methodInfo.Name);

            return !forbiddenMethods.Contains(name);
        }

        private void AddMethodToData(MethodInfo mi)
        {
            Type methodType = mi.ReturnType;

            try
            {
                var returnValue = mi.Invoke(elem, new object[0]);
{'fraction_non_alphanumeric': 0.08573987015894337, 'fraction_numerical': 0.001343183344526528, 'mean_word_length': 1.8224889450410613, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '925448', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1067, 'n_words': 267}