예제 #1
0
        public List <KeyValuePair <string, NamespaceOutput> > GetTypescript(TSNamespaceSet namespaceSet)
        {
            var ret = namespaceSet.Namespaces.Select(kvp => GetTypescript(kvp)).ToList();

            var mergedNominalsBuilder = new StringBuilder();
            var mergedNominals        = namespaceSet.Namespaces.SelectMany(x => x.Value.NominalTypes).Distinct().ForEach(x => writeNominalType(x, mergedNominalsBuilder));

            ret.Values().ForEach(x => x.MergedNominalTypes = mergedNominalsBuilder.ToString());

            return(ret);
        }
예제 #2
0
        public TSNamespaceSet Generate()
        {
            var ret = new TSNamespaceSet();

            Func <string, bool> fileFilter = s => {
                if (s.EndsWith("_8idl.xml"))
                {
                    return(false);
                }
                if (s.StartsWith("dir_"))
                {
                    return(false);
                }
                if (s == "index.xml")
                {
                    return(false);
                }
                return(true);
            };

            foreach (var x in EnumerateFiles(idlPath, "*.xml").Where(fileFilter).Select(x => (path: x, doc: XDocument.Load(x))))
            {
                var root        = x.doc.Root;
                var compounddef = root.Elements("compounddef").SingleOrDefault();
                if (compounddef == null)
                {
                    continue;
                }

                string ns;
                switch ((string)compounddef.Attribute("kind"))
                {
                case "file":
                case "page":
                case "dir":
                    continue;

                case "interface":
                case "exception":
                case "service":
                case "singleton":
                case "struct":
                    var kvp = parseCompound(compounddef);
                    (ns, _) = SplitName(kvp.Key);
                    kvp.AddInterfaceTo(ret.GetNamespace(ns));
                    break;

                case "namespace":
                    ns = compounddef.Element("compoundname").Value.DeJavaName();
                    var nsDesc = ret.GetNamespace(ns);
                    foreach (var sectiondef in compounddef.Elements("sectiondef"))
                    {
                        switch ((string)sectiondef.Attribute("kind"))
                        {
                        case "enum":
                            sectiondef.Elements("memberdef").Select(y => parseEnum(y, ns)).AddRangeTo(nsDesc.Enums);
                            break;

                        case "typedef":
                            sectiondef.Elements("memberdef").Select(y => parseTypedef(y, ns)).AddRangeTo(nsDesc.Aliases);
                            break;

                        case "var":
                            parseConstantGroup(sectiondef, ns).AddTo(nsDesc.Enums);
                            break;

                        default:
                            throw new NotImplementedException("Unrecognized sectiondef kind");
                        }
                    }
                    break;

                default:
                    throw new NotImplementedException("Unparsed compound type");
                }
            }

            var nominals = new List <string>()
            {
                "type", "sequence<>"
            };

            ret.Namespaces.ForEachKVP((key, rootNs) => nominals.AddRangeTo(rootNs.NominalTypes));

            //add strongly typed overloads for loadComponentFromURL
            var xcl = ret.FindTypeDescription("com.sun.star.frame.XComponentLoader").description as TSInterfaceDescription;
            var loadComponentFromURL = xcl.Members.FirstOrDefault(x => x.Key == "loadComponentFromURL");
            var insertPostion        = xcl.Members.IndexOf(kvp => kvp.Key == "loadComponentFromURL");

            new[] {