public static String annoAccessor() { try { Annotation[] annos = ScenarioB003.class.getDeclaredMethod("foo").getDeclaredAnnotations(); if (annos == null || annos.length == 0) { return "no annotations"; } else { return "found " + (annos[0]); } } catch (Exception e) { return "no annotations"; } }
public static String annoAccessor() { try { Annotation[] annos = ScenarioB002.class.getDeclaredMethod("foo").getDeclaredAnnotations(); if (annos == null || annos.length == 0) { return "no annotations"; } else { return "found " + (annos[0]); } } catch (Exception e) { return "no annotations"; } }
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by this method, * or an empty array if there are none. Does not include inherited annotations. * Does not include parameter annotations. */ public Annotation[] getDeclaredAnnotations () { java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations(); Annotation[] result = new Annotation[annotations.length]; for (int i = 0; i < annotations.length; i++) { result[i] = new Annotation(annotations[i]); } return result; }
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by this method, * or an empty array if there are none. Does not include inherited annotations. * Does not include parameter annotations. */ public Annotation[] getDeclaredAnnotations () { java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations(); Annotation[] result = new Annotation[annotations.length]; for (int i = 0; i < annotations.length; i++) { result[i] = new Annotation(annotations[i]); } return result; }
/** Returns an {@link Annotation} object reflecting the annotation provided, or null of this method doesn't * have such an annotation. This is a convenience function if the caller knows already which annotation * type he's looking for. */ public Annotation getDeclaredAnnotation (Class<? extends java.lang.annotation.Annotation> annotationType) { java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations(); if (annotations == null) { return null; } for (java.lang.annotation.Annotation annotation : annotations) { if (annotation.annotationType().equals(annotationType)) { return new Annotation(annotation); } } return null; }
/** Returns an {@link Annotation} object reflecting the annotation provided, or null of this method doesn't * have such an annotation. This is a convenience function if the caller knows already which annotation * type he's looking for. */ public Annotation getDeclaredAnnotation (Class<? extends java.lang.annotation.Annotation> annotationType) { java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations(); if (annotations == null) { return null; } for (java.lang.annotation.Annotation annotation : annotations) { if (annotation.annotationType().equals(annotationType)) { return new Annotation(annotation); } } return null; }
/** * Get the annotations associated with given TestCase. * @param test the TestCase. */ private static Annotation[] getAnnotations(TestCase test) { try { Method m = test.getClass().getMethod(test.getName()); return m.getDeclaredAnnotations(); } catch (SecurityException e) { } catch (NoSuchMethodException e) { } return new Annotation[0]; }
private void handleMetaAnnotations(ResourceMethod resourceMethod, Method method, List<ProvideLinkDescriptor> linkDescriptors) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { handleAnnotations(resourceMethod, linkDescriptors, annotation.annotationType(), annotation); } }
private boolean isDeprecated(Method method) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof Deprecated) { return true; } } return false; } }
public static Annotation getFirstDeclaredAnnotation(String name) throws Exception { Annotation[] annos = getDeclaredMethod(name).getDeclaredAnnotations(); if (annos == null || annos.length == 0) { return null; } else { return annos[0]; } }
private static boolean isRoutableMethod(@Nonnull Method m) { for (Annotation a : m.getDeclaredAnnotations()) { if (WebMethodConstants.WEB_METHOD_ANNOTATION_NAMES.contains(a.annotationType().getName())) { return true; } if (a.annotationType().isAnnotationPresent(InterceptorAnnotation.class)) { // This is a Stapler interceptor annotation like RequirePOST or JsonResponse return true; } } for (Annotation[] set : m.getParameterAnnotations()) { for (Annotation a : set) { if (WebMethodConstants.WEB_METHOD_PARAMETER_ANNOTATION_NAMES.contains(a.annotationType().getName())) { return true; } } } for (Class<?> parameterType : m.getParameterTypes()) { if (WebMethodConstants.WEB_METHOD_PARAMETERS_NAMES.contains(parameterType.getName())) { return true; } } return WebApp.getCurrent().getFilterForDoActions().keep(new Function.InstanceFunction(m)); }
/** * {@inheritDoc} */ @CachedReturnPlugin.Enhance("declaredAnnotations") public AnnotationList getDeclaredAnnotations() { return new AnnotationList.ForLoadedAnnotations(method.getDeclaredAnnotations()); }
public List<String> getMethodAnnotationNames(Member method) { Annotation[] annotations = method instanceof Method ? ((Method) method).getDeclaredAnnotations() : method instanceof Constructor ? ((Constructor) method).getDeclaredAnnotations() : null; return getAnnotationNames(annotations); }
/** * Method that will add annotations from specified source method to target method, * but only if target does not yet have them. */ protected void _addMixUnders(Method src, AnnotatedMethod target) { for (Annotation a : src.getDeclaredAnnotations()) { if (_annotationIntrospector.isHandled(a)) { target.addIfNotPresent(a); } } }
private void checkUnexpectedAnnotations(ResourceMethod resourceMethod) { Invocable invocable = resourceMethod.getInvocable(); for (Annotation annotation : invocable.getHandlingMethod().getDeclaredAnnotations()) { if (PARAM_ANNOTATION_SET.contains(annotation.annotationType())) { Errors.fatal(resourceMethod, LocalizationMessages.METHOD_UNEXPECTED_ANNOTATION( invocable.getHandlingMethod().getName(), invocable.getHandler().getHandlerClass().getName(), annotation.annotationType().getName()) ); } } }
private void checkUnexpectedAnnotations(ResourceMethod resourceMethod) { Invocable invocable = resourceMethod.getInvocable(); for (Annotation annotation : invocable.getHandlingMethod().getDeclaredAnnotations()) { if (PARAM_ANNOTATION_SET.contains(annotation.annotationType())) { Errors.fatal(resourceMethod, LocalizationMessages.METHOD_UNEXPECTED_ANNOTATION( invocable.getHandlingMethod().getName(), invocable.getHandler().getHandlerClass().getName(), annotation.annotationType().getName()) ); } } }
@Test public void isInjectTest() throws NoSuchMethodException { final Method injectableMethod = Child.class.getMethod("injectableMethod"); Assert.assertTrue(ReflectionUtils.isInject(Arrays.asList(injectableMethod.getDeclaredAnnotations()))); final Method methodToFind = Child.class.getMethod("parametrizedMethod1", Integer.class); Assert.assertFalse(ReflectionUtils.isInject(Arrays.asList(methodToFind.getDeclaredAnnotations()))); }
private BehaviorStructure newBehaviorStructure(final Method method) { return new BehaviorStructure( new AccessImplByJDKBehavior(method), method.getName(), this, newInstance(method.getReturnType()), newInstances(method.getParameterTypes()), newInstances(method.getExceptionTypes()), newInstances(getAnnotationTypeArray(method.getDeclaredAnnotations())) ); }
protected AnnotatedMethod _constructCreatorMethod(Method m) { if (_annotationIntrospector == null) { // when annotation processing is disabled return new AnnotatedMethod(m, _emptyAnnotationMap(), _emptyAnnotationMaps(m.getParameterTypes().length)); } return new AnnotatedMethod(m, _collectRelevantAnnotations(m.getDeclaredAnnotations()), _collectRelevantAnnotations(m.getParameterAnnotations())); }
protected AnnotatedMethod _constructMethod(Method m) { /* note: parameter annotations not used for regular (getter, setter) * methods; only for creator methods (static factory methods) * -- at least not yet! */ if (_annotationIntrospector == null) { // when annotation processing is disabled return new AnnotatedMethod(m, _emptyAnnotationMap(), null); } return new AnnotatedMethod(m, _collectRelevantAnnotations(m.getDeclaredAnnotations()), null); }