<commit_before>﻿using System;
using System.Linq;
using System.Reflection;

namespace Ploeh.Albedo
{
    /// <summary>
    /// Represents a Visitor base class which can visit
    /// <see cref="IReflectionElement" /> instances.
    /// </summary>
    /// <typeparam name="T">
    /// The type of observations or calculations the Visitor makes.
    /// </typeparam>
    /// <remarks>
    /// <para>
    /// Implementers should prefer deriving from this class instead of
    /// implementing <see cref="IReflectionVisitor{T}" /> directly. The reason
    /// for this is that future versions of Albedo may add more methods to the
    /// interface. This will be a breaking change, so will only happen on major
    /// releases, but still, deriving from the
    /// <strong>ReflectionVisitor&lt;T&gt;</strong> base class gives you a
    /// better chance that your implementation will be compatible across a
    /// major release.
    /// </para>
    /// <para>
    /// Consumers, on the other hand, should still rely on the
    /// <strong>IReflectionVisitor&lt;T&gt;</strong> interface.
    /// </para>
    /// </remarks>
    public abstract class ReflectionVisitor<T> : IReflectionVisitor<T>
    {
        /// <summary>
        /// Gets the observation or value produced by this instance.
        /// </summary>
        public abstract T Value { get; }

        /// <summary>
        /// Allows an <see cref="AssemblyElement"/> instances to be 'visited'.
        /// This method is called when the element 'accepts' this visitor instance.
        /// </summary>
        /// <param name="assemblyElements">
        /// The <see cref="AssemblyElement"/> instances being visited.
        /// </param>
        /// <returns>
        /// A (potentially) new <see cref="IReflectionVisitor{T}"/> instance which can be
        /// used to continue the visiting process with potentially updated observations.
        /// </returns>
        /// <remarks>
        /// <para>
        /// This implementation relaies each <see cref="AssemblyElement"/> instance
        /// to <see cref="Visit(AssemblyElement)"/>,
        /// but since the method is virtual, child classes can override it.
        /// </para>
        /// </remarks>
        public IReflectionVisitor<T> Visit(params AssemblyElement[] assemblyElements)
        {
            if (assemblyElements == null)
                throw new ArgumentNullException("assemblyElements");

            return assemblyElements.Aggregate((IReflectionVisitor<T>)this, (v, a) => v.Visit(a));
        }

        /// <summary>
        /// Allows an <see cref="AssemblyElement"/> to be visited. 
        /// This method is called when the element accepts this visitor
        /// instance.
        /// </summary>
        /// <param name="assemblyElement">
        /// The <see cref="AssemblyElement"/> being visited.
        /// </param>
        /// <returns>
        /// A <see cref="IReflectionVisitor{T}" /> instance which can be used
        /// to continue the visiting process with potentially updated
        /// observations.
        /// </returns>
        /// <remarks><commit_msg>Addressed the virtual keyword.<commit_after>﻿using System;
using System.Linq;
using System.Reflection;

namespace Ploeh.Albedo
{
    /// <summary>
    /// Represents a Visitor base class which can visit
    /// <see cref="IReflectionElement" /> instances.
    /// </summary>
    /// <typeparam name="T">
    /// The type of observations or calculations the Visitor makes.
    /// </typeparam>
    /// <remarks>
    /// <para>
    /// Implementers should prefer deriving from this class instead of
    /// implementing <see cref="IReflectionVisitor{T}" /> directly. The reason
    /// for this is that future versions of Albedo may add more methods to the
    /// interface. This will be a breaking change, so will only happen on major
    /// releases, but still, deriving from the
    /// <strong>ReflectionVisitor&lt;T&gt;</strong> base class gives you a
    /// better chance that your implementation will be compatible across a
    /// major release.
    /// </para>
    /// <para>
    /// Consumers, on the other hand, should still rely on the
    /// <strong>IReflectionVisitor&lt;T&gt;</strong> interface.
    /// </para>
    /// </remarks>
    public abstract class ReflectionVisitor<T> : IReflectionVisitor<T>
    {
        /// <summary>
        /// Gets the observation or value produced by this instance.
        /// </summary>
        public abstract T Value { get; }

        /// <summary>
        /// Allows an <see cref="AssemblyElement"/> instances to be 'visited'.
        /// This method is called when the element 'accepts' this visitor instance.
        /// </summary>
        /// <param name="assemblyElements">
        /// The <see cref="AssemblyElement"/> instances being visited.
        /// </param>
        /// <returns>
        /// A (potentially) new <see cref="IReflectionVisitor{T}"/> instance which can be
        /// used to continue the visiting process with potentially updated observations.
        /// </returns>
        /// <remarks>
        /// <para>
        /// This implementation relaies each <see cref="AssemblyElement"/> instance
        /// to <see cref="Visit(AssemblyElement)"/>,
        /// but since the method is virtual, child classes can override it.
        /// </para>
        /// </remarks>
        public virtual IReflectionVisitor<T> Visit(params AssemblyElement[] assemblyElements)
        {
            if (assemblyElements == null)
                throw new ArgumentNullException("assemblyElements");

            return assemblyElements.Aggregate((IReflectionVisitor<T>)this, (v, a) => v.Visit(a));
        }

        /// <summary>
        /// Allows an <see cref="AssemblyElement"/> to be visited. 
        /// This method is called when the element accepts this visitor
        /// instance.
        /// </summary>
        /// <param name="assemblyElement">
        /// The <see cref="AssemblyElement"/> being visited.
        /// </param>
        /// <returns>
        /// A <see cref="IReflectionVisitor{T}" /> instance which can be used
        /// to continue the visiting process with potentially updated
        /// observations.
        /// </returns>
        /// <remarks>
{'fraction_non_alphanumeric': 0.13560134163871587, 'fraction_numerical': 0.0, 'mean_word_length': 2.0457198443579765, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 99, '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': '1186034', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1556, 'n_words': 559}