List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:de.tynne.benchmarksuite.Main.java
private static Map<BenchmarkSuite, BenchmarkProducer> getBenchmarkSuites() throws InstantiationException, IllegalAccessException { Reflections reflections = new Reflections("de.tynne.benchmarksuite"); Set<Class<?>> benchmarkSuites = reflections.getTypesAnnotatedWith(BenchmarkSuite.class); Map<BenchmarkSuite, BenchmarkProducer> result = new HashMap<>(); for (Class<?> clazz : benchmarkSuites) { BenchmarkSuite benchmarkSuite = clazz.getAnnotation(BenchmarkSuite.class); BenchmarkProducer benchmarkProducer = clazz.asSubclass(BenchmarkProducer.class).newInstance(); result.put(benchmarkSuite, benchmarkProducer); }//from ww w . j a v a 2s . c om return result; }
From source file:edu.sabanciuniv.sentilab.sare.controllers.opinion.OpinionMiningEngine.java
/** * Gets the engine code of the provided class. * @param classOfEngine the {@link Class} of the engine. * @return the engine code.//from w w w . ja va 2 s.c o m */ public static String getCode(Class<? extends OpinionMiningEngine> classOfEngine) { OpinionMiningEngine.Of annotation = classOfEngine.getAnnotation(OpinionMiningEngine.Of.class); if (annotation == null) { return null; } return annotation.code(); }
From source file:com.crudetech.junit.categories.Categories.java
private static Collection<Class<?>> getExclusions(Class<?> testClass) { ExcludeCategory exc = testClass.getAnnotation(ExcludeCategory.class); if (isNull(exc) || isNullOrEmpty(exc.value())) { return emptyList(); }//from w ww . j a va 2 s.com return asList(exc.value()); }
From source file:me.xiaopan.android.gohttp.JsonHttpResponseHandler.java
/** * ??/*from w ww. j a v a2 s.co m*/ * @param context * @param responseClass ?class */ public static String parseResponseBodyAnnotation(Context context, Class<?> responseClass) { ResponseBody annotation = responseClass.getAnnotation(ResponseBody.class); if (annotation == null) { return null; } String annotationValue = annotation.value(); if (annotationValue != null && !"".equals(annotationValue)) { return annotationValue; } else if (context != null && annotation.resId() > 0) { return context.getString(annotation.resId()); } else { return null; } }
From source file:net.bull.javamelody.MonitoringSpringInterceptor.java
private static String getClassPart(MethodInvocation invocation) { // si guice et pas Spring, alors remplacer AopUtils.getTargetClass() par getMethod().getDeclaringClass() // http://ninomartinez.wordpress.com/2010/05/14/guice-caching-interceptors/ // (faire exemple avec un interceptor static) final Class<?> targetClass = AopUtils.getTargetClass(invocation.getThis()); final MonitoredWithSpring classAnnotation = targetClass.getAnnotation(MonitoredWithSpring.class); if (classAnnotation == null || classAnnotation.name() == null || classAnnotation.name().length() == 0) { final Class<?> declaringClass = invocation.getMethod().getDeclaringClass(); final MonitoredWithSpring declaringClassAnnotation = declaringClass .getAnnotation(MonitoredWithSpring.class); if (declaringClassAnnotation == null || declaringClassAnnotation.name() == null || declaringClassAnnotation.name().length() == 0) { return targetClass.getSimpleName(); }/*www . j av a2 s.c om*/ return declaringClassAnnotation.name(); } return classAnnotation.name(); }
From source file:com.thoughtworks.go.util.ConfigUtil.java
public static List<String> allTasks(ConfigElementImplementationRegistry registry) { List<String> allTasks = new ArrayList<>(); for (Class<? extends Task> task : registry.implementersOf(Task.class)) { AttributeAwareConfigTag attributeAwareConfigTag = task.getAnnotation(AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null && !allTasks.contains(attributeAwareConfigTag.value())) { allTasks.add(attributeAwareConfigTag.value()); }//from w w w .j av a 2s .co m ConfigTag tag = task.getAnnotation(ConfigTag.class); if (tag != null && !allTasks.contains(tag.value())) { allTasks.add(tag.value()); } } return allTasks; }
From source file:br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.java
private static <T> int getPriority(Class<T> type) { int result = Priority.MAX_PRIORITY; Priority priority = type.getAnnotation(Priority.class); if (priority != null) { result = priority.value();//from w w w . ja v a 2 s.co m } return result; }
From source file:de.micromata.genome.junittools.wicket.WicketPageBuilder.java
protected static Class<? extends Page> _getPageClassFromBuilder( Class<? extends WicketPageBuilder<?>> fromBuilder) { TpsbWicketPage ano = fromBuilder.getAnnotation(TpsbWicketPage.class); return ano.value(); }
From source file:com.curl.orb.security.RemoteServiceAnnotationChecker.java
/** * Check the PublicService annotation. Throw AccessException if false. * //www .j av a 2s. c om * @param cls the class * @throws AccessException */ public static void check(Class<?> cls, Environment environment) throws AccessException { // ignore security if (environment == null) return; RemoteService remoteServiceAnnotation = (RemoteService) cls.getAnnotation(RemoteService.class); if (!Modifier.isPublic(cls.getModifiers()) || remoteServiceAnnotation == null || !environment.contain(remoteServiceAnnotation.value())) { Log log = LogFactory.getLog(RemoteServiceAnnotationChecker.class); log.debug("Cannot allow to access the class [" + cls.getName() + "]"); throw new AccessException("Cannot allow to access the class [" + cls.getName() + "]"); } // TODO: Cache the class(cls). Which is faster, cache or annotation? }
From source file:com.crudetech.junit.categories.Categories.java
private static Collection<Class<?>> getInclusions(Class<?> testClass) throws InitializationError { IncludeCategory inc = testClass.getAnnotation(IncludeCategory.class); if (isNull(inc) || isNullOrEmpty(inc.value())) { return Arrays.<Class<?>>asList(All); }/*from w ww . ja v a 2 s . c o m*/ return asList(inc.value()); }