Refine search
private static String getMethodMapping(Method method) { Assert.notNull(method, "'method' must not be null"); RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); if (requestMapping == null) { throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString()); } String[] paths = requestMapping.path(); if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) { return "/"; } if (paths.length > 1 && logger.isTraceEnabled()) { logger.trace("Using first of multiple paths on " + method.toGenericString()); } return paths[0]; }
/** * Determine if the supplied {@link Class} meets the criteria for being * considered a <em>default configuration class</em> candidate. * <p>Specifically, such candidates: * <ul> * <li>must not be {@code null}</li> * <li>must not be {@code private}</li> * <li>must not be {@code final}</li> * <li>must be {@code static}</li> * <li>must be annotated or meta-annotated with {@code @Configuration}</li> * </ul> * @param clazz the class to check * @return {@code true} if the supplied class meets the candidate criteria */ private static boolean isDefaultConfigurationClassCandidate(@Nullable Class<?> clazz) { return (clazz != null && isStaticNonPrivateAndNonFinal(clazz) && AnnotatedElementUtils.hasAnnotation(clazz, Configuration.class)); }
/** * Obtain the annotation of the specified {@code annotationType} that is on this type descriptor. * <p>As of Spring Framework 4.2, this method supports arbitrary levels of meta-annotations. * @param annotationType the annotation type * @return the annotation, or {@code null} if no such annotation exists on this type descriptor */ @Nullable public <T extends Annotation> T getAnnotation(Class<T> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return null; } return AnnotatedElementUtils.getMergedAnnotation(this.annotatedElement, annotationType); }
/** * Determine a suggested value from any of the given candidate annotations. */ @Nullable protected Object findValue(Annotation[] annotationsToSearch) { if (annotationsToSearch.length > 0) { // qualifier annotations have to be local AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes( AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType); if (attr != null) { return extractValue(attr); } } return null; }
public AnnotationDescriptor(Class<?> rootDeclaringClass, Class<?> declaringClass, @Nullable Annotation composedAnnotation, T annotation) { Assert.notNull(rootDeclaringClass, "'rootDeclaringClass' must not be null"); Assert.notNull(annotation, "Annotation must not be null"); this.rootDeclaringClass = rootDeclaringClass; this.declaringClass = declaringClass; this.composedAnnotation = composedAnnotation; this.annotation = annotation; AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( rootDeclaringClass, annotation.annotationType().getName(), false, false); Assert.state(attributes != null, "No annotation attributes"); this.annotationAttributes = attributes; }
private ControllerAdviceBean(Object bean, @Nullable BeanFactory beanFactory) { this.bean = bean; this.beanFactory = beanFactory; Assert.hasText(beanName, "Bean name must not be null"); Assert.notNull(beanFactory, "BeanFactory must not be null"); if (!beanFactory.containsBean(beanName)) { throw new IllegalArgumentException("BeanFactory [" + beanFactory + Assert.notNull(bean, "Bean must not be null"); beanType = bean.getClass(); this.order = initOrderFromBean(bean); AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class) : null);
Assert.notNull(testClass, "testClass must not be null"); ProfileValueSourceConfiguration config = AnnotatedElementUtils.findMergedAnnotation(testClass, annotationType); if (logger.isDebugEnabled()) { logger.debug("Retrieved @ProfileValueSourceConfiguration [" + config + "] for test class [" + profileValueSourceType = (Class<? extends ProfileValueSource>) AnnotationUtils.getDefaultValue(annotationType); Assert.state(profileValueSourceType != null, "No default ProfileValueSource class");
private AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType) { Assert.notNull(annotationType, "annotationType must not be null"); return AnnotatedElementUtils.findMergedAnnotationAttributes(element, annotationType.getName(), false, false); }
Assert.notNull(localSqlConfig, "Local @SqlConfig must not be null"); Assert.notNull(testClass, "testClass must not be null"); AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( testClass, SqlConfig.class.getName(), false, false); Object value = AnnotationUtils.getValue(localSqlConfig, key); if (value != null) { attributes = AnnotationUtils.getAnnotationAttributes(localSqlConfig, false, false);
/** * Extract {@link org.springframework.web.bind.annotation.RequestMapping}'s list of {@link RequestMethod}s into an * array of {@link String}s. * * @param type * @param method * @return */ @Override public Collection<HttpMethod> getRequestMethod(Class<?> type, Method method) { Assert.notNull(type, "Type must not be null!"); Assert.notNull(method, "Method must not be null!"); Annotation mergedAnnotation = findMergedAnnotation(method, annotationType); Object value = getValue(mergedAnnotation, "method"); RequestMethod[] requestMethods = (RequestMethod[]) value; List<HttpMethod> requestMethodNames = new ArrayList<>(); for (RequestMethod requestMethod : requestMethods) { requestMethodNames.add(HttpMethod.valueOf(requestMethod.toString())); } return requestMethodNames; }
private void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result) { ExceptionHandler ann = AnnotatedElementUtils.findMergedAnnotation(method, ExceptionHandler.class); Assert.state(ann != null, "No ExceptionHandler annotation"); result.addAll(Arrays.asList(ann.value())); }
@Nullable private SendTo getSendTo(Method specificMethod) { SendTo ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod, SendTo.class); if (ann == null) { ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), SendTo.class); } return ann; }
private static Map<String, Object> findQueryHints(Method method) { Map<String, Object> queryHints = new HashMap<String, Object>(); QueryHints queryHintsAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, QueryHints.class); if (queryHintsAnnotation != null) { for (QueryHint hint : queryHintsAnnotation.value()) { queryHints.put(hint.name(), hint.value()); } } QueryHint queryHintAnnotation = AnnotationUtils.findAnnotation(method, QueryHint.class); if (queryHintAnnotation != null) { queryHints.put(queryHintAnnotation.name(), queryHintAnnotation.value()); } return Collections.unmodifiableMap(queryHints); }
@Nullable private static LockModeType findLockModeType(Method method) { Lock annotation = AnnotatedElementUtils.findMergedAnnotation(method, Lock.class); return annotation == null ? null : (LockModeType) AnnotationUtils.getValue(annotation); }
@Override @Nullable public Map<String, Object> getAnnotationAttributes(String annotationName, boolean classValuesAsString) { return AnnotatedElementUtils.getMergedAnnotationAttributes(this.introspectedMethod, annotationName, classValuesAsString, this.nestedAnnotationsAsMap); }
EndpointBean(String beanName, Object bean) { AnnotationAttributes attributes = AnnotatedElementUtils .findMergedAnnotationAttributes(bean.getClass(), Endpoint.class, true, true); String id = attributes.getString("id"); Assert.state(StringUtils.hasText(id), () -> "No @Endpoint id attribute specified for " + bean.getClass().getName()); this.beanName = beanName; this.bean = bean; this.id = EndpointId.of(id); this.enabledByDefault = (Boolean) attributes.get("enableByDefault"); this.filter = getFilter(this.bean.getClass()); }
@Nullable public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement element, Class<A> annotationType) { return AnnotationUtils.synthesizeAnnotation(annotation, element); if (AnnotationUtils.hasPlainJavaAnnotationsOnly(element)) { return null; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, annotationType); return (attributes != null ? AnnotationUtils.synthesizeAnnotation(attributes, annotationType, element) : null);
@Nullable public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) { return AnnotationUtils.synthesizeAnnotation(annotation, element); if (AnnotationUtils.hasPlainJavaAnnotationsOnly(element)) { return null; AnnotationAttributes attributes = findMergedAnnotationAttributes(element, annotationType, false, false); return (attributes != null ? AnnotationUtils.synthesizeAnnotation(attributes, annotationType, element) : null);
@Override @Nullable public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( element, Transactional.class, false, false); if (attributes != null) { return parseTransactionAnnotation(attributes); } else { return null; } }
public ApplicationListenerMethodTransactionalAdapter(String beanName, Class<?> targetClass, Method method) { super(beanName, targetClass, method); TransactionalEventListener ann = AnnotatedElementUtils.findMergedAnnotation(method, TransactionalEventListener.class); if (ann == null) { throw new IllegalStateException("No TransactionalEventListener annotation found on method: " + method); } this.annotation = ann; }