Exemplo n.º 1
0
 /// <summary>
 ///     Fills the list provided with the element matching the filter provided
 /// </summary>
 /// <param name="retVal">The list to be filled with the element matching the condition expressed in the filter</param>
 /// <param name="filter">The filter to apply</param>
 public void Fill(List <INamable> retVal, BaseFilter filter)
 {
     if (filter.AcceptableChoice(Ref))
     {
         retVal.Add(Ref);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Adds a reference which satisfies the provided expectation in the result set
        /// </summary>
        /// <param name="namable"></param>
        /// <param name="expectation"></param>
        /// <param name="asType">Indicates that we had to move from instance to type to perform the deferencing</param>
        /// <param name="resultSet"></param>
        private int addReference(INamable namable, BaseFilter expectation, bool asType, ReturnValue resultSet)
        {
            int retVal = 0;

            if (namable != null)
            {
                if (expectation.AcceptableChoice(namable))
                {
                    if (asType)
                    {
                        if (!(namable is IValue) && !(namable is Type))
                        {
                            resultSet.Add(namable);
                            retVal += 1;
                        }
                        else if (namable is State)
                        {
                            // TODO : Refactor model to avoid this
                            resultSet.Add(namable);
                            retVal += 1;
                        }
                    }
                    else
                    {
                        resultSet.Add(namable);
                        retVal += 1;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Fills the list provided with the element matching the filter provided
 /// </summary>
 /// <param name="retVal">The list to be filled with the element matching the condition expressed in the filter</param>
 /// <param name="filter">The filter to apply</param>
 public override void Fill(List <INamable> retVal, BaseFilter filter)
 {
     if (filter.AcceptableChoice(Value))
     {
         retVal.Add(Value);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Fills the list provided with the element matching the filter provided
        /// </summary>
        /// <param name="retVal">The list to be filled with the element matching the condition expressed in the filter</param>
        /// <param name="filter">The filter to apply</param>
        public override void Fill(List <INamable> retVal, BaseFilter filter)
        {
            if (Parameters != null)
            {
                foreach (Parameter parameter in Parameters)
                {
                    if (filter.AcceptableChoice(parameter))
                    {
                        retVal.Add(parameter);
                    }
                }
            }

            if (Expression != null)
            {
                Expression.Fill(retVal, filter);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Filters out value according to predicate
        /// </summary>
        /// <param name="accept"></param>
        public void Filter(BaseFilter accept)
        {
            ApplyUpdates();
            DiscardRemoved();

            // Only keep the most specific elements.
            string mostSpecific = null;

            foreach (ReturnValueElement element in Values)
            {
                if (accept.AcceptableChoice(element.Value))
                {
                    if (mostSpecific == null)
                    {
                        mostSpecific = element.Value.FullName;
                    }
                    else
                    {
                        if (mostSpecific.Length < element.Value.FullName.Length)
                        {
                            mostSpecific = element.Value.FullName;
                        }
                    }
                }
            }

            // if the filtering is about variables, ensure that there is at least one variable in the element chain
            if (accept is IsVariable)
            {
                List <ReturnValueElement> tmp = new List <ReturnValueElement>();
                foreach (ReturnValueElement element in Values)
                {
                    bool variableFound         = false;
                    bool onlyStructureElement  = true;
                    ReturnValueElement current = element;
                    while (!variableFound && current != null)
                    {
                        variableFound = IsStrictVariableOrValue.INSTANCE.AcceptableChoice(current.Value) ||
                                        current.AsType;
                        onlyStructureElement = onlyStructureElement && current.Value is StructureElement;
                        current = current.PreviousElement;
                    }

                    if (variableFound)
                    {
                        tmp.Add(element);
                    }
                    else if (onlyStructureElement)
                    {
                        tmp.Add(element);
                    }
                }

                // HaCK : If tmp is empty, this indicates that the filter above is too restrictive.
                // Keep the original set
                if (tmp.Count > 0)
                {
                    Values = tmp;
                }
            }

            // Build a new list with the filtered out elements
            bool variable = false;

            {
                List <ReturnValueElement> tmp = new List <ReturnValueElement>();
                foreach (ReturnValueElement element in Values)
                {
                    if (accept.AcceptableChoice(element.Value) &&
                        (mostSpecific == null || mostSpecific.Equals(element.Value.FullName)))
                    {
                        tmp.Add(element);
                        variable = variable || element.Value is IVariable;
                    }
                }
                Values = tmp;
            }

            // HaCK : If both Variable and StructureElement are found, only keep the variable
            if (variable)
            {
                List <ReturnValueElement> tmp = new List <ReturnValueElement>();
                foreach (ReturnValueElement element in Values)
                {
                    if (!(element.Value is StructureElement) && !(element.Value is Type))
                    {
                        tmp.Add(element);
                    }
                }

                Values = tmp;
            }
        }