Esempio n. 1
0
        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to DuneFeature return false.
            DuneFeature p = obj as DuneFeature;

            if ((System.Object)p == null)
            {
                return(false);
            }

            String ownRef = this.enumObject.getReference();
            String objRef = p.getReference();

            // If both objects have references then match them by reference
            if (ownRef != null && !ownRef.Equals("") && objRef != null && !objRef.Equals(""))
            {
                return(ownRef.Equals(objRef));
            }

            // Return true if the fields match:
            return((this.getFeatureName()).Equals(p.getFeatureName()));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override bool isApplicable(DuneFeature value)
        {
            if (value.GetType() != typeof(DuneClass) && value.GetType() != typeof(DuneVariable))
            {
                return(false);
            }


            // go over connection to indentify the innerClass/member variable with the constraint
            foreach (String con in connection)
            {
                if (value.GetType() == typeof(DuneClass))
                {
                    value = ((DuneClass)value).getInnerElement(con);
                }
                //else if (value.GetType() == typeof(DuneVariable))
                //   value = ((DuneVariable)value).getInnerElement(con);

                if (value == null)
                {
                    return(false);
                }
            }

            DuneFeature targetFeature = ((DuneClass)value).getInnerElement(target);

            if (targetFeature.GetType() == typeof(DuneVariable))
            {
                return(((DuneVariable)targetFeature).InitialValue.Value.Equals(this.valueToMatch));
            }


            return(false);
        }
        /// <summary>
        /// Add the refering dune feature.
        /// </summary>
        /// <param name="df">the dune feature the current element refers to</param>
        public void addInformation(DuneFeature df)
        {
            TemplateTree       newPart = new TemplateTree(this);
            List <DuneFeature> dfs     = new List <DuneFeature>();

            dfs.Add(df);
            newPart.referseTo       = dfs;
            newPart.type            = Kind.concrete;
            newPart.artificalString = df.getFeatureNameWithoutTemplateAndNamespace();
            newPart.isTerminal      = true;
            newPart.isNotParsable   = df.isNotParsable;

            newPart.parent = currElement;
            currElement.children.Add(newPart);

            lastElement = newPart;
        }
Esempio n. 4
0
 /// <summary>
 /// Tests whether the provided DuneFeature object is valid for the constraint.
 /// </summary>
 /// <param name="value">The DuneFeature to validate.</param>
 /// <returns>TRUE if the DuneFeature is valid for the constraint, FALSE otherwise.</returns>
 public abstract bool isApplicable(DuneFeature value);
Esempio n. 5
0
 /// <inheritdoc />
 public override bool isApplicable(DuneFeature value)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
        public static Dictionary <String, DuneFeature> getAlternativesRecursive(String input)
        {
            input = input.Trim();
            bool inputHasTemplate = false;


            List <String> alternatives   = new List <string>();
            DuneFeature   importantClass = null;
            TemplateTree  treeOfInterest = new TemplateTree();

            // split input in name and template parameters
            String name = "";

            String[] templateDefinedByUser = new String[0];

            if (input.Contains('<'))
            {
                inputHasTemplate = true;

                name = input.Substring(0, input.IndexOf('<')).Trim();
                templateDefinedByUser = getTemplateParts(input);
            }
            else
            {
                name = input;
            }

            // Search for internal representations of the given class...
            List <DuneClass> allOthers = new List <DuneClass>();

            foreach (DuneClass others in XMLParser.featuresWithPublicMethods)
            {
                if (others.getFeatureNameWithoutTemplate().Equals(name))
                {
                    importantClass = others;
                    allOthers.Add(others);
                }
            }

            if (allOthers.Count > 1)
            {
                Program.infoLogger.log("Potential error in getAlternativesRecursive() in the identification of the DuneClass of the given class for " + input + ".  ");
                Program.infoLogger.logLine("More than one internal class could match the given one.");
                importantClass = getDuneClassByNumberOfTemplateParameters(allOthers, templateDefinedByUser.Count());
            }


            // mapping from the default placeholder strings of the template in the strings of the given input template
            Dictionary <String, String> mapping = new Dictionary <string, string>();

            if (importantClass == null)
            {
                // input is the value of an enum
                foreach (DuneEnum currEnum in XMLParser.enums)
                {
                    foreach (String s in currEnum.getValues())
                    {
                        if (s.Equals(input))
                        {
                            importantClass = currEnum;
                        }
                    }
                }
            }
            else
            {
                List <TemplateTree> templateOfClass = ((DuneClass)importantClass).templateElements;

                String cont = "";
                for (int i = 0; i < templateOfClass.Count; i++)
                {
                    cont += templateOfClass[i].declmame_cont + " | ";

                    if (templateOfClass[i].declmame_cont.Trim().Length == 0)
                    {
                        if (mapping.ContainsKey(templateOfClass[i].deftype_cont))
                        {
                            mapping.Add(templateOfClass[i].deftype_cont + "_" + i, templateDefinedByUser[i]);
                        }
                        else
                        {
                            mapping.Add(templateOfClass[i].deftype_cont, templateDefinedByUser[i]);
                        }
                    }
                    else
                    {
                        if (mapping.ContainsKey(templateOfClass[i].declmame_cont))
                        {
                            mapping.Add(templateOfClass[i].declmame_cont + "_" + i, templateDefinedByUser[i]);
                        }
                        else
                        {
                            if (templateDefinedByUser.Count() - 1 < i)
                            {
                                if (templateOfClass[i].defaultValue == null)
                                {
                                    mapping.Add(templateOfClass[i].declmame_cont, templateOfClass[i].defval_cont);
                                }
                                else
                                {
                                    mapping.Add(templateOfClass[i].declmame_cont, templateOfClass[i].defaultValue.ToString());
                                }
                            }
                            else
                            {
                                mapping.Add(templateOfClass[i].declmame_cont, templateDefinedByUser[i]);
                            }
                        }
                    }
                }

                String s = cont;
            }

            if (importantClass == null)
            {
                Program.infoLogger.log("Potential error in getAlternativesRecursive() in the identification of the DuneClass of the given class for " + input + ".  ");
                Program.infoLogger.logLine("No internal representation for the given class could be found.");
                return(new Dictionary <String, DuneFeature>());
                //System.Environment.Exit(1);
            }

            Dictionary <String, DuneFeature> alternativesFirstLevel = ((DuneFeature)importantClass).getVariability();
            Dictionary <String, DuneFeature> alternativesFirstLevelWithConcreteParameters = new Dictionary <String, DuneFeature>();

            if (inputHasTemplate)
            {
                foreach (KeyValuePair <String, DuneFeature> element in alternativesFirstLevel)
                {
                    if (((DuneClass)element.Value).templateElements.Count > 0)
                    {
                        DuneClass alternative = (DuneClass)element.Value;
                        String    alternativStringWithUserInput = element.Value.getFeatureNameWithoutTemplate() + "<";
                        for (int i = 0; i < alternative.templateElements.Count; i++)
                        {
                            String nameTemplateParameter = alternative.templateElements[i].declmame_cont;

                            if (nameTemplateParameter.Trim().Length == 0)
                            {
                                if (mapping.ContainsKey(alternative.templateElements[i].deftype_cont))
                                {
                                    alternativStringWithUserInput += mapping[alternative.templateElements[i].deftype_cont];
                                }
                                else
                                {
                                    if (alternative.templateElements[i].deftype_cont.Length > 0)
                                    {
                                        if (alternative.templateElements[i].defval_cont.Length > 0)
                                        {
                                            if (mapping.ContainsKey(alternative.templateElements[i].defval_cont))
                                            {
                                                alternativStringWithUserInput += mapping[alternative.templateElements[i].defval_cont];
                                            }
                                            else
                                            {
                                                alternativStringWithUserInput += alternative.templateElements[i].defval_cont;
                                            }
                                        }
                                        else
                                        {
                                            alternativStringWithUserInput += alternative.templateElements[i].deftype_cont;
                                        }
                                    }
                                    else
                                    {
                                        String deftype_cont = alternative.templateElements[i].deftype_cont;
                                        Double res;
                                        if (Double.TryParse(deftype_cont, out res))
                                        {
                                            alternativStringWithUserInput += deftype_cont;
                                        }
                                        else
                                        {
                                            alternativStringWithUserInput += "??" + nameTemplateParameter + "??";
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (mapping.ContainsKey(nameTemplateParameter))
                                {
                                    alternativStringWithUserInput += mapping[nameTemplateParameter];
                                }
                                else
                                {
                                    if (alternative.templateElements[i].defval_cont.Length > 0)
                                    {
                                        alternativStringWithUserInput += alternative.templateElements[i].defval_cont;
                                    }
                                    else
                                    {
                                        alternativStringWithUserInput += "??" + nameTemplateParameter + "??";
                                    }
                                }
                            }

                            if (i < alternative.templateElements.Count - 1)
                            {
                                alternativStringWithUserInput += ",";
                            }
                            else
                            {
                                alternativStringWithUserInput += ">";
                            }
                        }
                        if (!alternativesFirstLevelWithConcreteParameters.ContainsKey(alternativStringWithUserInput))
                        {
                            alternativesFirstLevelWithConcreteParameters.Add(alternativStringWithUserInput, element.Value);
                        }
                    }
                    else
                    {
                        alternativesFirstLevelWithConcreteParameters.Add(element.Key, element.Value);
                    }
                }
            }
            else
            {
                foreach (KeyValuePair <String, DuneFeature> element in alternativesFirstLevel)
                {
                    if (element.Value.GetType() == typeof(DuneEnum))
                    {
                        alternativesFirstLevelWithConcreteParameters.Add(element.Key, element.Value);
                    }
                    else
                    {
                        DuneClass alternative = (DuneClass)element.Value;

                        String alternativStringWithUserInput = alternative.getFeatureNameWithoutTemplate();

                        if (alternative.templateElements.Count > 0)
                        {
                            alternativStringWithUserInput += " < ";

                            for (int i = 0; i < alternative.templateElements.Count; i++)
                            {
                                String nameTemplateParameter = alternative.templateElements[i].declmame_cont;

                                if (mapping.ContainsKey(nameTemplateParameter))
                                {
                                    alternativStringWithUserInput += mapping[nameTemplateParameter];
                                }
                                else
                                {
                                    if (alternative.templateElements[i].defval_cont.Length > 0)
                                    {
                                        alternativStringWithUserInput += alternative.templateElements[i].defval_cont;
                                    }
                                    else
                                    {
                                        alternativStringWithUserInput += "??" + nameTemplateParameter + "??";
                                    }
                                }


                                if (i < alternative.templateElements.Count - 1)
                                {
                                    alternativStringWithUserInput += ",";
                                }
                                else
                                {
                                    alternativStringWithUserInput += ">";
                                }
                            }
                        }

                        alternativesFirstLevelWithConcreteParameters.Add(alternativStringWithUserInput, element.Value);
                    }
                }
            }


            return(alternativesFirstLevelWithConcreteParameters);
        }