From 72f59f4e080a7d2f0451e31f007a83ef0d80bef0 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Mon, 13 Nov 2023 14:47:13 +0100 Subject: [PATCH] add toString method to Impl classes --- .../producers/JavaModelClassFileProducer.kt | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/languages/javalang/builder-renderer/java-builder-client/src/main/kotlin/io/vrap/codegen/languages/javalang/client/builder/producers/JavaModelClassFileProducer.kt b/languages/javalang/builder-renderer/java-builder-client/src/main/kotlin/io/vrap/codegen/languages/javalang/client/builder/producers/JavaModelClassFileProducer.kt index dbdce596..f3a474fa 100644 --- a/languages/javalang/builder-renderer/java-builder-client/src/main/kotlin/io/vrap/codegen/languages/javalang/client/builder/producers/JavaModelClassFileProducer.kt +++ b/languages/javalang/builder-renderer/java-builder-client/src/main/kotlin/io/vrap/codegen/languages/javalang/client/builder/producers/JavaModelClassFileProducer.kt @@ -57,6 +57,8 @@ class JavaModelClassFileProducer constructor(override val vrapTypeProvider: Vrap |import com.fasterxml.jackson.annotation.JsonProperty; |import org.apache.commons.lang3.builder.EqualsBuilder; |import org.apache.commons.lang3.builder.HashCodeBuilder; + |import org.apache.commons.lang3.builder.ToStringBuilder; + |import org.apache.commons.lang3.builder.ToStringStyle; | |/** |${type.toComment(" * ${vrapType.simpleClassName}").escapeAll()} @@ -127,26 +129,43 @@ class JavaModelClassFileProducer constructor(override val vrapTypeProvider: Vrap | <${this.allProperties.filterNot { it.deprecated() }.joinToString("\n") { it.hashMethod() }}> | .toHashCode(); |} + | + |@Override + |public String toString() { + | return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + | <${this.allProperties.filterNot { it.deprecated() }.joinToString("\n") { it.toStringMethod() }}> + | .build(); + |} """.trimMargin().keepIndentation() } private fun Property.equalsMethod(): String { - if (this.isPatternProperty()) { - return ".append(values, that.values)" + return if (this.isPatternProperty()) { + ".append(values, that.values)" } else if (this.name.equals("interface")) { - return ".append(_interface, that._interface)" + ".append(_interface, that._interface)" } else { - return ".append(${this.name.lowerCamelCase()}, that.${this.name.lowerCamelCase()})" + ".append(${this.name.lowerCamelCase()}, that.${this.name.lowerCamelCase()})" } } private fun Property.hashMethod(): String { - if (this.isPatternProperty()) { - return ".append(values)" + return if (this.isPatternProperty()) { + ".append(values)" + } else if (this.name.equals("interface")) { + ".append(_interface)" + } else { + ".append(${this.name.lowerCamelCase()})" + } + } + + private fun Property.toStringMethod(): String { + return if (this.isPatternProperty()) { + ".append(\"values\", values)" } else if (this.name.equals("interface")) { - return ".append(_interface)" + ".append(\"interface\", _interface)" } else { - return ".append(${this.name.lowerCamelCase()})" + ".append(\"${this.name.lowerCamelCase()}\", ${this.name.lowerCamelCase()})" } }