public void Test_Frameworks_Path_NoXml()
        {
            var fxpath       = "/some/path/with";
            var assemblyPath = "/some/path/with/fxname/thing.dll";
            var fxname       = FrameworkIndex.GetFrameworkNameFromPath(fxpath, assemblyPath);

            Assert.AreEqual("fxname", fxname);
        }
Exemplo n.º 2
0
        private FrameworkIndex LoadFrameworks(string folder)
        {
            var            frameworkFolder = Path.Combine(folder, "FrameworksIndex");
            FrameworkIndex frameworkIndex  = new FrameworkIndex()
            {
                DocIdToFrameworkDict = new Dictionary <string, List <string> >(),
                FrameworkAssemblies  = new Dictionary <string, Dictionary <string, AssemblyInfo> >(),
                AllFrameworks        = new HashSet <string>()
            };

            foreach (var fxFile in ListFiles(frameworkFolder, "*.xml").OrderBy(f => Path.GetFileNameWithoutExtension(f.AbsolutePath)))
            {
                XDocument fxDoc  = XDocument.Load(fxFile.AbsolutePath);
                var       fxName = fxDoc.Root.Attribute("Name").Value;
                frameworkIndex.AllFrameworks.Add(fxName);
                foreach (var nsElement in fxDoc.Root.Elements("Namespace"))
                {
                    var ns = nsElement.Attribute("Name").Value;
                    frameworkIndex.DocIdToFrameworkDict.AddWithKey("N:" + ns, fxName);
                    foreach (var tElement in nsElement.Elements("Type"))
                    {
                        var t = tElement.Attribute("Id").Value;
                        frameworkIndex.DocIdToFrameworkDict.AddWithKey(t, fxName);
                        foreach (var mElement in tElement.Elements("Member"))
                        {
                            var m = mElement.Attribute("Id").Value;
                            frameworkIndex.DocIdToFrameworkDict.AddWithKey(m, fxName);
                        }
                    }
                }

                var assemblyNodes = fxDoc.Root.Element("Assemblies")?.Elements("Assembly")?.Select(ele => new AssemblyInfo()
                {
                    Name    = ele.Attribute("Name")?.Value,
                    Version = ele.Attribute("Version")?.Value
                }).ToList();
                if (assemblyNodes != null)
                {
                    frameworkIndex.FrameworkAssemblies.Add(fxName, assemblyNodes.ToDictionary(a => a.Name, a => a));
                }
                else
                {
                    OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_Moniker_EmptyAssembly, null, fxFile.AbsolutePath);
                }
            }
            return(frameworkIndex);
        }
Exemplo n.º 3
0
        public void Parameters_Updating_BeginRead()
        {
            FrameworkIndex fx = new FrameworkIndex("", 3, null);

            fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks, fx.Frameworks)
            {
                Id = "One", Name = "One", Replace = "mdoc.Test2", With = "mdoc.Test"
            });
            fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks, fx.Frameworks)
            {
                Id = "Two", Name = "Two", Replace = "mdoc.Test2", With = "mdoc.Test"
            });
            fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks, fx.Frameworks)
            {
                Id = "Three", Name = "Three", Replace = "mdoc.Test2", With = "mdoc.Test"
            });

            var context = InitComplexContext <MyComplicatedClass>(XmlConsts.XML_METHOD_TESTMETHOD_BEFORE, "mdoc.Test", "BeginRead", fx);
            var theType = context.method.DeclaringType.Resolve();

            foreach (var it in fx.Frameworks)
            {
                var t = it.ProcessType(theType, theType.Module.Assembly);
                foreach (var m in theType.Methods)
                {
                    t.ProcessMember(m);
                }
            }

            var typeEntry = context.fx.Frameworks[2].Types.First();

            bool fxAlternateTriggered = true;

            context.updater.MakeParameters(context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry, ref fxAlternateTriggered);

            var afterXML = context.doc.OuterXml;

            // TODO: make representative post-method XML
            Assert.AreEqual(Normalize(XmlConsts.XML_METHOD_TESTMETHOD_AFTER), afterXML);
        }
Exemplo n.º 4
0
        private List <Namespace> Filter(IEnumerable <Namespace> namespaces, FilterStore filterStore, FrameworkIndex frameworks)
        {
            var filteredNS = namespaces.ToList();

            foreach (var ns in filteredNS)
            {
                if (ns.Types?.Count > 0)
                {
                    ns.Types = ns.Types.Where(t =>
                    {
                        bool expose = true;
                        if (filterStore?.TypeFilters?.Count > 0)
                        {
                            var applicableFilters = filterStore.TypeFilters.Where(tf => tf.Filter(t).HasValue).ToList();
                            if (applicableFilters.Count == 1)
                            {
                                expose = applicableFilters.First().Filter(t).Value;
                            }
                            else if (applicableFilters.Count > 1)
                            {
                                var filtersPerNS = applicableFilters.GroupBy(tf => tf.Namespace).Select(tfg => tfg.FirstOrDefault(tf => tf.Name != "*") ?? tfg.First()).ToList();
                                foreach (var filter in filtersPerNS)
                                {
                                    expose = expose && filter.Filter(t).Value;
                                }
                            }
                        }

                        return(expose && frameworks.DocIdToFrameworkDict.ContainsKey(t.DocId));
                    }).ToList();
                }
            }
            filteredNS = filteredNS.Where(ns => ns.Types?.Count > 0 && frameworks.DocIdToFrameworkDict.ContainsKey(ns.CommentId)).ToList();
            foreach (var ns in filteredNS)
            {
                foreach (var t in ns.Types)
                {
                    if (t.Members?.Count > 0)
                    {
                        t.Members = t.Members.Where(m =>
                        {
                            bool expose = true;
                            if (filterStore?.MemberFilters?.Count > 0)
                            {
                                foreach (var filter in filterStore.MemberFilters.Where(mf => mf.Filter(m).HasValue))
                                {
                                    expose = expose && filter.Filter(m).Value;
                                }
                            }
                            return(expose && frameworks.DocIdToFrameworkDict.ContainsKey(m.DocId));;
                        }).ToList();
                    }
                }
            }
            //workaournd for https://github.com/mono/api-doc-tools/issues/89, bug #1022788
            foreach (var ns in filteredNS)
            {
                foreach (var t in ns.Types)
                {
                    if (t.Signatures.IsPublishSealedClass)
                    {
                        t.Members = t.Members.Where(m => !m.Signatures.IsProtected).ToList();
                    }
                }
            }
            return(filteredNS);
        }
Exemplo n.º 5
0
        private ParamContext InitContext <T>(string methodXml, int fxIndex, bool forceAlignment = false, string ns1 = "mdoc.Test", string ns2 = "mdoc.Test2")
        {
            Func <int, bool> indexCheck = fi => fi < 2;

            if (typeof(T) == typeof(MyClass2))
            {
                indexCheck = fi => fi != 1;
            }

            bool useFirst = forceAlignment || indexCheck(fxIndex);
            var  doc      = new XmlDocument();

            //doc.PreserveWhitespace = true;
            doc.LoadXml(methodXml);
            var        beforeXML = doc.OuterXml;
            XmlElement root      = doc.SelectSingleNode("//Docs") as XmlElement; // Docs

            TypeDefinition type        = GetDefinition <T> (ns1);
            var            method      = type.Methods.First(m => m.Name == "Meth") as MethodReference;
            var            parameters  = method.Parameters.ToList();
            TypeDefinition type2       = GetDefinition <T> (ns2);
            var            method2     = type2.Methods.First(m => m.Name == "Meth") as MethodReference;
            var            parameters2 = method2.Parameters.ToList();

            // updater
            var updater = new MDocUpdater();
            var fx      = new FrameworkIndex("", 3, null);

            fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks, fx.Frameworks)
            {
                Id = "One", Name = "One", Replace = ns2, With = ns1
            });
            fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks, fx.Frameworks)
            {
                Id = "Three", Name = "Three", Replace = ns2, With = ns1
            });
            fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks, fx.Frameworks)
            {
                Id = "Two", Name = "Two", Replace = ns2, With = ns1
            });

            var i = 0;

            foreach (var f in fx.Frameworks)
            {
                if (indexCheck(i) || forceAlignment)
                {
                    var t = f.ProcessType(type, type.Module.Assembly);
                    t.ProcessMember(method);

                    var aset = new AssemblySet(new[] { "one.dll" });
                    f.AddAssemblySet(aset);
                }
                else
                {
                    var t = f.ProcessType(type2, type2.Module.Assembly);
                    t.ProcessMember(method2);
                }
                i++;
            }

            updater.InitializeFrameworksCache(fx);

            return(new ParamContext()
            {
                doc = doc,
                beforeXML = beforeXML,
                method = useFirst ? method : method2,
                parameters = useFirst ? parameters : parameters2,
                fx = fx,
                updater = updater
            });
        }
Exemplo n.º 6
0
        private ParamContext InitComplexContext <T>(string methodXml, string ns, string methodName, FrameworkIndex fx)
        {
            var doc = new XmlDocument();

            doc.LoadXml(methodXml);
            var beforeXML = doc.OuterXml;

            TypeDefinition type   = GetDefinition <T>(ns);
            var            method = type.Methods.First(m => m.Name == methodName) as MethodReference;

            var updater = new MDocUpdater();

            return(new ParamContext()
            {
                doc = doc,
                beforeXML = beforeXML,
                method = method,
                parameters = method.Parameters.ToList(),
                fx = fx,
                updater = updater
            });
        }