<commit_before>﻿using System;
using JetBrains.Application.Progress;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Feature.Services.Bulbs;
using JetBrains.ReSharper.Feature.Services.CSharp.Bulbs;
using JetBrains.ReSharper.Intentions.Extensibility;
using JetBrains.TextControl;
using JetBrains.Util;
using YC.ReSharper.AbstractAnalysis.LanguageApproximation;


namespace ApproximatorTester
{
    [ContextAction(Name = "RunApproximator", Description = "Run Approximator", Group = "C#")]
    public class RunApproximatorAction : ContextActionBase
    {
        private readonly ICSharpContextActionDataProvider _provider;

        public RunApproximatorAction(ICSharpContextActionDataProvider provider)
        {
            _provider = provider;
        }

        public override bool IsAvailable(IUserDataHolder cache)
        {
            return true;
        }

        protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var inputFile = _provider.PsiFile;
            Approximator.BuildApproximation(inputFile);
            return null;
        }

        public override string Text
        {
            get { return "Run Approximator"; }
        }
    }
}<commit_msg>Code to write out plugin test results added (needed to perform tests)<commit_after>﻿using System;
using System.IO;
using JetBrains.Application;
using JetBrains.Application.Progress;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Feature.Services.Bulbs;
using JetBrains.ReSharper.Feature.Services.CSharp.Bulbs;
using JetBrains.ReSharper.Intentions.Extensibility;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Tree;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.TextControl;
using JetBrains.Util;
using YC.ReSharper.AbstractAnalysis.LanguageApproximation;


namespace ApproximatorTester
{
    [ContextAction(Name = "RunApproximator", Description = "Run Approximator", Group = "C#")]
    public class RunApproximatorAction : ContextActionBase
    {
        private readonly ICSharpContextActionDataProvider _provider;

        public RunApproximatorAction(ICSharpContextActionDataProvider provider)
        {
            _provider = provider;
        }

        public override bool IsAvailable(IUserDataHolder cache)
        {
            return true;
        }

        protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var inputFile = _provider.PsiFile;
            Approximator.BuildApproximation(inputFile);
            OutputResults();
            return null;
        }

        public override string Text
        {
            get { return "Run Approximator"; }
        }

        private void OutputResults()
        {
            var firstToken = _provider.TokenAfterCaret;
            var namespaceDecl = firstToken == null ? null : firstToken.Parent;
            if (namespaceDecl == null)
            {
                const string msg = @"No namespace declaration after caret in test file. 
                                    Possibly incorrect test input file format,
                                    it must start with ""{caret}namespace""";
                throw new Exception(msg);
            }

            var resultString = ResultToString();
            var factory = CSharpElementFactory.GetInstance(_provider.PsiModule);
            var commentWithResult = factory.CreateComment("/*\n" + resultString + "\n*/");
            WriteLockCookie.Execute(() =>
            {
                ModificationUtil.ReplaceChild(namespaceDecl, commentWithResult);
            });
        }

        private string ResultToString()
        {
            return "result";
        }
    }
}
{'fraction_non_alphanumeric': 0.07473216618761432, 'fraction_numerical': 0.0, 'mean_word_length': 2.5675675675675675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7150897', 'n_tokens_mistral': 1006, 'n_tokens_neox': 975, 'n_words': 219}