Exemplo n.º 1
0
		public IMember RenameMember (IProgressMonitor monitor, IType cls, IMember member, string newName, RefactoryScope scope)
		{
			// rename overriden members
			if (cls.ClassType == ClassType.Interface | member.IsAbstract | member.IsVirtual) {
				foreach (IType t in cls.SourceProjectDom.GetSubclasses (cls)) {
					foreach (IMember m in t.SearchMember (member.Name, true)) {
						InnerRenameMember (monitor, t, m, newName, scope);
					}
				}
			}
			
			// rename base members that are overridden as well.
			if (member.IsOverride) {
				foreach (IType t in cls.SourceProjectDom.GetInheritanceTree (cls)) {
					if (t == cls)
						continue;
					foreach (IMember m in t.SearchMember (member.Name, true)) {
						InnerRenameMember (monitor, t, m, newName, scope);
					}
				}
			}
			
			return InnerRenameMember (monitor, cls, member, newName, scope);
		}
Exemplo n.º 2
0
		public MemberReferenceCollection FindMemberReferences (IProgressMonitor monitor, IType cls, IMember member, RefactoryScope scope, bool includeXmlComment)
		{
			MemberReferenceCollection refs = new MemberReferenceCollection ();
			Refactor (monitor, cls, scope, new RefactorDelegate (new RefactorFindMemberReferences (cls, member, refs, includeXmlComment).Refactor));
			return refs;
		}
Exemplo n.º 3
0
		public IType RenameClass (IProgressMonitor monitor, IType cls, string newName, RefactoryScope scope)
		{
			try {
				MemberReferenceCollection refs = new MemberReferenceCollection ();
				Refactor (monitor, cls, scope, new RefactorDelegate (new RefactorFindClassReferences (cls, refs, false).Refactor));
				refs.RenameAll (newName);
				
				RefactorerContext gctx = GetGeneratorContext (cls);
				IRefactorer r = GetGeneratorForClass (cls);
				
				foreach (IMethod method in cls.Methods) {
					if (method.IsConstructor)
						r.RenameMember (gctx, cls, (IMember) method, newName);
				}
				
				cls = r.RenameClass (gctx, cls, newName);
				
				gctx.Save ();
				
				return cls;
			} catch (Exception e) {
				LoggingService.LogError (GettextCatalog.GetString ("Error while renaming {0} to {1}: {2}",  cls, newName, e.ToString ()));
				return null;
			}
		}
Exemplo n.º 4
0
		IMember InnerRenameMember (IProgressMonitor monitor, IType cls, IMember member, string newName, RefactoryScope scope)
		{
			try {
				MemberReferenceCollection refs = new MemberReferenceCollection ();
				Refactor (monitor, cls, scope, new RefactorDelegate (new RefactorFindMemberReferences (cls, member, refs, false).Refactor));
				refs.RenameAll (newName);
				
				RefactorerContext gctx = GetGeneratorContext (cls);
				
				IRefactorer gen = GetGeneratorForClass (cls);
				IMember m = gen.RenameMember (gctx, cls, member, newName);
				gctx.Save ();
				return m;
			} catch (Exception e) {
				LoggingService.LogError (GettextCatalog.GetString ("Error while renaming {0} to {1}: {2}",  member, newName, e.ToString ()));
				return null;
			}
		}
Exemplo n.º 5
0
		static IEnumerable<SearchCollector.FileList> GetFileNames (Solution solution, object node, RefactoryScope scope, 
		                                                           IProgressMonitor monitor, IEnumerable<object> searchNodes)
		{
			if (!(node is IField) && !(node is IParameter) && node is IVariable || scope == RefactoryScope.File) {
				string fileName;
				if (node is IEntity) {
					fileName = ((IEntity)node).Region.FileName;
				} else if (node is ITypeParameter) {
					fileName = ((ITypeParameter)node).Region.FileName;
				} else {
					fileName = ((IVariable)node).Region.FileName;
				}
				var fileList =  GetFileList (fileName);
				if (fileList != null)
					yield return fileList;
				yield break;
			}
			
			if (node is ITypeParameter) {
				var typeParameter = node as ITypeParameter;
				if (typeParameter.Owner != null) {
					yield return SearchCollector.CollectDeclaringFiles (typeParameter.Owner);
					yield break;
				}
				var fileList =  GetFileList (typeParameter.Region.FileName);
				if (fileList != null)
					yield return fileList;
				yield break;
			}
			var par = node as IParameter;
			if (par != null) {
				node = par.Owner;
			}

			var compilationProvider = (ICompilationProvider)node;
			switch (scope) {
			case RefactoryScope.DeclaringType:
				var entity = (IEntity)compilationProvider;
				if (entity.DeclaringTypeDefinition != null)
					yield return SearchCollector.CollectDeclaringFiles (entity.DeclaringTypeDefinition);
				else
					yield return SearchCollector.CollectDeclaringFiles (entity);
				break;
			case RefactoryScope.Project:
				var sourceProject = TypeSystemService.GetProject (compilationProvider.Compilation.MainAssembly.UnresolvedAssembly.Location);
				foreach (var file in SearchCollector.CollectFiles (sourceProject, searchNodes))
					yield return file;
				break;
			default:
				var files = SearchCollector.CollectFiles (solution, searchNodes).ToList ();
				if (monitor != null)
					monitor.BeginTask (GettextCatalog.GetString ("Searching for references in solution..."), files.Count);
				foreach (var file in files) {
					if (monitor != null && monitor.IsCancelRequested)
						yield break;
					yield return file;
					if (monitor != null)
						monitor.Step (1);
				}
				if (monitor != null)
					monitor.EndTask ();
				break;
			}
		}
Exemplo n.º 6
0
 internal static IEnumerable <IMember> CollectMembers(Solution solution, IMember member, RefactoryScope scope, bool includeOverloads = true)
 {
     return(MemberCollector.CollectMembers(solution, member, scope, includeOverloads));
 }
Exemplo n.º 7
0
        public static IEnumerable <MemberReference> FindReferences(Solution solution, object member, RefactoryScope scope = RefactoryScope.Unknown, IProgressMonitor monitor = null)
        {
            if (member == null)
            {
                yield break;
            }
            if (solution == null && member is IEntity)
            {
                var project = TypeSystemService.GetProject((member as IEntity).Compilation.MainAssembly.UnresolvedAssembly.Location);
                if (project == null)
                {
                    yield break;
                }
                solution = project.ParentSolution;
            }

            IList <object> searchNodes = new [] { member };

            if (member is ITypeParameter)
            {
                // nothing
            }
            else if (member is IType)
            {
                searchNodes = CollectMembers((IType)member).ToList <object> ();
            }
            else if (member is IEntity)
            {
                var e = (IEntity)member;
                if (e.EntityType == EntityType.Destructor)
                {
                    foreach (var r in FindReferences(solution, e.DeclaringType, scope, monitor))
                    {
                        yield return(r);
                    }
                    yield break;
                }
                if (member is IMember)
                {
                    searchNodes = CollectMembers(solution, (IMember)member, scope).ToList <object> ();
                }
            }
            // prepare references finder
            var preparedFinders = new List <Tuple <ReferenceFinder, Project, IProjectContent, List <FilePath> > > ();
            var curList         = new List <FilePath> ();

            foreach (var info in GetFileNames(solution, member, scope, monitor, searchNodes))
            {
                string oldMime = null;
                foreach (var file in info.Files)
                {
                    if (monitor != null && monitor.IsCancelRequested)
                    {
                        yield break;
                    }

                    string mime = DesktopService.GetMimeTypeForUri(file);
                    if (mime != oldMime)
                    {
                        var finder = GetReferenceFinder(mime);
                        if (finder == null)
                        {
                            continue;
                        }

                        oldMime = mime;

                        curList = new List <FilePath> ();
                        preparedFinders.Add(Tuple.Create(finder, info.Project, info.Content, curList));
                    }
                    curList.Add(file);
                }
            }

            // execute search
            foreach (var tuple in preparedFinders)
            {
                var finder = tuple.Item1;
                foreach (var foundReference in finder.FindReferences(tuple.Item2, tuple.Item3, tuple.Item4, searchNodes))
                {
                    if (monitor != null && monitor.IsCancelRequested)
                    {
                        yield break;
                    }
                    yield return(foundReference);
                }
            }
        }
Exemplo n.º 8
0
		internal static IEnumerable<IMember> CollectMembers (Solution solution, IMember member, RefactoryScope scope, bool includeOverloads = true)
		{
			return MemberCollector.CollectMembers (solution, member, scope, includeOverloads);
		}
Exemplo n.º 9
0
        public MemberReferenceCollection FindMemberReferences(IProgressMonitor monitor, IType cls, IMember member, RefactoryScope scope, bool includeXmlComment)
        {
            MemberReferenceCollection refs = new MemberReferenceCollection();

            Refactor(monitor, cls, scope, new RefactorDelegate(new RefactorFindMemberReferences(cls, member, refs, includeXmlComment).Refactor));
            return(refs);
        }
Exemplo n.º 10
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.º 11
0
        public IMember RenameMember(IProgressMonitor monitor, IType cls, IMember member, string newName, RefactoryScope scope)
        {
            // rename overriden members
            if (cls.ClassType == ClassType.Interface | member.IsAbstract | member.IsVirtual)
            {
                foreach (IType t in cls.SourceProjectDom.GetSubclasses(cls))
                {
                    foreach (IMember m in t.SearchMember(member.Name, true))
                    {
                        InnerRenameMember(monitor, t, m, newName, scope);
                    }
                }
            }

            // rename base members that are overridden as well.
            if (member.IsOverride)
            {
                foreach (IType t in cls.SourceProjectDom.GetInheritanceTree(cls))
                {
                    if (t == cls)
                    {
                        continue;
                    }
                    foreach (IMember m in t.SearchMember(member.Name, true))
                    {
                        InnerRenameMember(monitor, t, m, newName, scope);
                    }
                }
            }

            return(InnerRenameMember(monitor, cls, member, newName, scope));
        }
Exemplo n.º 12
0
        IMember InnerRenameMember(IProgressMonitor monitor, IType cls, IMember member, string newName, RefactoryScope scope)
        {
            try {
                MemberReferenceCollection refs = new MemberReferenceCollection();
                Refactor(monitor, cls, scope, new RefactorDelegate(new RefactorFindMemberReferences(cls, member, refs, false).Refactor));
                refs.RenameAll(newName);

                RefactorerContext gctx = GetGeneratorContext(cls);

                IRefactorer gen = GetGeneratorForClass(cls);
                IMember     m   = gen.RenameMember(gctx, cls, member, newName);
                gctx.Save();
                return(m);
            } catch (Exception e) {
                LoggingService.LogError(GettextCatalog.GetString("Error while renaming {0} to {1}: {2}", member, newName, e.ToString()));
                return(null);
            }
        }
Exemplo n.º 13
0
        public IType RenameClass(IProgressMonitor monitor, IType cls, string newName, RefactoryScope scope)
        {
            try {
                MemberReferenceCollection refs = new MemberReferenceCollection();
                Refactor(monitor, cls, scope, new RefactorDelegate(new RefactorFindClassReferences(cls, refs, false).Refactor));
                refs.RenameAll(newName);

                RefactorerContext gctx = GetGeneratorContext(cls);
                IRefactorer       r    = GetGeneratorForClass(cls);

                foreach (IMethod method in cls.Methods)
                {
                    if (method.IsConstructor)
                    {
                        r.RenameMember(gctx, cls, (IMember)method, newName);
                    }
                }

                cls = r.RenameClass(gctx, cls, newName);

                gctx.Save();

                return(cls);
            } catch (Exception e) {
                LoggingService.LogError(GettextCatalog.GetString("Error while renaming {0} to {1}: {2}", cls, newName, e.ToString()));
                return(null);
            }
        }
Exemplo n.º 14
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.º 15
0
 internal static IEnumerable <IMember> CollectMembers(Solution solution, IMember member, RefactoryScope scope)
 {
     return(MemberCollector.CollectMembers(solution, member, scope));
 }
Exemplo n.º 16
0
		public static IEnumerable<MemberReference> FindReferences (Solution solution, object member, bool searchForAllOverloads, RefactoryScope scope = RefactoryScope.Unknown, IProgressMonitor monitor = null)
		{
			if (member == null)
				yield break;
			if (solution == null && member is IEntity) {
				var project = TypeSystemService.GetProject ((member as IEntity).Compilation.MainAssembly.UnresolvedAssembly.Location);
				if (project == null)
					yield break;
				solution = project.ParentSolution;
			}
			
			IList<object> searchNodes = new [] { member };
			if (member is ITypeParameter) {
				// nothing
			} else if (member is IType) {
				searchNodes = CollectMembers ((IType)member).ToList<object> ();
			} else if (member is IEntity) {
				var e = (IEntity)member;
				if (e.SymbolKind == SymbolKind.Destructor) {
					foreach (var r in FindReferences (solution, e.DeclaringType, searchForAllOverloads, scope, monitor)) {
						yield return r;
					}
					yield break;
				}
				if (member is IMember)
					searchNodes = CollectMembers (solution, (IMember)member, scope, searchForAllOverloads).ToList<object> ();
			}
			// prepare references finder
			var preparedFinders = new List<Tuple<ReferenceFinder, Project, IProjectContent, List<FilePath>>> ();
			var curList = new List<FilePath> ();
			int totalFiles = 0;
			foreach (var info in GetFileNames (solution, member, scope, monitor, searchNodes)) {
				string oldMime = null;
				foreach (var file in info.Files) {
					if (monitor != null && monitor.IsCancelRequested)
						yield break;
					
					string mime = DesktopService.GetMimeTypeForUri (file);
					if (mime != oldMime) {
						var finder = GetReferenceFinder (mime);
						if (finder == null)
							continue;
						
						oldMime = mime;
						
						curList = new List<FilePath> ();
						preparedFinders.Add (Tuple.Create (finder, info.Project, info.Content, curList));
					}
					curList.Add (file);
					totalFiles++;
				}
			}
			
			// execute search
			if (monitor != null)
				monitor.BeginTask (GettextCatalog.GetString ("Analyzing files..."), totalFiles);
			foreach (var tuple in preparedFinders) {
				var finder = tuple.Item1;
				foreach (var foundReference in finder.FindReferences (tuple.Item2, tuple.Item3, tuple.Item4, monitor, searchNodes)) {
					if (monitor != null && monitor.IsCancelRequested)
						yield break;
					yield return foundReference;
				}
			}
			if (monitor != null)
				monitor.EndTask ();
		}
Exemplo n.º 17
0
 public static IEnumerable <MemberReference> FindReferences(object member, RefactoryScope scope, IProgressMonitor monitor = null)
 {
     return(FindReferences(IdeApp.ProjectOperations.CurrentSelectedSolution, member, scope, monitor));
 }
Exemplo n.º 18
0
		public static IEnumerable<MemberReference> FindReferences (object member, bool searchForAllOverloads, RefactoryScope scope, IProgressMonitor monitor = null)
		{
			return FindReferences (IdeApp.ProjectOperations.CurrentSelectedSolution, member, searchForAllOverloads, scope, monitor);
		}
Exemplo n.º 19
0
		internal static IEnumerable<IMember> CollectMembers (Solution solution, IMember member, RefactoryScope scope)
		{
			return MemberCollector.CollectMembers (solution, member, scope);
		}
Exemplo n.º 20
0
        static IEnumerable <SearchCollector.FileList> GetFileNames(Solution solution, object node, RefactoryScope scope,
                                                                   IProgressMonitor monitor, IEnumerable <object> searchNodes)
        {
            if (!(node is IField) && !(node is IParameter) && node is IVariable || scope == RefactoryScope.File)
            {
                string fileName;
                if (node is IEntity)
                {
                    fileName = ((IEntity)node).Region.FileName;
                }
                else if (node is ITypeParameter)
                {
                    fileName = ((ITypeParameter)node).Region.FileName;
                }
                else
                {
                    fileName = ((IVariable)node).Region.FileName;
                }
                var fileList = GetFileList(fileName);
                if (fileList != null)
                {
                    yield return(fileList);
                }
                yield break;
            }

            if (node is ITypeParameter)
            {
                var typeParameter = node as ITypeParameter;
                if (typeParameter.Owner != null)
                {
                    yield return(SearchCollector.CollectDeclaringFiles(typeParameter.Owner));

                    yield break;
                }
                var fileList = GetFileList(typeParameter.Region.FileName);
                if (fileList != null)
                {
                    yield return(fileList);
                }
                yield break;
            }
            var par = node as IParameter;

            if (par != null)
            {
                node = par.Owner;
            }

            var compilationProvider = (ICompilationProvider)node;

            switch (scope)
            {
            case RefactoryScope.DeclaringType:
                var entity = (IEntity)compilationProvider;
                if (entity.DeclaringTypeDefinition != null)
                {
                    yield return(SearchCollector.CollectDeclaringFiles(entity.DeclaringTypeDefinition));
                }
                else
                {
                    yield return(SearchCollector.CollectDeclaringFiles(entity));
                }
                break;

            case RefactoryScope.Project:
                var sourceProject = TypeSystemService.GetProject(compilationProvider.Compilation.MainAssembly.UnresolvedAssembly.Location);
                foreach (var file in SearchCollector.CollectFiles(sourceProject, searchNodes))
                {
                    yield return(file);
                }
                break;

            default:
                var files = SearchCollector.CollectFiles(solution, searchNodes).ToList();
                if (monitor != null)
                {
                    monitor.BeginTask(GettextCatalog.GetString("Searching for references in solution..."), files.Count);
                }
                foreach (var file in files)
                {
                    if (monitor != null && monitor.IsCancelRequested)
                    {
                        yield break;
                    }
                    yield return(file);

                    if (monitor != null)
                    {
                        monitor.Step(1);
                    }
                }
                if (monitor != null)
                {
                    monitor.EndTask();
                }
                break;
            }
        }
Exemplo n.º 21
0
        public static IEnumerable <MemberReference> FindReferences(Solution solution, object member, bool searchForAllOverloads, RefactoryScope scope = RefactoryScope.Unknown, IProgressMonitor monitor = null)
        {
            if (member == null)
            {
                yield break;
            }
            if (solution == null && member is IEntity)
            {
                var project = TypeSystemService.GetProject((member as IEntity).Compilation.MainAssembly.UnresolvedAssembly.Location);
                if (project == null)
                {
                    yield break;
                }
                solution = project.ParentSolution;
            }

            IList <object> searchNodes = new [] { member };

            if (member is ITypeParameter)
            {
                // nothing
            }
            else if (member is IType)
            {
                searchNodes = CollectMembers((IType)member).ToList <object> ();
            }
            else if (member is IEntity)
            {
                var e = (IEntity)member;
                if (e.SymbolKind == SymbolKind.Destructor)
                {
                    foreach (var r in FindReferences(solution, e.DeclaringType, searchForAllOverloads, scope, monitor))
                    {
                        yield return(r);
                    }
                    yield break;
                }
                if (member is IMember)
                {
                    searchNodes = CollectMembers(solution, (IMember)member, scope, searchForAllOverloads).ToList <object> ();
                }
            }
            // prepare references finder
            var preparedFinders = new List <Tuple <ReferenceFinder, Project, IProjectContent, List <FilePath> > > ();
            var curList         = new List <FilePath> ();
            int totalFiles      = 0;

            foreach (var info in GetFileNames(solution, member, scope, monitor, searchNodes))
            {
                string oldMime = null;
                foreach (var file in info.Files)
                {
                    if (monitor != null && monitor.IsCancelRequested)
                    {
                        yield break;
                    }

                    string mime = DesktopService.GetMimeTypeForUri(file);
                    if (mime != oldMime)
                    {
                        var finder = GetReferenceFinder(mime);
                        if (finder == null)
                        {
                            continue;
                        }

                        oldMime = mime;

                        curList = new List <FilePath> ();
                        preparedFinders.Add(Tuple.Create(finder, info.Project, info.Content, curList));
                    }
                    curList.Add(file);
                    totalFiles++;
                }
            }

            // execute search
            if (monitor != null)
            {
                monitor.BeginTask(GettextCatalog.GetString("Analyzing files..."), totalFiles);
            }
            var foundOccurrences = new HashSet <Tuple <string, DomRegion> > ();

            foreach (var tuple in preparedFinders)
            {
                var finder = tuple.Item1;
                foreach (var foundReference in finder.FindReferences(tuple.Item2, tuple.Item3, tuple.Item4, monitor, searchNodes))
                {
                    if (monitor != null && monitor.IsCancelRequested)
                    {
                        yield break;
                    }
                    var tag = Tuple.Create(foundReference.FileName, foundReference.Region);
                    if (foundOccurrences.Contains(tag))
                    {
                        continue;
                    }
                    foundOccurrences.Add(tag);
                    yield return(foundReference);
                }
            }
            if (monitor != null)
            {
                monitor.EndTask();
            }
        }