net.optionfactory.spring.upstream.annotations.Annotations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of upstream Show documentation
Show all versions of upstream Show documentation
optionfactory-spring REST upstream core project
package net.optionfactory.spring.upstream.annotations;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Optional;
public class Annotations {
public static List closestRepeatable(Method m, Class annotation) {
final var manns = m.getAnnotationsByType(annotation);
if (manns.length > 0) {
return List.of(manns);
}
return closestRepeatable(m.getDeclaringClass(), annotation);
}
public static List closestRepeatable(Class> k, Class annotation) {
for (var curr = k; curr != null; curr = curr.getSuperclass()) {
var canns = curr.getAnnotationsByType(annotation);
if (canns.length > 0) {
return List.of(canns);
}
}
return List.of();
}
public static Optional closest(Method m, Class annotation) {
final var mann = m.getAnnotation(annotation);
if (mann != null) {
return Optional.of(mann);
}
return closest(m.getDeclaringClass(), annotation);
}
public static Optional closest(Class> k, Class annotation) {
for (var curr = k; curr != null; curr = curr.getSuperclass()) {
var cann = curr.getAnnotation(annotation);
if (cann != null) {
return Optional.of(cann);
}
}
return Optional.empty();
}
}