Ejemplo n.º 1
0
        private static void ValidateSpecificTypes(
            string methodUsedName,
            DotMethodTypeEnum type,
            DotMethodFPParam[] foundParams,
            DotMethodFPProvidedParam[] @params)
        {
            for (int i = 0; i < foundParams.Length; i++)
            {
                DotMethodFPParam         found    = foundParams[i];
                DotMethodFPProvidedParam provided = @params[i];

                // Lambda-type expressions not validated here
                if (found.LambdaParamNum > 0)
                {
                    continue;
                }

                EPLValidationUtil.ValidateParameterType(
                    methodUsedName,
                    type.GetTypeName(),
                    false,
                    found.ParamType,
                    found.SpecificType,
                    provided.ReturnType,
                    i,
                    provided.Expression);
            }
        }
Ejemplo n.º 2
0
        public static void ValidateSpecificType(String methodUsedName, DotMethodTypeEnum type, DotMethodFPParamTypeEnum expectedTypeEnum, Type expectedTypeClass, Type providedType, int parameterNum, ExprNode parameterExpression)
        {
            string message = string.Format("Error validating {0} method '{1}', ", type.GetTypeName(), methodUsedName);

            if (expectedTypeEnum == DotMethodFPParamTypeEnum.BOOLEAN && (!providedType.IsBoolean()))
            {
                throw new ExprValidationException(
                          string.Format("{0}expected a boolean-type result for expression parameter {1} but received {2}",
                                        message, parameterNum, providedType.FullName));
            }
            if (expectedTypeEnum == DotMethodFPParamTypeEnum.NUMERIC && (!providedType.IsNumeric()))
            {
                throw new ExprValidationException(
                          string.Format("{0}expected a number-type result for expression parameter {1} but received {2}",
                                        message, parameterNum, providedType.FullName));
            }
            if (expectedTypeEnum == DotMethodFPParamTypeEnum.SPECIFIC)
            {
                var boxedExpectedType = expectedTypeClass.GetBoxedType();
                var boxedProvidedType = providedType.GetBoxedType();
                if (!TypeHelper.IsSubclassOrImplementsInterface(boxedProvidedType, boxedExpectedType))
                {
                    throw new ExprValidationException(
                              string.Format("{0}expected a {1}-type result for expression parameter {2} but received {3}",
                                            message, boxedExpectedType.Name, parameterNum, providedType.FullName));
                }
            }
            else if (expectedTypeEnum == DotMethodFPParamTypeEnum.TIME_PERIOD_OR_SEC)
            {
                if (parameterExpression is ExprTimePeriod || parameterExpression is ExprStreamUnderlyingNode)
                {
                    return;
                }
                if (!providedType.IsNumeric())
                {
                    throw new ExprValidationException(message +
                                                      "expected a time-period expression or a numeric-type result for expression parameter " +
                                                      parameterNum + " but received " +
                                                      TypeHelper.GetTypeNameFullyQualPretty(providedType));
                }
            }
            else if (expectedTypeEnum == DotMethodFPParamTypeEnum.DATETIME)
            {
                if (!providedType.IsDateTime())
                {
                    throw new ExprValidationException(message +
                                                      "expected a long-typed or DateTime-typed result for expression parameter " +
                                                      parameterNum + " but received " +
                                                      TypeHelper.GetTypeNameFullyQualPretty(providedType));
                }
            }
        }
Ejemplo n.º 3
0
        public static String GetTypeName(this DotMethodTypeEnum value)
        {
            switch (value)
            {
            case DotMethodTypeEnum.ENUM:
                return("enumeration");

            case DotMethodTypeEnum.DATETIME:
                return("date-time");

            default:
                throw new ArgumentException("invalid value", "value");
            }
        }
Ejemplo n.º 4
0
        public static DotMethodFP ValidateParametersDetermineFootprint(DotMethodFP[] footprints, DotMethodTypeEnum methodType, String methodUsedName, DotMethodFPProvided providedFootprint, DotMethodInputTypeMatcher inputTypeMatcher)
        {
            Boolean isLambdaApplies = DotMethodTypeEnum.ENUM == methodType;

            // determine footprint candidates strictly based on parameters
            List <DotMethodFP> candidates = null;
            DotMethodFP        bestMatch  = null;

            foreach (var footprint in footprints)
            {
                var requiredParams = footprint.Parameters;
                if (requiredParams.Length != providedFootprint.Parameters.Length)
                {
                    continue;
                }

                if (bestMatch == null)
                {    // take first if number of parameters matches
                    bestMatch = footprint;
                }

                var paramMatch = true;
                var count      = 0;
                foreach (var requiredParam in requiredParams)
                {
                    var providedParam = providedFootprint.Parameters[count++];
                    if (requiredParam.LambdaParamNum != providedParam.LambdaParamNum)
                    {
                        paramMatch = false;
                    }
                }

                if (paramMatch)
                {
                    if (candidates == null)
                    {
                        candidates = new List <DotMethodFP>();
                    }
                    candidates.Add(footprint);
                }
            }

            // if there are multiple candidates, eliminate by input (event bean collection or component collection)
            if (candidates != null && candidates.Count > 1)
            {
                candidates
                .Where(fp => !inputTypeMatcher.Matches(fp))
                .ToList()
                .ForEach(fp => candidates.Remove(fp));
            }

            // handle single remaining candidate
            if (candidates != null && candidates.Count == 1)
            {
                DotMethodFP found = candidates[0];
                ValidateSpecificTypes(methodUsedName, methodType, found.Parameters, providedFootprint.Parameters);
                return(found);
            }

            // check all candidates in detail to see which one matches, take first one
            if (candidates != null && !candidates.IsEmpty())
            {
                bestMatch = candidates[0];
                var candidateIt = candidates.GetEnumerator();
                ExprValidationException firstException = null;
                while (candidateIt.MoveNext())
                {
                    DotMethodFP fp = candidateIt.Current;
                    try
                    {
                        ValidateSpecificTypes(methodUsedName, methodType, fp.Parameters, providedFootprint.Parameters);
                        return(fp);
                    }
                    catch (ExprValidationException ex)
                    {
                        if (firstException == null)
                        {
                            firstException = ex;
                        }
                    }
                }
                if (firstException != null)
                {
                    throw firstException;
                }
            }
            var message = string.Format("Parameters mismatch for {0} method '{1}', the method ", methodType.GetTypeName(), methodUsedName);

            if (bestMatch != null)
            {
                var buf = new StringWriter();
                buf.Write(bestMatch.ToStringFootprint(isLambdaApplies));
                buf.Write(", but receives ");
                buf.Write(DotMethodFP.ToStringProvided(providedFootprint, isLambdaApplies));
                throw new ExprValidationException(
                          string.Format("{0}requires {1}", message, buf));
            }

            if (footprints.Length == 1)
            {
                throw new ExprValidationException(
                          string.Format("{0}requires {1}", message, footprints[0].ToStringFootprint(isLambdaApplies)));
            }
            else
            {
                var buf       = new StringWriter();
                var delimiter = "";
                foreach (DotMethodFP footprint in footprints)
                {
                    buf.Write(delimiter);
                    buf.Write(footprint.ToStringFootprint(isLambdaApplies));
                    delimiter = ", or ";
                }

                throw new ExprValidationException(message + "has multiple footprints accepting " + buf +
                                                  ", but receives " + DotMethodFP.ToStringProvided(providedFootprint, isLambdaApplies));
            }
        }