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.
This commit is contained in:
Kai S. K. Engelbart 2021-02-22 19:12:06 +01:00
parent d9ddc0e1a9
commit 6c74af608c
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
2 changed files with 18 additions and 5 deletions

View File

@ -1,6 +1,6 @@
package dev.kske.eventbus.core; 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 static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.*; 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. * Allows an event handler to receive events that are subtypes of the declared event type.
* <p> * <p>
* 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.
* <p>
* This is useful when defining an event handler for an interface or an abstract class. * This is useful when defining an event handler for an interface or an abstract class.
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
@ -16,5 +19,12 @@ import java.lang.annotation.*;
*/ */
@Documented @Documented
@Retention(RUNTIME) @Retention(RUNTIME)
@Target(METHOD) @Target({ METHOD, TYPE })
public @interface Polymorphic {} public @interface Polymorphic {
/**
* @return whether the event handler is polymorphic
* @since 1.1.0
*/
boolean value() default true;
}

View File

@ -1,6 +1,6 @@
package dev.kske.eventbus.core; 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 static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.*; 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 * Defines the priority of an event handler. Handlers are executed in descending order of their
* priority. * priority.
* <p> * <p>
* 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.
* <p>
* Handlers without this annotation have the default priority of 100. * Handlers without this annotation have the default priority of 100.
* <p> * <p>
* The execution order of handlers with the same priority is undefined. * The execution order of handlers with the same priority is undefined.
@ -19,7 +22,7 @@ import java.lang.annotation.*;
*/ */
@Documented @Documented
@Retention(RUNTIME) @Retention(RUNTIME)
@Target(METHOD) @Target({ METHOD, TYPE })
public @interface Priority { public @interface Priority {
/** /**