pull/11/head
Markus Kreth 1 year ago
parent 9306a3987e
commit 5985320b97
  1. 87
      src/main/java/de/kreth/property2java/Configuration.java
  2. 202
      src/main/java/de/kreth/property2java/Generator.java
  3. 122
      src/main/java/de/kreth/property2java/cli/ArgumentConfiguration.java
  4. 6
      src/main/java/de/kreth/property2java/cli/CliConfig.java
  5. 46
      src/main/java/de/kreth/property2java/config/FreemarkerConfig.java
  6. 40
      src/main/java/de/kreth/property2java/processor/Format.java
  7. 4
      src/main/java/de/kreth/property2java/processor/GenerateProperty2Java.java
  8. 4
      src/main/java/de/kreth/property2java/processor/GenerateResourceBundleProperty2Java.java
  9. 4
      src/main/java/de/kreth/property2java/processor/GenerateResourceBundleProperty2Javas.java
  10. 148
      src/main/java/de/kreth/property2java/processor/ProcessorConfiguration.java
  11. 96
      src/main/java/de/kreth/property2java/processor/Property2JavaGenerator.java

@ -16,50 +16,47 @@ import de.kreth.property2java.processor.Format;
public interface Configuration {
/**
* Package for generated Java Classes eg. "de.kreth.property2java". If null - no
* package line is generated.
*
* @return
*/
String getPackage();
default Format getFormat() {
return Format.WithUnaryOperatorParameter;
}
/**
* Filename to InputReader Entries
*
* @return
*/
Map<String, Reader> getInput();
/**
* Path of java source folder.
*
* @return
*/
Path getRootPath();
default Writer outWriter(String fileName) throws IOException {
return new FileWriter(new File(getRootPath().toFile(), mapFilenameToClassName(fileName) + ".java"),
outputCharset());
}
default Charset outputCharset() {
return Charset.defaultCharset();
}
default String mapFilenameToClassName(String fileName) {
String path = Regex.PATTERN.matcher(fileName)
.replaceAll(".")
.replaceAll("\\.", "_")
.replaceAll(" ", "_")
.replaceAll("/", "_");
path = WordUtils.capitalize(path, '_');
return path;
}
/**
* Package for generated Java Classes eg. "de.kreth.property2java". If null - no
* package line is generated.
*
* @return
*/
String getPackage();
default Format getFormat() {
return Format.WithUnaryOperatorParameter;
}
/**
* Filename to InputReader Entries
*
* @return
*/
Map<String, Reader> getInput();
/**
* Path of java source folder.
*
* @return
*/
Path getRootPath();
default Writer outWriter(String fileName) throws IOException {
return new FileWriter(new File(getRootPath().toFile(), mapFilenameToClassName(fileName) + ".java"),
outputCharset());
}
default Charset outputCharset() {
return Charset.defaultCharset();
}
default String mapFilenameToClassName(String fileName) {
String path = Regex.PATTERN.matcher(fileName).replaceAll(".").replaceAll("\\.", "_").replaceAll(" ", "_")
.replaceAll("/", "_");
path = WordUtils.capitalize(path, '_');
return path;
}
}

@ -22,143 +22,137 @@ import freemarker.template.TemplateException;
public class Generator {
private static final DateFormat dateTimeInstance = DateFormat.getDateTimeInstance();
private static final DateFormat dateTimeInstance = DateFormat.getDateTimeInstance();
private final Configuration config;
private final Configuration config;
private final Template template;
private final Template template;
public Generator(Configuration config) {
this.config = config;
try {
template = FreemarkerConfig.INSTANCE.getTemplate(config.getFormat());
} catch (IOException e) {
throw new IllegalStateException("Unable to load freemarker template", e);
public Generator(Configuration config) {
this.config = config;
try {
template = FreemarkerConfig.INSTANCE.getTemplate(config.getFormat());
} catch (IOException e) {
throw new IllegalStateException("Unable to load freemarker template", e);
}
}
}
public void start() throws IOException, GeneratorException {
public void start() throws IOException, GeneratorException {
for (Map.Entry<String, Reader> entry : config.getInput().entrySet()) {
String fileName = entry.getKey();
try (Writer out = config.outWriter(fileName)) {
for (Map.Entry<String, Reader> entry : config.getInput().entrySet()) {
String fileName = entry.getKey();
try (Writer out = config.outWriter(fileName)) {
Properties properties = new Properties();
properties.load(entry.getValue());
try {
generate(properties, out, fileName, config);
} catch (TemplateException e) {
throw new GeneratorException("Error configuring Engine", e);
Properties properties = new Properties();
properties.load(entry.getValue());
try {
generate(properties, out, fileName, config);
} catch (TemplateException e) {
throw new GeneratorException("Error configuring Engine", e);
}
}
}
}
}
}
void generate(Properties properties, Writer out, String fileName, Configuration config)
throws IOException, TemplateException {
void generate(Properties properties, Writer out, String fileName, Configuration config)
throws IOException, TemplateException {
Map<String, Object> root = new HashMap<>();
root.put("generator_name", getClass().getName());
root.put("generation_date", dateTimeInstance.format(new Date()));
root.put("package", config.getPackage());
root.put("fileName", fileName);
root.put("bundle_base_name", fileName.substring(0, min(fileName.length(), fileName.lastIndexOf('.'))));
root.put("classname", config.mapFilenameToClassName(fileName));
Map<String, Object> root = new HashMap<>();
root.put("generator_name", getClass().getName());
root.put("generation_date", dateTimeInstance.format(new Date()));
root.put("package", config.getPackage());
root.put("fileName", fileName);
root.put("bundle_base_name", fileName.substring(0, min(fileName.length(), fileName.lastIndexOf('.'))));
root.put("classname", config.mapFilenameToClassName(fileName));
List<Entry> entries = new ArrayList<>();
List<Entry> entries = new ArrayList<>();
root.put("entries", entries);
root.put("entries", entries);
@SuppressWarnings("unchecked")
List<String> propertyNames = Collections.list((Enumeration<String>) properties.propertyNames());
Collections.sort(propertyNames);
@SuppressWarnings("unchecked")
List<String> propertyNames = Collections.list((Enumeration<String>) properties.propertyNames());
Collections.sort(propertyNames);
for (String propertyKeyString : propertyNames) {
final String propertyValue = properties.getProperty(propertyKeyString);
for (String propertyKeyString : propertyNames) {
final String propertyValue = properties.getProperty(propertyKeyString);
entries.add(new Entry(propertyKeyString.toUpperCase().replaceAll("[\\.-]", "_"), propertyKeyString,
propertyValue));
entries.add(new Entry(propertyKeyString.toUpperCase().replaceAll("[\\.-]", "_"), propertyKeyString,
propertyValue));
}
template.process(root, out);
}
template.process(root, out);
}
int min(int a, int b) {
int result = Math.min(a, b);
if (result < 0) {
result = Math.max(a, b);
int min(int a, int b) {
int result = Math.min(a, b);
if (result < 0) {
result = Math.max(a, b);
}
return result;
}
return result;
}
public static void main(String[] args) throws IOException, GeneratorException {
Generator generator = new Generator(ArgumentConfiguration.parse(args));
generator.start();
}
public static void generateFor(Class<?> locationClass, List<URL> rescources, String relativeTargetDir)
throws IOException, GeneratorException {
ArgumentConfiguration.Builder config = new ArgumentConfiguration.Builder();
rescources
.stream()
.map(URL::getFile)
.map(File::new)
.map(File::getAbsolutePath)
.forEach(config::addPropFile);
config.setPackageName(locationClass.getPackageName())
.setTarget(relativeTargetDir);
public static void main(String[] args) throws IOException, GeneratorException {
Generator generator = new Generator(ArgumentConfiguration.parse(args));
generator.start();
}
Generator g = new Generator(config.build());
g.start();
}
public static void generateFor(Class<?> locationClass, List<URL> rescources, String relativeTargetDir)
throws IOException, GeneratorException {
/**
* Represents an Property Entry for the generated java class.
*
* @author markus
*
*/
public class Entry {
ArgumentConfiguration.Builder config = new ArgumentConfiguration.Builder();
public final String constant;
rescources.stream().map(URL::getFile).map(File::new).map(File::getAbsolutePath).forEach(config::addPropFile);
public final String key;
config.setPackageName(locationClass.getPackageName()).setTarget(relativeTargetDir);
public final String value;
Generator g = new Generator(config.build());
g.start();
}
/**
* Creates Property Entry data for the generated java class.
* Represents an Property Entry for the generated java class.
*
* @author markus
*
* @param constant name for the created constant.
* @param key property key
* @param value property value
*/
public Entry(String constant, String key, String value) {
super();
this.constant = constant;
this.key = key;
this.value = value;
}
public class Entry {
public final String constant;
public final String key;
public final String value;
/**
* Creates Property Entry data for the generated java class.
*
* @param constant name for the created constant.
* @param key property key
* @param value property value
*/
public Entry(String constant, String key, String value) {
super();
this.constant = constant;
this.key = key;
this.value = value;
}
public String getConstant() {
return constant;
}
public String getConstant() {
return constant;
}
public String getKey() {
return key;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return "Entry [constant=" + constant + ", key=" + key + ", value=" + value + "]";
}
@Override
public String toString() {
return "Entry [constant=" + constant + ", key=" + key + ", value=" + value + "]";
}
}
}
}

@ -16,81 +16,81 @@ import de.kreth.property2java.Configuration;
public class ArgumentConfiguration implements Configuration {
private final String packageName;
private final String packageName;
private final Map<String, Reader> files;
private final Map<String, Reader> files;
private final Path rootPath;
private final Path rootPath;
private ArgumentConfiguration(Builder builder) throws IOException {
this.packageName = builder.packageName;
rootPath = new File(builder.target).toPath();
files = new HashMap<>();
for (String filePath : builder.propFiles) {
File f = new File(filePath);
files.put(f.getName(), new FileReader(f));
}
private ArgumentConfiguration(Builder builder) throws IOException {
this.packageName = builder.packageName;
rootPath = new File(builder.target).toPath();
files = new HashMap<>();
for (String filePath : builder.propFiles) {
File f = new File(filePath);
files.put(f.getName(), new FileReader(f));
}
}
@Override
public String getPackage() {
return packageName;
}
@Override
public Map<String, Reader> getInput() {
return files;
}
@Override
public Path getRootPath() {
return rootPath;
}
@Override
public Writer outWriter(String fileName) throws IOException {
File dir;
if (packageName != null && packageName.isBlank() == false) {
dir = new File(rootPath.toFile(), packageName.replace('.', File.separatorChar));
} else {
dir = rootPath.toFile();
}
return new FileWriter(new File(dir, mapFilenameToClassName(fileName) + ".java"), false);
}
public static Configuration parse(String[] args) throws IOException {
CliConfig cliConfig = new CliConfig();
@Override
public String getPackage() {
return packageName;
}
Builder builder = new Builder();
cliConfig.fill(builder, args);
return builder.build();
}
@Override
public Map<String, Reader> getInput() {
return files;
}
public static class Builder {
String target;
@Override
public Path getRootPath() {
return rootPath;
}
List<String> propFiles = new ArrayList<>();
@Override
public Writer outWriter(String fileName) throws IOException {
File dir;
if (packageName != null && packageName.isBlank() == false) {
dir = new File(rootPath.toFile(), packageName.replace('.', File.separatorChar));
} else {
dir = rootPath.toFile();
}
return new FileWriter(new File(dir, mapFilenameToClassName(fileName) + ".java"), false);
}
String packageName;
public static Configuration parse(String[] args) throws IOException {
CliConfig cliConfig = new CliConfig();
public Builder setTarget(String target) {
this.target = target;
return this;
Builder builder = new Builder();
cliConfig.fill(builder, args);
return builder.build();
}
public Builder addPropFile(String propFile) {
this.propFiles.add(propFile);
return this;
}
public static class Builder {
String target;
public Builder setPackageName(String packageName) {
this.packageName = packageName;
return this;
}
List<String> propFiles = new ArrayList<>();
String packageName;
public Builder setTarget(String target) {
this.target = target;
return this;
}
public Builder addPropFile(String propFile) {
this.propFiles.add(propFile);
return this;
}
public Builder setPackageName(String packageName) {
this.packageName = packageName;
return this;
}
public Configuration build() throws IOException {
return new ArgumentConfiguration(this);
public Configuration build() throws IOException {
return new ArgumentConfiguration(this);
}
}
}
}

@ -35,12 +35,10 @@ public class CliConfig {
for (String value : cmd.getOptionValues("f")) {
builder.addPropFile(value);
}
}
catch (MissingOptionException e) {
} catch (MissingOptionException e) {
printHelp();
throw new IllegalStateException(e);
}
catch (ParseException e) {
} catch (ParseException e) {
throw new IOException("Unable to parse Arguments", e);
}
}

@ -8,30 +8,30 @@ import freemarker.template.Template;
public enum FreemarkerConfig {
INSTANCE;
private final Configuration cfg;
public Template getTemplate(Format format) throws IOException {
switch (format) {
case WithInitializer:
return cfg.getTemplate("enum_template_with_initializer.tpl");
case WithInnerPropertyLoader:
return cfg.getTemplate("enum_template_with_inner_properties.tpl");
case WithInnerPropertyResourceBundle:
return cfg.getTemplate("enum_template_with_inner_propertyresourcebundle.tpl");
case WithUnaryOperatorParameter:
return cfg.getTemplate("enum_template.tpl");
default:
throw new IllegalArgumentException("Format " + format + " is not supported.");
}
INSTANCE;
private final Configuration cfg;
public Template getTemplate(Format format) throws IOException {
switch (format) {
case WithInitializer:
return cfg.getTemplate("enum_template_with_initializer.tpl");
case WithInnerPropertyLoader:
return cfg.getTemplate("enum_template_with_inner_properties.tpl");
case WithInnerPropertyResourceBundle:
return cfg.getTemplate("enum_template_with_inner_propertyresourcebundle.tpl");
case WithUnaryOperatorParameter:
return cfg.getTemplate("enum_template.tpl");
default:
throw new IllegalArgumentException("Format " + format + " is not supported.");
}
}
}
private FreemarkerConfig() {
cfg = new Configuration(Configuration.VERSION_2_3_28);
cfg.setClassForTemplateLoading(this.getClass(), "/template/");
cfg.setDefaultEncoding("UTF-8");
}
private FreemarkerConfig() {
cfg = new Configuration(Configuration.VERSION_2_3_28);
cfg.setClassForTemplateLoading(this.getClass(), "/template/");
cfg.setDefaultEncoding("UTF-8");
}
}

@ -4,24 +4,24 @@ import java.util.PropertyResourceBundle;
public enum Format {
/**
* Offers a getString(UnaryOperator resourceFunction) method to access the
* String value
*/
WithUnaryOperatorParameter,
/**
* Generates {@link PropertyResourceBundle} to offer a getText() method without
* parameters.
*/
WithInnerPropertyResourceBundle,
/**
* Offers a generated {@link PropertyResourceBundle} to offer a getText() method
* without parameters.
*/
WithInnerPropertyLoader,
/**
* Offers a static init(UnaryOperator resourceFunction) method to offer a
* getText() method. The init method must be called before any getText() call.
*/
WithInitializer
/**
* Offers a getString(UnaryOperator resourceFunction) method to access the
* String value
*/
WithUnaryOperatorParameter,
/**
* Generates {@link PropertyResourceBundle} to offer a getText() method without
* parameters.
*/
WithInnerPropertyResourceBundle,
/**
* Offers a generated {@link PropertyResourceBundle} to offer a getText() method
* without parameters.
*/
WithInnerPropertyLoader,
/**
* Offers a static init(UnaryOperator resourceFunction) method to offer a
* getText() method. The init method must be called before any getText() call.
*/
WithInitializer
}

@ -36,7 +36,7 @@ import java.lang.annotation.Target;
*
*/
public @interface GenerateProperty2Java {
String[] resources();
String[] resources();
Format format() default Format.WithUnaryOperatorParameter;
Format format() default Format.WithUnaryOperatorParameter;
}

@ -40,7 +40,7 @@ import java.lang.annotation.Target;
*
*/
public @interface GenerateResourceBundleProperty2Java {
String resource();
String resource();
Format format();
Format format();
}

@ -15,7 +15,7 @@ import java.lang.annotation.Target;
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface GenerateResourceBundleProperty2Javas {
@interface GenerateResourceBundleProperty2Javas {
GenerateResourceBundleProperty2Java[] value();
GenerateResourceBundleProperty2Java[] value();
}

@ -24,93 +24,93 @@ import de.kreth.property2java.GeneratorException;
public class ProcessorConfiguration implements Configuration {
private final Filer filer;
private final Element element;
private final Map<String, Reader> input;
private final Format format;
ProcessorConfiguration(Builder builder) throws IOException {
this.filer = builder.filer;
this.element = builder.element;
this.format = Objects.requireNonNullElse(builder.format, Format.WithUnaryOperatorParameter);
this.input = new HashMap<>();
for (String resource : builder.resourcenames) {
FileObject ressource = filer.getResource(StandardLocation.CLASS_PATH, "", resource);
input.put(resource, ressource.openReader(false));
private final Filer filer;
private final Element element;
private final Map<String, Reader> input;
private final Format format;
ProcessorConfiguration(Builder builder) throws IOException {
this.filer = builder.filer;
this.element = builder.element;
this.format = Objects.requireNonNullElse(builder.format, Format.WithUnaryOperatorParameter);
this.input = new HashMap<>();
for (String resource : builder.resourcenames) {
FileObject ressource = filer.getResource(StandardLocation.CLASS_PATH, "", resource);
input.put(resource, ressource.openReader(false));
}
}
}
@Override
public String getPackage() {
@Override
public String getPackage() {
String packageName = "";
if (element instanceof TypeElement) {
TypeElement typeElement = (TypeElement) element;
PackageElement packageElement = (PackageElement) typeElement.getEnclosingElement();
packageName = packageElement.getQualifiedName().toString();
String packageName = "";
if (element instanceof TypeElement) {
TypeElement typeElement = (TypeElement) element;
PackageElement packageElement = (PackageElement) typeElement.getEnclosingElement();
packageName = packageElement.getQualifiedName().toString();
}
return packageName;
}
return packageName;
}
@Override
public Format getFormat() {
return format;
}
@Override
public Map<String, Reader> getInput() {
return input;
}
@Override
public Path getRootPath() {
throw new UnsupportedOperationException(
"For Annotation Processor this is not supported as outWriter is overwritten.");
}
@Override
public Writer outWriter(String fileName) throws IOException {
String packageName = getPackage();
if (packageName != null && !packageName.isBlank()) {
fileName = packageName + "." + mapFilenameToClassName(fileName);
}
return filer.createSourceFile(fileName, element).openWriter();
}
static Builder builder(Filer filer, Element element) {
return new Builder(filer, element);
}
static class Builder {
private final Filer filer;
private final Element element;
private final List<String> resourcenames;
private Format format = Format.WithUnaryOperatorParameter;
@Override
public Format getFormat() {
return format;
}
private Builder(Filer filer, Element element) {
this.filer = filer;
this.element = element;
this.resourcenames = new ArrayList<>();
@Override
public Map<String, Reader> getInput() {
return input;
}
public Builder withFormat(Format format) {
this.format = format;
return this;
@Override
public Path getRootPath() {
throw new UnsupportedOperationException(
"For Annotation Processor this is not supported as outWriter is overwritten.");
}
public Builder addAll(String[] resourceNames) {
this.resourcenames.addAll(Arrays.asList(resourceNames));
return this;
@Override
public Writer outWriter(String fileName) throws IOException {
String packageName = getPackage();
if (packageName != null && !packageName.isBlank()) {
fileName = packageName + "." + mapFilenameToClassName(fileName);
}
return filer.createSourceFile(fileName, element).openWriter();
}
public Builder addAll(List<String> resourceNames) {
this.resourcenames.addAll(resourceNames);
return this;
static Builder builder(Filer filer, Element element) {
return new Builder(filer, element);
}
public void startGeneration() throws IOException, GeneratorException {
Generator g = new Generator(new ProcessorConfiguration(this));
g.start();
static class Builder {
private final Filer filer;
private final Element element;
private final List<String> resourcenames;
private Format format = Format.WithUnaryOperatorParameter;
private Builder(Filer filer, Element element) {
this.filer = filer;
this.element = element;
this.resourcenames = new ArrayList<>();
}
public Builder withFormat(Format format) {
this.format = format;
return this;
}
public Builder addAll(String[] resourceNames) {
this.resourcenames.addAll(Arrays.asList(resourceNames));
return this;
}
public Builder addAll(List<String> resourceNames) {
this.resourcenames.addAll(resourceNames);
return this;
}
public void startGeneration() throws IOException, GeneratorException {
Generator g = new Generator(new ProcessorConfiguration(this));
g.start();
}
}
}
}

@ -19,73 +19,65 @@ import javax.tools.Diagnostic.Kind;
import de.kreth.property2java.GeneratorException;
@SupportedAnnotationTypes({ "de.kreth.property2java.processor.GenerateProperty2Java",
"de.kreth.property2java.processor.GenerateResourceBundleProperty2Javas",
"de.kreth.property2java.processor.GenerateResourceBundleProperty2Java" })
"de.kreth.property2java.processor.GenerateResourceBundleProperty2Javas",
"de.kreth.property2java.processor.GenerateResourceBundleProperty2Java" })
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class Property2JavaGenerator extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
processGenerateProperty2Java(roundEnv);
processGenerateResourceBundleProperty2Javas(roundEnv);
} else {
processingEnv.getMessager().printMessage(Kind.NOTE,
"finished working on annotation " + annotations);
if (!roundEnv.processingOver()) {
processGenerateProperty2Java(roundEnv);
processGenerateResourceBundleProperty2Javas(roundEnv);
} else {
processingEnv.getMessager().printMessage(Kind.NOTE, "finished working on annotation " + annotations);
}
return true;
}
return true;
}
private void processGenerateProperty2Java(RoundEnvironment roundEnv) {
processingEnv.getMessager().printMessage(Kind.NOTE,
"Processing annotation " + GenerateProperty2Java.class);
private void processGenerateProperty2Java(RoundEnvironment roundEnv) {
processingEnv.getMessager().printMessage(Kind.NOTE, "Processing annotation " + GenerateProperty2Java.class);
Set<? extends Element> elementsAnnotatedWith = roundEnv
.getElementsAnnotatedWith(GenerateProperty2Java.class);
Set<? extends Element> elementsAnnotatedWith = roundEnv.getElementsAnnotatedWith(GenerateProperty2Java.class);
for (Element element : elementsAnnotatedWith) {
GenerateProperty2Java generateAnnotation = element.getAnnotation(GenerateProperty2Java.class);
String[] resources = generateAnnotation.resources();
Format format = generateAnnotation.format();
generateElementProperties(element, Arrays.asList(resources), format);
for (Element element : elementsAnnotatedWith) {
GenerateProperty2Java generateAnnotation = element.getAnnotation(GenerateProperty2Java.class);
String[] resources = generateAnnotation.resources();
Format format = generateAnnotation.format();
generateElementProperties(element, Arrays.asList(resources), format);
}
}
}
private void processGenerateResourceBundleProperty2Javas(RoundEnvironment roundEnv) {
private void processGenerateResourceBundleProperty2Javas(RoundEnvironment roundEnv) {
processingEnv.getMessager().printMessage(Kind.NOTE,
"Processing annotation " + GenerateResourceBundleProperty2Javas.class);
processingEnv.getMessager().printMessage(Kind.NOTE,
"Processing annotation " + GenerateResourceBundleProperty2Javas.class);
Set<? extends Element> elementsAnnotatedWith = roundEnv
.getElementsAnnotatedWith(GenerateResourceBundleProperty2Javas.class);
Set<? extends Element> elementsAnnotatedWith = roundEnv
.getElementsAnnotatedWith(GenerateResourceBundleProperty2Javas.class);
for (Element element : elementsAnnotatedWith) {
GenerateResourceBundleProperty2Java[] value = element
.getAnnotation(GenerateResourceBundleProperty2Javas.class).value();
for (GenerateResourceBundleProperty2Java generateResourceBundleProperty2Java : value) {
List<String> resources = Arrays.asList(generateResourceBundleProperty2Java.resource());
generateElementProperties(element, resources, generateResourceBundleProperty2Java.format());
}
for (Element element : elementsAnnotatedWith) {
GenerateResourceBundleProperty2Java[] value = element
.getAnnotation(GenerateResourceBundleProperty2Javas.class).value();
for (GenerateResourceBundleProperty2Java generateResourceBundleProperty2Java : value) {
List<String> resources = Arrays.asList(generateResourceBundleProperty2Java.resource());
generateElementProperties(element, resources, generateResourceBundleProperty2Java.format());
}
}
}
}
private void generateElementProperties(Element element, List<String> resources, Format format) {
processingEnv.getMessager().printMessage(Kind.NOTE,
"Generating Java for " + Arrays.asList(resources));
try {
ProcessorConfiguration
.builder(processingEnv.getFiler(), element)
.addAll(resources)
.withFormat(format)
.startGeneration();
} catch (IOException | GeneratorException e) {
StringWriter out = new StringWriter();
e.printStackTrace(new PrintWriter(out));
out.flush();
processingEnv.getMessager().printMessage(Kind.ERROR, "Exception " + e + "\n" + out.toString(),
element);
private void generateElementProperties(Element element, List<String> resources, Format format) {
processingEnv.getMessager().printMessage(Kind.NOTE, "Generating Java for " + Arrays.asList(resources));
try {
ProcessorConfiguration.builder(processingEnv.getFiler(), element).addAll(resources).withFormat(format)
.startGeneration();
} catch (IOException | GeneratorException e) {
StringWriter out = new StringWriter();
e.printStackTrace(new PrintWriter(out));
out.flush();
processingEnv.getMessager().printMessage(Kind.ERROR, "Exception " + e + "\n" + out.toString(), element);
}
}
}
}

Loading…
Cancel
Save