template refactored, parts extracted.

pull/11/head
Markus Kreth 1 year ago
parent f0a9b158c4
commit 98072dcdfb
  1. 16
      src/main/resources/template/enum_template.tpl
  2. 16
      src/main/resources/template/enum_template_with_initializer.tpl
  3. 16
      src/main/resources/template/enum_template_with_inner_properties.tpl
  4. 16
      src/main/resources/template/enum_template_with_inner_propertyresourcebundle.tpl
  5. 11
      src/main/resources/template/parts/enum_head_values.tpl
  6. 3
      src/main/resources/template/parts/package_part.tpl
  7. 2
      src/test/java/de/kreth/property2java/GeneratorWithInnerPropertiesTest.java
  8. 4
      src/test/java/de/kreth/property2java/generated/Property_Loader_Properties.java
  9. 4
      src/test/java/de/kreth/property2java/generated/Resource_Bundle_Properties.java
  10. 4
      src/test/java/de/kreth/property2java/generated/Unary_Operator_Properties.java

@ -1,6 +1,4 @@
<#if package??>package ${package};
</#if>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<String>)}
* 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>,
</#sep>
</#list>;
<#include "parts/enum_head_values.tpl">
private final String value;
private ${classname} (String value) {

@ -1,6 +1,4 @@
<#if package??>package ${package};
</#if>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>,
</#sep>
</#list>;
<#include "parts/enum_head_values.tpl">
private static UnaryOperator<String> function;
private final String value;

@ -1,6 +1,4 @@
<#if package??>package ${package};
</#if>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>,
</#sep>
</#list>;
<#include "parts/enum_head_values.tpl">
private ${classname} (String value) {
this.value = value;
}

@ -1,6 +1,4 @@
<#if package??>package ${package};
</#if>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>,
</#sep>
</#list>;
<#include "parts/enum_head_values.tpl">
private static ResourceBundle bundle = PropertyResourceBundle.getBundle("${bundle_base_name}");
private final String value;

@ -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>,
</#sep>
</#list>;

@ -0,0 +1,3 @@
<#if package??>package ${package};
</#if>

@ -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\"));"));
}

@ -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;
}

@ -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;

@ -11,7 +11,8 @@ import javax.annotation.processing.Generated;
* {@link #getValue()} gives the key for the entry, with {@link #getString(UnaryOperator<String>)}
* 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) {

Loading…
Cancel
Save