/// <summary>
        /// Builds a graph of derived type definitions.
        /// </summary>
        public static TypeGraphNode BuildDerivedTypesGraph(ITypeDefinition baseType)
        {
            if (baseType == null)
            {
                throw new ArgumentNullException("baseType");
            }
            var solutionSnapshot = GetSolutionSnapshot(baseType.Compilation);
            var assemblies       = GetProjectsThatCouldReferenceEntity(baseType).Select(p => solutionSnapshot.GetCompilation(p).MainAssembly);
            var graph            = new TypeGraph(assemblies);
            var node             = graph.GetNode(baseType);

            if (node != null)
            {
                // only derived types were requested, so don't return the base types
                // (this helps the GC to collect the unused parts of the graph more quickly)
                node.BaseTypes.Clear();
                return(node);
            }
            else
            {
                return(new TypeGraphNode(baseType));
            }
        }
Ejemplo n.º 2
0
        public void Run()
        {
            var assemblies = GetAllAssemblies();

            assemblies.ContinueWith(delegate(Task <HashSet <IAssembly> > arg) {
                using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true)) {
                    monitor.BeginTask(GettextCatalog.GetString("Building type graph in solution ..."), 1);
                    var tg   = new TypeGraph(arg.Result);
                    var node = tg.GetNode(entity.DeclaringTypeDefinition);
                    monitor.EndTask();
                    if (node == null)
                    {
                        return;
                    }
                    Gtk.Application.Invoke(delegate {
                        Stack <IList <TypeGraphNode> > derivedTypes = new Stack <IList <TypeGraphNode> > ();
                        derivedTypes.Push(node.DerivedTypes);
                        HashSet <ITypeDefinition> visitedType = new HashSet <ITypeDefinition> ();
                        while (derivedTypes.Count > 0)
                        {
                            foreach (var derived in derivedTypes.Pop())
                            {
                                if (visitedType.Contains(derived.TypeDefinition))
                                {
                                    continue;
                                }
                                derivedTypes.Push(tg.GetNode(derived.TypeDefinition).DerivedTypes);
                                visitedType.Add(derived.TypeDefinition);
                                var impMember = derived.TypeDefinition.Compilation.Import(entity);
                                if (impMember == null)
                                {
                                    continue;
                                }
                                IMember derivedMember;
                                if (entity.DeclaringTypeDefinition.Kind == TypeKind.Interface)
                                {
                                    derivedMember = derived.TypeDefinition.GetMembers(null, GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault(
                                        m => m.ImplementedInterfaceMembers.Any(im => im.Region == entity.Region)
                                        );
                                }
                                else
                                {
                                    derivedMember = InheritanceHelper.GetDerivedMember(impMember, derived.TypeDefinition);
                                }
                                if (derivedMember == null || string.IsNullOrEmpty(derivedMember.Region.FileName))
                                {
                                    continue;
                                }
                                var tf    = TextFileProvider.Instance.GetReadOnlyTextEditorData(derivedMember.Region.FileName);
                                var start = tf.LocationToOffset(derivedMember.Region.Begin);
                                tf.SearchRequest.SearchPattern = derivedMember.Name;
                                var sr = tf.SearchForward(start);
                                if (sr != null)
                                {
                                    start = sr.Offset;
                                }

                                monitor.ReportResult(new MemberReference(derivedMember, derivedMember.Region, start, derivedMember.Name.Length));
                            }
                        }
                    });
                }
            });
        }
Ejemplo n.º 3
0
        public void Run()
        {
            var assemblies = new HashSet <IAssembly> ();

            foreach (var project in IdeApp.ProjectOperations.CurrentSelectedSolution.GetAllProjects())
            {
                var comp = TypeSystemService.GetCompilation(project);
                if (comp == null)
                {
                    continue;
                }
                assemblies.Add(comp.MainAssembly);
            }

            TypeGraph tg   = new TypeGraph(assemblies);
            var       node = tg.GetNode(entity.DeclaringTypeDefinition);

            using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true)) {
                Stack <IList <TypeGraphNode> > derivedTypes = new Stack <IList <TypeGraphNode> > ();
                derivedTypes.Push(node.DerivedTypes);
                HashSet <ITypeDefinition> visitedType = new HashSet <ITypeDefinition> ();
                while (derivedTypes.Count > 0)
                {
                    foreach (var derived in derivedTypes.Pop())
                    {
                        if (visitedType.Contains(derived.TypeDefinition))
                        {
                            continue;
                        }
                        derivedTypes.Push(tg.GetNode(derived.TypeDefinition).DerivedTypes);
                        visitedType.Add(derived.TypeDefinition);
                        var impMember = derived.TypeDefinition.Compilation.Import(entity);
                        if (impMember == null)
                        {
                            continue;
                        }
                        IMember derivedMember;
                        if (entity.DeclaringTypeDefinition.Kind == TypeKind.Interface)
                        {
                            derivedMember = derived.TypeDefinition.GetMembers(null, GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault(
                                m => m.ImplementedInterfaceMembers.Any(im => im.Region == entity.Region)
                                );
                        }
                        else
                        {
                            derivedMember = InheritanceHelper.GetDerivedMember(impMember, derived.TypeDefinition);
                        }
                        if (derivedMember == null)
                        {
                            continue;
                        }
                        var tf    = TextFileProvider.Instance.GetReadOnlyTextEditorData(derivedMember.Region.FileName);
                        var start = tf.LocationToOffset(derivedMember.Region.Begin);
                        tf.SearchRequest.SearchPattern = derivedMember.Name;
                        var sr = tf.SearchForward(start);
                        if (sr != null)
                        {
                            start = sr.Offset;
                        }

                        monitor.ReportResult(new MemberReference(derivedMember, derivedMember.Region, start, derivedMember.Name.Length));
                    }
                }
            }
        }