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

using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

namespace AutoProperties.Fody
{
    internal static class MethodVisitor
    {
        internal static void VisitAllMethods(this ModuleDefinition moduleDefinition, ILogger logger)
        {
            var allTypes = moduleDefinition.GetTypes();

            var allClasses = allTypes
                .Where(x => x.IsClass && (x.BaseType != null));

            foreach (var classDefinition in allClasses)
            {
                var shouldBypassAutoPropertySetters = classDefinition.ShouldBypassAutoPropertySettersInConstructors() 
                    ?? moduleDefinition.ShouldBypassAutoPropertySettersInConstructors() 
                    ?? false;

                var autoPropertyToBackingFieldMap = new AutoPropertyToBackingFieldMap(classDefinition);

                var allMethods = classDefinition.Methods.Where(method => method.HasBody);

                foreach (var method in allMethods)
                {
                    if (method.IsConstructor && shouldBypassAutoPropertySetters)
                        method.BypassAutoPropertySetters(autoPropertyToBackingFieldMap, logger);

                    method.ProcessSetBackingFieldCalls(autoPropertyToBackingFieldMap, logger);
                    method.ProcessSetPropertyCalls(autoPropertyToBackingFieldMap, logger);
                }
            }
        }

        private static void BypassAutoPropertySetters(this MethodDefinition method, AutoPropertyToBackingFieldMap autoPropertyToBackingFieldMap, ILogger logger)
        {
            var instructions = method.Body.Instructions;
<commit_msg>must read global attributes from ModuleDefinition.Assembly, not from ModuleDefinition<commit_after>﻿using System.Linq;

using Mono.Cecil;
using Mono.Cecil.Cil;

namespace AutoProperties.Fody
{
    internal static class MethodVisitor
    {
        internal static void VisitAllMethods(this ModuleDefinition moduleDefinition, ILogger logger)
        {
            var allTypes = moduleDefinition.GetTypes();

            var allClasses = allTypes
                .Where(x => x.IsClass && (x.BaseType != null));

            foreach (var classDefinition in allClasses)
            {
                var shouldBypassAutoPropertySetters = classDefinition.ShouldBypassAutoPropertySettersInConstructors() 
                    ?? moduleDefinition.Assembly.ShouldBypassAutoPropertySettersInConstructors() 
                    ?? false;

                var autoPropertyToBackingFieldMap = new AutoPropertyToBackingFieldMap(classDefinition);

                var allMethods = classDefinition.Methods.Where(method => method.HasBody);

                foreach (var method in allMethods)
                {
                    if (method.IsConstructor && shouldBypassAutoPropertySetters)
                        method.BypassAutoPropertySetters(autoPropertyToBackingFieldMap, logger);

                    method.ProcessSetBackingFieldCalls(autoPropertyToBackingFieldMap, logger);
                    method.ProcessSetPropertyCalls(autoPropertyToBackingFieldMap, logger);
                }
            }
        }

        private static void BypassAutoPropertySetters(this MethodDefinition method, AutoPropertyToBackingFieldMap autoPropertyToBackingFieldMap, ILogger logger)
        {
            var instructions = method.Body.Instructions;

{'fraction_non_alphanumeric': 0.06105755185509787, 'fraction_numerical': 0.0, 'mean_word_length': 2.4761421319796955, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4764540', 'n_tokens_mistral': 832, 'n_tokens_neox': 791, 'n_words': 162}