public override PostfixTemplateInfo TryCreateInfo(CSharpPostfixTemplateContext context)
        {
            var withValuesContexts = CSharpPostfixUtils.FindExpressionWithValuesContexts(context);

            return(withValuesContexts.Length == 0
                ? null
                : new PostfixTemplateInfo("writeLine", withValuesContexts, availableInPreciseMode: true));
        }
예제 #2
0
        public override PostfixTemplateInfo TryCreateInfo(CSharpPostfixTemplateContext context)
        {
            var withValuesContexts = CSharpPostfixUtils.FindExpressionWithValuesContexts(context);
            var validatorTypes     = GetPossibleValidatorTypes(context, withValuesContexts);

            return(validatorTypes.Length == 0
                ? null
                : new ValidatePostfixTemplateInfo(withValuesContexts, validatorTypes, availableInPreciseMode: true));
        }
예제 #3
0
        private static ITypeElement[] GetPossibleValidatorTypes(
            CSharpPostfixTemplateContext context,
            CSharpPostfixExpressionContext[] withValuesContexts)
        {
            var name        = (withValuesContexts.FirstOrDefault()?.ExpressionType as IDeclaredType)?.GetClrName().ShortName;
            var psiServices = context.PsiModule.GetPsiServices();
            var symbolScope =
                psiServices.Symbols.GetSymbolScope(context.PsiModule, withReferences: true, caseSensitive: false);

            return(symbolScope.GetElementsByShortName(name + "Validator").OfType <ITypeElement>().ToArray());
        }
        public static CSharpPostfixExpressionContext[] FindExpressionWithValuesContexts(
            [NotNull] CSharpPostfixTemplateContext context, [CanBeNull] Predicate <ICSharpExpression> predicate = null)
        {
            var results = new LocalList <CSharpPostfixExpressionContext>();

            foreach (var expressionContext in context.Expressions.Reverse())
            {
                if (IsValidExpressionWithValue(expressionContext.Expression))
                {
                    if (predicate == null || predicate(expressionContext.Expression))
                    {
                        results.Add(expressionContext);
                    }
                }
            }

            return(results.ToArray());
        }
예제 #5
0
        public override PostfixTemplateInfo TryCreateInfo(CSharpPostfixTemplateContext context)
        {
            string lengthName;

            if (!CanBeLoopedOver(context, out lengthName))
            {
                return(null);
            }

            var expressionContext = context.InnerExpression;

            if (expressionContext == null)
            {
                return(null);
            }

            return(new ForLoopPostfixTemplateInfo("for", expressionContext, lengthName));
        }
예제 #6
0
        protected override CheckForNullPostfixTemplateInfo TryCreateInfo(CSharpPostfixTemplateContext context)
        {
            var outerExpression = context.OuterExpression;

            if (outerExpression != null && outerExpression.CanBeStatement)
            {
                if (IsNullable(outerExpression))
                {
                    if (context.IsPreciseMode && !MakeSenseToCheckInPreciseMode(outerExpression))
                    {
                        return(null); // reduce noise
                    }
                    return(new CheckForNullPostfixTemplateInfo(
                               "null", outerExpression, checkNotNull: false, target: PostfixTemplateTarget.Statement));
                }
            }
            else if (!context.IsPreciseMode)
            {
                var nullableExpressions = new List <CSharpPostfixExpressionContext>();
                foreach (var expressionContext in context.Expressions)
                {
                    if (IsNullable(expressionContext))
                    {
                        nullableExpressions.Add(expressionContext);
                    }
                }

                if (nullableExpressions.Count > 0)
                {
                    nullableExpressions.Reverse();

                    return(new CheckForNullPostfixTemplateInfo(
                               "null", nullableExpressions, checkNotNull: false, target: PostfixTemplateTarget.Expression));
                }
            }

            return(null);
        }