Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Maven Central](https://img.shields.io/maven-central/v/org.microbean/microbean-event.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.microbean/microbean-event)

![0% AI](https://img.shields.io/badge/%F0%9F%A4%96_AI-0%25_%F0%9F%8C%BC-brightgreen)

The microBean™ Event project provides classes and interfaces assisting with implementing simple Java events.

# Status
Expand All @@ -27,7 +29,7 @@ dependency:
<groupId>org.microbean</groupId>
<artifactId>microbean-event</artifactId>
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-event for up-to-date available versions. -->
<version>0.0.3</version>
<version>0.0.4</version>
</dependency>
```

Expand Down
30 changes: 9 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<!-- maven-javadoc-plugin properties -->
<bottom><![CDATA[Copyright &copy; ${project.inceptionYear}&ndash;{currentYear}, <a href="${project.organization.url}" target="_top">${project.organization.name}</a>. All rights reserved.]]></bottom>
<doctitle>&lt;a href="${project.url}" target="_top"&gt;&lt;span style="font-family:Lobster, cursive;"&gt;µb&lt;/span&gt; ${project.artifactId}&lt;/a&gt; ${project.version}</doctitle>
<links>https://microbean.github.io/microbean-assign/apidocs/,https://microbean.github.io/microbean-attributes/apidocs/,https://microbean.github.io/microbean-bean/apidocs/,https://microbean.github.io/microbean-construct/apidocs/,https://microbean.github.io/microbean-qualifier/apidocs/</links>
<links>https://microbean.github.io/microbean-assign/apidocs/,https://microbean.github.io/microbean-bean/apidocs/,https://microbean.github.io/microbean-construct/apidocs/,https://microbean.github.io/microbean-qualifier/apidocs/</links>
<sourcetab>2</sourcetab>

<!-- maven-release-plugin properties -->
Expand Down Expand Up @@ -127,25 +127,19 @@
<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-assign</artifactId>
<version>0.0.11</version>
</dependency>

<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-attributes</artifactId>
<version>0.0.5</version>
<version>0.0.14</version>
</dependency>

<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-bean</artifactId>
<version>0.0.22</version>
<version>0.0.23</version>
</dependency>

<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-construct</artifactId>
<version>0.0.18</version>
<version>0.0.24</version>
</dependency>

</dependencies>
Expand All @@ -159,12 +153,6 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-attributes</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-bean</artifactId>
Expand Down Expand Up @@ -324,7 +312,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>12.3.0</version>
<version>13.2.0</version>
</dependency>
</dependencies>
</plugin>
Expand All @@ -345,7 +333,7 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<version>3.15.0</version>
<configuration>
<compilerArgs>
<arg>-Xlint:all</arg>
Expand All @@ -355,7 +343,7 @@
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.9.0</version>
<version>3.10.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down Expand Up @@ -457,7 +445,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.20.1</version>
<version>2.21.0</version>
</plugin>
<plugin>
<groupId>io.smallrye</groupId>
Expand All @@ -467,7 +455,7 @@
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.9.0</version>
<version>0.10.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central.sonatype.com</publishingServerId>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
*
* Copyright © 2025 microBean™.
* Copyright © 2025–2026 microBean™.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -23,7 +23,6 @@

requires transitive java.compiler;
requires transitive org.microbean.assign;
requires transitive org.microbean.attributes;
requires transitive org.microbean.bean;
requires org.microbean.constant;
requires transitive org.microbean.construct;
Expand Down
57 changes: 16 additions & 41 deletions src/main/java/org/microbean/event/EventListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
*
* Copyright © 2025 microBean™.
* Copyright © 2025–2026 microBean™.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -17,16 +17,14 @@

import javax.lang.model.element.Element;

import org.microbean.assign.Annotated;
import org.microbean.assign.Aggregate;
import org.microbean.assign.AttributedElement;
import org.microbean.assign.AttributedType;
import org.microbean.assign.AttributedTyped;

import org.microbean.bean.ReferencesSelector;

/**
* An {@link java.util.EventListener EventListener}, an {@link Aggregate}, and an {@link AttributedTyped} that
* {@linkplain #eventReceived(Object, ReferencesSelector) receives} <dfn>events</dfn>.
* An {@link java.util.EventListener EventListener}, and an {@link Aggregate} that {@linkplain #eventReceived(Object,
* ReferencesSelector) receives} <dfn>events</dfn>.
*
* @param <R> the result of reception; almost always {@link Void}
*
Expand Down Expand Up @@ -56,71 +54,48 @@
// * eventDependency() includes VariableElement-representing-e and nothing else
// * receive() calls onEvent() supplying it with event and a @Complicated Frob acquired via r
//
// TODO: Does this actually need to be an AttributedTyped?
public interface EventListener<R, E> extends AttributedTyped, Aggregate, java.util.EventListener {
public interface EventListener<R, E> extends Aggregate, java.util.EventListener {

/**
* Returns a non-{@code null}, determinate {@link AttributedType} describing the kinds of events this {@link
* EventListener} is prepared to handle.
*
* <p>The default implementation of this method extracts this information from an invocation of the {@link
* #eventDependency()} method ({@linkplain #eventDependency() <i>q.v.</i>}).</p>
*
* @return a non-{@code null}, determinate {@link AttributedType}
*
* @exception NullPointerException if the default implementation of this method receives a {@code null} return value
* from an invocation of the {@link #eventDependency()} method
*
* @see #eventDependency()
*/
@Override // AttributedTypedAggregate (AttributedTyped)
public default AttributedType attributedType() {
return this.eventDependency().attributedType();
}

/**
* Returns a non-{@code null}, determinate, immutable {@link SequencedSet} of {@link AttributedElement}s representing
* Returns a non-{@code null}, determinate, immutable {@link SequencedSet} of {@link Element}s representing
* dependencies this {@link EventListener} has that must be resolved before any invocation of the {@link
* #eventReceived(Object, ReferencesSelector)} method may properly occur.
* #eventReceived(Object, ReferencesSelector2)} method may properly occur.
*
* <p>Implementations of this method must not include a result of any invocation of the {@link #eventDependency()}
* method as an element of the return value.</p>
*
* <p>The default implementation of this method returns an {@linkplain SequencedSet#isEmpty() empty} {@link
* SequencedSet}. Overrides are expected.</p>
*
* @return a non-{@code null}, determinate, immutable {@link SequencedSet} of {@link AttributedElement}s
* @return a non-{@code null}, determinate, immutable {@link SequencedSet} of {@link Element}s
*
* @see #eventReceived(Object, ReferencesSelector)
* @see #eventReceived(Object, ReferencesSelector2)
*
* @see #eventDependency()
*/
// Returns dependencies that are not the event dependency. These are resolved by the system. Think of an observer
// method with an observed parameter and other parameters. The other parameters are these dependencies.
@Override // AttributedTypedAggregate (Aggregate)
public default SequencedSet<AttributedElement> dependencies() {
@Override // Aggregate
public default SequencedSet<? extends Annotated<? extends Element>> dependencies() {
return Aggregate.super.dependencies();
}

/**
* Returns a non-{@code null}, determinate {@link AttributedElement} representing the program element for which an
* event is destined.
* Returns a non-{@code null}, determinate {@link Element} representing the program element for which an event is
* destined.
*
* <p>The result of an invocation of this method must not appear as an element of the return value of an invocation of
* the {@link #dependencies()} method.</p>
*
* <p>Note that the default implementation of the {@link #attributedType()} method calls this method and requires it
* to return a non-{@code null} value.</p>
*
* @return a non-{@code null}, determinate {@link AttributedElement}
* @return a non-{@code null}, determinate {@link Element}
*
* @see #dependencies()
*/
// An AttributedElement describing the event event "slot" (the observed parameter).
// An Element describing the event event "slot" (the observed parameter).
// Conceptually just another dependency (see dependencies()) but it is supplied by the user, not the system.
// Normally a method parameter.
// T's argument (the event event type) must be among its types.
public AttributedElement eventDependency();
public Annotated<? extends Element> eventDependency();

/**
* Receives and handles an event, normally as delivered by an invocation of the {@link Events#fire(TypeMirror, List,
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/org/microbean/event/EventQualifiersMatcher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
*
* Copyright © 2025 microBean™.
* Copyright © 2025–2026 microBean™.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -15,23 +15,23 @@

import java.util.Collection;

import javax.lang.model.element.AnnotationMirror;

import org.microbean.assign.Matcher;
import org.microbean.assign.Qualifiers;

import org.microbean.attributes.Attributes;

import static java.util.Objects.requireNonNull;

/**
* A {@link Matcher} encapsulating <a
* href="https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#observer_resolution">CDI-compatible event
* href="https://jakarta.ee/specifications/cdi/4.1/jakarta-cdi-spec-4.1#observer_resolution">CDI-compatible event
* qualifier matching rules</a>.
*
* @author <a href="https://about.me/lairdnelson/" target="_top">Laird Nelson</a>
*
* @see #test(Collection, Collection)
*/
public final class EventQualifiersMatcher implements Matcher<Collection<? extends Attributes>, Collection<? extends Attributes>> {
public final class EventQualifiersMatcher implements Matcher<Collection<? extends AnnotationMirror>, Collection<? extends AnnotationMirror>> {


/*
Expand Down Expand Up @@ -67,30 +67,30 @@ public EventQualifiersMatcher(final Qualifiers qualifiers) {

/**
* Returns {@code true} if and only if either the {@linkplain org.microbean.assign.Qualifiers#qualifiers(Collection)
* qualifiers present} in {@code receiverAttributes} are {@linkplain Collection#isEmpty() empty}, or if the collection
* of {@linkplain org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code
* payloadAttributes} {@linkplain Collection#containsAll(Collection) contains all} of the {@linkplain
* org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code receiverAttributes}.
* qualifiers present} in {@code receiverAnnotations} are {@linkplain Collection#isEmpty() empty}, or if the
* collection of {@linkplain org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code
* payloadAnnotations} {@linkplain Collection#containsAll(Collection) contains all} of the {@linkplain
* org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code receiverAnnotations}.
*
* @param receiverAttributes a {@link Collection} of {@link Attributes} instances; must not be {@code null}
* @param receiverAnnotations a {@link Collection} of {@link AnnotationMirror} instances; must not be {@code null}
*
* @param payloadAttributes a {@link Collection} of {@link Attributes} instances; must not be {@code null}
* @param payloadAnnotations a {@link Collection} of {@link AnnotationMirror} instances; must not be {@code null}
*
* @return {@code true} if and only if either the {@linkplain org.microbean.assign.Qualifiers#qualifiers(Collection)
* qualifiers present} in {@code receiverAttributes} are {@linkplain Collection#isEmpty() empty}, or if the collection
* of {@linkplain org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code
* payloadAttributes} {@linkplain Collection#containsAll(Collection) contains all} of the {@linkplain
* org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code receiverAttributes}
* qualifiers present} in {@code receiverAnnotations} are {@linkplain Collection#isEmpty() empty}, or if the
* collection of {@linkplain org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code
* payloadAnnotations} {@linkplain Collection#containsAll(Collection) contains all} of the {@linkplain
* org.microbean.assign.Qualifiers#qualifiers(Collection) qualifiers present} in {@code receiverAnnotations}
*
* @exception NullPointerException if either argument is {@code null}
*/
@Override // Matcher<Collection<? extends NamedAttributeMap<?>>, Collection<? extends NamedAttributeMap<?>>>
public final boolean test(final Collection<? extends Attributes> receiverAttributes,
final Collection<? extends Attributes> payloadAttributes) {
public final boolean test(final Collection<? extends AnnotationMirror> receiverAnnotations,
final Collection<? extends AnnotationMirror> payloadAnnotations) {
// "An event is delivered to an observer method if...the observer method has no event qualifiers or has a subset of
// the event qualifiers."
final Collection<? extends Attributes> receiverQualifiers = qualifiers.qualifiers(receiverAttributes);
return receiverQualifiers.isEmpty() || qualifiers.qualifiers(payloadAttributes).containsAll(receiverQualifiers);
final Collection<? extends AnnotationMirror> receiverQualifiers = qualifiers.qualifiers(receiverAnnotations);
return receiverQualifiers.isEmpty() || qualifiers.qualifiers(payloadAnnotations).containsAll(receiverQualifiers);
}

}
Loading