Merge pull request 'Additional Warnings in Event Bus Proc' (#8) from f/additional-warnings into develop

Reviewed-on: https://git.kske.dev/kske/event-bus/pulls/8
Reviewed-by: delvh <leon@kske.dev>
This commit is contained in:
Kai S. K. Engelbart 2021-02-20 21:46:08 +01:00
commit 9379e6bb94
Signed by: Käfer & Engelbart Git
GPG Key ID: 70F2F9206EDC1FCE

View File

@ -63,6 +63,10 @@ public class EventProcessor extends AbstractProcessor {
else
pass = true;
// Warn the user about unused return values
if (useParameter && eventHandler.getReturnType().getKind() != TypeKind.VOID)
warning(eventHandler, "Unused return value");
// Abort checking if the handler signature is incorrect
if (!pass)
continue;
@ -80,14 +84,20 @@ public class EventProcessor extends AbstractProcessor {
}
}
// Check for handlers for abstract types that aren't polymorphic
// Detect missing or useless @Polymorphic
boolean polymorphic = eventHandler.getAnnotation(Polymorphic.class) != null;
Element eventElement = ((DeclaredType) eventType).asElement();
if (eventHandler.getAnnotation(Polymorphic.class) == null
&& (eventElement.getKind() == ElementKind.INTERFACE
|| eventElement.getModifiers().contains(Modifier.ABSTRACT))) {
// Check for handlers for abstract types that aren't polymorphic
if (!polymorphic && (eventElement.getKind() == ElementKind.INTERFACE
|| eventElement.getModifiers().contains(Modifier.ABSTRACT)))
warning(eventHandler,
"Parameter should be instantiable or handler should use @Polymorphic");
}
// Check for handlers for final types that are polymorphic
else if (polymorphic && eventElement.getModifiers().contains(Modifier.FINAL))
warning(eventHandler,
"@Polymorphic should be removed as parameter cannot be subclassed");
}
}