Skip to content

Commit

Permalink
- fixes backward compatible indexer method for Go
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Aug 23, 2023
1 parent accaca0 commit 70bc8f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Kiota.Builder/CodeDOM/CodeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CodeComposedTypeBase? OriginalComposedType
{
get; set;
}
public CodeIndexer? Indexer => InnerChildElements.Values.OfType<CodeIndexer>().FirstOrDefault(static x => !x.Deprecation?.IsDeprecated ?? true);
public CodeIndexer? Indexer => InnerChildElements.Values.OfType<CodeIndexer>().FirstOrDefault(static x => !x.IsLegacyIndexer);
public void AddIndexer(params CodeIndexer[] indexers)
{
if (indexers == null || Array.Exists(indexers, static x => x == null))
Expand Down
26 changes: 16 additions & 10 deletions src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,27 @@ protected static void ReplaceIndexersByMethodsWithParameter(CodeElement currentE
{
if (indexerParentClass.ContainsMember(currentElement.Name)) // TODO remove condition for v2 necessary because of the second case of Go block
indexerParentClass.RemoveChildElement(currentElement);
//TODO remove who block except for last else if body for v2
if (currentIndexer.IsLegacyIndexer && language == GenerationLanguage.Go)
//TODO remove whole block except for last else if body for v2
if (language == GenerationLanguage.Go)
{
if (indexerParentClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && x.OriginalIndexer is not null && !x.OriginalIndexer.IsLegacyIndexer) is CodeMethod typeSpecificCompatibleMethod &&
typeSpecificCompatibleMethod.OriginalIndexer is not null)
if (currentIndexer.IsLegacyIndexer)
{
indexerParentClass.RenameChildElement(typeSpecificCompatibleMethod.Name, typeSpecificCompatibleMethod.Name + typeSpecificCompatibleMethod.OriginalIndexer.IndexParameter.Type.Name.ToFirstCharacterUpperCase());
if (indexerParentClass.Indexer is CodeIndexer specificIndexer && specificIndexer != currentIndexer && !specificIndexer.IsLegacyIndexer)
{
indexerParentClass.RemoveChildElement(specificIndexer);
indexerParentClass.AddMethod(CodeMethod.FromIndexer(specificIndexer, methodNameCallback, parameterNameCallback, parameterNullable, true));
}
indexerParentClass.AddMethod(CodeMethod.FromIndexer(currentIndexer, methodNameCallback, parameterNameCallback, parameterNullable));
}
else if (indexerParentClass.Indexer != null && indexerParentClass.Indexer != currentIndexer && !indexerParentClass.Indexer.IsLegacyIndexer)
else
{
var specificIndexer = indexerParentClass.Indexer;
indexerParentClass.RemoveChildElement(specificIndexer);
indexerParentClass.AddMethod(CodeMethod.FromIndexer(specificIndexer, methodNameCallback, parameterNameCallback, parameterNullable, true));
if (indexerParentClass.GetChildElements(true).OfType<CodeIndexer>().FirstOrDefault(static x => x.IsLegacyIndexer) is CodeIndexer legacyIndexer)
{
indexerParentClass.RemoveChildElement(legacyIndexer);
indexerParentClass.AddMethod(CodeMethod.FromIndexer(legacyIndexer, methodNameCallback, parameterNameCallback, parameterNullable));
}
indexerParentClass.AddMethod(CodeMethod.FromIndexer(currentIndexer, methodNameCallback, parameterNameCallback, parameterNullable, true));
}
indexerParentClass.AddMethod(CodeMethod.FromIndexer(currentIndexer, methodNameCallback, parameterNameCallback, parameterNullable));
}
else if (!currentIndexer.IsLegacyIndexer)
indexerParentClass.AddMethod(CodeMethod.FromIndexer(currentIndexer, methodNameCallback, parameterNameCallback, parameterNullable));
Expand Down

0 comments on commit 70bc8f9

Please sign in to comment.