From 6c74af608c08aa42e9e9b53e1bbfbbe193767f9b Mon Sep 17 00:00:00 2001 From: kske Date: Mon, 22 Feb 2021 19:12:06 +0100 Subject: [PATCH] Allow @Polymorphic and @Priority on types, add value to @Polymorphic This is the first step for listener level handler properties. To allow a handler inside a polymorphic listener to be non-polymorphic, the @Polymorphic annotation now has a boolean value that defaults to true. In that case, it can be explicitly set to false to override the listener-level default. --- .../java/dev/kske/eventbus/core/Polymorphic.java | 16 +++++++++++++--- .../java/dev/kske/eventbus/core/Priority.java | 7 +++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/event-bus-core/src/main/java/dev/kske/eventbus/core/Polymorphic.java b/event-bus-core/src/main/java/dev/kske/eventbus/core/Polymorphic.java index bbed5d8..1f77726 100644 --- a/event-bus-core/src/main/java/dev/kske/eventbus/core/Polymorphic.java +++ b/event-bus-core/src/main/java/dev/kske/eventbus/core/Polymorphic.java @@ -1,6 +1,6 @@ package dev.kske.eventbus.core; -import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.*; @@ -8,6 +8,9 @@ import java.lang.annotation.*; /** * Allows an event handler to receive events that are subtypes of the declared event type. *

+ * When used on a type, the value applies to all event handlers declared within that type that don't + * define a value on their own. + *

* This is useful when defining an event handler for an interface or an abstract class. * * @author Kai S. K. Engelbart @@ -16,5 +19,12 @@ import java.lang.annotation.*; */ @Documented @Retention(RUNTIME) -@Target(METHOD) -public @interface Polymorphic {} +@Target({ METHOD, TYPE }) +public @interface Polymorphic { + + /** + * @return whether the event handler is polymorphic + * @since 1.1.0 + */ + boolean value() default true; +} diff --git a/event-bus-core/src/main/java/dev/kske/eventbus/core/Priority.java b/event-bus-core/src/main/java/dev/kske/eventbus/core/Priority.java index 1218df3..ca82fa3 100644 --- a/event-bus-core/src/main/java/dev/kske/eventbus/core/Priority.java +++ b/event-bus-core/src/main/java/dev/kske/eventbus/core/Priority.java @@ -1,6 +1,6 @@ package dev.kske.eventbus.core; -import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.*; @@ -9,6 +9,9 @@ import java.lang.annotation.*; * Defines the priority of an event handler. Handlers are executed in descending order of their * priority. *

+ * When used on a type, the value applies to all event handlers declared within that type that don't + * define a value on their own. + *

* Handlers without this annotation have the default priority of 100. *

* The execution order of handlers with the same priority is undefined. @@ -19,7 +22,7 @@ import java.lang.annotation.*; */ @Documented @Retention(RUNTIME) -@Target(METHOD) +@Target({ METHOD, TYPE }) public @interface Priority { /**