Added the document annotation

This commit is contained in:
Jaredlll08 2017-05-28 23:43:54 +02:00
parent b5b16dc216
commit e0116672ed
2 changed files with 68 additions and 5 deletions

View file

@ -1,9 +1,15 @@
package com.blamejared;
import com.blamejared.api.annotations.Handler;
import com.blamejared.api.annotations.*;
import minetweaker.MineTweakerAPI;
import net.minecraftforge.fml.common.*;
import net.minecraftforge.fml.common.event.*;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import static com.blamejared.reference.Reference.*;
@ -11,23 +17,71 @@ import static com.blamejared.reference.Reference.*;
public class ModTweaker {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
public void preInit(FMLPreInitializationEvent e) throws IOException {
File output = new File("output.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(output));
e.getAsmData().getAll(Handler.class.getCanonicalName()).forEach(data -> {
try {
Class clazz = Class.forName(data.getClassName());
Handler handl = (Handler) clazz.getAnnotation(Handler.class);
if(Loader.isModLoaded(handl.modid())) {
if(Loader.isModLoaded(handl.value())) {
MineTweakerAPI.registerClass(clazz);
boolean document = false;
for(Method method : clazz.getDeclaredMethods()) {
if(method.isAnnotationPresent(Document.class)) {
document = true;
}
}
if(document) {
ZenClass zen = (ZenClass) clazz.getAnnotation(ZenClass.class);
writer.write("# " + handl.value() + "\n");
writer.write("## " + zen.value() + "\n\n");
for(Method method : clazz.getDeclaredMethods()) {
if(method.isAnnotationPresent(Document.class)) {
StringBuilder builder = new StringBuilder();
Document doc = method.getAnnotation(Document.class);
Map<String, Parameter> paramMap = new LinkedHashMap<>();
for(int i = 0; i < method.getParameters().length; i++) {
paramMap.put(doc.value()[i], method.getParameters()[i]);
}
builder.append("//");
paramMap.forEach((key, val) -> {
if(val.isAnnotationPresent(Optional.class)) {
builder.append("<span style=\"color:red\">");
}
builder.append(val.getType().getSimpleName()).append(" ").append(key);
if(val.isAnnotationPresent(Optional.class)) {
builder.append("</span>");
}
builder.append(", ");
});
builder.reverse().delete(0, 2).reverse();
builder.append("\n```");
builder.append(zen.value()).append(".");
builder.append(method.getName()).append("(");
paramMap.forEach((key, val) -> {
builder.append(val.getType().getSimpleName()).append(" ").append(key).append(", ");
});
builder.reverse().delete(0, 2).reverse();
builder.append(");");
builder.append("```\n");
writer.write(builder.toString());
}
}
}
}
} catch(ClassNotFoundException e1) {
} catch(ClassNotFoundException | IOException e1) {
e1.printStackTrace();
}
});
writer.close();
}
@Mod.EventHandler
public void init(FMLInitializationEvent e) {
}
@Mod.EventHandler

View file

@ -0,0 +1,9 @@
package com.blamejared.api.annotations;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Document {
String[] value();
}