use of com.laytonsmith.core.events.Event in project CommandHelper by EngineHub.
the class DocGenExportTool method export.
/**
* Triggers the export tool
*/
public void export() {
Set<Class<? extends Function>> functions = classDiscovery.loadClassesWithAnnotationThatExtend(api.class, Function.class, this.getClass().getClassLoader(), false);
Set<Class<? extends Event>> events = classDiscovery.loadClassesWithAnnotationThatExtend(api.class, Event.class, this.getClass().getClassLoader(), false);
Map<String, Object> topLevel = new HashMap<String, Object>();
List<Map<String, Object>> functionList = new ArrayList<Map<String, Object>>();
topLevel.put("functions", functionList);
List<Map<String, Object>> eventList = new ArrayList<Map<String, Object>>();
topLevel.put("events", eventList);
for (Class<? extends Function> functionC : functions) {
Map<String, Object> function = new HashMap<String, Object>();
Function f;
try {
f = ReflectionUtils.newInstance(functionC);
} catch (NoClassDefFoundError ex) {
StreamUtils.GetSystemErr().println("While attempting to load: " + functionC.getName() + ": " + ex.getMessage());
continue;
}
DocGen.DocInfo di = new DocGen.DocInfo(f.docs());
function.put("name", f.getName());
function.put("ret", di.ret);
function.put("args", di.originalArgs);
function.put("desc", di.desc);
functionList.add(function);
}
Pattern eventPattern = Pattern.compile("\\{(.*?)\\} *?(.*?) *?\\{(.*?)\\} *?\\{(.*?)\\}");
DocGen.MarkupType type = DocGen.MarkupType.TEXT;
for (Class<? extends Event> eventC : events) {
Map<String, Object> event = new HashMap<String, Object>();
Event e = ReflectionUtils.newInstance(eventC);
Matcher m = eventPattern.matcher(e.docs());
if (m.find()) {
String name = e.getName();
String description = m.group(2).trim();
String prefilter = DocGen.PrefilterData.Get(m.group(1).split("\\|"), type);
String eventData = DocGen.EventData.Get(m.group(3).split("\\|"), type);
String mutability = DocGen.MutabilityData.Get(m.group(4).split("\\|"), type);
event.put("name", name);
event.put("desc", description);
event.put("prefilter", prefilter);
event.put("eventData", eventData);
event.put("mutability", mutability);
eventList.add(event);
}
}
String output = JSONValue.toJSONString(topLevel) + StringUtils.nl();
try {
out.write(output.getBytes("UTF-8"));
out.flush();
} catch (IOException ex) {
Logger.getLogger(DocGenExportTool.class.getName()).log(Level.SEVERE, null, ex);
}
}
Aggregations