/// <summary> /// Returns the classes with which the current class may be replaced with. /// </summary> /// <returns>the classes in a list of strings with which the current class may be replaced with</returns> public override Dictionary <string, DuneFeature> getVariability() { List <DuneFeature> variability = XMLParser.getVariability(this); Dictionary <string, DuneFeature> result = new Dictionary <string, DuneFeature>(); foreach (DuneFeature df in variability) { //TODO: Be aware of an ArgumentException... result.Add(df.ToString(), df); // If a class is an alternative and has children, then also the children are alternatives if (df.GetType() == typeof(DuneClass)) { DuneClass dc = (DuneClass)df; if (dc.hasChildren()) { foreach (DuneClass d in dc.children) { if (!variability.Contains(d) && !result.ContainsKey(d.ToString())) { if (!result.ContainsKey(d.ToString())) { result.Add(d.ToString(), d); } } } } } } return(result); }
public override bool Equals(System.Object obj) { // If parameter is null return false. if (obj == null) { return(false); } // If parameter cannot be cast to DuneClass return false. DuneClass p = obj as DuneClass; if ((System.Object)p == null) { return(false); } // If both objects have references then match them by reference if (this.reference != null && !this.reference.Equals("") && p.reference != null && !p.reference.Equals("")) { return(this.reference.Equals(p.reference)); } // Return true if the fields match: return((this.getFeatureName()).Equals(p.getFeatureName())); }
/// <summary> /// Adds the specializations of the class to a list. /// </summary> /// <param name="dc">the specialization class to add</param> public void addSpecialization(DuneClass dc) { if (this.specializations == null) { this.specializations = new List <DuneClass>(); } this.specializations.Add(dc); }
private static DuneClass getDuneClassByNumberOfTemplateParameters(List <DuneClass> allOthers, int p) { DuneClass f = null; for (int i = 0; i < allOthers.Count; i++) { if (allOthers[i].getTemplateArgumentCount().getLowerBound() <= p && allOthers[i].getTemplateArgumentCount().getUpperBound() >= p) { if (f == null) { f = allOthers[i]; } else { Program.infoLogger.logLine("Multiple classes found that could match with the input"); } } } return(f); }
/// <summary> /// Returns if the class has a relation(also considering the transitive hull) to the given class. /// </summary> /// <param name="df">the class, a relation should be searched to</param> /// <param name="analyzed">the list which contains the classes which were already analyzed</param> /// <returns><code>true</code> if the class has a relation(also indirect) to the given class; <code>false</code> otherwise</returns> private Boolean hasRelationTo(DuneClass df, DuneClass root, List <DuneClass> analyzed) { if (analyzed.Contains(this) || root == this) { return(false); } if (df == this) { return(true); } if (!hasDirectRelationTo(df)) { analyzed.Add(this); foreach (DuneClass p in parents) { if (p != root && !analyzed.Contains(p) && p.hasRelationTo(df, root, analyzed)) { return(true); } } foreach (DuneClass c in children) { if (c.hasRelationTo(df, root, analyzed)) { return(true); } } return(false); } else { return(true); } }
/// <summary> /// Adds a child feature. /// </summary> /// <param name="d">the feature to add to the children-list</param> public void addChildren(DuneClass d) { this.children.Add(d); }
/// <summary> /// Adds a parent feature. /// </summary> /// <param name="d">the parent feature</param> public void addParent(DuneClass d) { parents.Add(d); }
/// <summary> /// Returns if the class has a relation(also considering the transitive hull) to the given class. /// </summary> /// <param name="df">the class, a relation should be searched to</param> /// <returns><code>true</code> if the class has a relation(also indirect) to the given class; <code>false</code> otherwise</returns> public Boolean hasRelationTo(DuneClass df, DuneClass root) { return(hasRelationTo(df, root, new List <DuneClass>())); }
/// <summary> /// This method returns <code>true</code> if the respective feature has the given feature as a child. /// </summary> /// <param name="df">the feature to search for</param> /// <returns><code>true</code> if the respective feature has the given feature as a child; <code>false</code> otherwise</returns> public Boolean hasDirectChildRelationTo(DuneClass df) { return(this.children.Contains(df)); }
/// <summary> /// Returns whether this feature has parents or not. /// </summary> /// <param name="root">the root feature</param> /// <returns><code>true</code> if this feature has parents; <code>false</code> otherwise</returns> public Boolean hasParents(DuneClass root) { return(parents.Contains(root) ? false : parents.Any()); }
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); }