com.mageddo.commons.AnnotationUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toggle-first-core Show documentation
Show all versions of toggle-first-core Show documentation
Enable and disable your features in production on a button click
package com.mageddo.commons;
import com.mageddo.togglefirst.Feature;
import java.lang.annotation.Annotation;
public final class AnnotationUtils {
private AnnotationUtils() {}
public static A getAnnotation(Feature feature, Class annotationType) {
try {
Class extends Feature> featureClass = feature.getClass();
A fieldAnnotation = featureClass.getField(feature.name()).getAnnotation(annotationType);
A classAnnotation = featureClass.getAnnotation(annotationType);
return fieldAnnotation != null ? fieldAnnotation : classAnnotation;
} catch (SecurityException e) {
// ignore
} catch (NoSuchFieldException e) {
// ignore
}
return null;
}
}