From ca7403863cbf9bd87db19ca7c1f6dfb31ee2cca6 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Thu, 30 May 2024 11:40:36 +0200 Subject: [PATCH] fix csharp formatting issues --- .../model/CsharpModelInterfaceRenderer.kt | 8 ++--- .../csharp/model/CsharpObjectTypeRenderer.kt | 12 +++---- .../csharp/model/CsharpStringTypeRenderer.kt | 32 +++++++++---------- .../CsharpQueryPredicateRenderer.kt | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) 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 54589935..28c71bd7 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 @@ -43,7 +43,7 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr | <${type.DeserializationAttributes()}> | public partial interface I${vrapType.simpleClassName} ${if (extends.isNotEmpty()) { ": ${extends.joinToString(separator = ", ")}" } else ""} | { - | <${type.toProperties()}> + | ${type.toProperties(" ")} | | <${type.subtypeFactories()}> | } @@ -65,10 +65,10 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr ) } - private fun ObjectType.toProperties() : String = this.properties + private fun ObjectType.toProperties(indent: String = "") : String = this.properties .filterNot { it.deprecated() } .filterNot { property -> property.isPatternProperty() } - .map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n") + .map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n$indent") private fun Property.toCsharpProperty(objectType: ObjectType): String { val propName = this.name.firstUpperCase() @@ -80,7 +80,7 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr val deprecationAttr = if(this.deprecationAnnotation() == "") "" else this.deprecationAnnotation()+"\n"; return """ - |${deprecationAttr}${newKeyword}${typeName}$nullableChar $propName { get; set;}${if (this.type.toVrapType() is VrapArrayType) """ + |${deprecationAttr}${newKeyword}${typeName}$nullableChar $propName { get; set; }${if (this.type.toVrapType() is VrapArrayType) """ |${deprecationAttr}${newKeyword}IEnumerable\<${(this.type.toVrapType() as VrapArrayType).itemType.simpleName()}\>$nullableChar ${propName}Enumerable { set =\> $propName = value$nullableChar.ToList(); } |""" else ""} """.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 4ca911f4..6d9aa365 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 @@ -30,7 +30,7 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy | ${if (type.markDeprecated()) "[Obsolete(\"usage of this endpoint has been deprecated.\", false)]" else ""} | public partial class ${type.objectClassName()} : I${vrapType.simpleClassName} | { - | <${if(type.isADictionaryType()) "" else type.toProperties()}> + | ${if(type.isADictionaryType()) "" else type.toProperties(" ")} | <${type.renderConstructor(vrapType.simpleClassName)}> | } |} @@ -70,10 +70,10 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy """ } - private fun ObjectType.toProperties() : String = this.allProperties + private fun ObjectType.toProperties(indent: String = "") : String = this.allProperties .filterNot { it.deprecated() } .filterNot { property -> property.isPatternProperty() } - .map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n") + .map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n$indent") private fun Property.toCsharpProperty(objectType: ObjectType): String { val propName = this.name.firstUpperCase() @@ -83,7 +83,7 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy val deprecationAttr = if(this.deprecationAnnotation() == "") "" else this.deprecationAnnotation()+"\n"; return """ - |${deprecationAttr}public ${typeName}$nullableChar $propName { get; set;}${if (this.type.toVrapType() is VrapArrayType) """ + |${deprecationAttr}public ${typeName}$nullableChar $propName { get; set; }${if (this.type.toVrapType() is VrapArrayType) """ |${deprecationAttr}public IEnumerable\<${(this.type.toVrapType() as VrapArrayType).itemType.simpleName()}\>$nullableChar ${propName}Enumerable { set =\> $propName = value$nullableChar.ToList(); } |""" else ""} """.trimMargin() @@ -103,8 +103,8 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy val isEmptyConstructor = this.getConstructorContentForDiscriminator() == ""; return if(!isEmptyConstructor) """public ${className}() - |{ - | ${this.getConstructorContentForDiscriminator()} + |{ + | ${this.getConstructorContentForDiscriminator()} |}""" else "" diff --git a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpStringTypeRenderer.kt b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpStringTypeRenderer.kt index c4a35ad5..c4d19db9 100644 --- a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpStringTypeRenderer.kt +++ b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/model/CsharpStringTypeRenderer.kt @@ -40,7 +40,7 @@ class CsharpStringTypeRenderer constructor(override val vrapTypeProvider: VrapTy | { | return JsonName; | } - | + | | IEnumerator IEnumerable.GetEnumerator() | { | return GetEnumerator(); @@ -55,21 +55,21 @@ class CsharpStringTypeRenderer constructor(override val vrapTypeProvider: VrapTy | [EnumInterfaceCreator(typeof(I${vrapType.simpleClassName}), "FindEnum")] | public interface I${vrapType.simpleClassName} : IJsonName, IEnumerable\ | { - | <${type.enumStaticFields("${vrapType.simpleClassName}")}> + | <${type.enumStaticFields("${vrapType.simpleClassName}")}> + | + | ${vrapType.simpleClassName}? Value { get; } | - | ${vrapType.simpleClassName}? Value { get; } - | - | static I${vrapType.simpleClassName}[] Values() - | { - | return new[] - | { + | static I${vrapType.simpleClassName}[] Values() + | { + | return new[] + | { | <${type.enumFieldsAsNames()}> | }; - | } - | static I${vrapType.simpleClassName} FindEnum(string value) - | { - | return Values().FirstOrDefault(origin =\> origin.JsonName == value) ?? new ${vrapType.simpleClassName}Wrapper() {JsonName = value}; - | } + | } + | static I${vrapType.simpleClassName} FindEnum(string value) + | { + | return Values().FirstOrDefault(origin =\> origin.JsonName == value) ?? new ${vrapType.simpleClassName}Wrapper() { JsonName = value }; + | } | } |} """.trimMargin().keepIndentation() @@ -95,7 +95,7 @@ class CsharpStringTypeRenderer constructor(override val vrapTypeProvider: VrapTy ?.map { """ |public static I${enumName} ${it.value.enumValueName()} = new ${enumName}Wrapper - | {Value = ${enumName}.${it.value.enumValueName()}, JsonName = "${it.value}"}; + |{ Value = ${enumName}.${it.value.enumValueName()}, JsonName = "${it.value}" }; """.trimMargin() } ?.joinToString(separator = "\n\n", postfix = "") @@ -103,10 +103,10 @@ class CsharpStringTypeRenderer constructor(override val vrapTypeProvider: VrapTy fun StringType.enumFieldsAsNames() = enumValues() ?.map { """ - |${it.value.enumValueName()} + |${it.value.enumValueName()} """.trimMargin() } - ?.joinToString(separator = ",\n", postfix = "") + ?.joinToString(separator = " ,\n", postfix = "") fun StringType.enumValues() = enum?.filter { it is StringInstance } diff --git a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/predicates/CsharpQueryPredicateRenderer.kt b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/predicates/CsharpQueryPredicateRenderer.kt index c14b3db6..cd4c88d2 100644 --- a/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/predicates/CsharpQueryPredicateRenderer.kt +++ b/languages/csharp/src/main/kotlin/io/vrap/codegen/languages/csharp/predicates/CsharpQueryPredicateRenderer.kt @@ -56,7 +56,7 @@ class CsharpQueryPredicateRenderer constructor(val basePackage: String, override | } | | <${type.allProperties.filterNot { it.deprecated() }.filterNot { it.isPatternProperty() }.joinToString("\n") { it.toBuilderDsl(type) }}> - | + | | <${type.namedSubTypes().filterIsInstance().joinToString("\n") { it.toBuilderDsl("As${it.subtypeName()}", vrapType) }}> | } |}