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); } } }
public ServiceManagerModel(CodeModelJvaf codeModel, SegmentFluentMethodGroups fluentMethodGroups) { this.codeModel = codeModel; this.fluentMethodGroups = fluentMethodGroups; this.ns = Settings.Instance.Namespace.ToLower(); }
public TestModel(CodeModelJvaf codeModel) { this.codeModel = codeModel; }
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); }
private FluentMethodGroups(CodeModelJvaf codeModel) { this.CodeModel = codeModel; }
private void ResolveDeferedFluentMethodGroups(CodeModelJvaf codeModel) { foreach (KeyValuePair <String, List <FluentMethodGroup> > kvPair in this) { string currentInnerFluentMethodGroupName = kvPair.Key; List <FluentMethodGroup> fluentMethodGroupsInCurrentInnerMethodGroup = kvPair.Value; // // Retrieve the list of method group in the current inner FMG defered from resolution. // List <FluentMethodGroup> deferredFluentMethodGroups = fluentMethodGroupsInCurrentInnerMethodGroup .Where(fmg => fmg.LocalNameInPascalCase.StartsWith(DeferFMGResolution)) .ToList(); FluentMethodGroup level0FluentMethodGroup = null; // foreach (FluentMethodGroup deferredFluentMethodGroup in deferredFluentMethodGroups) { // deferredFluentMethodGroup.LocalName -> "<Defered_FluentMethodGroup_Resolution>:[possibleFluentMethodGroupName]" // string possibleFluentMethodGroupName = deferredFluentMethodGroup.LocalNameInPascalCase.Substring(DeferFMGResolution.Length); // // Check there is a real FMG with this possible FMG name // var realFluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup .FirstOrDefault(fmg => fmg.LocalNameInPascalCase.EqualsIgnoreCase(possibleFluentMethodGroupName)); // if (realFluentMethodGroup != null) { // Each defered FMG contains one method, migrate it to realFluentMethodGroup // realFluentMethodGroup .InnerMethods .AddRange(deferredFluentMethodGroup.InnerMethods); // Given we have taken care of deferred FluentMethodGroup methods, remove it from being tracked. // int index = fluentMethodGroupsInCurrentInnerMethodGroup.Select((fmg, i) => new { fmg, i }) .Where(fmgi => fmgi.fmg.LocalNameInPascalCase.Equals(deferredFluentMethodGroup.LocalNameInPascalCase)) .Select(fmgi => fmgi.i) .First(); fluentMethodGroupsInCurrentInnerMethodGroup.RemoveAt(index); } else { // If there is no FMG with "possibleFluentMethodGroupName" then if (level0FluentMethodGroup == null) { // Pick a level 0 fluent method group in the current inner method group // level0FluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup .Where(fmg => fmg.Level == 0) .Where(fmg => { string innerMethodGroupName = fmg.InnerMethodGroup.Name.ToString(); return(innerMethodGroupName.StartsWith(fmg.LocalNameInPascalCase, StringComparison.OrdinalIgnoreCase)); }) .FirstOrDefault(); if (level0FluentMethodGroup == null) { level0FluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup .OrderBy(fmg => fmg.LocalNameInPascalCase) .Where(fmg => fmg.Level == 0) .FirstOrDefault(); } if (level0FluentMethodGroup == null) { level0FluentMethodGroup = new FluentMethodGroup(this) { LocalNameInPascalCase = kvPair.Key, InnerMethodGroup = (MethodGroupJvaf)codeModel .AllOperations .First(mg => mg.Name.EqualsIgnoreCase(kvPair.Key)) }; fluentMethodGroupsInCurrentInnerMethodGroup.Add(level0FluentMethodGroup); } } // Each defered FMG contains one method, migrate it to level 0 FluentMethodGroup // level0FluentMethodGroup .InnerMethods .AddRange(deferredFluentMethodGroup.InnerMethods); // Given we have taken care of deferred FluentMethodGroup methods, remove it from being tracked. // int index = fluentMethodGroupsInCurrentInnerMethodGroup.Select((fmg, i) => new { fmg, i }) .Where(fmgi => fmgi.fmg.LocalNameInPascalCase.Equals(deferredFluentMethodGroup.LocalNameInPascalCase)) .Select(fmgi => fmgi.i) .First(); fluentMethodGroupsInCurrentInnerMethodGroup.RemoveAt(index); } } } }
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); }
private SegmentFluentMethodGroups(CodeModelJvaf codeModel) { this.codeModel = codeModel; }