<commit_before>﻿using JetBrains.Annotations;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.CSharp.Util;

namespace AsyncConverter.AsyncHelpers.AwaitElideChecker
{
    [SolutionComponent]
    internal class AwaitElideChecker : IAwaitElideChecker
    {
        public bool MayBeElided(IAwaitExpression element)
        {
            var statement = element.Parent as ICSharpStatement;
            if (statement != null
                && IsFinalStatement(statement)
                && statement.GetContainingNode<IUsingStatement>() == null
                && statement.GetContainingNode<ITryStatement>() == null)
                return true;

            var arrowExpressionClause = element.Parent as IArrowExpressionClause;
            if (arrowExpressionClause != null)
                return true;

            var lambdaExpression = element.Parent as ILambdaExpression;
            if (lambdaExpression != null)
                return true;

            return false;

        }

        private bool IsFinalStatement([NotNull]ICSharpStatement statement)<commit_msg>fix: add analyze ILoopStatement when elide await<commit_after>﻿using JetBrains.Annotations;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.CSharp.Util;

namespace AsyncConverter.AsyncHelpers.AwaitElideChecker
{
    [SolutionComponent]
    internal class AwaitElideChecker : IAwaitElideChecker
    {
        public bool MayBeElided(IAwaitExpression element)
        {
            var statement = element.Parent as ICSharpStatement;
            if (statement != null
                && IsFinalStatement(statement)
                && statement.GetContainingNode<IUsingStatement>() == null
                && statement.GetContainingNode<ITryStatement>() == null
                && statement.GetContainingNode<ILoopStatement>() == null)
                return true;

            var arrowExpressionClause = element.Parent as IArrowExpressionClause;
            if (arrowExpressionClause != null)
                return true;

            var lambdaExpression = element.Parent as ILambdaExpression;
            if (lambdaExpression != null)
                return true;

            return false;

        }

        private bool IsFinalStatement([NotNull]ICSharpStatement statement)
{'fraction_non_alphanumeric': 0.0720949957591179, 'fraction_numerical': 0.0, 'mean_word_length': 2.5104166666666665, 'pattern_counts': {'":': 0, '<': 8, '<?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': '3227922', 'n_tokens_mistral': 598, 'n_tokens_neox': 577, 'n_words': 127}