diff --git a/src/main/resources/template/enum_template.tpl b/src/main/resources/template/enum_template.tpl index 643dd3c..0c7bc3c 100644 --- a/src/main/resources/template/enum_template.tpl +++ b/src/main/resources/template/enum_template.tpl @@ -1,6 +1,4 @@ -<#if package??>package ${package}; - -import java.util.Properties; +<#include "parts/package_part.tpl">import java.util.Properties; import java.util.ResourceBundle; import java.util.function.UnaryOperator; @@ -11,17 +9,7 @@ import javax.annotation.processing.Generated; * {@link #getValue()} gives the key for the entry, with {@link #getString(UnaryOperator)} * the value is given directly. */ -@Generated(date = "${generation_date}", value = "${generator_name}") -public enum ${classname} { - -<#list entries as e> - /** - * ${e.key} = "${e.value}" - */ - ${e.constant} ("${e.key}")<#sep>, - -; - +<#include "parts/enum_head_values.tpl"> private final String value; private ${classname} (String value) { diff --git a/src/main/resources/template/enum_template_with_initializer.tpl b/src/main/resources/template/enum_template_with_initializer.tpl index 6101d32..739530f 100644 --- a/src/main/resources/template/enum_template_with_initializer.tpl +++ b/src/main/resources/template/enum_template_with_initializer.tpl @@ -1,6 +1,4 @@ -<#if package??>package ${package}; - -import java.util.Properties; +<#include "parts/package_part.tpl">import java.util.Properties; import java.util.ResourceBundle; import java.util.function.UnaryOperator; @@ -11,17 +9,7 @@ import javax.annotation.processing.Generated; * {@link #getValue()} gives the key for the entry, with {@link #getText()} the value for the key is given directly. * This enum needs to be initialized before any use by {@link #init(UnaryOperator)}. */ -@Generated(date = "${generation_date}", value = "${generator_name}") -public enum ${classname} { - -<#list entries as e> - /** - * ${e.key} = "${e.value}" - */ - ${e.constant} ("${e.key}")<#sep>, - -; - +<#include "parts/enum_head_values.tpl"> private static UnaryOperator function; private final String value; diff --git a/src/main/resources/template/enum_template_with_inner_properties.tpl b/src/main/resources/template/enum_template_with_inner_properties.tpl index 13020c3..d7ea0d2 100644 --- a/src/main/resources/template/enum_template_with_inner_properties.tpl +++ b/src/main/resources/template/enum_template_with_inner_properties.tpl @@ -1,6 +1,4 @@ -<#if package??>package ${package}; - -import java.io.IOException; +<#include "parts/package_part.tpl">import java.io.IOException; import java.io.UncheckedIOException; import java.util.Properties; @@ -9,17 +7,7 @@ import javax.annotation.processing.Generated; /** * Property keys from ${fileName} */ -@Generated(date = "${generation_date}", value = "${generator_name}") -public enum ${classname} { - -<#list entries as e> - /** - * ${e.key} = "${e.value}" - */ - ${e.constant} ("${e.key}")<#sep>, - -; - +<#include "parts/enum_head_values.tpl"> private ${classname} (String value) { this.value = value; } diff --git a/src/main/resources/template/enum_template_with_inner_propertyresourcebundle.tpl b/src/main/resources/template/enum_template_with_inner_propertyresourcebundle.tpl index a1a2df0..7263dc3 100644 --- a/src/main/resources/template/enum_template_with_inner_propertyresourcebundle.tpl +++ b/src/main/resources/template/enum_template_with_inner_propertyresourcebundle.tpl @@ -1,6 +1,4 @@ -<#if package??>package ${package}; - -import java.util.PropertyResourceBundle; +<#include "parts/package_part.tpl">import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import javax.annotation.processing.Generated; @@ -10,17 +8,7 @@ import javax.annotation.processing.Generated; * {@link #getValue()} gives the key for the entry, with {@link #getText()} the value for the key is given directly. * Initializationis generated also. */ -@Generated(date = "${generation_date}", value = "${generator_name}") -public enum ${classname} { - -<#list entries as e> - /** - * ${e.key} = "${e.value}" - */ - ${e.constant} ("${e.key}")<#sep>, - -; - +<#include "parts/enum_head_values.tpl"> private static ResourceBundle bundle = PropertyResourceBundle.getBundle("${bundle_base_name}"); private final String value; diff --git a/src/main/resources/template/parts/enum_head_values.tpl b/src/main/resources/template/parts/enum_head_values.tpl new file mode 100644 index 0000000..e21070c --- /dev/null +++ b/src/main/resources/template/parts/enum_head_values.tpl @@ -0,0 +1,11 @@ + +@Generated(date = "${generation_date}", value = "${generator_name}") +public enum ${classname} { + +<#list entries as e> + /** + * ${e.key} = "${e.value}" + */ + ${e.constant} ("${e.key}")<#sep>, + +; diff --git a/src/main/resources/template/parts/package_part.tpl b/src/main/resources/template/parts/package_part.tpl new file mode 100644 index 0000000..fe7bc94 --- /dev/null +++ b/src/main/resources/template/parts/package_part.tpl @@ -0,0 +1,3 @@ +<#if package??>package ${package}; + + \ No newline at end of file diff --git a/src/test/java/de/kreth/property2java/GeneratorWithInnerPropertiesTest.java b/src/test/java/de/kreth/property2java/GeneratorWithInnerPropertiesTest.java index 705fda5..93f5e00 100644 --- a/src/test/java/de/kreth/property2java/GeneratorWithInnerPropertiesTest.java +++ b/src/test/java/de/kreth/property2java/GeneratorWithInnerPropertiesTest.java @@ -134,7 +134,7 @@ public class GeneratorWithInnerPropertiesTest { Matchers.stringContainsInOrder(Arrays.asList("private", "static", "Properties", "properties", "=", "new Properties()", ";"))); assertThat(load, - Matchers.containsString("properties.load(Application_Properties.class.getResourceAsStream(\"application.properties\"));")); + Matchers.containsString("properties.load(Application_Properties.class.getResourceAsStream(\"/application.properties\"));")); } diff --git a/src/test/java/de/kreth/property2java/generated/Property_Loader_Properties.java b/src/test/java/de/kreth/property2java/generated/Property_Loader_Properties.java index b9026da..26fda57 100644 --- a/src/test/java/de/kreth/property2java/generated/Property_Loader_Properties.java +++ b/src/test/java/de/kreth/property2java/generated/Property_Loader_Properties.java @@ -9,7 +9,8 @@ import javax.annotation.processing.Generated; /** * Property keys from property_loader.properties */ -@Generated(date = "05.08.2024, 22:08:26", value = "de.kreth.property2java.Generator") + +@Generated(date = "05.08.2024, 22:43:54", value = "de.kreth.property2java.Generator") public enum Property_Loader_Properties { /** @@ -97,7 +98,6 @@ public enum Property_Loader_Properties { * message.user.passwordmissmatch = "Passwords don't match." */ MESSAGE_USER_PASSWORDMISSMATCH ("message.user.passwordmissmatch"); - private Property_Loader_Properties (String value) { this.value = value; } diff --git a/src/test/java/de/kreth/property2java/generated/Resource_Bundle_Properties.java b/src/test/java/de/kreth/property2java/generated/Resource_Bundle_Properties.java index c9e426a..4c83060 100644 --- a/src/test/java/de/kreth/property2java/generated/Resource_Bundle_Properties.java +++ b/src/test/java/de/kreth/property2java/generated/Resource_Bundle_Properties.java @@ -10,7 +10,8 @@ import javax.annotation.processing.Generated; * {@link #getValue()} gives the key for the entry, with {@link #getText()} the value for the key is given directly. * Initializationis generated also. */ -@Generated(date = "05.08.2024, 22:08:26", value = "de.kreth.property2java.Generator") + +@Generated(date = "05.08.2024, 22:43:54", value = "de.kreth.property2java.Generator") public enum Resource_Bundle_Properties { /** @@ -98,7 +99,6 @@ public enum Resource_Bundle_Properties { * message.user.passwordmissmatch = "Passwords don't match." */ MESSAGE_USER_PASSWORDMISSMATCH ("message.user.passwordmissmatch"); - private static ResourceBundle bundle = PropertyResourceBundle.getBundle("resource_bundle"); private final String value; diff --git a/src/test/java/de/kreth/property2java/generated/Unary_Operator_Properties.java b/src/test/java/de/kreth/property2java/generated/Unary_Operator_Properties.java index 4cf86ba..8a51ec5 100644 --- a/src/test/java/de/kreth/property2java/generated/Unary_Operator_Properties.java +++ b/src/test/java/de/kreth/property2java/generated/Unary_Operator_Properties.java @@ -11,7 +11,8 @@ import javax.annotation.processing.Generated; * {@link #getValue()} gives the key for the entry, with {@link #getString(UnaryOperator)} * the value is given directly. */ -@Generated(date = "05.08.2024, 22:08:26", value = "de.kreth.property2java.Generator") + +@Generated(date = "05.08.2024, 22:43:54", value = "de.kreth.property2java.Generator") public enum Unary_Operator_Properties { /** @@ -99,7 +100,6 @@ public enum Unary_Operator_Properties { * message.user.passwordmissmatch = "Passwords don't match." */ MESSAGE_USER_PASSWORDMISSMATCH ("message.user.passwordmissmatch"); - private final String value; private Unary_Operator_Properties (String value) {