<commit_before>﻿using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

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

using Phil.Core;
using Phil.Extensions;

namespace Phil.Refactorings
{
    [ExportCodeRefactoringProvider(LanguageNames.CSharp)]
    public class FillConstrutorBodyRefactoring : CodeRefactoringProvider
    {
        public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            var document = context.Document;
            var textSpan = context.Span;
            var cancellationToken = context.CancellationToken;
            var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
            var token = root.FindToken(textSpan.Start);
            if (token.Parent == null)
            {
                return;
            }
            var node = token.Parent.FirstAncestorOrSelf <ConstructorDeclarationSyntax>();
            if (node != null)
            {
                var semanticModel = (SemanticModel)await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
                
                var body = node.Body;
                
                var properties = semanticModel.GetTypeSymbols(node)
                    .Where(x => x.Name != "this");
                var unimplemntedProperties =
                    properties.Where(
                        x =>
                            body.Statements.OfType<ExpressionStatementSyntax>()
                            .Where(ex => ex.Expression is AssignmentExpressionSyntax)
                            .Select(ex => ex.Expression as AssignmentExpressionSyntax)
                            .All(
                                y => GetNameSyntax(y)?.Identifier.Text != x.Name));
                if (unimplemntedProperties.Any())
                {
                    ReportForUnimplemented(context, unimplemntedProperties, semanticModel, node);
                }<commit_msg>Nullcheck<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

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

using Phil.Core;
using Phil.Extensions;

namespace Phil.Refactorings
{
    [ExportCodeRefactoringProvider(LanguageNames.CSharp)]
    public class FillConstrutorBodyRefactoring : CodeRefactoringProvider
    {
        public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            var document = context.Document;
            var textSpan = context.Span;
            var cancellationToken = context.CancellationToken;
            var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
            var token = root.FindToken(textSpan.Start);
            if (token.Parent == null)
            {
                return;
            }
            var node = token.Parent.FirstAncestorOrSelf <ConstructorDeclarationSyntax>();
            if (node != null)
            {
                var semanticModel = (SemanticModel)await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
                
                var body = node.Body;
                if(body==null)
                    return;
                var properties = semanticModel.GetTypeSymbols(node)
                    .Where(x => x.Name != "this");
                var unimplemntedProperties =
                    properties.Where(
                        x =>
                            body.Statements.OfType<ExpressionStatementSyntax>()
                            .Where(ex => ex.Expression is AssignmentExpressionSyntax)
                            .Select(ex => ex.Expression as AssignmentExpressionSyntax)
                            .All(
                                y => GetNameSyntax(y)?.Identifier.Text != x.Name));
                if (unimplemntedProperties.Any())
                {
                    ReportForUnimplemented(context, unimplemntedProperties, semanticModel, node);
                }
{'fraction_non_alphanumeric': 0.07830025884383089, 'fraction_numerical': 0.0, 'mean_word_length': 2.0790172642762283, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2887495', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1098, 'n_words': 218}