Beispiel #1
0
        private void CreateModuleTree(XSharpLibraryProject prjNode, XFile scope, XSharpModuleId moduleId)
        {
            if (null == scope || XSolution.IsClosing)
            {
                return;
            }

            if (!scope.HasCode)
            {
                return;
            }
            // Retrieve all Types
            // !!! WARNING !!! The XFile object (scope) comes from the DataBase
            // We should retrieve TypeList from the DataBase.....
            var namespaces = XSharpModel.XDatabase.GetNamespacesInFile(scope.Id.ToString());

            if (namespaces == null)
            {
                return;
            }
            //
            var elements = XDbResultHelpers.BuildTypesInFile(scope, namespaces);

            // First search for NameSpaces
            foreach (XTypeDefinition xType in elements)
            {
                if (xType.Kind == Kind.Namespace)
                {
                    // Does that NameSpace already exist ?
                    // Search for the corresponding NameSpace
                    XSharpLibraryNode newNode;
                    LibraryNode       nsNode = prjNode.SearchNameSpace(xType.Name);
                    if (nsNode is XSharpLibraryNode)
                    {
                        newNode = (XSharpLibraryNode)nsNode;
                        newNode.Depends(moduleId.ItemID);
                    }
                    else
                    {
                        newNode = new XSharpLibraryNode(xType, "", moduleId.Hierarchy, moduleId.ItemID);

                        // NameSpaces are always added to the root.
                        prjNode.AddNode(newNode);
                        newNode.parent = prjNode;
                    }
                    // Handle Global Scope here
                    // It contains Function/Procedure/etc...
                    if (newNode.Name == "(Global Scope)")
                    {
                        CreateGlobalTree(newNode, xType, moduleId);
                    }
                    lock (files)
                    {
                        files.Add(moduleId, newNode);
                    }
                }
            }

            // Retrieve Classes from the file
            var types = XSharpModel.XDatabase.GetTypesInFile(scope.Id.ToString());

            if (types == null)
            {
                return;
            }
            elements = XDbResultHelpers.BuildFullTypesInFile(scope, types);
            // Now, look for Classes
            foreach (XTypeDefinition xType in elements)
            {
                // Is it a kind of Type ?
                if ((xType.Kind.IsType()))
                {
                    string nSpace = prjNode.DefaultNameSpace;
                    if (!String.IsNullOrEmpty(xType.Namespace))
                    {
                        nSpace = xType.Namespace;
                    }
                    // Search for the corresponding NameSpace
                    LibraryNode nsNode = prjNode.SearchNameSpace(nSpace);
                    if (nsNode == null)
                    {
                        nsNode = prjNode.SearchClass(nSpace);
                    }

                    if (nsNode is XSharpLibraryNode)
                    {
                        XSharpLibraryNode xsNSNode = (XSharpLibraryNode)nsNode;
                        // So the Class node will belong to that NameSpace Node
                        // Now, try to check if such Type already exist
                        XSharpLibraryNode newNode;
                        LibraryNode       newTmpNode;
                        newTmpNode = xsNSNode.SearchClass(xType.Name);
                        if (newTmpNode is XSharpLibraryNode)
                        {
                            newNode = (XSharpLibraryNode)newTmpNode;
                            newNode.Depends(moduleId.ItemID);
                        }
                        else
                        {
                            newNode = new XSharpLibraryNode(xType, "", moduleId.Hierarchy, moduleId.ItemID);
                            nsNode.AddNode(newNode);
                            newNode.parent = nsNode;
                        }
                        //
                        // Insert Members
                        CreateMembersTree(newNode, xType, moduleId);
                        //
                        lock (files)
                        {
                            files.Add(moduleId, newNode);
                        }
                    }
                    else
                    {
                        // Not found !?
                    }
                }
            }
        }
        private void CreateModuleTree(XSharpLibraryProject prjNode, XFile scope, XSharpModuleId moduleId)
        {
            if ((null == scope))
            {
                return;
            }
            if (!scope.HasCode)
            {
                return;
            }
            // Retrieve all Types
            var elements = scope.TypeList;

            if (elements == null)
            {
                return;
            }
            //
            // First search for NameSpaces
            foreach (KeyValuePair <string, XType> pair in elements)
            {
                XType xType = pair.Value;
                if (xType.Kind == Kind.Namespace)
                {
                    // Does that NameSpave already exist ?
                    // Search for the corresponding NameSpace
                    XSharpLibraryNode newNode;
                    LibraryNode       nsNode = prjNode.SearchNameSpace(xType.Name);
                    if (nsNode is XSharpLibraryNode)
                    {
                        newNode = (XSharpLibraryNode)nsNode;
                        newNode.Depends(moduleId.ItemID);
                    }
                    else
                    {
                        newNode = new XSharpLibraryNode(xType, "", moduleId.Hierarchy, moduleId.ItemID);

                        // NameSpaces are always added to the root.
                        prjNode.AddNode(newNode);
                        newNode.parent = prjNode;
                    }
                    // Handle Global Scope here
                    // It contains Function/Procedure/etc...
                    if (newNode.Name == "(Global Scope)")
                    {
                        CreateGlobalTree(newNode, xType, moduleId);
                    }
                    lock (files)
                    {
                        files.Add(moduleId, newNode);
                    }
                }
            }

            // Now, look for Classes
            foreach (KeyValuePair <string, XType> pair in elements)
            {
                XType xType = pair.Value;
                // Is it a kind of Type ?
                if ((xType.Kind.IsType()))
                {
                    string nSpace = prjNode.DefaultNameSpace;
                    if (!String.IsNullOrEmpty(xType.NameSpace))
                    {
                        nSpace = xType.NameSpace;
                    }
                    // Search for the corresponding NameSpace
                    LibraryNode nsNode = prjNode.SearchNameSpace(nSpace);
                    if (nsNode is XSharpLibraryNode)
                    {
                        XSharpLibraryNode xsNSNode = (XSharpLibraryNode)nsNode;
                        // So the Class node will belong to that NameSpace Node
                        // Now, try to check if such Type already exist
                        XSharpLibraryNode newNode;
                        LibraryNode       newTmpNode;
                        newTmpNode = xsNSNode.SearchClass(xType.Name);
                        if (newTmpNode is XSharpLibraryNode)
                        {
                            newNode = (XSharpLibraryNode)newTmpNode;
                            newNode.Depends(moduleId.ItemID);
                        }
                        else
                        {
                            newNode = new XSharpLibraryNode(xType, "", moduleId.Hierarchy, moduleId.ItemID);
                            nsNode.AddNode(newNode);
                            newNode.parent = nsNode;
                        }
                        // Insert Members
                        CreateMembersTree(newNode, xType, moduleId);
                        //
                        lock (files)
                        {
                            files.Add(moduleId, newNode);
                        }
                    }
                    else
                    {
                        // Not found !?
                    }
                }
            }
        }