Ejemplo n.º 1
0
 public Framework(Framework f)
 {
     this.assembly = f.assembly;
     this.name = f.name;
     this.path = f.path;
     this.source = f.source;
     this.usings = f.usings;
 }
        protected void PatchDiscussion(String baseFolder, DocSet docSet, Framework f, FrameworkEntity entity)
        {
            String path = entity.GetPath (baseFolder, this.Type);
            if (path == null || !File.Exists(path)) {
                return;
            }

            String contents = File.ReadAllText (path);
            bool modified = false;

            // Search for discussion parts
            int index = 0;
            int beginning = 0;
            int ending = 0;
            while ((beginning = contents.IndexOf(DISCUSSION_BEGIN, index)) != -1) {
                ending = contents.IndexOf (DISCUSSION_END, beginning);
                String content = contents.Substring (beginning, ending + DISCUSSION_END.Length - beginning);
                String replacement = content;

                // Count opening and closing paragraphs
                int opening = DISCUSSION_OPENING_REGEX.Matches (replacement).Count;
                int closing = DISCUSSION_CLOSING_REGEX.Matches (replacement).Count;

                if (opening < closing) {
                    throw new NotSupportedException ();
                }
                if (opening > closing) {
                    replacement = replacement.Replace ("<!-- begin discussion -->", String.Empty);
                    replacement = replacement.Replace ("<!-- end discussion -->", String.Empty);
                    for (int i = closing; i < opening; i++) {
                        replacement += "</p>";
                    }
                    replacement = "<!-- begin discussion -->" + replacement;
                    replacement = replacement + "<!-- end discussion -->";

                    contents = contents.Replace (content, replacement);
                    modified |= true;
                }

                index = beginning + replacement.Length;
            }

            if (modified) {
                this.Log (Level.Info, String.Format ("Patching {0} for '{1}'...", this.Type, entity.name));
                File.WriteAllText (path, contents);
            } else {
                this.Log (Level.Debug, String.Format ("Skipping {0} for '{1}'...", this.Type, entity.name));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Generate an XML fragment ready to be included in the entities list of the generator.
        /// </summary>
        private void GenerateDescriptor(String baseFolder, Framework f)
        {
            this.Log (Level.Info, "Placing Doxygen files for '{0}'...", f.name);

            // Set file names
            String doxygenFolder = Path.Combine (baseFolder, f.name, DocumentType.Doxygen.ToString ());
            String indexPath = Path.Combine (doxygenFolder, "index.xml");
            String descriptorPath = Path.Combine (baseFolder, f.name, f.name + ".xml");

            // Deserialize Doxygen index
            DoxygenType index;
            XmlSerializer serializer = new XmlSerializer (typeof(DoxygenType));
            using (StreamReader reader = new StreamReader(indexPath)) {
                index = (DoxygenType)serializer.Deserialize (reader);
            }

            // Collect entities
            List<FrameworkType> types = new List<FrameworkType> ();
            List<FrameworkClass> classes = new List<FrameworkClass> ();
            List<FrameworkProtocol> protocols = new List<FrameworkProtocol> ();
            List<FrameworkStructure> structures = new List<FrameworkStructure> ();
            List<FrameworkEnumeration> enumerations = new List<FrameworkEnumeration> ();

            foreach (CompoundType compound in index.compound.Where(c => c.kind == CompoundKind.@class)) {
                String name = compound.name;
                String categoryName = name.Replace ('(', '_').Trim (')');
                int pos = name.IndexOf ("(");
                String className = (pos != -1) ? name.Substring (0, pos) : name;

                FrameworkClass entity = new FrameworkClass ();
                entity.Framework = f;
                entity.name = categoryName;
                if (className != categoryName) {
                    Patch patch = new Patch ();
                    patch.type = DocumentType.Model;
                    patch.Change = new String[]{ "<![CDATA[AdditionFor=\"" + className + "\"]]>"};
                    entity.Patch = new Patch[]{ patch};
                }
                classes.Add (entity);

                // Place the xml file in the right folder
                String inputFile = Path.Combine (doxygenFolder, compound.refid + ".xml");
                String outputFile = entity.GetPath (baseFolder, DocumentType.Xhtml);
                File.Copy (inputFile, outputFile, true);
            }

            foreach (CompoundType compound in index.compound.Where(c => c.kind == CompoundKind.category)) {
                String name = compound.name;
                String categoryName = name.Replace ('(', '_').Trim (')');
                String className = name.Substring (0, name.IndexOf ("("));

                FrameworkClass entity = new FrameworkClass ();
                entity.Framework = f;
                entity.name = categoryName;
                Patch patch = new Patch ();
                patch.type = DocumentType.Model;
                patch.Change = new String[]{ "<![CDATA[AdditionFor=\"" + className + "\"]]>"};
                entity.Patch = new Patch[]{ patch};
                classes.Add (entity);

                // Place the xml file in the right folder
                String inputFile = Path.Combine (doxygenFolder, compound.refid + ".xml");
                String outputFile = entity.GetPath (baseFolder, DocumentType.Xhtml);
                File.Copy (inputFile, outputFile, true);
            }

            foreach (CompoundType compound in index.compound.Where(c => c.kind == CompoundKind.file)) {
                String name = compound.name;
                if (!name.EndsWith (".h")) {
                    continue;
                }
                name = name.Replace ("+", "_").Replace (".h", String.Empty);
                String className = name + "_Definitions";

                FrameworkClass entity = new FrameworkClass ();
                entity.Framework = f;
                entity.name = className;
                Patch patch = new Patch ();
                patch.type = DocumentType.Model;
                patch.Change = new String[]{ "<![CDATA[AdditionFor=\"" + className + "\"]]>"};
                entity.Patch = new Patch[]{ patch};
                classes.Add (entity);

                // Place the xml file in the right folder
                String inputFile = Path.Combine (doxygenFolder, compound.refid + ".xml");
                String outputFile = entity.GetPath (baseFolder, DocumentType.Xhtml);
                File.Copy (inputFile, outputFile, true);
            }

            foreach (CompoundType compound in index.compound.Where(c => c.kind == CompoundKind.protocol)) {
                String name = compound.name;
                if (name.EndsWith ("-p")) {
                    name = name.Replace ("-p", String.Empty);
                }

                FrameworkProtocol entity = new FrameworkProtocol ();
                entity.Framework = f;
                entity.name = name;
                protocols.Add (entity);

                // Place the xml file in the right folder
                String inputFile = Path.Combine (doxygenFolder, compound.refid + ".xml");
                String outputFile = entity.GetPath (baseFolder, DocumentType.Xhtml);
                File.Copy (inputFile, outputFile, true);
            }

            foreach (CompoundType compound in index.compound.Where(c => c.kind == CompoundKind.@struct)) {
                String name = compound.name;
                name = name.TrimStart ('_');

                FrameworkStructure entity = new FrameworkStructure ();
                entity.Framework = f;
                entity.name = name;
                structures.Add (entity);

                // Place the xml file in the right folder
                String inputFile = Path.Combine (doxygenFolder, compound.refid + ".xml");
                String outputFile = entity.GetPath (baseFolder, DocumentType.Xhtml);
                File.Copy (inputFile, outputFile, true);
            }

            // Save the framework descriptor
            Framework framework = new Framework (f);
            framework.Types = types.ToArray ();
            framework.Classes = classes.ToArray ();
            framework.Protocols = protocols.ToArray ();
            framework.Structures = structures.ToArray ();
            framework.Enumerations = enumerations.ToArray ();
            framework.SaveToFile (descriptorPath);
        }
Ejemplo n.º 4
0
 private IXhtmlTypeParser GetTypeParser(Framework f, FrameworkEntity e, TextWriter writer)
 {
     switch (f.style) {
     case PageStyle.Cocoa:
         return new XhtmlCocoaTypeParser (this.settings, this.typeManager, writer);
     case PageStyle.Classic:
         return new XhtmlClassicTypeParser (this.settings, this.typeManager, writer);
     case PageStyle.Doxygen:
         return new XhtmlDoxygenTypeParser (this.settings, this.typeManager, writer);
     default:
         throw new NotSupportedException ("No style defined for " + f.name);
     }
 }
Ejemplo n.º 5
0
        private void Convert(Framework f, FrameworkEntity e, String sourcePath, String destinationPath, TextWriter writer = null)
        {
            switch (e.type) {
            case FrameworkEntityType.T:
                {
                    IXhtmlTypeParser parser = this.GetTypeParser (f, e, writer);

                    TypedEntity entity = new TypedEntity ();
                    entity.Namespace = f.name;
                    entity.Name = e.name;
                    entity.Nature = e.type;

                    parser.Parse (entity, sourcePath);
                    entity.SaveTo (destinationPath);
                }
                break;
            case FrameworkEntityType.C:
                {
                    IXhtmlClassParser parser = this.GetClassParser (f, e, writer);

                    ClassEntity entity = new ClassEntity ();
                    entity.Namespace = f.name;
                    entity.Name = e.name;
                    entity.Nature = e.type;

                    parser.Parse (entity, sourcePath);
                    entity.SaveTo (destinationPath);
                }
                break;
            case FrameworkEntityType.P:
                {
                    IXhtmlClassParser parser = this.GetProtocolParser (f, e, writer);

                    ProtocolEntity entity = new ProtocolEntity ();
                    entity.Namespace = f.name;
                    entity.Name = e.name;
                    entity.Nature = e.type;

                    parser.Parse (entity, sourcePath);
                    entity.SaveTo (destinationPath);
                }
                break;
            default:
                break;
            }
        }