Skip to content

Commit

Permalink
Update _enumName_.kt.ejs
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Aug 7, 2024
1 parent 4334f85 commit fe39867
Showing 1 changed file with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License")
Licensed under the Apache License, Version 2.0 (the "
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -18,46 +18,21 @@
-%>
package <%= entityAbsolutePackage %>.domain.enumeration
<%_ if (enumJavadoc) { _%>
<%- enumJavadoc %>
<%_ } else { _%>
<%_ if (typeof javadoc === 'undefined') { _%>
/**
* The <%= enumName %> enumeration.
*/
<%_ } else { _%>
<%= javadoc %>
<%_ } _%>
public enum <%= enumName %> {
<%_ if (withoutCustomValues) { _%>
<%= enumValues.map(enumValue => `${enumValue.comment && `\n${enumValue.comment}\n` || ''} ${enumValue.name}`).join(', ') %>
<%_ } else {
// The following code redefines the variable state to be 'without CustomValue' when name equals value.
withoutCustomValues = enumValues.every(({name, value}) => name === value);
withCustomValues = enumValues.every(({name, value}) => name !== value);
withSomeCustomValues = !withoutCustomValues && !withCustomValues
enumValues.forEach((enumWithCustomValue, index) => {
if (enumWithCustomValue.comment){ _%>
<%= enumWithCustomValue.comment %>
<%_ }
if (enumWithCustomValue.name === enumWithCustomValue.value) { _%>
<%= enumWithCustomValue.name %><% if (index < enumValues.length - 1) { %>,<% } else { %>;<% } %>
<%_ } else { _%>
<%= enumWithCustomValue.name %>("<%= enumWithCustomValue.value %>")<% if (index < enumValues.length - 1) { %>,<% } else { %>;<% } %>
<%_ }
}); _%>
<%_ if (!withoutCustomValues) { _%>
private<% if (withCustomValues) { %> final<% } %> String value
<%_ if (withSomeCustomValues) { _%>
<%= enumName %>() {}
<%_ } _%>
<%= enumName %>(String value) {
this.value = value
}
fun getValue(): String {
return value
}
<%_ } _%>
<%_ } _%>
enum class <%= enumName %><%if (!withoutCustomValues) { %>(val <%= enumName %>: String) <% } %>{
<%_ if (withoutCustomValues) { _%>
<%= enumValues.map(enumValue => `${enumValue.comment && `\n${enumValue.comment}\n` || ''} ${enumValue.name}`).join(', ') %>
<%_ } else {
enumValues.forEach((enumWithCustomValue, index) => { _%>
<%_ if (enumWithCustomValue.comment){ _%>
<%= enumWithCustomValue.comment %>
<%_ } _%>
<%= enumWithCustomValue.name %>("<%= enumWithCustomValue.value %>")<% if (index < enumValues.length - 1) { %>,<% } %>
<%_ }); }_%>
}

0 comments on commit fe39867

Please sign in to comment.