Exemplo n.º 1
0
 private static void ReplaceEventInvokeByMatches(List <RefactorDelegate> delegateList, StringBuilder newAllContent, string moduleName, MatchCollection matches)
 {
     foreach (Match match in matches)
     {
         string           matchValue   = match.Value;
         string           eventName    = match.Groups["STR1"].Value;
         string           param        = match.Groups["STR2"].Value;
         RefactorDelegate delegateItem = delegateList.Find(item => item.eventName == eventName);
         if (delegateItem != null)
         {
             string replace = null;
             if (string.IsNullOrEmpty(param))
             {
                 replace = Regex.Replace(matchValue, SendEventMatch, SendEventReplace2);
                 replace = string.Format(replace, moduleName);
             }
             else
             {
                 replace = Regex.Replace(matchValue, SendEventMatch, SendEventReplace);
                 replace = string.Format(replace, moduleName);
             }
             newAllContent.Replace(matchValue, replace);
         }
     }
 }
Exemplo n.º 2
0
        void Refactor(IProgressMonitor monitor, LocalVariable var, RefactorDelegate refactorDelegate)
        {
            RefactorerContext gctx = GetGeneratorContext(var);
            string            file = var.FileName;

            IRefactorer gen = LanguageBindingService.GetRefactorerForFile(file);

            if (gen == null)
            {
                return;
            }

            refactorDelegate(monitor, gctx, gen, file);
            gctx.Save();
        }
Exemplo n.º 3
0
        private void ReplaceClearEvent(string allContent, List <RefactorDelegate> delegateList, StringBuilder newAllContent, string moduleName)
        {
            MatchCollection matches = Regex.Matches(allContent, ModuleRemoveListenerMatch);

            foreach (Match match in matches)
            {
                string           matchValue   = match.Value;
                string           eventName    = match.Groups["STR"].Value;
                RefactorDelegate delegateItem = delegateList.Find(item => item.eventName == eventName);
                if (delegateItem != null)
                {
                    string replace = Regex.Replace(matchValue, ModuleRemoveListenerMatch, ModuleRemoveListenerReplace);
                    replace = string.Format(replace, moduleName);
                    newAllContent.Replace(matchValue, replace);
                }
            }
        }
Exemplo n.º 4
0
        private static void RemoveModelEvent(string moduleName, string allContent, List <RefactorDelegate> delegateList, StringBuilder newAllContent)
        {
            MatchCollection matches = Regex.Matches(allContent, EventMatch);

            foreach (Match match in matches)
            {
                string matchValue = match.Value;
                newAllContent.Replace(matchValue, "");
                RefactorDelegate refactorDelegate = new RefactorDelegate(moduleName);
                string           eventName        = match.Groups["STR2"].Value;
                refactorDelegate.eventName         = eventName;
                refactorDelegate.generateEventName = moduleName + '_' + eventName;
                string param = match.Groups["STR"].Value;
                refactorDelegate.param = param;

                delegateList.Add(refactorDelegate);
            }
        }
Exemplo n.º 5
0
        private string ReplaceGameEventThisFile(string allContent)
        {
            StringBuilder   newAllContent      = new StringBuilder(allContent);
            MatchCollection AddListenerMatches = Regex.Matches(allContent, AddListenerMatch);

            foreach (Match match in AddListenerMatches)
            {
                string matchValue = match.Value;
                string moduleName = match.Groups["STR"].Value;
                string eventName  = match.Groups["STR2"].Value;
                List <RefactorDelegate> list;
                if (refactorDic.TryGetValue(moduleName, out list))
                {
                    RefactorDelegate delegateItem = list.Find(item => item.eventName == eventName);
                    if (delegateItem != null)
                    {
                        string addLissten = Regex.Replace(matchValue, AddListenerMatch, AddListenerReplace);
                        newAllContent.Replace(matchValue, addLissten);
                    }
                }
            }

            MatchCollection RemoveListenerMatches = Regex.Matches(allContent, RemoveListenerMatch);

            foreach (Match match in RemoveListenerMatches)
            {
                string matchValue = match.Value;
                string moduleName = match.Groups["STR"].Value;
                string eventName  = match.Groups["STR2"].Value;
                List <RefactorDelegate> list;
                if (refactorDic.TryGetValue(moduleName, out list))
                {
                    RefactorDelegate delegateItem = list.Find(item => item.eventName == eventName);
                    if (delegateItem != null)
                    {
                        string RemoveListener = Regex.Replace(matchValue, RemoveListenerMatch, RemoveListenerReplace);
                        newAllContent.Replace(matchValue, RemoveListener);
                    }
                }
            }
            return(newAllContent.ToString());
        }
Exemplo n.º 6
0
        void RefactorProject(IProgressMonitor monitor, Project p, RefactorDelegate refactorDelegate)
        {
            RefactorerContext gctx = GetGeneratorContext(p);

            monitor.Log.WriteLine(GettextCatalog.GetString("Refactoring project {0}", p.Name));
            foreach (ProjectFile file in p.Files)
            {
                if (file.BuildAction != BuildAction.Compile || !System.IO.File.Exists(file.FilePath))
                {
                    continue;
                }
                IRefactorer gen = LanguageBindingService.GetRefactorerForFile(file.Name);
                if (gen == null)
                {
                    continue;
                }
                refactorDelegate(monitor, gctx, gen, file.Name);
                gctx.Save();
            }
        }
Exemplo n.º 7
0
        void Refactor(IProgressMonitor monitor, IParameter param, RefactorDelegate refactorDelegate)
        {
            IMember           member = param.DeclaringMember;
            RefactorerContext gctx   = GetGeneratorContext(member.DeclaringType);
            IType             cls    = member.DeclaringType;
            IRefactorer       gen;
            string            file;

            foreach (IType part in cls.Parts)
            {
                file = part.CompilationUnit.FileName;

                if ((gen = LanguageBindingService.GetRefactorerForFile(file)) == null)
                {
                    continue;
                }

                refactorDelegate(monitor, gctx, gen, file);
                gctx.Save();
            }
        }
Exemplo n.º 8
0
		void RefactorProject (IProgressMonitor monitor, Project p, RefactorDelegate refactorDelegate)
		{
			RefactorerContext gctx = GetGeneratorContext (p);
			monitor.Log.WriteLine (GettextCatalog.GetString ("Refactoring project {0}", p.Name));
			foreach (ProjectFile file in p.Files) {
				if (file.BuildAction != BuildAction.Compile || !System.IO.File.Exists (file.FilePath))
					continue;
				IRefactorer gen = LanguageBindingService.GetRefactorerForFile (file.Name);
				if (gen == null)
					continue;
				refactorDelegate (monitor, gctx, gen, file.Name);
				gctx.Save ();
			}
		}
Exemplo n.º 9
0
		void Refactor (IProgressMonitor monitor, IParameter param, RefactorDelegate refactorDelegate)
		{
			IMember member = param.DeclaringMember;
			RefactorerContext gctx = GetGeneratorContext (member.DeclaringType);
			IType cls = member.DeclaringType;
			IRefactorer gen;
			string file;
			
			foreach (IType part in cls.Parts) {
				file = part.CompilationUnit.FileName;
				
				if ((gen = LanguageBindingService.GetRefactorerForFile (file)) == null)
					continue;
				
				refactorDelegate (monitor, gctx, gen, file);
				gctx.Save ();
			}
		}
Exemplo n.º 10
0
		void Refactor (IProgressMonitor monitor, LocalVariable var, RefactorDelegate refactorDelegate)
		{
			RefactorerContext gctx = GetGeneratorContext (var);
			string file = var.FileName;
			
			IRefactorer gen = LanguageBindingService.GetRefactorerForFile (file);
			if (gen == null)
				return;
			
			refactorDelegate (monitor, gctx, gen, file);
			gctx.Save ();
		}
Exemplo n.º 11
0
		void Refactor (IProgressMonitor monitor, IType cls, RefactoryScope scope, RefactorDelegate refactorDelegate)
		{
			switch (scope) {
			case RefactoryScope.DeclaringType:
				ProjectDom ctx = GetParserContext (cls);
				if (cls is InstantiatedType)
					cls = ((InstantiatedType)cls).UninstantiatedType;
				IType resolvedType = ctx.GetType (cls.FullName, cls.TypeParameters.Count, true, true);
				if (resolvedType == null) 
					goto case RefactoryScope.Solution;
				foreach (IType part in resolvedType.Parts) {
					string file = part.CompilationUnit.FileName;
					RefactorerContext gctx = GetGeneratorContext (part);
					IRefactorer gen = LanguageBindingService.GetRefactorerForFile (file);
					if (gen == null)
						return;
					refactorDelegate (monitor, gctx, gen, file);
					gctx.Save ();
				}
				break;
			case RefactoryScope.File: {
				string file = cls.CompilationUnit.FileName;
				RefactorerContext gctx = GetGeneratorContext (cls);
				IRefactorer gen = LanguageBindingService.GetRefactorerForFile (file);
				if (gen == null)
					return;
				refactorDelegate (monitor, gctx, gen, file);
				gctx.Save ();
				break;
				}
			case RefactoryScope.Project:
				Project prj = GetProjectForFile (cls.CompilationUnit.FileName);
				if (prj == null)
					return;
				RefactorProject (monitor, prj, refactorDelegate);
				break;
			case RefactoryScope.Solution:
				if (solution == null)
					goto case RefactoryScope.File;
				foreach (Project project in solution.GetAllProjects ())
					RefactorProject (monitor, project, refactorDelegate);
				break;
			}
				
		}
Exemplo n.º 12
0
        void Refactor(IProgressMonitor monitor, IType cls, RefactoryScope scope, RefactorDelegate refactorDelegate)
        {
            switch (scope)
            {
            case RefactoryScope.DeclaringType:
                ProjectDom ctx = GetParserContext(cls);
                if (cls is InstantiatedType)
                {
                    cls = ((InstantiatedType)cls).UninstantiatedType;
                }
                IType resolvedType = ctx.GetType(cls.FullName, cls.TypeParameters.Count, true, true);
                if (resolvedType == null)
                {
                    goto case RefactoryScope.Solution;
                }
                foreach (IType part in resolvedType.Parts)
                {
                    string            file = part.CompilationUnit.FileName;
                    RefactorerContext gctx = GetGeneratorContext(part);
                    IRefactorer       gen  = LanguageBindingService.GetRefactorerForFile(file);
                    if (gen == null)
                    {
                        return;
                    }
                    refactorDelegate(monitor, gctx, gen, file);
                    gctx.Save();
                }
                break;

            case RefactoryScope.File: {
                string            file = cls.CompilationUnit.FileName;
                RefactorerContext gctx = GetGeneratorContext(cls);
                IRefactorer       gen  = LanguageBindingService.GetRefactorerForFile(file);
                if (gen == null)
                {
                    return;
                }
                refactorDelegate(monitor, gctx, gen, file);
                gctx.Save();
                break;
            }

            case RefactoryScope.Project:
                Project prj = GetProjectForFile(cls.CompilationUnit.FileName);
                if (prj == null)
                {
                    return;
                }
                RefactorProject(monitor, prj, refactorDelegate);
                break;

            case RefactoryScope.Solution:
                if (solution == null)
                {
                    goto case RefactoryScope.File;
                }
                foreach (Project project in solution.GetAllProjects())
                {
                    RefactorProject(monitor, project, refactorDelegate);
                }
                break;
            }
        }