private void generateEvent(final Event event) throws Exception { final ClassWriter classWriter = new ClassWriter( this, getSrcGeneratedDirectory(), GeneratorHelper.getEventPackage(domain), GeneratorHelper.getEventClassName(event)); if (event.getParameter() != null) { for (final Parameter parameter : event.getParameter()) { classWriter.addClassMembers(parameter); } } classWriter.addExtend(GeneratorHelper.getBusinessEventExtends(event)); // Constant classWriter.addConstants( "public static final com.ponysdk.core.event.Event.Type<" + GeneratorHelper.getHandlerClassName(event) + "> TYPE = new com.ponysdk.core.event.Event.Type<" + GeneratorHelper.getHandlerClassName(event) + ">();"); // Build constructor final Parameter sourceComponentParameter = new Parameter(); sourceComponentParameter.setName("sourceComponent"); sourceComponentParameter.setClazz("java.lang.Object"); final List<Parameter> superConstructorParameters = new ArrayList<Parameter>(); superConstructorParameters.add(sourceComponentParameter); final List<Parameter> constructorParameters = new ArrayList<Parameter>(event.getParameter()); constructorParameters.add(0, sourceComponentParameter); final Constructor constructor = new Constructor(constructorParameters, superConstructorParameters); classWriter.addConstructor(constructor); // Build methods classWriter.addLine("@Override"); classWriter.addLine( "protected void dispatch(" + GeneratorHelper.getHandlerClassName(event) + " handler) {"); classWriter.addLine(" handler.on" + event.getName() + "(this);"); classWriter.addLine("}"); classWriter.addNewLine(); classWriter.addLine("@Override"); classWriter.addLine( "public com.ponysdk.core.event.Event.Type<" + GeneratorHelper.getHandlerClassName(event) + "> getAssociatedType() {"); classWriter.addLine(" return TYPE;"); classWriter.addLine("}"); // Adding classWriter.setGenerateGetter(true); classWriter.generateContentAndStore(); }
private void generateHandler(final Event event) throws Exception { final ClassWriter classWriter = new ClassWriter( this, getSrcGeneratedDirectory(), GeneratorHelper.getEventPackage(domain), GeneratorHelper.getHandlerClassName(event)); classWriter.setInterface(true); classWriter.addExtend("com.ponysdk.core.event.EventHandler"); // Build event method classWriter.addLine( "public void on" + event.getName() + "(" + GeneratorHelper.getEventClassName(event) + " event);"); classWriter.generateContentAndStore(); }