示例#1
0
 private void ResolveDeferredFluentMethodGroups(CodeModelJvaf codeModel)
 {
     // For each "Inner Method Group", process list of "Fluent Method Groups" belongs to it.
     //
     foreach (FluentMethodGroupList fluentMethodGroupList in this.Values)
     {
         List <FluentMethodGroup> deferredFluentMethodGroups = fluentMethodGroupList.DeferredFluentMethodGroups;
         //
         foreach (FluentMethodGroup deferredFluentMethodGroup in deferredFluentMethodGroups)
         {
             string possibleFluentMethodGroupName = DeferredFluentMethodGroupNamePrefix.RemovePrefix(deferredFluentMethodGroup.LocalNameInPascalCase);
             //
             // Find a "Fluent Method Group" that can own the methods in the "Deferred Fluent Method Group".
             //
             FluentMethodGroup newOwnerFluentMethodGroup = fluentMethodGroupList.FindFluentMethodGroup(possibleFluentMethodGroupName);
             if (newOwnerFluentMethodGroup == null)
             {
                 newOwnerFluentMethodGroup = fluentMethodGroupList.FindBestMatchingLevel0FluentMethodGroupOrCreateOne(this);
             }
             // Migrate methods in "Defered Fluent Method Group" to new owner
             //
             newOwnerFluentMethodGroup.AddInnerMethods(deferredFluentMethodGroup.InnerMethods);
             // Remove "Defered Fluent Method Group", given it's methods has new owner
             //
             fluentMethodGroupList.RemoveFluentMethodGroup(deferredFluentMethodGroup.LocalNameInPascalCase);
         }
     }
 }
示例#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);
        }