internal void addInformation(string token)
        {
            TemplateTree newPart = new TemplateTree(this);

            if (XMLParser.nameWithoutPackageToDuneFeatures.ContainsKey(token))
            {
                XMLParser.easyToFind += 1;
                if (XMLParser.nameWithoutPackageToDuneFeatures[token].Count > 1)
                {
                    XMLParser.ambiguities += 1;
                    Program.infoLogger.logLine("TODO:: addInformation with mehrdeutigkeit");
                }

                List <DuneFeature> dfs = new List <DuneFeature>();
                dfs.Add(XMLParser.nameWithoutPackageToDuneFeatures[token].First());
                newPart.referseTo       = dfs;
                newPart.artificalString = token;
                newPart.type            = Kind.concrete;
                newPart.isTerminal      = true;
            }
            else
            {
                newPart.artificalString = token;
                //newPart.declmame_cont = token;
                newPart.type       = Kind.placeholder;
                newPart.isTerminal = true;
            }

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

            lastElement = newPart;
        }
        internal void incHierarchy()
        {
            TemplateTree nonTerminal = lastChild();

            nonTerminal.isTerminal = false;
            currElement            = nonTerminal;
        }
 internal void addInvocation(string method)
 {
     if (this.lastElement == null)
     {
         this.lastElement = new TemplateTree();
     }
     this.lastElement.methodInvocation = method;
 }
        internal void addNumericValue(string token)
        {
            TemplateTree newPart = new TemplateTree(this);

            newPart.artificalString = token;
            newPart.type            = Kind.value;
            newPart.isTerminal      = true;

            newPart.parent = currElement;
            currElement.children.Add(newPart);
            lastElement = newPart;
        }
        /// <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;
        }
        internal void addInformation(string token, TemplateTree furtherInformation)
        {
            TemplateTree newPart = new TemplateTree(this);

            newPart.artificalString = token;
            newPart.type            = Kind.concrete;

            newPart.informationFromTemplateParamlist = furtherInformation;

            // TODO
            newPart.isTerminal = true;


            newPart.parent = currElement;
            currElement.children.Add(newPart);
            lastElement = newPart;
        }
        public void addInformation(List <DuneFeature> dfs)
        {
            if (this.referseTo != null)
            {
                this.referseTo.AddRange(dfs);
            }
            else
            {
                this.referseTo = dfs;
            }
            TemplateTree newPart = new TemplateTree(this);

            newPart.type       = Kind.concrete;
            newPart.isTerminal = true;

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

            lastElement = newPart;
        }
 /// <summary>
 /// Sets the template tree of the <code>DuneClass</code> to the given template tree.
 /// </summary>
 /// <param name="t">the template tree to set to</param>
 public void setTemplateTree(TemplateTree t)
 {
     this.tempTree = t;
 }
 /// <summary>
 /// Adds a template element to the list of template elements.
 /// </summary>
 /// <param name="te">the template element to add</param>
 public void addTemplateElement(TemplateTree te)
 {
     this.templateElements.Add(te);
 }
 public TemplateTree(TemplateTree tt)
 {
     currElement           = this;
     this.refersToAliasing = tt.refersToAliasing;
 }
 public TemplateTree()
 {
     currElement           = this;
     this.refersToAliasing = new util.RefersToAliasing();
 }
 internal void decHierarchy()
 {
     currElement = currElement.parent;
     lastElement = lastElement.parent;
 }
Ejemplo n.º 13
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);
        }