List of usage examples for java.lang.reflect Method getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:com.opensymphony.xwork2.util.AnnotationUtils.java
/** * Adds all methods with the specified Annotation of class clazz and its superclasses to allFields * * @param annotationClass the {@link Annotation}s to find * @param clazz The {@link Class} to inspect * @param allMethods list of all methods *//*from www. ja va 2 s . c om*/ public static void addAllMethods(Class<? extends Annotation> annotationClass, Class clazz, List<Method> allMethods) { if (clazz == null) { return; } Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { Annotation ann = method.getAnnotation(annotationClass); if (ann != null) { allMethods.add(method); } } addAllMethods(annotationClass, clazz.getSuperclass(), allMethods); }
From source file:com.github.benmanes.caffeine.cache.testing.CacheValidationListener.java
/** Checks whether the {@link TrackingExecutor} had unexpected failures. */ private static void checkExecutor(ITestResult testResult, CacheContext context) { Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); CacheSpec cacheSpec = testMethod.getAnnotation(CacheSpec.class); if (cacheSpec == null) { return;/*from w ww . j a v a2 s.c o m*/ } assertThat("CacheContext required", context, is(not(nullValue()))); TrackingExecutor executor = context.executor(); if (cacheSpec.executorFailure() == ExecutorFailure.EXPECTED) { assertThat(executor.failureCount(), is(greaterThan(0))); } else if (cacheSpec.executorFailure() == ExecutorFailure.DISALLOWED) { assertThat(executor.failureCount(), is(0)); } }
From source file:com.github.benmanes.caffeine.cache.testing.CacheValidationListener.java
/** Checks the writer if {@link CheckNoWriter} is found. */ private static void checkWriter(ITestResult testResult, CacheContext context) { Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); CheckNoWriter checkWriter = testMethod.getAnnotation(CheckNoWriter.class); if (checkWriter == null) { return;/*from w w w . j a va 2 s . c om*/ } assertThat("Test requires CacheContext param for validation", context, is(not(nullValue()))); verifyWriter(context, (verifier, writer) -> verifier.zeroInteractions()); }
From source file:net.sf.companymanager.qbe.JpaUtil.java
private static boolean isManuallyAssigned(final Method method) { if (method.getAnnotation(Id.class) != null) { return method.getAnnotation(GeneratedValue.class) == null; } else if (method.getAnnotation(EmbeddedId.class) != null) { return true; } else {//from ww w.java 2 s . com return true; } }
From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixJerseyAPIConfig.java
private static void searchForAPIFenixScope(Class<?> apiClass) { if (apiClass != null) { Path pathAnnotation = apiClass.getAnnotation(Path.class); if (pathAnnotation != null) { for (Method method : apiClass.getMethods()) { Path methodPathAnnotation = method.getAnnotation(Path.class); FenixAPIScope apiScopeAnnotation = method.getAnnotation(FenixAPIScope.class); if (apiScopeAnnotation != null) { if (methodPathAnnotation != null) { String path = ends(pathAnnotation.value()); String methodPath = ends(methodPathAnnotation.value()); String absolutePath = Joiner.on("/").join(path, methodPath); String scopeName = apiScopeAnnotation.value(); scopePathsMap.put(scopeName, absolutePath); LOGGER.debug("add {} to scope {}", absolutePath, scopeName); } else { LOGGER.debug("No path for method {}", method.getName()); }/* w w w . ja v a 2 s . c o m*/ } else { FenixAPIPublic publicAPIAnnotation = method.getAnnotation(FenixAPIPublic.class); if (publicAPIAnnotation != null) { if (methodPathAnnotation != null) { String path = ends(pathAnnotation.value()); String methodPath = ends(methodPathAnnotation.value()); String absolutePath = Joiner.on("/").join(path, methodPath); publicScopes.add(absolutePath); LOGGER.debug("add public endpoint {}", absolutePath); } } } } } else { LOGGER.debug("No api class"); } } }
From source file:lite.flow.util.ActivityInspector.java
protected static EntryPoint[] getEntryAnnotatedMethods(Class<?> clazz) { Method[] methods = MethodUtils.getMethodsWithAnnotation(clazz, Entry.class); EntryPoint[] entryPoints = new EntryPoint[methods.length]; for (int i = 0; i < methods.length; i++) { Method method = methods[i]; Entry annotation = method.getAnnotation(Entry.class); EntryPoint entryPoint = new EntryPoint(method, annotation.inNames(), annotation.outName()); entryPoints[i] = entryPoint;/*ww w . j av a 2 s .co m*/ } return entryPoints; }
From source file:com.manydesigns.portofino.buttons.ButtonsLogic.java
public static List<Guard> getGuards(Method method, GuardType type) { List<Guard> guardList = new ArrayList<Guard>(); Guard guard = method.getAnnotation(Guard.class); if (guard != null && (type == null || type == guard.type())) { guardList.add(guard);// w w w . jav a 2 s. co m } else { Guards guards = method.getAnnotation(Guards.class); if (guards != null) { for (Guard g : guards.value()) { if (type == null || type == g.type()) { guardList.add(g); } } } } return guardList; }
From source file:com.lonepulse.zombielink.request.RequestUtils.java
/** * <p>Finds all <b><i>constant</i> form parameters</b> in the given {@link InvocationContext}.</p> * <p>Constant form parameters are introduced with @{@link Param} at <b>request level</b> using * the @{@link FormParams} annotation.</p> * * @param context/* w w w. java2 s. c o m*/ * the {@link InvocationContext} from which all {@link FormParams} annotations applied * on the endpoint method will be extracted * <br><br> * @return an <b>unmodifiable</b> {@link List} which aggregates all the @{@link Param} annotations * found on the {@link FormParams} annotation * <br><br> * @throws NullPointerException * if the supplied {@link InvocationContext} was {@code null} * <br><br> * @since 1.3.0 */ static List<Param> findStaticFormParams(InvocationContext context) { Method request = assertNotNull(context).getRequest(); FormParams formParams = request.getAnnotation(FormParams.class); return Collections .unmodifiableList(formParams != null ? Arrays.asList(formParams.value()) : new ArrayList<Param>()); }
From source file:com.lonepulse.zombielink.request.RequestUtils.java
/** * <p>Finds all <b><i>constant</i> request parameters</b> in the given {@link InvocationContext}.</p> * <p>Constant request parameters are introduced with @{@link Param} at <b>request level</b> using * the @{@link QueryParams} annotation.</p> * * @param context/*from w ww . j av a2 s . c o m*/ * the {@link InvocationContext} from which all {@link QueryParams} annotations applied * on the endpoint method will be extracted * <br><br> * @return an <b>unmodifiable</b> {@link List} which aggregates all the @{@link Param} annotations * found on the {@link QueryParams} annotation * <br><br> * @throws NullPointerException * if the supplied {@link InvocationContext} was {@code null} * <br><br> * @since 1.3.0 */ static List<Param> findStaticQueryParams(InvocationContext context) { Method request = assertNotNull(context).getRequest(); QueryParams queryParams = request.getAnnotation(QueryParams.class); return Collections.unmodifiableList( queryParams != null ? Arrays.asList(queryParams.value()) : new ArrayList<Param>()); }
From source file:com.lonepulse.zombielink.request.RequestUtils.java
/** * <p>Finds all <b>static headers</b> in the given {@link InvocationContext} and returns an unmodifiable * {@link List} of {@link Map.Entry} instances with the header <i>name</i> as the key and the runtime * argument as the <i>value</i>. * /*ww w. j a v a 2s. c o m*/ * <b>Note</b> that this implementation of {@link Map.Entry#setValue(Object)} throws an * {@link UnsupportedOperationException}. This list may contain multiple entries with the <i>same name</i> * as these headers are meant to be <b>added</b> ant not overwritten for a request.</p> * * <p><i>Static-headers</i> are specified at request-level with @{@link Headers}</p> * * <br><br> * @param context * the {@link InvocationContext} from which all static headers will be discovered * <br><br> * @return an <b>unmodifiable</b> {@link List} of {@link Map.Entry} instances with the header <i>name</i> * as the key and the runtime argument as the <i>value</i>; <b>note</b> that this implementation * of {@link Map.Entry#setValue(Object)} hrows an {@link UnsupportedOperationException} * <br><br> * @throws NullPointerException * if the supplied {@link InvocationContext} was {@code null} * <br><br> * @since 1.3.0 */ static List<Map.Entry<String, Object>> findStaticHeaders(InvocationContext context) { assertNotNull(context); Method request = context.getRequest(); Headers headerSet = request.getAnnotation(Headers.class); List<Map.Entry<String, Object>> headers = new ArrayList<Map.Entry<String, Object>>(); if (headerSet != null && headerSet.value() != null && headerSet.value().length > 0) { List<Headers.Header> staticHeaders = Arrays.asList(headerSet.value()); for (final Headers.Header staticHeader : staticHeaders) { headers.add(new Map.Entry<String, Object>() { @Override public String getKey() { return staticHeader.name(); } @Override public Object getValue() { return staticHeader.value(); } @Override public Object setValue(Object value) { throw new UnsupportedOperationException(); } }); } } return Collections.unmodifiableList(headers); }