/** * Returns the annotations on this method */ public Annotation[] getAnnotations() { return method.getAnnotations(); }
/** * Returns the annotations on this method */ @Override public Annotation[] getAnnotations() { return fMethod.getAnnotations(); }
protected Annotation[] testAnnotations(Method method) { return method.getAnnotations(); }
Builder(Retrofit retrofit, Method method) { this.retrofit = retrofit; this.method = method; this.methodAnnotations = method.getAnnotations(); this.parameterTypes = method.getGenericParameterTypes(); this.parameterAnnotationsArray = method.getParameterAnnotations(); }
public DefaultCacheMethodDetails(Method method, A cacheAnnotation, String cacheName) { this.method = method; this.annotations = Collections.unmodifiableSet( new LinkedHashSet<>(Arrays.asList(method.getAnnotations()))); this.cacheAnnotation = cacheAnnotation; this.cacheName = cacheName; }
public static List<Method> findPublicStaticMethodsWithAnnotation(Class<?> clazz, Class<?> annotationClass) { ImmutableList.Builder<Method> methods = ImmutableList.builder(); for (Method method : clazz.getMethods()) { for (Annotation annotation : method.getAnnotations()) { if (annotationClass.isInstance(annotation)) { checkArgument(Modifier.isStatic(method.getModifiers()) && Modifier.isPublic(method.getModifiers()), "%s annotated with %s must be static and public", method.getName(), annotationClass.getSimpleName()); methods.add(method); } } } return methods.build(); }
private static <ResponseT, ReturnT> CallAdapter<ResponseT, ReturnT> createCallAdapter( Retrofit retrofit, Method method) { Type returnType = method.getGenericReturnType(); Annotation[] annotations = method.getAnnotations(); try { //noinspection unchecked return (CallAdapter<ResponseT, ReturnT>) retrofit.callAdapter(returnType, annotations); } catch (RuntimeException e) { // Wide exception range because factories are user code. throw methodError(method, e, "Unable to create call adapter for %s", returnType); } }
@Override public T invoke(Object proxy, Method method, Object[] args) throws Throwable { Type returnType = method.getGenericReturnType(); Annotation[] methodAnnotations = method.getAnnotations(); CallAdapter<R, T> callAdapter = (CallAdapter<R, T>) retrofit.callAdapter(returnType, methodAnnotations); return callAdapter.adapt(behaviorCall); } });
@Override public List<Annotation> getAnnotations() { Annotation[] annotations = null; if (read != null) { annotations = read.getAnnotations(); } else if (field != null) { annotations = field.getAnnotations(); } return annotations != null ? Arrays.asList(annotations) : delegate.getAnnotations(); }
@SafeVarargs public static Set<Method> findPublicMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation>... annotationClasses) { ImmutableSet.Builder<Method> methods = ImmutableSet.builder(); for (Method method : clazz.getDeclaredMethods()) { for (Annotation annotation : method.getAnnotations()) { for (Class<?> annotationClass : annotationClasses) { if (annotationClass.isInstance(annotation)) { checkArgument(Modifier.isPublic(method.getModifiers()), "Method [%s] annotated with @%s must be public", method, annotationClass.getSimpleName()); methods.add(method); } } } } return methods.build(); }
public static String getHttpMethodFromCustomAnnotations(Method method) { for (Annotation methodAnnotation : method.getAnnotations()) { HttpMethod httpMethod = methodAnnotation.annotationType().getAnnotation(HttpMethod.class); if (httpMethod != null) { return httpMethod.value().toLowerCase(); } } return null; } }
private static <ResponseT> Converter<ResponseBody, ResponseT> createResponseConverter( Retrofit retrofit, Method method, Type responseType) { Annotation[] annotations = method.getAnnotations(); try { return retrofit.responseBodyConverter(responseType, annotations); } catch (RuntimeException e) { // Wide exception range because factories are user code. throw methodError(method, e, "Unable to create converter for %s", responseType); } }
@Override public boolean hasAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { return true; } } return false; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap)); } } return annotatedMethods; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
private boolean isAnnotated(Method method) { Annotation[] anns = method.getAnnotations(); if (anns == null) { return false; } for (Annotation ann : anns) { String name = ann.annotationType().getName(); if (name.endsWith("Anno")) { return true; } } return false; }
/** * Get all {@link Annotation Annotations} that are <em>present</em> on the * supplied {@link Method}. * <p>Correctly handles bridge {@link Method Methods} generated by the compiler. * <p>Meta-annotations will <em>not</em> be searched. * @param method the Method to retrieve annotations from * @return the annotations found, an empty array, or {@code null} if not * resolvable (e.g. because nested Class values in annotation attributes * failed to resolve at runtime) * @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method) * @see AnnotatedElement#getAnnotations() */ @Nullable public static Annotation[] getAnnotations(Method method) { try { return synthesizeAnnotationArray(BridgeMethodResolver.findBridgedMethod(method).getAnnotations(), method); } catch (Throwable ex) { handleIntrospectionFailure(method, ex); return null; } }
/** * Filter on methods not annotated with the given annotation type. */ @SafeVarargs public final Builder<T> annotNotPresent(Class<? extends Annotation>... annotationTypes) { String message = "annotationNotPresent=" + Arrays.toString(annotationTypes); addFilter(message, method -> { if (annotationTypes.length != 0) { return Arrays.stream(annotationTypes).noneMatch(annotType -> AnnotatedElementUtils.findMergedAnnotation(method, annotType) != null); } else { return method.getAnnotations().length == 0; } }); return this; }
/** * Filter on methods not annotated with the given annotation type. */ @SafeVarargs public final Builder<T> annotNotPresent(Class<? extends Annotation>... annotationTypes) { String message = "annotationNotPresent=" + Arrays.toString(annotationTypes); addFilter(message, method -> { if (annotationTypes.length != 0) { return Arrays.stream(annotationTypes).noneMatch(annotType -> AnnotatedElementUtils.findMergedAnnotation(method, annotType) != null); } else { return method.getAnnotations().length == 0; } }); return this; }
@Test public void testGetElementKey_WithQualifier() throws NoSuchMethodException { Method method = KeysTest.class.getDeclaredMethod("qualifiedElementProvides", new Class<?>[]{}); assertThat(Keys.getSetKey(method.getGenericReturnType(), method.getAnnotations(), method)) .isEqualTo("@javax.inject.Named(value=foo)/java.util.Set<java.lang.String>"); }
@Test public void testGetElementKey_NoQualifier() throws NoSuchMethodException { Method method = KeysTest.class.getDeclaredMethod("elementProvides", new Class<?>[]{}); assertThat(Keys.getSetKey(method.getGenericReturnType(), method.getAnnotations(), method)) .isEqualTo("java.util.Set<java.lang.String>"); }