Exemplo n.º 1
0
        public static IMethod FindEquivalentAsyncMethod([NotNull] IParametersOwner originalMethod, [CanBeNull] IType invokedObjectType, [NotNull] IPsiModule psiModule)
        {
            if (!originalMethod.IsValid())
            {
                return(null);
            }

            var @class = GetClassForMethodSearch(invokedObjectType, originalMethod, psiModule);

            if (@class == null)
            {
                return(null);
            }

            var originalReturnType = originalMethod.Type();

            foreach (var candidateMethod in @class.Methods)
            {
                if (originalMethod.ShortName + "Async" != candidateMethod.ShortName)
                {
                    continue;
                }

                var returnType = candidateMethod.Type();
                if (returnType.IsTask() && !originalReturnType.IsVoid())
                {
                    continue;
                }

                if (!returnType.IsGenericTaskOf(originalReturnType))
                {
                    continue;
                }

                if (!IsParameterEquals(candidateMethod.Parameters, originalMethod.Parameters))
                {
                    continue;
                }

                return(candidateMethod);
            }
            return(null);
        }
Exemplo n.º 2
0
        public FindingReslt FindEquivalentAsyncMethod(IParametersOwner originalMethod, IType invokedType)
        {
            if (!originalMethod.IsValid())
            {
                return(FindingReslt.CreateFail());
            }

            var @class = classForSearchResolver.GetClassForSearch(originalMethod, invokedType);

            if (@class == null)
            {
                return(FindingReslt.CreateFail());
            }

            var originalReturnType = originalMethod.Type();

            foreach (var candidateMethod in @class.Methods)
            {
                if (originalMethod.ShortName + "Async" != candidateMethod.ShortName)
                {
                    continue;
                }

                var returnType = candidateMethod.Type();
                if (!returnType.IsTaskOf(originalReturnType))
                {
                    continue;
                }

                var parameterCompareResult = parameterComparer.ComparerParameters(candidateMethod.Parameters, originalMethod.Parameters);
                if (!parameterCompareResult.CanBeConvertedToAsync())
                {
                    continue;
                }

                return(new FindingReslt
                {
                    Method = candidateMethod,
                    ParameterCompareResult = parameterCompareResult,
                });
            }
            return(FindingReslt.CreateFail());
        }