Permission and config improvements, fixes #66

Merged
NorbiPeti merged 13 commits from dev into master 2019-06-06 18:39:52 +00:00
2 changed files with 30 additions and 16 deletions
Showing only changes of commit 87189eb1ad - Show all commits

View file

@ -12,6 +12,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />

View file

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