Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Sep 11, 2023
1 parent e7195ac commit 4a63318
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ current.Parent is CodeClass parentClass &&
var refinedName = refineAccessorName(currentProperty.Name);

if (!refinedName.Equals(currentProperty.Name, StringComparison.Ordinal) &&
!parentClass.Properties.Any(property => !property.Name.Equals(property.Name, StringComparison.Ordinal) && refinedName.Equals(property.Name, StringComparison.OrdinalIgnoreCase)))// ensure the refinement won't generate a duplicate
!parentClass.Properties.Any(property => !property.Name.Equals(property.Name, StringComparison.Ordinal) && refinedName.Equals(property.Name, StringComparison.Ordinal)))// ensure the refinement won't generate a duplicate
{
if (string.IsNullOrEmpty(currentProperty.SerializationName))
currentProperty.SerializationName = currentProperty.Name;
Expand Down
2 changes: 0 additions & 2 deletions src/Kiota.Builder/Refiners/JavaRefiner.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Kiota.Builder.CodeDOM;
using Kiota.Builder.Configuration;
using Kiota.Builder.Extensions;
using Kiota.Builder.Writers.Java;
using Microsoft.VisualBasic;

namespace Kiota.Builder.Refiners;
public class JavaRefiner : CommonLanguageRefiner, ILanguageRefiner
Expand Down
8 changes: 4 additions & 4 deletions src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho
.Where(static x => x.Type is not CodeType propType || propType.TypeDefinition is not CodeClass propertyClass || propertyClass.OriginalComposedType is null)
.OrderBy(static x => x.Name))
{
var setterName = propWithDefault.SetterFromCurrentOrBaseType?.Name is string sName && !string.IsNullOrEmpty(sName) ? sName : $"set{propWithDefault.Name}";
var setterName = propWithDefault.SetterFromCurrentOrBaseType?.Name is string sName && !string.IsNullOrEmpty(sName) ? sName : $"set{propWithDefault.Name.ToFirstCharacterUpperCase()}";
var defaultValue = propWithDefault.DefaultValue;
if (propWithDefault.Type is CodeType propertyType && propertyType.TypeDefinition is CodeEnum enumDefinition)
{
Expand All @@ -358,7 +358,7 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho
private static void WriteSetterBody(CodeMethod codeElement, LanguageWriter writer, CodeClass parentClass)
{
if (parentClass.GetBackingStoreProperty() is CodeProperty backingStore)
writer.WriteLine($"this.get{backingStore.Name}().set(\"{codeElement.AccessedProperty?.Name}\", value);");
writer.WriteLine($"this.get{backingStore.Name.ToFirstCharacterUpperCase()}().set(\"{codeElement.AccessedProperty?.Name}\", value);");
else
{
string value = "PeriodAndDuration".Equals(codeElement.AccessedProperty?.Type?.Name, StringComparison.OrdinalIgnoreCase) ? "PeriodAndDuration.ofPeriodAndDuration(value);" : "value;";
Expand All @@ -379,12 +379,12 @@ private void WriteGetterBody(CodeMethod codeElement, LanguageWriter writer, Code
writer.WriteLine($"{conventions.GetTypeString(codeElement.AccessedProperty.Type, codeElement)} value = this.{backingStore.NamePrefix}{backingStore.Name}\");");
writer.StartBlock("if(value == null) {");
writer.WriteLines($"value = {codeElement.AccessedProperty.DefaultValue};",
$"this.set{codeElement.AccessedProperty?.Name}(value);");
$"this.set{codeElement.AccessedProperty?.Name.ToFirstCharacterUpperCase()}(value);");
writer.CloseBlock();
writer.WriteLine("return value;");
}
else
writer.WriteLine($"return this.get{backingStore.Name}().get(\"{codeElement.AccessedProperty?.Name}\");");
writer.WriteLine($"return this.get{backingStore.Name.ToFirstCharacterUpperCase()}().get(\"{codeElement.AccessedProperty?.Name}\");");

}
private void WriteIndexerBody(CodeMethod codeElement, CodeClass parentClass, LanguageWriter writer, string returnType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public async Task DoesNotEscapesReservedKeywordsForClassOrPropertyKind()
// Assert
Assert.Equal("break", model.Name);
Assert.DoesNotContain("@", model.Name); // classname will be capitalized
Assert.Equal("alias", property.Name);
Assert.Equal("Alias", property.Name);
Assert.DoesNotContain("@", property.Name); // classname will be capitalized
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public async Task DoesNotReplacesReservedEnumOptions()
}).First();
var option = new CodeEnumOption
{
Name = "break", // this a keyword
Name = "Void", // this a keyword
};
model.AddOption(option);
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Java }, root);
Assert.Equal("break", option.Name);
Assert.Equal("Void", option.Name);
Assert.Empty(option.SerializationName);
}
[Fact]
Expand Down Expand Up @@ -436,7 +436,7 @@ public async Task NormalizeMethodTypesNames()
method.AddParameter(nonNormalizedParam);
method.AddParameter(normalizedParam);
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Java }, root);
Assert.Equal("foo_bar", method.Parameters.First().Type.Name);
Assert.Equal("Foo_bar", method.Parameters.First().Type.Name);
Assert.Equal("FooBaz", method.Parameters.Last().Type.Name);
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ public void WritesEnumSerializationValue()
currentEnum.AddOption(option);
writer.Write(currentEnum);
var result = tw.ToString();
Assert.Contains($"Plus_1(\"+1\")", result);
Assert.Contains($"plus_1(\"+1\")", result);
}
}
Loading

0 comments on commit 4a63318

Please sign in to comment.