From 87189eb1adce5784d5e16a1f29d0cbbb072dcdf7 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 10 Apr 2019 13:48:47 +0200 Subject: [PATCH] Config doc gen fix & markdown instead of yaml --- BuildConfigUpdater/BuildConfigUpdater.iml | 1 + .../buttonproc/ConfigProcessor.java | 45 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml index 274b3de..f14440c 100644 --- a/BuildConfigUpdater/BuildConfigUpdater.iml +++ b/BuildConfigUpdater/BuildConfigUpdater.iml @@ -12,6 +12,7 @@ + diff --git a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java index 8895fa9..c06169a 100644 --- a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java +++ b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java @@ -1,7 +1,5 @@ package buttondevteam.buttonproc; -import org.bukkit.configuration.file.YamlConfiguration; - import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; @@ -12,23 +10,24 @@ import javax.lang.model.type.TypeMirror; import javax.tools.FileObject; import javax.tools.StandardLocation; import java.io.File; +import java.io.FileWriter; import java.io.IOException; public class ConfigProcessor { private final ProcessingEnvironment procEnv; - private final YamlConfiguration yaml; - private final File file; + private final FileWriter sw; public ConfigProcessor(ProcessingEnvironment procEnv) { this.procEnv = procEnv; - FileObject file = null; + FileWriter sw = null; try { - file = procEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "config.yml"); + FileObject file = procEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "configHelp.md"); + sw = new FileWriter(new File(file.toUri())); + System.out.println(file.toUri()); } catch (IOException e) { e.printStackTrace(); } - yaml = new YamlConfiguration(); - this.file = new File(file.toUri()); + this.sw = sw; } public void process(Element targetcl) { @@ -43,23 +42,37 @@ public class ConfigProcessor { TypeMirror tm = ((ExecutableElement) e).getReturnType(); if (tm.getKind() != TypeKind.DECLARED) continue; DeclaredType dt = (DeclaredType) tm; - if (!dt.asElement().getSimpleName().contentEquals("ConfigData")) return; + if (!dt.asElement().getSimpleName().contentEquals("ConfigData")) + continue; //Ahhha! There was a return here! (MinecraftChatModule getListener()) System.out.println("Config: " + e.getSimpleName()); - System.out.println("Value: " + ((ExecutableElement) e).getDefaultValue()); + String doc = procEnv.getElementUtils().getDocComment(e); if (doc == null) continue; System.out.println("DOC: " + doc); - yaml.set(path + "." + e.getSimpleName() + "_doc", doc); //methodName_doc + try { + sw.append(path).append(".").append(String.valueOf(e.getSimpleName())).append(System.lineSeparator()).append(System.lineSeparator()); + sw.append(doc.trim()).append(System.lineSeparator()).append(System.lineSeparator()); + } catch (IOException e1) { + e1.printStackTrace(); + } } String javadoc = procEnv.getElementUtils().getDocComment(targetcl); - if (javadoc == null) return; - System.out.println("JAVADOC"); - System.out.println(javadoc); - yaml.set(path + "._doc", javadoc); try { - yaml.save(file); + if (javadoc != null) { + System.out.println("JAVADOC"); + System.out.println(javadoc.trim()); + sw.append(path).append(System.lineSeparator()).append(System.lineSeparator()); + sw.append(javadoc).append(System.lineSeparator()).append(System.lineSeparator()); + } + sw.flush(); } catch (IOException e) { e.printStackTrace(); } } + + @Override + protected void finalize() throws Throwable { + sw.close(); + super.finalize(); + } }