Search in sources :

Example 6 with Event

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Function(com.laytonsmith.core.functions.Function) Event(com.laytonsmith.core.events.Event) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Event (com.laytonsmith.core.events.Event)6 ArrayList (java.util.ArrayList)4 Function (com.laytonsmith.core.functions.Function)3 HashMap (java.util.HashMap)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 DynamicClassLoader (com.laytonsmith.PureUtilities.ClassLoading.DynamicClassLoader)2 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 ClassDiscovery (com.laytonsmith.PureUtilities.ClassLoading.ClassDiscovery)1 ClassDiscoveryCache (com.laytonsmith.PureUtilities.ClassLoading.ClassDiscoveryCache)1 ClassMirror (com.laytonsmith.PureUtilities.ClassLoading.ClassMirror.ClassMirror)1 SimpleVersion (com.laytonsmith.PureUtilities.SimpleVersion)1 Documentation (com.laytonsmith.core.Documentation)1 CFunction (com.laytonsmith.core.constructs.CFunction)1 AbstractEvent (com.laytonsmith.core.events.AbstractEvent)1 EventMixinInterface (com.laytonsmith.core.events.EventMixinInterface)1