EventStubGenerator { public List<GeneratedClass> getEvents() { List<GeneratedClass> events = new ArrayList<>(); for (JavaMethod method : listenerMethods) { List<JavaVar> arguments = method.getArguments(); ClassBuilder cb = new ClassBuilder(myEventWrapperName(method), stubsPackage); addGeneratedAnnotation(cb); cb.implement(eventInterface); cb.implement(JavaType.of(Serializable.class)); cb.fieldsAndConstructorParameters(arguments); String eventToString = cb.imports.getSimpleName(JavaType.of(EventToString.class)); String listenerName = cb.imports.getSimpleName(listenerInterface); for (JavaVar argument : arguments) { cb.addMethod("" + " public " + cb.imports.getSimpleName(argument.getType()) + " " + getterName(argument.getName()) + "() {\n" + " return " + argument.getName() + ";\n" + " }\n"); } cb.addMethod("" + " @Override\n" + " public void fireOn(" + listenerName + " target) {\n" + " target." + method.getName() + "(" + JavaVar.toActualArguments(arguments) + ");\n" + " }\n"); cb.addMethod("" + " @Override\n" + " public String toString() {\n" + " return " + eventToString + ".format(\"" + listenerName + "\", \"" + method.getName() + "\"" + JavaVar.toActualVarargs(arguments) + ");\n" + " }\n"); events.add(cb.build()); } Collections.sort(events, (o1, o2) -> o1.name.compareTo(o2.name)); return events; } EventStubGenerator(TypeElement listenerType, String targetPackage); void setGeneratorName(String generatorName); void setGenerationDate(Date generationDate); List<GeneratedClass> getGeneratedClasses(); GeneratedClass getEventizer(); GeneratedClass getFrontend(); GeneratedClass getBackend(); List<GeneratedClass> getEvents();  }
@Test public void generates_event_classes() throws IOException { List<GeneratedClass> events = generator.getEvents(); assertClassEquals("fi.jumi.actors.generator.reference.dummyListener.OnOtherEvent", events.get(0)); assertClassEquals("fi.jumi.actors.generator.reference.dummyListener.OnSomethingEvent", events.get(1)); }
@Test public void generates_event_classes_for_every_listener_method() { generator = newEventStubGenerator(TwoMethodInterface.class); List<GeneratedClass> events = generator.getEvents(); assertThat(events.size(), is(2)); assertThat(events.get(0).name, endsWith(".OnOneEvent")); assertThat(events.get(1).name, endsWith(".OnTwoEvent")); }