List of usage examples for java.lang.reflect Method getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:com.mirth.connect.client.core.api.util.OperationUtil.java
public static Set<Operation> getOperations(Class<?> servletInterface) { Set<Operation> operations = new HashSet<Operation>(); for (Method method : servletInterface.getMethods()) { MirthOperation annotation = method.getAnnotation(MirthOperation.class); if (annotation != null) { operations.add(new Operation(annotation.name(), annotation.display(), annotation.type(), annotation.auditable())); }/*from w w w . j av a2s. c o m*/ } return operations; }
From source file:com.mirth.connect.client.core.api.util.OperationUtil.java
public static Set<Operation> getAbortableOperations(Class<?> servletInterface) { Set<Operation> operations = new HashSet<Operation>(); for (Method method : servletInterface.getMethods()) { MirthOperation annotation = method.getAnnotation(MirthOperation.class); if (annotation != null && annotation.abortable()) { operations.add(new Operation(annotation.name(), annotation.display(), annotation.type(), annotation.auditable())); }//from w w w . j a v a 2 s. c om } return operations; }
From source file:de.micromata.genome.util.bean.PropertyDescriptorUtils.java
/** * Find anotation first on getter than from field. * * @param <T> the generic type/*from w w w.j a v a 2 s . com*/ * @param beanClazz the bean clazz * @param pd the pd * @param anotclass the anotclass * @return the t */ public static <T extends Annotation> T findAnotation(Class<?> beanClazz, PropertyDescriptor pd, Class<T> anotclass) { Method rm = pd.getReadMethod(); if (rm != null) { T anot = rm.getAnnotation(anotclass); if (anot != null) { return anot; } } Field field = PrivateBeanUtils.findField(beanClazz, pd.getName()); if (field == null) { return null; } T anot = field.getAnnotation(anotclass); return anot; }
From source file:com.monarchapis.driver.spring.rest.ApiRequestHandlerInterceptor.java
/** * Looks for an annotation first on the method, then inspects the class. * /*from w w w . j av a 2s .co m*/ * @param method * The method search for the desired annotation. * @param clazz * THe class to search if the annotation is not present on the * method. * @return the annotation if found, null otherwise. */ private static <T extends Annotation> T getAnnotation(Method method, Class<T> clazz) { T annotation = method.getAnnotation(clazz); if (annotation == null) { Class<?> declaringClass = method.getDeclaringClass(); annotation = declaringClass.getAnnotation(clazz); while (annotation == null && declaringClass.getSuperclass() != null) { declaringClass = declaringClass.getSuperclass(); annotation = declaringClass.getAnnotation(clazz); } } return annotation; }
From source file:com.mirth.connect.client.core.api.util.OperationUtil.java
private static void addOperationName(String permissionName, Class<?> servletInterface, Set<String> operationNames) { for (Method method : servletInterface.getMethods()) { MirthOperation operationAnnotation = method.getAnnotation(MirthOperation.class); if (operationAnnotation != null && operationAnnotation.permission().equals(permissionName)) { operationNames.add(operationAnnotation.name()); }/*from w w w. j a v a 2s .c o m*/ } }
From source file:com.evolveum.midpoint.provisioning.ucf.api.UcfUtil.java
public static boolean hasAnnotation(PropertyDescriptor prop, Class<? extends Annotation> annotationClass) { Method readMethod = prop.getReadMethod(); if (readMethod != null && readMethod.getAnnotation(annotationClass) != null) { return true; }//from w ww. java 2s.c o m Method writeMethod = prop.getWriteMethod(); if (writeMethod != null && writeMethod.getAnnotation(annotationClass) != null) { return true; } Class<?> propertyType = prop.getPropertyType(); if (propertyType.isAnnotationPresent(annotationClass)) { return true; } return false; }
From source file:com.dukescript.presenters.androidapp.test.Knockout.java
public static Map<String, Method> assertMethods(Class<?> test) throws Exception { Map<String, Method> all = new HashMap<String, Method>(); StringBuilder errors = new StringBuilder(); int cnt = 0;//from w ww .j a va 2 s.c om final Class<?>[] classes = testClasses(); for (Class<?> c : classes) { for (Method method : c.getMethods()) { if (method.getAnnotation(KOTest.class) != null) { cnt++; String name = method.getName(); if (!name.startsWith("test")) { name = "test" + Character.toUpperCase(name.charAt(0)) + name.substring(1); } try { Method m = test.getMethod(name); all.put(name, method); } catch (NoSuchMethodException ex) { errors.append("\n").append(name); } } } } if (errors.length() > 0) { errors.append("\nTesting classes: ").append(Arrays.toString(classes)); fail("Missing method: " + errors); } assert cnt > 0 : "Some methods found"; return all; }
From source file:com.nineteendrops.tracdrops.client.core.Utils.java
public static TracClassMethod getTracClassMethodAnnotation(Method method) { TracClassMethod annotationsForTracClassMethod = (TracClassMethod) method .getAnnotation(TracClassMethod.class); return annotationsForTracClassMethod; }
From source file:com.mirth.connect.client.core.api.util.OperationUtil.java
public static Operation getOperation(Class<?> servletInterface, String methodName, Class<?>... parameterTypes) { try {/* w w w . java 2s.c o m*/ Method matchingMethod = servletInterface.getMethod(methodName, parameterTypes); MirthOperation annotation = matchingMethod.getAnnotation(MirthOperation.class); if (annotation != null) { return new Operation(annotation.name(), annotation.display(), annotation.type(), annotation.auditable()); } } catch (Exception e) { } return null; }
From source file:com.netflix.hystrix.contrib.javanica.cache.CacheInvocationContextFactory.java
/** * Create {@link CacheInvocationContext} parametrized with {@link CacheResult} annotation. * * @param metaHolder the meta holder, see {@link com.netflix.hystrix.contrib.javanica.command.MetaHolder} * @return initialized and configured {@link CacheInvocationContext} *///from ww w . j av a2 s .com public static CacheInvocationContext<CacheResult> createCacheResultInvocationContext(MetaHolder metaHolder) { Method method = metaHolder.getMethod(); if (method.isAnnotationPresent(CacheResult.class)) { CacheResult cacheResult = method.getAnnotation(CacheResult.class); MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheResult.cacheKeyMethod(), metaHolder); return new CacheInvocationContext<CacheResult>(cacheResult, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs()); } return null; }