Skip to content

Commit

Permalink
add toString method to Impl classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Nov 13, 2023
1 parent e9e4d19 commit 72f59f4
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down Expand Up @@ -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()})"
}
}

Expand Down

0 comments on commit 72f59f4

Please sign in to comment.