public static MethodMappings createSavedMethodMappings(this O2MappedAstData astData, Dictionary <string, List <KeyValuePair <INode, IMethodOrProperty> > > mappings)
        {
            //"creating SavedMethodMappings object from {0} mappings".info(mappings.size());
            var savedMethodMappings = new MethodMappings();

            foreach (var mapping in mappings)
            {
                try
                {
                    string key = mapping.Key;
                    var    methodMappingItem = new MethodMappingItem()
                    {
                        Key = key
                    };
                    List <KeyValuePair <INode, IMethodOrProperty> > items = mapping.Value;
                    foreach (var keyValuePair in items)
                    {
                        var iNode             = keyValuePair.Key;
                        var iMethodOrProperty = keyValuePair.Value;
                        methodMappingItem.MethodMappings.Add(astData.methodMapping(iMethodOrProperty, iNode, key));
                    }
                    savedMethodMappings.MethodMappingItems.Add(methodMappingItem);
                }
                catch (Exception ex)
                {
                    ex.log("in createSavedMethodMappings");
                }
            }
            return(savedMethodMappings);
        }
        public static Dictionary <string, List <MethodMapping> > indexedByKey(this MethodMappings methodMappings, string filter)
        {
            var result = new Dictionary <string, List <MethodMapping> >();

            if (methodMappings.MethodMappingItems.isNull())
            {
                "In IndexedByKey there were no methodMappingsItems (filer = '{0}'".error(filter ?? "");
            }
            else
            {
                foreach (var mappingItem in methodMappings.MethodMappingItems)
                {
                    var key = mappingItem.Key;
                    if (filter.valid().isFalse() || key.regEx(filter))
                    {
                        foreach (var methodMapping in mappingItem.MethodMappings)
                        {
                            methodMapping.Key = key;                                                                    //Hack(26-Aug-2010): fix until we create all methodMappings with this Key valu	e
                            result.add(key, methodMapping);
                        }
                    }
                }
            }
            return(result);
        }
        public static MethodMappings loadAndMergeMethodMappings(this List <string> targetFiles)
        {
            "Creating MethodMappings from {0} files".info(targetFiles.size());
            var mergedMethodMappings = new Dictionary <string, List <MethodMapping> >();

            foreach (var targetFile in targetFiles)
            {
                var tempMethodMappings = loadMethodMappings(targetFile);
                var indexedMappings    = tempMethodMappings.indexedByKey("");
                foreach (var item in indexedMappings)
                {
                    foreach (var methodMapping in item.Value)
                    {
                        mergedMethodMappings.add(item.Key, methodMapping);
                    }
                }
            }
            var methodMappings = new MethodMappings();

            foreach (var item in mergedMethodMappings)
            {
                var methodMappingItem = new MethodMappingItem()
                {
                    Key = item.Key
                };
                methodMappingItem.MethodMappings = item.Value;
                methodMappings.MethodMappingItems.Add(methodMappingItem);
            }
            return(methodMappings);
        }
        public static void showInTreeView(this MethodMappings methodMappings, TreeView treeView, string filter, bool showSourceCodeSnippets, bool onlyShowSourceCodeLine)
        {
            treeView.parent().backColor("LightPink");
            treeView.visible(false);
            treeView.clear();
            var indexedMappings = methodMappings.indexedByKey(filter);

            if (onlyShowSourceCodeLine)
            {
                //do this so that we don't add more than one item per line
                var indexedByFileAndLine = new Dictionary <string, MethodMapping>();

                foreach (var item in indexedMappings)
                {
                    foreach (var methodMapping in item.Value)
                    {
                        if (methodMapping.File.valid())
                        {
                            var key = "{0}_{1}".format(methodMapping.File, methodMapping.Start_Line);
                            indexedByFileAndLine.add(key, methodMapping);
                        }
                    }
                }
                // now group then by the same text in the SourceCodeLine
                var indexedBySourceCodeLine = new Dictionary <string, List <MethodMapping> >();
                foreach (var methodMapping in indexedByFileAndLine.Values)
                {
                    indexedBySourceCodeLine.add(methodMapping.sourceCodeLine(), methodMapping);
                }

                //Finally show then
                foreach (var item  in indexedBySourceCodeLine)
                {
                    var uniqueTextNode = treeView.add_Node(item.Key, item.Value, true);
                }
            }
            else
            {
                foreach (var item in indexedMappings)
                {
                    var keyNodeText = "{0}                       ({1})".format(item.Key, item.Value.size());
                    var keyNode     = treeView.add_Node(keyNodeText, item.Value, true);
                }
                treeView.afterSelect <List <MethodMapping> >(
                    (mappings) => {
                    var keyNode = treeView.selected();
                    keyNode.clear();
                    foreach (var methodMapping in mappings)
                    {
                        var nodeText = (showSourceCodeSnippets)
                                                                                                                        ? methodMapping.sourceCodeLine()
                                                                                                                        : "{0} - {1}".format(methodMapping.INodeType, methodMapping.SourceCode);
                        keyNode.add_Node(nodeText, methodMapping);
                    }
                });
            }
            treeView.parent().backColor("Control");
            treeView.visible(true);
        }
        public static string saveMappings(this MethodMappings savedMethodMappings)
        {
            if (savedMethodMappings.isNull())
            {
                "in saveMappings savedMethodMappings was Null".error();
            }
            //"__*****>>> in saveMappings: {0}".info(savedMethodMappings.MethodMappingItems.size());
            //show.info(savedMethodMappings);
            var savedMappingsFile = savedMethodMappings.save();

            //"*****>>> Saved Mappings File: {0}".info(savedMappingsFile);
            return(savedMappingsFile);
        }
        public static string saveMappings(this MethodMappings savedMethodMappings, string targetFile)
        {
            var savedFile = savedMethodMappings.saveMappings();

            if (savedFile.fileExists())
            {
                Files.MoveFile(savedFile, targetFile);
                if (targetFile.fileExists())
                {
                    return(targetFile);
                }
            }
            return("");
        }
 public static void showInTreeView(this MethodMappings methodMappings, TreeView treeView, string filter)
 {
     methodMappings.showInTreeView(treeView, filter, false, false);
 }
		public static MethodMappings createSavedMethodMappings(this O2MappedAstData astData, Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>> mappings)
		{
			//"creating SavedMethodMappings object from {0} mappings".info(mappings.size());			
			var savedMethodMappings = new MethodMappings();
			foreach(var mapping in mappings)			
			{
				try
				{										
					string key = mapping.Key;					
					var methodMappingItem = new MethodMappingItem() { Key =  key};
					List<KeyValuePair<INode,IMethodOrProperty>> items = mapping.Value; 
					foreach(var keyValuePair in items)
					{							
						var iNode = keyValuePair.Key;				
						var iMethodOrProperty = keyValuePair.Value;
						methodMappingItem.MethodMappings.Add(astData.methodMapping(iMethodOrProperty,iNode,key));
					}						
					savedMethodMappings.MethodMappingItems.Add(methodMappingItem);				
				}
				catch(Exception ex)
				{
					ex.log("in createSavedMethodMappings");
				}
			}			
			return savedMethodMappings;			
		}			
	public static MethodMappings loadAndMergeMethodMappings (this List<string> targetFiles)
	{
		"Creating MethodMappings from {0} files".info(targetFiles.size());
		var mergedMethodMappings = new Dictionary<string, List<MethodMapping>>();
		foreach(var targetFile in targetFiles)
		{
		
			var tempMethodMappings = loadMethodMappings(targetFile); 
			var indexedMappings = tempMethodMappings.indexedByKey(""); 
			foreach(var item in indexedMappings)
				foreach(var methodMapping in item.Value)									
					mergedMethodMappings.add(item.Key, methodMapping);																	
		}
		var methodMappings = new MethodMappings();							
		foreach(var item in mergedMethodMappings)
		{
			var methodMappingItem = new MethodMappingItem() { Key = item.Key};
			methodMappingItem.MethodMappings = item.Value;
			methodMappings.MethodMappingItems.Add(methodMappingItem); 
		}
		return methodMappings;
	}