public static FluentMethodGroups InnerMethodGroupToFluentMethodGroups(CodeModelJvaf codeModel)
        {
            FluentMethodGroups innerMethodGroupToFluentMethodGroups = new FluentMethodGroups(codeModel);

            foreach (MethodGroupJvaf innerMethodGroup in codeModel.AllOperations)
            {
                List <FluentMethodGroup> fluentMGroupsInCurrentInnerMGroup = new List <FluentMethodGroup>();
                innerMethodGroupToFluentMethodGroups.Add(innerMethodGroup.Name, fluentMGroupsInCurrentInnerMGroup);

                foreach (MethodJvaf innerMethod in innerMethodGroup.Methods)
                {
                    var uri = new ARMUri(innerMethod);

                    if (String.IsNullOrEmpty(innerMethod.FluentUrl()))
                    {
                        // Skip empty Url e.g. listNextPage
                        //
                        continue;
                    }
                    else if (innerMethod.Name.ToLowerInvariant().StartsWith("begin"))
                    {
                        // Skip LRO begin methods
                        //
                        continue;
                    }
                    else
                    {
                        List <String> urlParts = GetPartsAfterProvider(innerMethod.FluentUrl());
                        if (urlParts.Any())
                        {
                            string providerNamespace = urlParts[0];
                            // skip provider namespace.
                            urlParts = urlParts.Skip(1).ToList();

                            FluentMethodGroup fluentMGroup = null;
                            if (urlParts.Count() == 1)
                            {
                                string possibleFMGName = urlParts[0];
                                //
                                fluentMGroup = new FluentMethodGroup(innerMethodGroupToFluentMethodGroups)
                                {
                                    LocalNameInPascalCase = $"{DeferFMGResolution}{possibleFMGName}"
                                };
                            }
                            else
                            {
                                fluentMGroup = FluentMethodGroup.ResolveFluentMethodGroup(innerMethodGroupToFluentMethodGroups, urlParts, innerMethod.HttpMethod);
                            }

                            Debug.Assert(fluentMGroup != null);
                            // Checks whether we already derived a method group with same name in the current "Operation group" (inner method group)
                            //
                            FluentMethodGroup matchedFluentMethodGroup = fluentMGroupsInCurrentInnerMGroup.FirstOrDefault(fmg => fmg.LocalNameInPascalCase.EqualsIgnoreCase(fluentMGroup.LocalNameInPascalCase));

                            if (matchedFluentMethodGroup != null)
                            {
                                matchedFluentMethodGroup.InnerMethods.Add(innerMethod);
                            }
                            else
                            {
                                fluentMGroup.InnerMethods.Add(innerMethod);
                                fluentMGroup.InnerMethodGroup = innerMethodGroup;
                                fluentMGroupsInCurrentInnerMGroup.Add(fluentMGroup);
                            }
                        }
                    }
                }
            }
            innerMethodGroupToFluentMethodGroups.ResolveDeferedFluentMethodGroups(codeModel);
            innerMethodGroupToFluentMethodGroups.LinkFluentMethodGroups();
            innerMethodGroupToFluentMethodGroups.InjectPlaceHolderFluentMethodGroups();
            innerMethodGroupToFluentMethodGroups.EnsureUniqueJavaInterfaceNameForFluentMethodGroup();
            innerMethodGroupToFluentMethodGroups.DeriveStandardFluentModelForMethodGroups();
            innerMethodGroupToFluentMethodGroups.EnsureUniqueJvaModelInterfaceName();
            innerMethodGroupToFluentMethodGroups.SpecializeFluentModels();

            return(innerMethodGroupToFluentMethodGroups);
        }
示例#2
0
        public static FluentMethodGroups InnerMethodGroupToFluentMethodGroups(CodeModelJvaf codeModel)
        {
            IEnumerable <MethodGroupJv> allInnerMethodGroups = codeModel.AllOperations;
            //
            FluentMethodGroups fluentMethodGroups = new FluentMethodGroups(codeModel);

            //
            foreach (MethodGroupJvaf currentInnerMethodGroup in allInnerMethodGroups)
            {
                FluentMethodGroupList fluentMethodGroupsInCurrentInnerMethodGroup = new FluentMethodGroupList(currentInnerMethodGroup);
                //
                fluentMethodGroups.Add(fluentMethodGroupsInCurrentInnerMethodGroup);
                //
                foreach (MethodJvaf innerMethod in currentInnerMethodGroup.Methods)
                {
                    if (innerMethod.Name.ToLowerInvariant().StartsWith("begin", StringComparison.OrdinalIgnoreCase))
                    {
                        // Skip LRO begin methods
                        continue;
                    }
                    else
                    {
                        ARMUri armUri = new ARMUri(innerMethod);
                        // Skip below two methods
                        //    1. uri can be empty for method such as 'listNext'
                        //    2. uri can be just 'nextLink' for method to retrieve next page
                        if (!armUri.IsNullOrEmpty() && !(armUri.Count == 1 && armUri.First().Name.EqualsIgnoreCase("nextLink")))
                        {
                            IEnumerable <Segment> segments = armUri.SegmentsAfterProvider;
                            segments = segments.Any() ? segments : armUri;
                            //
                            if (segments.Any())
                            {
                                FluentMethodGroup fluentMethodGroup = null;
                                if (segments.Count() == 1 && (segments.First() is TerminalSegment))
                                {
                                    // e.g. providers/Microsoft.Network/networkInterfaces
                                    // e.g. providers/Microsoft.Network/checkNameAvailability
                                    //
                                    string name = segments.First().Name;
                                    fluentMethodGroup = new FluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                                              localName: DeferredFluentMethodGroupNamePrefix.AddPrefix(name));
                                }
                                else
                                {
                                    string methodGroupDefaultName = Utils.TrimInnerSuffix(currentInnerMethodGroup.Name.ToString());
                                    fluentMethodGroup = FluentMethodGroup.ResolveFluentMethodGroup(fluentMethodGroups, innerMethod, segments, methodGroupDefaultName);
                                    fluentMethodGroup = fluentMethodGroup ?? throw new ArgumentNullException(nameof(fluentMethodGroup));
                                }
                                // Checks whether we already derived a method group with same name in the current "Inner Method Group"
                                //
                                FluentMethodGroup matchedFluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup.FindFluentMethodGroup(fluentMethodGroup.LocalNameInPascalCase);
                                if (matchedFluentMethodGroup != null)
                                {
                                    matchedFluentMethodGroup.AddInnerMethod(innerMethod);
                                }
                                else
                                {
                                    fluentMethodGroup.AddInnerMethod(innerMethod);
                                    fluentMethodGroupsInCurrentInnerMethodGroup.AddFluentMethodGroup(fluentMethodGroup);
                                }
                            }
                        }
                    }
                }
            }
            //
            fluentMethodGroups.ResolveDeferredFluentMethodGroups(codeModel);
            fluentMethodGroups.LinkFluentMethodGroups();
            fluentMethodGroups.InjectPlaceHolderFluentMethodGroups();
            fluentMethodGroups.DeriveStandardInnerModelForMethodGroups();
            fluentMethodGroups.PruneMethodGroups();
            fluentMethodGroups.Select(m => m.Value).SelectMany(fluentMethodGroupList => fluentMethodGroupList)
            .ForEach(fluentMethodGroup =>
            {
                fluentMethodGroup.JavaInterfaceName = fluentMethodGroup.LocalNameInPascalCase;
            });
            fluentMethodGroups.EnsureUniqueJvaModelInterfaceName();
            fluentMethodGroups.SpecializeFluentModels();
            //
            return(fluentMethodGroups);
        }