<commit_before>using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

namespace DebuggerStepThroughRemover
{
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    public class DebuggerStepThroughRemoverAnalyzer : DiagnosticAnalyzer
    {
        public const string DiagnosticId = "DebuggerStepThroughRemover";

        private static readonly string Title = "Type is decorated with DebuggerStepThrough attribute";
        private static readonly string MessageFormat = "Type '{0}' is decorated with DebuggerStepThrough attribute";
        private static readonly string Description = "";
        private const string Category = "Debugging";

        private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(
            DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning,
            isEnabledByDefault: true, description: Description);

        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

        public override void Initialize(AnalysisContext context)
        {
            context.RegisterSyntaxNodeAction(AnalyzeAttributeNode, SyntaxKind.Attribute);
        }

        private static void AnalyzeAttributeNode(SyntaxNodeAnalysisContext context)
        {
            var attributeNode = (AttributeSyntax)context.Node;
            var model = context.SemanticModel;
            var attributeClassSymbol = GetAttributeClassSymbolFromModel(model, attributeNode);
            var debuggerStepThroughAttributeSymbol = GetDebuggerStepThroughAttributeSymbol(model);
            if (debuggerStepThroughAttributeSymbol.Equals(attributeClassSymbol))
            {
                ReportDiagnostic(context, attributeNode);
            }
        }

        private static INamedTypeSymbol GetDebuggerStepThroughAttributeSymbol(SemanticModel model)
        {
            var debuggerStepThroughAttributeType = typeof (DebuggerStepThroughAttribute);
            var mscorlib = GetMscorlib(model, debuggerStepThroughAttributeType.GetTypeInfo().Assembly);
            var assemblySymbol = (IAssemblySymbol) model.Compilation.GetAssemblyOrModuleSymbol(mscorlib);
            return assemblySymbol.GetTypeByMetadataName(debuggerStepThroughAttributeType.FullName);
        }

        private static MetadataReference GetMscorlib(SemanticModel model, Assembly mscorlibAssembly)
        {
            var mscorlibAssemblyName = mscorlibAssembly.GetName().Name;
            return model.Compilation.References.Single(x => x.Display.Contains(mscorlibAssemblyName));
        }

        private static ITypeSymbol GetAttributeClassSymbolFromModel(SemanticModel model, AttributeSyntax attributeNode)
        {
            var attributeSymbolInfo = model.GetSymbolInfo(attributeNode);
            var constructorSymbol = (IMethodSymbol) attributeSymbolInfo.Symbol;
            return constructorSymbol.ReceiverType;
        }<commit_msg>Simplify analyzer, tremendously ;)<commit_after>using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

namespace DebuggerStepThroughRemover
{
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    public class DebuggerStepThroughRemoverAnalyzer : DiagnosticAnalyzer
    {
        public const string DiagnosticId = "DebuggerStepThroughRemover";

        private static readonly string Title = "Type is decorated with DebuggerStepThrough attribute";
        private static readonly string MessageFormat = "Type '{0}' is decorated with DebuggerStepThrough attribute";
        private static readonly string Description = "";
        private const string Category = "Debugging";

        private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(
            DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning,
            isEnabledByDefault: true, description: Description);

        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

        public override void Initialize(AnalysisContext context)
        {
            context.RegisterSyntaxNodeAction(AnalyzeAttributeNode, SyntaxKind.Attribute);
        }

        private static void AnalyzeAttributeNode(SyntaxNodeAnalysisContext context)
        {
            var attributeNode = (AttributeSyntax)context.Node;
            var symbol = context.SemanticModel.GetSymbolInfo(attributeNode).Symbol;
            if (symbol.ContainingType.MetadataName == typeof(DebuggerStepThroughAttribute).Name)
            {
                ReportDiagnostic(context, attributeNode);
            }
        }
{'fraction_non_alphanumeric': 0.062348178137651825, 'fraction_numerical': 0.0004048582995951417, 'mean_word_length': 3.678977272727273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '377983', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1098, 'n_words': 265}