Example #1
0
        private void GetEfferentGraph(string parent, string fullName, IDictionary <string, bool> cutOffs, List <ChangeContext> found, AffectedGraph graph, bool isRootNode, TypeDefinition originalContext)
        {
            var entry    = _cache.TryGetEfferentCouplingNode(fullName);
            var afferent = _cache.TryGetAfferentCouplingNode(fullName);

            if (isRootNode)
            {
                entry = entry ?? afferent;
                found.Add(new ChangeContext(fullName, null));
                graph.AddNode(GetGraphNode(fullName, entry, true, true));
                if (entry != null && entry.MemberReference != null)
                {
                    var refer = entry.MemberReference as MethodReference;
                    if (refer != null && _testStrategies.IsTest(refer))
                    {
                        return;
                    }
                }
            }
            //TODO Greg this hamstrings some stuff but should work better in most cases
            //I think we only really need statics past here but need to look it over a bit.
            return;

            WriteWalkerDebug("checking " + fullName, 0);
            if (entry == null)
            {
                WriteWalkerDebug("efferent entry is null", 0);
                if (afferent != null && afferent.MemberReference is MethodReference)
                {
                    return;                                                                  //Leaf node to a method call
                }
            }
            if (afferent == null)
            {
                WriteWalkerDebug("afferent entry is null", 0);
            }
            if (afferent != null)
            {
                var memref           = afferent.MemberReference as MethodReference;
                MethodDefinition def = null;
                if (memref != null)
                {
                    def = memref.ThreadSafeResolve();
                }
                if (!isRootNode && def != null)
                {
                    if (def.IsGetter)
                    {
                        return;
                    }
                    if (def.DeclaringType.IsInterface)
                    {
                        return;                                //don't recurse forward on interface calls
                    }
                    if (!def.HasThis)
                    {
                        return;
                    }
                }
                var reference = afferent.MemberReference as FieldReference; //Leaf node to a field reference
                if (reference != null)
                {
                    graph.AddNode(GetGraphNode(fullName, afferent, isRootNode, false));
                    if (parent != null)
                    {
                        graph.AddConnection(parent, fullName, true);
                    }

                    found.Add(new ChangeContext(fullName, originalContext));
                }
            }

            if (entry == null)
            {
                return;
            }
            graph.AddNode(GetGraphNode(fullName, entry, isRootNode, false));
            if (parent != null)
            {
                graph.AddConnection(parent, fullName, true);
            }
            foreach (var current in entry.Couplings)
            {
                if (cutOffs.ContainsKey(current.To))
                {
                    continue;
                }
                if (current.IgnoreWalk)
                {
                    continue;
                }
                if (current.ActualReference is MethodReference && !current.IsSelfCall)
                {
                    continue;
                }
                cutOffs.Add(current.To, true);
                GetEfferentGraph(fullName, current.To, cutOffs, found, graph, false, originalContext);
            }
        }