Compare commits
2 Commits
67f4b40989
...
4c2b2a5580
| Author | SHA1 | Date |
|---|---|---|
|
|
4c2b2a5580 | 3 years ago |
|
|
204740ca8b | 3 years ago |
@ -0,0 +1,9 @@ |
||||
package de.kreth.property2java.processor; |
||||
|
||||
public enum Format { |
||||
|
||||
WithUnaryOperatorParameter, |
||||
WithInnerPropertyResourceBundle, |
||||
WithInnerPropertyLoader, |
||||
WithInitializer |
||||
} |
||||
@ -0,0 +1,46 @@ |
||||
package de.kreth.property2java.processor; |
||||
|
||||
import static java.lang.annotation.ElementType.TYPE; |
||||
|
||||
import java.lang.annotation.Repeatable; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
@Target(TYPE) |
||||
@Retention(RetentionPolicy.SOURCE) |
||||
@Repeatable(value = GenerateResourceBundleProperty2Javas.class) |
||||
/** |
||||
* Für die konfigurierten Resourcen wird jeweils eine Java Klasse erzeugt. Es |
||||
* muss nur die Abhängigkeit eingebunden werden und die Annotation in einer |
||||
* Klasse verwendet werden, in deren Package die neuen Klassen generiert werden. |
||||
* Wenn mehrere Resourcen verarbeitet werden sollen, kann diese Annotation |
||||
* mehrfach parallel angegeben werden. |
||||
* |
||||
* Für die Ausgabe der Prozessornachrichten muss folgendes im maven compiler |
||||
* konfiguriert werden: |
||||
* |
||||
* <pre> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>3.8.0</version> |
||||
<configuration> |
||||
<release>${java.version}</release> |
||||
<b><showWarnings>true</showWarnings></b> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
* </pre> |
||||
* |
||||
* @author Markus |
||||
* |
||||
*/ |
||||
public @interface GenerateResourceBundleProperty2Java { |
||||
String resource(); |
||||
|
||||
Format format(); |
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
package de.kreth.property2java.processor; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* Diese Annotation sollte nicht verwendet werden. Sie sammelt nur |
||||
* {@link GenerateResourceBundleProperty2Java} wenn diese mehrfach verwendet |
||||
* wird. |
||||
* |
||||
* @author Markus |
||||
* |
||||
*/ |
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface GenerateResourceBundleProperty2Javas { |
||||
|
||||
GenerateResourceBundleProperty2Java[] value(); |
||||
} |
||||
@ -0,0 +1,59 @@ |
||||
<#if package??>package ${package}; |
||||
|
||||
</#if>import java.util.Properties; |
||||
import java.util.ResourceBundle; |
||||
import java.util.function.UnaryOperator; |
||||
|
||||
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>; |
||||
private static UnaryOperator<String> function; |
||||
private final String value; |
||||
|
||||
private ${classname} (String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
public static void init(UnaryOperator<String> resourceFunction) { |
||||
function = resourceFunction; |
||||
} |
||||
|
||||
/** |
||||
* Represented Key in property File. |
||||
* @return key |
||||
*/ |
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
/** |
||||
* Resolves the value for this key. |
||||
* {@link #init(UnaryOperator<String>)} must be called before. |
||||
*/ |
||||
public String getText() { |
||||
return function.apply(value); |
||||
} |
||||
|
||||
/** |
||||
* Resolves the value for this key from the parameter function. |
||||
* <p> |
||||
* e.g. <code>${classname}.getString(resBundle::getString)</code> |
||||
* @param resourceFunction {@link Properties#getProperty(String)} or {@link ResourceBundle#getString(String)} |
||||
* @return |
||||
*/ |
||||
public String getString(UnaryOperator<String> resourceFunction) { |
||||
return resourceFunction.apply(value); |
||||
} |
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
<#if package??>package ${package}; |
||||
|
||||
</#if>import java.util.Properties; |
||||
import java.util.PropertyResourceBundle; |
||||
import java.util.ResourceBundle; |
||||
import java.util.function.UnaryOperator; |
||||
|
||||
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>; |
||||
|
||||
private final String value; |
||||
|
||||
private ${classname} (String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
/** |
||||
* Represented Key in property File. |
||||
* @return key |
||||
*/ |
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
private static ResourceBundle bundle = PropertyResourceBundle.getBundle("${bundle_base_name}"); |
||||
|
||||
/** |
||||
* The Text for this Key from PropertyResourceBundle |
||||
* @return human readable text |
||||
*/ |
||||
public String getText() { |
||||
return bundle.getString(value); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
<#if package??>package ${package}; |
||||
|
||||
</#if>import java.util.Properties; |
||||
import java.util.PropertyResourceBundle; |
||||
import java.util.ResourceBundle; |
||||
import java.util.function.UnaryOperator; |
||||
|
||||
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>; |
||||
|
||||
private final String value; |
||||
|
||||
private ${classname} (String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
/** |
||||
* Represented Key in property File. |
||||
* @return key |
||||
*/ |
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
private static ResourceBundle bundle = PropertyResourceBundle.getBundle("${bundle_base_name}"); |
||||
|
||||
/** |
||||
* The Text for this Key from PropertyResourceBundle |
||||
* @return human readable text |
||||
*/ |
||||
public String getText() { |
||||
return bundle.getString(value); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue