Skip to content

Commit 2025211

Browse files
committed
Declare that event listeners do not have to be public
1 parent 042cdd2 commit 2025211

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

src/ap/java/org/spongepowered/plugin/processor/ListenerProcessor.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.spongepowered.plugin.processor;
2626

2727
import static javax.tools.Diagnostic.Kind.ERROR;
28+
import static javax.tools.Diagnostic.Kind.WARNING;
2829

2930
import org.spongepowered.api.event.Event;
3031
import org.spongepowered.api.event.Listener;
@@ -50,7 +51,7 @@
5051
import javax.tools.Diagnostic;
5152

5253
@SupportedAnnotationTypes(ListenerProcessor.LISTENER_ANNOTATION_CLASS)
53-
@SupportedSourceVersion(SourceVersion.RELEASE_8)
54+
@SupportedSourceVersion(SourceVersion.RELEASE_16)
5455
public class ListenerProcessor extends AbstractProcessor {
5556

5657
static final String LISTENER_ANNOTATION_CLASS = "org.spongepowered.api.event.Listener";
@@ -68,19 +69,16 @@ public boolean process(final Set<? extends TypeElement> annotations, final Round
6869

6970
final Messager msg = this.processingEnv.getMessager();
7071
if (method.getModifiers().contains(Modifier.STATIC)) {
71-
msg.printMessage(Diagnostic.Kind.ERROR, "method must not be static", method);
72-
}
73-
if (!method.getModifiers().contains(Modifier.PUBLIC)) {
74-
msg.printMessage(Diagnostic.Kind.ERROR, "method must be public", method);
72+
msg.printMessage(Diagnostic.Kind.ERROR, "Event listener method must not be static", method);
7573
}
7674
if (method.getModifiers().contains(Modifier.ABSTRACT)) {
77-
msg.printMessage(Diagnostic.Kind.ERROR, "method must not be abstract", method);
75+
msg.printMessage(Diagnostic.Kind.ERROR, "Event listener method must not be abstract", method);
7876
}
7977
if (method.getEnclosingElement().getKind().isInterface()) {
8078
msg.printMessage(Diagnostic.Kind.ERROR, "interfaces cannot declare listeners", method);
8179
}
8280
if (method.getReturnType().getKind() != TypeKind.VOID) {
83-
msg.printMessage(Diagnostic.Kind.ERROR, "method must return void", method);
81+
msg.printMessage(Diagnostic.Kind.ERROR, "Event listener method must return void", method);
8482
}
8583
final List<? extends VariableElement> parameters = method.getParameters();
8684
if (parameters.isEmpty() || !this.isTypeSubclass(parameters.get(0), ListenerProcessor.EVENT_CLASS)) {

src/main/java/org/spongepowered/api/event/EventManager.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ public interface EventManager {
3636
* Registers {@link Event} methods annotated with @{@link Listener} in the
3737
* specified object.
3838
*
39-
* <p>Only methods that are public will be registered and the class must be
40-
* public as well.</p>
39+
* <p>This will not include any methods declared in supertypes, but will
40+
* test for private and package-private listener methods.</p>
4141
*
42-
* @param plugin The plugin instance
42+
* @param plugin The plugin container
4343
* @param obj The object
44-
* @throws IllegalArgumentException Thrown if {@code plugin} is not a plugin
45-
* instance
4644
*/
4745
void registerListeners(PluginContainer plugin, Object obj);
4846

src/main/java/org/spongepowered/api/event/Listener.java

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232

3333
/**
3434
* Used to annotate a method as an {@link EventListener}.
35-
*
36-
* <p>The method being targeted must be public and must be in a class that is
37-
* also public.</p>
3835
*/
3936
@Retention(RUNTIME)
4037
@Target(METHOD)

0 commit comments

Comments
 (0)