private void ParseCompounds(string path)
        {
            this.currentFileName = @"..\..\javadoc\html\" + path;
            HtmlDocument document = new HtmlDocument();
            try
            {
                document.Load(currentFileName);
            }
            catch(Exception)
            {
                this.Log(LogKind.Warning, "Can't open "+path);
                return;
            }
            HtmlNode root = document.DocumentNode;

            String packagename = path.Split('/')[0];
            DoxNamespace ns = (DoxNamespace) Model.Compounds.First(c => c.Name == packagename);

            // Get the HtmlNode, what represents the html tag
            HtmlNode htmlnode = root.ChildNodes.First(node => node.Name == "html");
            HtmlNode bodyNode = null;
            try
            {
                bodyNode = htmlnode.ChildNodes.First(node => node.Name == "body");
            }
            // If the aren't any body tag, than the html is invalid or corrupted
            catch (InvalidOperationException)
            {
                this.Log(LogKind.Error, "Missing body tag in the html. In " + packagename);
                return;
            }

            // Get the div tag, within the compound informations are.
            HtmlNode compoundDivNode = null;
            try
            {
                compoundDivNode = bodyNode.ChildNodes.First(node => node.Name == "div" && node.Attributes.FirstOrDefault(attr => attr.Name == "class" && attr.Value == "contentContainer") != null);
            }
            // If the program can't find the package, than it exit with error.
            catch (InvalidOperationException)
            {
                this.Log(LogKind.Error, "Can't find the compounds in the package. ");
                return;
            }

            //Get the list of the compoundinformations
            HtmlNode compoundListNode = null;
            try
            {
                compoundListNode = compoundDivNode.ChildNodes.First(node => node.Name == "ul");
            }
            // If the program can't find the list of the compounds, than it exit with error.
            catch (InvalidOperationException)
            {
                this.Log(LogKind.Error, "Can't find the list of the compounds in the package.");
                return;
            }

            foreach (HtmlNode CompoundTypeList in compoundListNode.ChildNodes.Where(node => node.Name == "li"))
            {
                HtmlNode CompoundTypeTable = CompoundTypeList.ChildNodes.First(node => node.Name == "table");
                string Type = normalizeHtml(CompoundTypeTable.ChildNodes.First(node => node.Name == "tr").ChildNodes.First(node => node.Name == "th").InnerText);

                foreach (HtmlNode CompoundNode in CompoundTypeTable.ChildNodes.First(node => node.Name=="tbody").ChildNodes.Where(node => node.Name=="tr"))
                {
                    HtmlNode[] CompoundRows = CompoundNode.ChildNodes.Where(node => node.Name == "td").ToArray();
                    CompoundIndex ci = new CompoundIndex();
                    this.Index.Compounds.Add(ci);
                    ParseCompound(ci, Type);
                    ci.Name = CompoundRows[0].InnerText;
                    ci.Identifier = ns.Name + "_" + ci.Name;

                    DoxClassifier c;
                    if (Type == "Class")
                    {
                        ci.Kind = CompoundKind.Class;
                        c = new DoxClass();
                    }
                    else if (Type == "Interface")
                    {
                        ci.Kind = CompoundKind.Interface;
                        c = new DoxInterface();
                    }
                    else if (Type == "Exception" || Type == "Error")
                    {
                        ci.Kind = CompoundKind.Exception;
                        c = new DoxClass();

                    }
                    else if (Type == "Enum")
                    {
                        ci.Kind = CompoundKind.Enum;
                        c = new DoxEnum();
                    }
                    else
                    {
                        this.Log(LogKind.Warning, Type + " isn't a valid compound type.");
                        continue;
                    }

                    c.Identifier = ci.Identifier;
                    c.Name = ci.Name;
                    c.Kind = ci.Kind;

                    this.ProcessCompounds.Add(CompoundRows[0].ChildNodes.First(node => node.Name == "a").Attributes.First(attr => attr.Name == "href").Value);

                    // NEED TO CHANGE!
                    String description = normalizeHtml(CompoundRows[1].InnerText);

                    ci.Compound = c;
                    ns.Classifiers.Add(c);
                    this.Model.Compounds.Add(c);
                    this.Index.CompoundIndexRefs.Add(ci.Identifier, ci);
                    this.Model.CompoundRefs.Add(ci.Identifier, ci.Compound);
                }

            }
            HtmlNode briefDescriptionNode = compoundDivNode.ChildNodes.FirstOrDefault(node => node.Name == "div" && node.Attributes.First(attr => attr.Name == "class" && attr.Value == "block")!=null);
            if(briefDescriptionNode != null)
            {
                String briefDescription = normalizeHtml(briefDescriptionNode.InnerText);
            }
            this.Log(LogKind.Info, "Processing of " + this.currentFileName + " has ended.");
        }
 void ParseCompound(CompoundIndex ci, string type)
 {
     if(type == "Class")
     {
         ci.Kind = CompoundKind.Class;
     }
     else if(type == "Interface")
     {
         ci.Kind = CompoundKind.Interface;
     }
     else if(type == "Exception" || type == "Error")
     {
         ci.Kind = CompoundKind.Exception;
     }
     else if (type == "Enum")
     {
         ci.Kind = CompoundKind.Enum;
     }
     else
     {
         this.Log(LogKind.Warning, type + " isn't a valid compound type.");
     }
 }
Exemplo n.º 3
0
        private void parseInterface(Type Interface)
        {
            if (Interface.Namespace == null || Interface.Name.Any(c => c == '<' || c == '>'))
            {
                //this.Log(LogKind.Warning,Class.ToString()+ " isn't in any namespace.");
                return;
            }
            FieldInfo[] field = Interface.GetFields(BindingFlags.NonPublic | BindingFlags.Public
            | BindingFlags.Instance | BindingFlags.Static);
            PropertyInfo[] propertys = Interface.GetProperties(
            BindingFlags.NonPublic | BindingFlags.Public
            | BindingFlags.Instance | BindingFlags.Static);
            MethodInfo[] methods = Interface.GetMethods(BindingFlags.NonPublic | BindingFlags.Public
            | BindingFlags.Instance | BindingFlags.Static);
            ConstructorInfo[] constructors = Interface.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public
            | BindingFlags.Instance | BindingFlags.Static);
            Type[] NestedTypes = Interface.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public
            | BindingFlags.Instance | BindingFlags.Static);

            DoxNamespace dns = (DoxNamespace)Model.Compounds.FirstOrDefault(c => c.Identifier.Equals(Interface.Namespace));
            if(dns == null)
            {
                CompoundIndex ci = new CompoundIndex();
                this.Index.Compounds.Add(ci);
                ci.Name = Interface.Namespace;
                ci.Identifier = ci.Name;
                ci.Kind = CompoundKind.Namespace;

                DoxNamespace c = new DoxNamespace();
                c.Identifier = ci.Identifier;
                c.Name = ci.Name;
                c.Kind = ci.Kind;

                dns = c;

                ci.Compound = c;
                this.Model.Compounds.Add(c);
                this.Index.CompoundIndexRefs.Add(ci.Identifier, ci);
                this.Model.CompoundRefs.Add(ci.Identifier, ci.Compound);
            }
            DoxInterface dc = new DoxInterface();
            dc.Abstract = Interface.IsAbstract;
            dc.Identifier = Interface.FullName;
            dc.Kind = CompoundKind.Interface;
            dc.Name = Interface.FullName;
            dc.Sealed = Interface.IsSealed;

            if (propertys.Length > 0)
            {
                parseProperty(propertys, dc);
            }
            if (field.Length > 0)
            {
                parseField(field, dc);
            }
            if (constructors.Length > 0)
            {
                parseCtor(constructors, dc);
            }
            if(methods.Length > 0)
            {
                parseMethod(methods, dc);
            }

            dns.Classifiers.Add(dc);
            CompoundIndex compi = new CompoundIndex();
            this.Index.Compounds.Add(compi);
            compi.Name = dc.Name;
            compi.Identifier = dc.Identifier;
            compi.Kind = CompoundKind.Namespace;
            compi.Compound = dc;
            this.Model.Compounds.Add(dc);
            this.Index.CompoundIndexRefs.Add(compi.Identifier, compi);
            this.Model.CompoundRefs.Add(compi.Identifier, compi.Compound);
        }
        private void ParsePackages()
        {
            this.currentFileName = this.IndexFile;
            HtmlDocument document = new HtmlDocument();
            try
            {
                document.Load(currentFileName);
            }
            catch (Exception)
            {
                this.Log(LogKind.Error, "Can't open " + this.currentFileName + ".");
                return;
            }
            HtmlNode root = document.DocumentNode;

            // Get the HtmlNode, what represents the html tag
            HtmlNode htmlnode = root.ChildNodes.First(node => node.Name == "html");
            // Get the node, what represents the head tag
            HtmlNode headNode = null;
            try
            {
                headNode = htmlnode.ChildNodes.First(node => node.Name == "head");
            }
            // If the aren't any head tag, than the html is invalid or corrupted
            catch(InvalidOperationException)
            {
                this.Log(LogKind.Error, "Missing head tag in the html. Program is terminating.");
                return;
            }
            // Find the comment, where the version of the javadoc was writen
            HtmlNode versionnode = headNode.ChildNodes.First(node => node.Name == "#comment");
            String version = versionnode.InnerHtml;
            version = version.Split('(', ')')[1];
            this.Index.Version = version;

            HtmlNode bodyNode = null;
            try
            {
                bodyNode = htmlnode.ChildNodes.First(node => node.Name == "body");
            }
            // If the aren't any body tag, than the html is invalid or corrupted
            catch (InvalidOperationException)
            {
                this.Log(LogKind.Error, "Missing body tag in the html. Program is terminating.");
                return;
            }
            // Get the div tag, what contains the informations about the packages
            HtmlNode packageDivNode = null;
            try
            {
                packageDivNode = bodyNode.ChildNodes.First(node => node.Name == "div" && node.Attributes.FirstOrDefault(attr => attr.Name == "class" && attr.Value =="contentContainer")!=null);
            }
            // If the program can't find the package, than it exit with error.
            catch (InvalidOperationException)
            {
                this.Log(LogKind.Error, "Can't find the packages. Program is terminating.");
                return;
            }
            // Get the table, where is the data of the packages.
            HtmlNode packageTableNode = null;
            try
            {
                packageTableNode = packageDivNode.ChildNodes.First(node => node.Name == "table").ChildNodes.First(node => node.Name == "tbody");
            }
            catch (InvalidOperationException)
            {
                this.Log(LogKind.Error, "Can't find the data of the packages. Program is terminating.");
                return;
            }
            foreach (var packagerow in packageTableNode.ChildNodes.Where(node => node.Name == "tr"))
            {
                HtmlNode[] datas = packagerow.ChildNodes.Where(node => node.Name == "td").ToArray();
                CompoundIndex ci = new CompoundIndex();
                this.Index.Compounds.Add(ci);
                ci.Name = datas[0].ChildNodes.ElementAt(0).InnerHtml;
                ci.Identifier = ci.Name;
                ci.Kind = CompoundKind.Namespace;

                DoxNamespace c = new DoxNamespace();
                c.Identifier = ci.Identifier;
                c.Name = ci.Name;
                c.Kind = ci.Kind;

                this.ProcessPackages.Add(datas[0].ChildNodes.ElementAt(0).Attributes.ElementAt(0).Value);
                // NEED TO CHANGE!
                HtmlNode desc = datas[1].ChildNodes.FirstOrDefault(node => node.Name == "div" && node.Attributes.FirstOrDefault(attr => attr.Name == "class" && attr.Value == "block") != null);
                if(desc != null)
                {
                    String Description = normalizeHtml(desc.InnerText);
                    DocPara newPara = new DocPara();
                    DocText desc_text = new DocText();
                    desc_text.Text = Description;
                    newPara.Commands.Add(desc_text);
                    c.Description.Paragraphs.Add(newPara);
                }

                ci.Compound = c;

                this.Model.Compounds.Add(c);
                this.Index.CompoundIndexRefs.Add(ci.Identifier, ci);
                this.Model.CompoundRefs.Add(ci.Identifier, ci.Compound);
            }
            this.Log(LogKind.Info, "Processing of " + this.currentFileName + " has ended.");
        }
Exemplo n.º 5
0
        private void parseEnum(Type Enum)
        {
            if (Enum.Namespace == null || Enum.Name.Any(c => c == '<' || c == '>'))
            {
                //this.Log(LogKind.Warning,Class.ToString()+ " isn't in any namespace.");
                return;
            }
            FieldInfo[] field = Enum.GetFields().Where(c => !c.Name.Equals("value__")).ToArray();
            PropertyInfo[] propertys = Enum.GetProperties();
            MethodInfo[] methods = Enum.GetMethods();
            ConstructorInfo[] constructors = Enum.GetConstructors();
            Type[] NestedTypes = Enum.GetNestedTypes();

            DoxNamespace dns = (DoxNamespace)Model.Compounds.FirstOrDefault(c => c.Identifier.Equals(Enum.Namespace));
            if (dns == null)
            {
                CompoundIndex ci = new CompoundIndex();
                this.Index.Compounds.Add(ci);
                ci.Name = Enum.Namespace;
                ci.Identifier = ci.Name;
                ci.Kind = CompoundKind.Namespace;

                DoxNamespace c = new DoxNamespace();
                c.Identifier = ci.Identifier;
                c.Name = ci.Name;
                c.Kind = ci.Kind;

                dns = c;

                ci.Compound = c;
                this.Model.Compounds.Add(c);
                this.Index.CompoundIndexRefs.Add(ci.Identifier, ci);
                this.Model.CompoundRefs.Add(ci.Identifier, ci.Compound);
            }
            DoxEnum dc = new DoxEnum();
            dc.Abstract = Enum.IsAbstract;
            dc.Identifier = Enum.FullName.Replace('+', '.');
            dc.Kind = CompoundKind.Enum;
            dc.Name = Enum.FullName;
            dc.Sealed = Enum.IsSealed;

            if (propertys.Length > 0)
            {
                parseProperty(propertys, dc);
            }
            if (field.Length > 0)
            {
                parseField(field, dc);
            }
            if (methods.Length > 0)
            {
                parseMethod(methods, dc);
            }
            if (constructors.Length > 0)
            {
                parseCtor(constructors, dc);
            }

            dns.Classifiers.Add(dc);
            CompoundIndex compi = new CompoundIndex();
            this.Index.Compounds.Add(compi);
            compi.Name = dc.Name;
            compi.Identifier = dc.Identifier;
            compi.Kind = CompoundKind.Namespace;
            compi.Compound = dc;
            this.Model.Compounds.Add(dc);
            this.Index.CompoundIndexRefs.Add(compi.Identifier, compi);
            this.Model.CompoundRefs.Add(compi.Identifier, compi.Compound);
        }