Exemple #1
0
        private static List <ClassWrapperNode> GetReversePostOrderListIterative(List <ClassWrapperNode
                                                                                      > roots)
        {
            List <ClassWrapperNode>       res       = new List <ClassWrapperNode>();
            LinkedList <ClassWrapperNode> stackNode = new LinkedList <ClassWrapperNode>();
            LinkedList <int>           stackIndex   = new LinkedList <int>();
            HashSet <ClassWrapperNode> setVisited   = new HashSet <ClassWrapperNode>();

            foreach (ClassWrapperNode root in roots)
            {
                stackNode.AddLast(root);
                stackIndex.AddLast(0);
            }
            while (!(stackNode.Count == 0))
            {
                ClassWrapperNode node = stackNode.Last.Value;
                int index             = Sharpen.Collections.RemoveLast(stackIndex);
                setVisited.Add(node);
                List <ClassWrapperNode> lstSubs = node.GetSubclasses();
                for (; index < lstSubs.Count; index++)
                {
                    ClassWrapperNode sub = lstSubs[index];
                    if (!setVisited.Contains(sub))
                    {
                        stackIndex.AddLast(index + 1);
                        stackNode.AddLast(sub);
                        stackIndex.AddLast(0);
                        break;
                    }
                }
                if (index == lstSubs.Count)
                {
                    res.Add(0, node);
                    Sharpen.Collections.RemoveLast(stackNode);
                }
            }
            return(res);
        }
Exemple #2
0
        private void BuildInheritanceTree()
        {
            Dictionary <string, ClassWrapperNode> nodes = new Dictionary <string, ClassWrapperNode
                                                                          >();
            Dictionary <string, StructClass> classes        = context.GetClasses();
            List <ClassWrapperNode>          rootClasses    = new List <ClassWrapperNode>();
            List <ClassWrapperNode>          rootInterfaces = new List <ClassWrapperNode>();

            foreach (StructClass cl in classes.Values)
            {
                if (!cl.IsOwn())
                {
                    continue;
                }
                LinkedList <StructClass>      stack         = new LinkedList <StructClass>();
                LinkedList <ClassWrapperNode> stackSubNodes = new LinkedList <ClassWrapperNode>();
                stack.AddLast(cl);
                stackSubNodes.AddLast((ClassWrapperNode)null);
                while (!(stack.Count == 0))
                {
                    StructClass      clStr     = Sharpen.Collections.RemoveFirst(stack);
                    ClassWrapperNode child     = Sharpen.Collections.RemoveFirst(stackSubNodes);
                    ClassWrapperNode node      = nodes.GetOrNull(clStr.qualifiedName);
                    bool             isNewNode = (node == null);
                    if (isNewNode)
                    {
                        Sharpen.Collections.Put(nodes, clStr.qualifiedName, node = new ClassWrapperNode(clStr
                                                                                                        ));
                    }
                    if (child != null)
                    {
                        node.AddSubclass(child);
                    }
                    if (!isNewNode)
                    {
                        break;
                    }
                    else
                    {
                        bool isInterface  = clStr.HasModifier(ICodeConstants.Acc_Interface);
                        bool found_parent = false;
                        if (isInterface)
                        {
                            foreach (string ifName in clStr.GetInterfaceNames())
                            {
                                StructClass clParent = classes.GetOrNull(ifName);
                                if (clParent != null)
                                {
                                    stack.AddLast(clParent);
                                    stackSubNodes.AddLast(node);
                                    found_parent = true;
                                }
                            }
                        }
                        else if (clStr.superClass != null)
                        {
                            // null iff java/lang/Object
                            StructClass clParent = classes.GetOrNull(clStr.superClass.GetString());
                            if (clParent != null)
                            {
                                stack.AddLast(clParent);
                                stackSubNodes.AddLast(node);
                                found_parent = true;
                            }
                        }
                        if (!found_parent)
                        {
                            // no super class or interface
                            (isInterface ? rootInterfaces : rootClasses).Add(node);
                        }
                    }
                }
            }
            this.rootClasses    = rootClasses;
            this.rootInterfaces = rootInterfaces;
        }
 public virtual void AddSubclass(ClassWrapperNode node)
 {
     subclasses.Add(node);
 }