From 8b174efc26ae397dc72e5b7d5bc0e9d5754c3a1d Mon Sep 17 00:00:00 2001 From: Michele George Date: Tue, 16 Nov 2021 17:04:02 +0100 Subject: [PATCH] adjust whitespaces in the generated csharp files --- .../extensions/CsharpObjectTypeExtensions.kt | 3 +- .../model/CsharpModelInterfaceRenderer.kt | 6 +- .../csharp/model/CsharpObjectTypeRenderer.kt | 10 +- .../requests/CsharpHttpRequestRenderer.kt | 102 ++++++++++-------- 4 files changed, 62 insertions(+), 59 deletions(-) diff --git a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/extensions/CsharpObjectTypeExtensions.kt b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/extensions/CsharpObjectTypeExtensions.kt index eb4034b32..abbbca066 100644 --- a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/extensions/CsharpObjectTypeExtensions.kt +++ b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/extensions/CsharpObjectTypeExtensions.kt @@ -50,8 +50,7 @@ interface CsharpObjectTypeExtensions : ExtensionsBase { |using System.Collections.Generic; |using System.Linq; |using System.Text.Json.Serialization; - |using commercetools.Base.CustomAttributes; - |""" + |using commercetools.Base.CustomAttributes;""" } public fun ObjectType.objectClassName(): String { diff --git a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpModelInterfaceRenderer.kt b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpModelInterfaceRenderer.kt index 5ba6b9d36..80ac81450 100644 --- a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpModelInterfaceRenderer.kt +++ b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpModelInterfaceRenderer.kt @@ -30,9 +30,7 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr | { | <${type.toProperties()}> | } - |} - | - """.trimMargin().keepIndentation() + |}""".trimMargin().keepIndentation() if(type.isADictionaryType()) @@ -61,7 +59,7 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr var deprecationAttr = if(this.deprecationAnnotation() == "") "" else this.deprecationAnnotation()+"\n"; return """ - |${deprecationAttr}${newKeyword}${typeName}$nullableChar $propName { get; set;} + |${deprecationAttr}${newKeyword}${typeName}$nullableChar $propName { get; set; } """.trimMargin() } diff --git a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpObjectTypeRenderer.kt b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpObjectTypeRenderer.kt index a47edf564..2b0dfceca 100644 --- a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpObjectTypeRenderer.kt +++ b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpObjectTypeRenderer.kt @@ -29,9 +29,7 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy | <${if(type.isADictionaryType()) "" else type.toProperties()}> | <${type.renderConstructor(vrapType.simpleClassName)}> | } - |} - | - """.trimMargin().keepIndentation() + |}""".trimMargin().keepIndentation() if(type.isADictionaryType()) { @@ -59,9 +57,7 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy | public partial class ${vrapType.simpleClassName} : Dictionary\, I${vrapType.simpleClassName} | { | } - |} - | - """ + |}""" } private fun ObjectType.toProperties() : String = this.allProperties @@ -75,7 +71,7 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy var deprecationAttr = if(this.deprecationAnnotation() == "") "" else this.deprecationAnnotation()+"\n"; return """ - |${deprecationAttr}public ${typeName}$nullableChar $propName { get; set;} + |${deprecationAttr}public ${typeName}$nullableChar $propName { get; set; } """.trimMargin() } diff --git a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/requests/CsharpHttpRequestRenderer.kt b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/requests/CsharpHttpRequestRenderer.kt index 44e8b4f25..6b47757fb 100644 --- a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/requests/CsharpHttpRequestRenderer.kt +++ b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/requests/CsharpHttpRequestRenderer.kt @@ -49,11 +49,10 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT |using commercetools.Base.Client; |using commercetools.Base.Serialization; |${type.usings()} - | |namespace ${cPackage} |{ - | public partial class ${type.toRequestName()} : ApiMethod\<${type.toRequestName()}\> { - | + | public partial class ${type.toRequestName()} : ApiMethod\<${type.toRequestName()}\> + | { | <${type.properties()}> | | <${type.constructor()}> @@ -68,9 +67,7 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT | | <${type.formParamMethods()}> | } - |} - """.trimMargin() - .keepIndentation() + |}""".trimMargin().keepIndentation() val relativePath = cPackage .replace(basePackagePrefix, "").replace(".", "/") @@ -108,11 +105,12 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT "" } - return """| - |<$pathArgs> - | - |<$body> - """.trimMargin() + return if(body != "") + """|<$pathArgs> + | + |<$body>""".trimMargin() + else + """|<$pathArgs>""".trimMargin() } private fun Method.constructor(): String? { @@ -154,7 +152,8 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT constructorAssignments.add("this.RequestUrl = $\"${requestUrl}\";") return """ - |public ${this.toRequestName()}(${constructorArguments.joinToString(separator = ", ")}) { + |public ${this.toRequestName()}(${constructorArguments.joinToString(separator = ", ")}) + |{ | <${constructorAssignments.joinToString(separator = "\n")}> |} """.trimMargin().keepIndentation().escapeAll() @@ -182,7 +181,8 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT private fun Method.queryParamsGetters() : String = this.queryParameters .filter { it.getAnnotation(PLACEHOLDER_PARAM_ANNOTATION, true) == null } .map { """ - |public List Get${it.fieldName().firstUpperCase()}() { + |public List Get${it.fieldName().firstUpperCase()}() + |{ | return this.GetQueryParam("${it.name}"); |} """.trimMargin().escapeAll() } @@ -191,7 +191,8 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT private fun Method.queryParamsSetters() : String = this.queryParameters .filter { it.getAnnotation(PLACEHOLDER_PARAM_ANNOTATION, true) == null } .map { """ - |public ${this.toRequestName()} With${it.fieldName().firstUpperCase()}(${it.witherType()} ${it.fieldName()}){ + |public ${this.toRequestName()} With${it.fieldName().firstUpperCase()}(${it.witherType()} ${it.fieldName()}) + |{ | return this.AddQueryParam("${it.name}", ${it.fieldNameAsString(it.witherType())}); |} """.trimMargin().escapeAll() } @@ -210,8 +211,8 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT """ |public async Task\<${this.csharpReturnType(vrapTypeProvider)}\> ExecuteAsync() |{ - | var requestMessage = Build(); - | return await ApiHttpClient.ExecuteAsync\<${this.csharpReturnType(vrapTypeProvider)}\>(requestMessage); + | var requestMessage = Build(); + | return await ApiHttpClient.ExecuteAsync\<${this.csharpReturnType(vrapTypeProvider)}\>(requestMessage); |} """.trimMargin() @@ -235,12 +236,12 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT | |public override HttpRequestMessage Build() |{ - | var request = base.Build(); - | if ($bodyName != null && $bodyName.Length \> 0) - | { - | request.Content = new StreamContent($bodyName); - | } - | return request; + | var request = base.Build(); + | if ($bodyName != null && $bodyName.Length \> 0) + | { + | request.Content = new StreamContent($bodyName); + | } + | return request; |} """.trimMargin() } @@ -249,10 +250,9 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT | |public override HttpRequestMessage Build() |{ - | var request = base.Build(); - | - | request.Content = new FormUrlEncodedContent(_formParams); - | return request; + | var request = base.Build(); + | request.Content = new FormUrlEncodedContent(_formParams); + | return request; |} """.trimMargin() else @@ -261,16 +261,16 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT | |public override HttpRequestMessage Build() |{ - | var request = base.Build(); - | if (SerializerService != null) - | { - | var body = this.SerializerService.Serialize(${bodyName}); - | if(!string.IsNullOrEmpty(body)) - | { - | request.Content = new StringContent(body, Encoding.UTF8, "application/json"); - | } - | } - | return request; + | var request = base.Build(); + | if (SerializerService != null) + | { + | var body = this.SerializerService.Serialize(${bodyName}); + | if(!string.IsNullOrEmpty(body)) + | { + | request.Content = new StringContent(body, Encoding.UTF8, "application/json"); + | } + | } + | return request; |} """.trimMargin() } @@ -281,12 +281,14 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT private fun Method.formParamMethods() : String = if (this.bodies != null && !this.bodies.isEmpty() && this.bodies[0].contentMediaType.`is`(MediaType.FORM_DATA)) { """ - public ${this.toRequestName()} AddFormParam(string key, TValue value) { + public ${this.toRequestName()} AddFormParam(string key, TValue value) + { this._formParams.Add(new KeyValuePair(key, value.ToString())); return this; } - public ${this.toRequestName()} WithFormParam(string key, TValue value) { + public ${this.toRequestName()} WithFormParam(string key, TValue value) + { return WithoutFormParam(key).AddFormParam(key, value); } @@ -295,7 +297,8 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT * @param key form parameter name * @return T */ - public ${this.toRequestName()} WithoutFormParam(string key) { + public ${this.toRequestName()} WithoutFormParam(string key) + { this._formParams = this._formParams.FindAll(pair => !pair.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)); return this; } @@ -305,28 +308,34 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT * @param formParams list of form parameters * @return T */ - public ${this.toRequestName()} WithFormParams(List> formParams) { + public ${this.toRequestName()} WithFormParams(List> formParams) + { this._formParams = formParams; return this; } - public List> GetFormParams() { + public List> GetFormParams() + { return this._formParams.ToList(); } - public List GetFormParam(string key) { + public List GetFormParam(string key) + { return this._formParams.FindAll(pair => pair.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)).Select(pair => pair.Value).ToList(); } - public List GetFormParamUriStrings() { + public List GetFormParamUriStrings() + { return this._formParams.Select(ToUriString).ToList(); } - public string GetFormParamUriString() { + public string GetFormParamUriString() + { return string.Join('&', this._formParams.Select(ToUriString)); } - private static string ToUriString(KeyValuePair entry) { + private static string ToUriString(KeyValuePair entry) + { return entry.Key + "=" + WebUtility.UrlEncode(entry.Value); } @@ -370,7 +379,8 @@ class CsharpHttpRequestRenderer constructor(override val vrapTypeProvider: VrapT val parameters = "string " + StringCaseFormat.LOWER_CAMEL_CASE.apply(placeholder.value) + ", ${it.witherType()} " + paramName.value return """ - |public ${this.toRequestName()} With$methodName($parameters){ + |public ${this.toRequestName()} With$methodName($parameters) + |{ | return this.AddQueryParam($value, ${paramName.value}); |} """.trimMargin().escapeAll()