
de.skuzzle.inject.async.internal.Annotations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guice-async-extension Show documentation
Show all versions of guice-async-extension Show documentation
Allows to execute tagged methods asynchronously
package de.skuzzle.inject.async.internal;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import de.skuzzle.inject.async.annotation.Trigger;
final class Annotations {
private Annotations() {
// hidden ctor
}
/**
* Searches the annotations of the provided method for an annotation type
* that itself is annotated with {@link Trigger}. An exception is thrown if
* the method does not have a unique Trigger annotation.
*
* @param method The method to search.
* @return The unique trigger annotation.
*/
static Annotation findTriggerAnnotation(Method method) {
Annotation result = null;
for (final Annotation annotation : method.getAnnotations()) {
if (isTriggerAnnotation(annotation)) {
if (result == null) {
result = annotation;
} else {
throw new IllegalStateException(String.format(
"Multiple @Trigger annotations found on '%s': %s, %s",
method, result, annotation));
}
}
}
if (result == null) {
throw new IllegalStateException(String.format(
"No @Trigger annotation found on '%s'", method));
}
return result;
}
private static boolean isTriggerAnnotation(Annotation annotation) {
final Class> type = annotation.annotationType();
if (type.isAnnotationPresent(Trigger.class)) {
return true;
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy