Exemplo n.º 1
0
            public InstanceProducer TryGetProducer(Type serviceType, InjectionConsumerInfo consumer,
                                                   bool handled)
            {
                Type closedImplementation = this.ImplementationType != null
                    ? GenericTypeBuilder.MakeClosedImplementation(serviceType, this.ImplementationType)
                    : null;

                Func <Type> implementationTypeProvider = () => this.ImplementationType != null
                    ? closedImplementation
                    : this.GetImplementationTypeThroughFactory(serviceType, consumer);

                var context = new PredicateContext(serviceType, implementationTypeProvider, consumer, handled);

                // NOTE: The producer should only get built after it matches the delegate, to prevent
                // unneeded producers from being created, because this might cause diagnostic warnings,
                // such as torn lifestyle warnings.
                var shouldBuildProducer =
                    (this.ImplementationType == null || closedImplementation != null) &&
                    this.MatchesPredicate(context) &&
                    context.ImplementationType != null;

                return(shouldBuildProducer
                    ? this.GetProducer(serviceType, context.ImplementationType)
                    : null);
            }
Exemplo n.º 2
0
        public static QsiExpressionNode VisitPredicate(PredicateContext context)
        {
            switch (context)
            {
            case InPredicateContext inPredicateContext:
                return(VisitInPredicate(inPredicateContext));

            case IsNullPredicateContext isNullPredicateContext:
                return(VisitIsNullPredicate(isNullPredicateContext));

            case BinaryComparisonPredicateContext binaryComparisonPredicateContext:
                return(VisitBinaryComparisonPredicate(binaryComparisonPredicateContext));

            case BetweenPredicateContext betweenPredicateContext:
                return(VisitBetweenPredicate(betweenPredicateContext));

            case LikePredicateContext _:
                throw TreeHelper.NotSupportedFeature("LIKE");

            case RegexpPredicateContext _:
                throw TreeHelper.NotSupportedFeature("RLIKE, REGEXP");

            case ExpressionAtomPredicateContext expressionAtomPredicateContext:
                return(VisitExpressionAtomPredicate(expressionAtomPredicateContext));
            }

            throw TreeHelper.NotSupportedTree(context);
        }
Exemplo n.º 3
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();
            WTableReference          tableReference;

            if (PredicateContext != null)
            {
                parameters.Add(SqlUtil.GetScalarSubquery(PredicateContext.ToSelectQueryBlock()));
                parameters.Add(SqlUtil.GetScalarSubquery(TrueChoiceContext.ToSelectQueryBlock()));
                parameters.Add(SqlUtil.GetScalarSubquery(FalseChocieContext.ToSelectQueryBlock()));
                tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Choose, parameters, GetVariableName());
            }
            else
            {
                parameters.Add(SqlUtil.GetScalarSubquery(ChoiceContext.ToSelectQueryBlock()));
                foreach (var option in Options)
                {
                    if (option.Key is GremlinKeyword.Pick && (GremlinKeyword.Pick)option.Key == GremlinKeyword.Pick.None)
                    {
                        parameters.Add(SqlUtil.GetValueExpr(null));
                    }
                    else
                    {
                        parameters.Add(SqlUtil.GetValueExpr(option.Key));
                    }

                    parameters.Add(SqlUtil.GetScalarSubquery(option.Value.ToSelectQueryBlock()));
                }
                tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.ChooseWithOptions, parameters, GetVariableName());
            }

            return(SqlUtil.GetCrossApplyTableReference(tableReference));
        }
Exemplo n.º 4
0
        public void GetInstance_InjectingPropertyWithConditionalRegistration_UsesTheExpectedPredicateContext()
        {
            // Arrange
            PredicateContext context = null;

            var container = CreateContainerThatInjectsAllProperties();

            container.RegisterConditional <ITimeProvider, RealTimeProvider>(c =>
            {
                context = c;

                Assert.AreSame(c.ServiceType, typeof(ITimeProvider));
                Assert.AreSame(c.ImplementationType, typeof(RealTimeProvider));
                Assert.IsNotNull(c.Consumer, "c.Consumer is null");
                Assert.AreSame(context.Consumer.ImplementationType, typeof(ServiceWithProperty <ITimeProvider>));
                Assert.AreEqual(context.Consumer.Target.Name, "Dependency");
                Assert.AreSame(context.Consumer.Target.TargetType, typeof(ITimeProvider));

                return(true);
            });

            container.Register <ServiceWithProperty <ITimeProvider> >();

            // Act
            var service = container.GetInstance <ServiceWithProperty <ITimeProvider> >();

            // Assert
            Assert.IsNotNull(service.Dependency);
        }
 private bool predicate_sempred(PredicateContext _localctx, int predIndex)
 {
     switch (predIndex)
     {
     case 0: return(Precpred(Context, 3));
     }
     return(true);
 }
        bool Predicate(PredicateContext context)
        {
            if (context.Consumer.ImplementationType != typeof(TConsumer))
            {
                return(false);
            }

            return(_predicate != null?_predicate(context) : true);
        }
                private bool MatchesPredicate(InjectionConsumerInfo consumer, bool handled)
                {
                    if (this.producer.IsConditional)
                    {
                        var context = new PredicateContext(this.producer, consumer, handled);

                        return(this.producer.Predicate(context));
                    }

                    return(true);
                }
Exemplo n.º 8
0
            public InstanceProducer?TryGetProducer(InjectionConsumerInfo consumer, bool handled)
            {
                Type GetImplementationType() => this.GetImplementationTypeThroughFactory(consumer);

                var context =
                    new PredicateContext(this.serviceType, GetImplementationType, consumer, handled);

                // NOTE: The producer should only get built after it matches the delegate, to prevent
                // unneeded producers from being created, because this might cause diagnostic warnings,
                // such as torn lifestyle warnings.
                return(this.predicate(context) ? this.GetProducer(context) : null);
            }
            private Registration GetRegistration(PredicateContext context)
            {
                Type key = context.ImplementationType;

                // Never build a registration for a particular implementation type twice. This would break
                // the promise of returning singletons.
                if (!this.registrationCache.TryGetValue(key, out Registration registration))
                {
                    this.registrationCache[key] = registration = this.CreateNewRegistrationFor(context);
                }

                return(registration);
            }
Exemplo n.º 10
0
    public PredicateContext predicate()
    {
        PredicateContext _localctx = new PredicateContext(Context, State);

        EnterRule(_localctx, 10, RULE_predicate);
        int _la;

        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 84; Match(IDENTIFIER);
                State = 96;
                ErrorHandler.Sync(this);
                _la = TokenStream.LA(1);
                if (_la == TERMS_BEGIN)
                {
                    {
                        State = 85; Match(TERMS_BEGIN);
                        State = 86; term();
                        State = 91;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                        while (_la == COMMA)
                        {
                            {
                                {
                                    State = 87; Match(COMMA);
                                    State = 88; term();
                                }
                            }
                            State = 93;
                            ErrorHandler.Sync(this);
                            _la = TokenStream.LA(1);
                        }
                        State = 94; Match(TERMS_END);
                    }
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
            private IEnumerable <InstanceProducer> GetInstanceProducers(InjectionConsumerInfo consumer)
            {
                bool handled = false;

                foreach (var producer in this.producers)
                {
                    var context = new PredicateContext(producer, consumer, handled);
                    if (!producer.IsConditional || producer.Predicate(context))
                    {
                        yield return(producer);

                        handled = true;
                    }
                }
            }
Exemplo n.º 12
0
                public InstanceProducer TryGetProducer(Type serviceType, InjectionConsumerInfo consumer,
                                                       bool handled)
                {
                    Type closedImplementation =
                        GenericTypeBuilder.MakeClosedImplementation(serviceType, this.ImplementationType);

                    var context = new PredicateContext(serviceType, closedImplementation, consumer, handled);

                    // NOTE: The producer should only get built after it matches the delegate, to prevent
                    // unneeded producers from being created, because this might cause diagnostic warnings,
                    // such as torn lifestyle warnings.
                    return(closedImplementation != null && this.MatchesPredicate(context)
                        ? this.GetProducer(serviceType, closedImplementation)
                        : null);
                }
                public InstanceProducer TryGetProducer(Type serviceType, InjectionConsumerInfo consumer,
                                                       bool handled, bool unconditionally)
                {
                    InstanceProducer producer = this.GetOrBuildProducerFromCache(serviceType);

                    if (producer != null)
                    {
                        var context = new PredicateContext(producer, consumer, handled);

                        return(unconditionally || this.MatchesPredicate(context)
                            ? producer
                            : null);
                    }

                    return(null);
                }
Exemplo n.º 14
0
            private InstanceProducer GetProducer(PredicateContext context)
            {
                InstanceProducer producer;

                // Never build a producer twice. This could cause components with a torn lifestyle.
                lock (this.cache)
                {
                    // We need to cache on implementation, because service type is always the same.
                    if (!this.cache.TryGetValue(context.ImplementationType, out producer))
                    {
                        this.cache[context.ImplementationType] = producer = this.CreateNewProducerFor(context);
                    }
                }

                return(producer);
            }
Exemplo n.º 15
0
        public override Expression VisitPredicate(PredicateContext context)
        {
            var property = VisitProperty(context.property());
            var constant = VisitConstant(context.constant());

            if (context.relational_operator() != null)
            {
                return HandleRelationalOperatorPredicate(context.@relational_operator(), property, constant);
            }

            if (context.COLON() != null)
            {
                return HandlePropertyModifierPredicate(context.property_modifier(), property, constant);
            }

            return null;
        }
Exemplo n.º 16
0
            private InstanceProducer GetProducer(PredicateContext context)
            {
                InstanceProducer producer;

                // Never build a producer twice. This could cause components with a torn lifestyle.
                lock (this.cache)
                {
                    // Use both the service and implementation type as key. Using just the service type would
                    // case multiple consumers to accidentally get the same implementation type, which
                    // using only the implementation type, would break when one implementation type could be
                    // used for multiple services (implements multiple closed interfaces).
                    var key = new { context.ServiceType, context.ImplementationType };

                    if (!this.cache.TryGetValue(key, out producer))
                    {
                        this.cache[key] = producer = this.CreateNewProducerFor(context);
                    }
                }

                return(producer);
            }
Exemplo n.º 17
0
        internal override List <GremlinVariable> FetchAllTableVars()
        {
            List <GremlinVariable> variableList = new List <GremlinVariable>()
            {
                this
            };

            if (PredicateContext != null)
            {
                variableList.AddRange(PredicateContext.FetchAllTableVars());
                variableList.AddRange(TrueChoiceContext.FetchAllTableVars());
                variableList.AddRange(FalseChocieContext.FetchAllTableVars());
            }
            else
            {
                variableList.AddRange(ChoiceContext.FetchAllTableVars());
                foreach (var option in Options)
                {
                    variableList.AddRange(option.Value.FetchAllTableVars());
                }
            }
            return(variableList);
        }
Exemplo n.º 18
0
 private Registration CreateNewRegistrationFor(PredicateContext context) =>
 this.lifestyle.CreateRegistration(context.ImplementationType, context.ImplementationType,
                                   this.container);
Exemplo n.º 19
0
 private InstanceProducer CreateNewProducerFor(PredicateContext context) =>
 new InstanceProducer(context.ServiceType, this.GetRegistration(context), this.Predicate);
Exemplo n.º 20
0
 public static ConditionalContext ToConditionalContext(this PredicateContext context)
 => new ConditionalContext(context.ServiceType, context.ImplementationType, context.Handled);
            public InstanceProducer TryGetProducer(InjectionConsumerInfo consumer, bool handled)
            {
                Func<Type> implementationTypeProvider = 
                    () => this.GetImplementationTypeThroughFactory(consumer);

                var context = 
                    new PredicateContext(this.serviceType, implementationTypeProvider, consumer, handled);

                // NOTE: The producer should only get built after it matches the delegate, to prevent
                // unneeded producers from being created, because this might cause diagnostic warnings, 
                // such as torn lifestyle warnings.
                return this.predicate(context) ? this.GetProducer(context) : null;
            }
 private static bool IfNotHandled(PredicateContext c) => !c.Handled;
            public InstanceProducer TryGetProducer(Type serviceType, InjectionConsumerInfo consumer,
                bool handled)
            {
                Type closedImplementation = this.ImplementationType != null
                    ? GenericTypeBuilder.MakeClosedImplementation(serviceType, this.ImplementationType)
                    : null;

                Func<Type> implementationTypeProvider = () => this.ImplementationType != null
                    ? closedImplementation
                    : this.GetImplementationTypeThroughFactory(serviceType, consumer);

                var context = new PredicateContext(serviceType, implementationTypeProvider, consumer, handled);

                // NOTE: The producer should only get built after it matches the delegate, to prevent
                // unneeded producers from being created, because this might cause diagnostic warnings, 
                // such as torn lifestyle warnings.
                var shouldBuildProducer =
                    (this.ImplementationType == null || closedImplementation != null)
                    && this.MatchesPredicate(context)
                    && context.ImplementationType != null;

                return shouldBuildProducer
                    ? this.GetProducer(serviceType, context.ImplementationType)
                    : null;
            }
                private bool MatchesPredicate(InjectionConsumerInfo consumer, bool handled)
                {
                    if (this.producer.IsConditional)
                    {
                        var context = new PredicateContext(this.producer, consumer, handled);

                        return this.producer.Predicate(context);
                    }

                    return true;
                }
 private Registration CreateNewRegistrationFor(PredicateContext context) =>
     this.lifestyle.CreateRegistration(context.ImplementationType, context.ImplementationType,
         this.container);
            private Registration GetRegistration(PredicateContext context)
            {
                Type key = context.ImplementationType;

                Registration registration;

                // Never build a registration for a particular implementation type twice. This would break
                // the promise of returning singletons.
                if (!this.registrationCache.TryGetValue(key, out registration))
                {
                    this.registrationCache[key] = registration = this.CreateNewRegistrationFor(context);
                }

                return registration;
            }
Exemplo n.º 27
0
                public InstanceProducer TryGetProducer(Type serviceType, InjectionConsumerInfo consumer,
                    bool handled)
                {
                    Type closedImplementation =
                        GenericTypeBuilder.MakeClosedImplementation(serviceType, this.ImplementationType);

                    var context = new PredicateContext(serviceType, closedImplementation, consumer, handled);

                    // NOTE: The producer should only get built after it matches the delegate, to prevent
                    // unneeded producers from being created, because this might cause diagnostic warnings, 
                    // such as torn lifestyle warnings.
                    return closedImplementation != null && this.MatchesPredicate(context)
                        ? this.GetProducer(serviceType, closedImplementation)
                        : null;
                }
                public InstanceProducer TryGetProducer(Type serviceType, InjectionConsumerInfo consumer,
                    bool handled, bool unconditionally)
                {
                    InstanceProducer producer = this.GetOrBuildProducerFromCache(serviceType);

                    if (producer != null)
                    {
                        var context = new PredicateContext(producer, consumer, handled);

                        return unconditionally || this.MatchesPredicate(context)
                            ? producer
                            : null;
                    }

                    return null;
                }
 private static bool Fallback(PredicateContext context) => !context.Handled;
            private InstanceProducer GetProducer(PredicateContext context)
            {
                InstanceProducer producer;

                // Never build a producer twice. This could cause components with a torn lifestyle.
                lock (this.cache)
                {
                    // We need to cache on implementation, because service type is always the same.
                    if (!this.cache.TryGetValue(context.ImplementationType, out producer))
                    {
                        this.cache[context.ImplementationType] = producer = this.CreateNewProducerFor(context);
                    }
                }

                return producer;
            }
Exemplo n.º 31
0
 private bool MatchesPredicate(PredicateContext context) =>
 this.Predicate != null?this.Predicate(context) : true;
Exemplo n.º 32
0
 private bool WhenInjectedInto <T>(PredicateContext context) => context.Consumer.ImplementationType == typeof(T);
            private IEnumerable<InstanceProducer> GetInstanceProducers(InjectionConsumerInfo consumer)
            {
                bool handled = false;

                foreach (var producer in this.producers)
                {
                    var context = new PredicateContext(producer, consumer, handled);
                    if (!producer.IsConditional || producer.Predicate(context))
                    {
                        yield return producer;
                        handled = true;
                    }
                }
            }
 private bool MatchesPredicate(PredicateContext context) =>
     this.Predicate != null ? this.Predicate(context) : true;
Exemplo n.º 35
0
 private InstanceProducer CreateNewProducerFor(PredicateContext context) =>
 new InstanceProducer(
     this.serviceType,
     this.lifestyle.CreateRegistration(context.ServiceType, context.ImplementationType,
                                       this.container),
     this.predicate);
 private InstanceProducer CreateNewProducerFor(PredicateContext context) =>
     new InstanceProducer(
         this.serviceType,
         this.lifestyle.CreateRegistration(context.ServiceType, context.ImplementationType, 
             this.container),
         this.predicate);
    private PredicateContext predicate(int _p)
    {
        ParserRuleContext _parentctx = Context;
        int _parentState             = State;
        PredicateContext _localctx   = new PredicateContext(Context, _parentState);
        PredicateContext _prevctx    = _localctx;
        int _startState = 2;

        EnterRecursionRule(_localctx, 2, RULE_predicate, _p);
        try {
            int _alt;
            EnterOuterAlt(_localctx, 1);
            {
                State = 22;
                ErrorHandler.Sync(this);
                switch (TokenStream.LA(1))
                {
                case OpenParen:
                {
                    State = 14; Match(OpenParen);
                    State = 15; predicate(0);
                    State = 16; Match(CloseParen);
                }
                break;

                case Number:
                case String:
                case Property:
                {
                    State = 18; operand();
                    State = 19; @operator();
                    State = 20; operand();
                }
                break;

                default:
                    throw new NoViableAltException(this);
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 30;
                ErrorHandler.Sync(this);
                _alt = Interpreter.AdaptivePredict(TokenStream, 1, Context);
                while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                {
                    if (_alt == 1)
                    {
                        if (ParseListeners != null)
                        {
                            TriggerExitRuleEvent();
                        }
                        _prevctx = _localctx;
                        {
                            {
                                _localctx = new PredicateContext(_parentctx, _parentState);
                                PushNewRecursionContext(_localctx, _startState, RULE_predicate);
                                State = 24;
                                if (!(Precpred(Context, 3)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 3)");
                                }
                                State = 25; booleanOperator();
                                State = 26; predicate(4);
                            }
                        }
                    }
                    State = 32;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 1, Context);
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            UnrollRecursionContexts(_parentctx);
        }
        return(_localctx);
    }
            private InstanceProducer GetProducer(PredicateContext context)
            {
                InstanceProducer producer;

                // Never build a producer twice. This could cause components with a torn lifestyle.
                lock (this.cache)
                {
                    // Use both the service and implementation type as key. Using just the service type would
                    // case multiple consumers to accidentally get the same implementation type, which
                    // using only the implementation type, would break when one implementation type could be
                    // used for multiple services (implements multiple closed interfaces).
                    var key = new { context.ServiceType, context.ImplementationType };

                    if (!this.cache.TryGetValue(key, out producer))
                    {
                        this.cache[key] = producer = this.CreateNewProducerFor(context);
                    }
                }

                return producer;
            }
 private InstanceProducer CreateNewProducerFor(PredicateContext context) =>
     new InstanceProducer(context.ServiceType, this.GetRegistration(context), this.Predicate);
 private bool MatchesPredicate(PredicateContext context)
 {
     return(this.Predicate != null?this.Predicate(context) : true);
 }
 private static bool Fallback(PredicateContext context)
 {
     return(!context.Handled);
 }