Replace priority with @Priority

The new @Priority annotation serves the exact same purpose as
@Event(priority = ...), but should be easier to read in complex handler
declarations. It has to be used in conjunction with the @Event
annotation, not instead of it.
This commit is contained in:
2021-02-15 12:06:33 +01:00
parent 3a6ebe9a19
commit 9b1c708514
7 changed files with 75 additions and 43 deletions

View File

@ -39,13 +39,15 @@ class CancelTest implements EventListener {
assertEquals(1, hits);
}
@Event(eventType = SimpleEvent.class, priority = 100)
@Event(eventType = SimpleEvent.class)
@Priority(100)
void onSimpleFirst() {
++hits;
bus.cancel();
}
@Event(eventType = SimpleEvent.class, priority = 50)
@Event(eventType = SimpleEvent.class)
@Priority(50)
void onSimpleSecond() {
++hits;
}

View File

@ -38,20 +38,22 @@ class DispatchTest implements EventListener {
bus.dispatch(new SimpleEvent());
}
@Event(eventType = SimpleEvent.class, priority = 200)
@Event(eventType = SimpleEvent.class)
@Priority(200)
@Polymorphic
void onSimpleEventFirst() {
++hits;
assertTrue(hits == 1 || hits == 2);
}
@Event(eventType = SimpleEvent.class, priority = 150)
@Event(eventType = SimpleEvent.class)
@Priority(150)
static void onSimpleEventSecond() {
++hits;
assertEquals(3, hits);
}
@Event(priority = 100)
@Event
void onSimpleEventThird(SimpleEvent event) {
++hits;
assertEquals(4, hits);