Polishing

This commit is contained in:
Juergen Hoeller
2018-07-31 22:25:44 +02:00
parent e24ac55480
commit ae6d778c3e
4 changed files with 46 additions and 47 deletions

View File

@@ -479,12 +479,12 @@ public class AnnotatedElementUtils {
* @param annotationType the annotation type to find (never {@code null})
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @since 4.3
* @see #getMergedAnnotation(AnnotatedElement, Class)
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
* @see #getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
*/
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType) {
@@ -510,13 +510,13 @@ public class AnnotatedElementUtils {
* {@link java.lang.annotation.Repeatable}
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @since 4.3
* @see #getMergedAnnotation(AnnotatedElement, Class)
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @throws AnnotationConfigurationException if the supplied {@code containerType}
* is not a valid container annotation for the supplied {@code annotationType}
* @since 4.3
* @see #getMergedAnnotation(AnnotatedElement, Class)
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
*/
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType, Class<? extends Annotation> containerType) {
@@ -803,12 +803,12 @@ public class AnnotatedElementUtils {
* @param annotationType the annotation type to find (never {@code null})
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @since 4.3
* @see #findMergedAnnotation(AnnotatedElement, Class)
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
* @see #findMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
*/
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType) {
@@ -834,13 +834,13 @@ public class AnnotatedElementUtils {
* {@link java.lang.annotation.Repeatable}
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @since 4.3
* @see #findMergedAnnotation(AnnotatedElement, Class)
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @throws AnnotationConfigurationException if the supplied {@code containerType}
* is not a valid container annotation for the supplied {@code annotationType}
* @since 4.3
* @see #findMergedAnnotation(AnnotatedElement, Class)
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
*/
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType, Class<? extends Annotation> containerType) {
@@ -1326,9 +1326,9 @@ public class AnnotatedElementUtils {
* annotation for the supplied repeatable {@code annotationType} (i.e.,
* that it declares a {@code value} attribute that holds an array of the
* {@code annotationType}).
* @since 4.3
* @throws AnnotationConfigurationException if the supplied {@code containerType}
* is not a valid container annotation for the supplied {@code annotationType}
* @since 4.3
*/
private static void validateContainerType(Class<? extends Annotation> annotationType,
Class<? extends Annotation> containerType) {
@@ -1351,9 +1351,6 @@ public class AnnotatedElementUtils {
}
}
/**
* @since 4.3
*/
private static <A extends Annotation> Set<A> postProcessAndSynthesizeAggregatedResults(AnnotatedElement element,
Class<A> annotationType, List<AnnotationAttributes> aggregatedResults) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
public void visitEnd() {
super.visitEnd();
Class<?> annotationClass = this.attributes.annotationType();
Class<? extends Annotation> annotationClass = this.attributes.annotationType();
if (annotationClass != null) {
List<AnnotationAttributes> attributeList = this.attributesMap.get(this.annotationType);
if (attributeList == null) {
@@ -72,21 +72,23 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
else {
attributeList.add(0, this.attributes);
}
Set<Annotation> visited = new LinkedHashSet<Annotation>();
Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
if (!ObjectUtils.isEmpty(metaAnnotations)) {
for (Annotation metaAnnotation : metaAnnotations) {
if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
recursivelyCollectMetaAnnotations(visited, metaAnnotation);
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationClass.getName())) {
Set<Annotation> visited = new LinkedHashSet<Annotation>();
Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
if (!ObjectUtils.isEmpty(metaAnnotations)) {
for (Annotation metaAnnotation : metaAnnotations) {
if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
recursivelyCollectMetaAnnotations(visited, metaAnnotation);
}
}
}
}
if (this.metaAnnotationMap != null) {
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>(visited.size());
for (Annotation ann : visited) {
metaAnnotationTypeNames.add(ann.annotationType().getName());
if (this.metaAnnotationMap != null) {
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>(visited.size());
for (Annotation ann : visited) {
metaAnnotationTypeNames.add(ann.annotationType().getName());
}
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
}
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
}
}
}

View File

@@ -136,20 +136,22 @@ class DefaultMvcResult implements MvcResult {
" was not set during the specified timeToWait=" + timeToWait);
}
Object result = this.asyncResult.get();
Assert.state(result != RESULT_NONE, "Async result for handler [" + this.handler + "] was not set");
if (result == RESULT_NONE) {
throw new IllegalStateException("Async result for handler [" + this.handler + "] was not set");
}
return this.asyncResult.get();
}
/**
* True if is there a latch was not set, or the latch count reached 0.
* True if the latch count reached 0 within the specified timeout.
*/
private boolean awaitAsyncDispatch(long timeout) {
Assert.state(this.asyncDispatchLatch != null,
"The asynDispatch CountDownLatch was not set by the TestDispatcherServlet.\n");
"The asyncDispatch CountDownLatch was not set by the TestDispatcherServlet.");
try {
return this.asyncDispatchLatch.await(timeout, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e) {
catch (InterruptedException ex) {
return false;
}
}

View File

@@ -119,7 +119,6 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
@Override
public BeanDefinition parse(Element element, ParserContext context) {
Object source = context.extractSource(element);
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
context.pushContainingComponent(compDefinition);
@@ -150,13 +149,12 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
String pathAttribute = endpointElem.getAttribute("path");
Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
for (String path : paths) {
Assert.hasText(pathAttribute, "Invalid <stomp-endpoint> (no path mapping)");
for (String path : StringUtils.tokenizeToStringArray(pathAttribute, ",")) {
path = path.trim();
Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
Assert.hasText(path, "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
path = path.endsWith("/") ? path + "**" : path + "/**";
path = (path.endsWith("/") ? path + "**" : path + "/**");
}
urlMap.put(path, requestHandler);
}
@@ -174,7 +172,6 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
}
private RuntimeBeanReference registerUserRegistry(Element element, ParserContext context, Object source) {
Element relayElement = DomUtils.getChildElementByTagName(element, "stomp-broker-relay");
boolean multiServer = (relayElement != null && relayElement.hasAttribute("user-registry-broadcast"));
@@ -192,9 +189,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
}
}
private ManagedMap<String, Object> registerHandlerMapping(Element element,
ParserContext context, Object source) {
private ManagedMap<String, Object> registerHandlerMapping(Element element, ParserContext context, Object source) {
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
String orderAttribute = element.getAttribute("order");
@@ -240,6 +235,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
}
}
}
ConstructorArgumentValues argValues = new ConstructorArgumentValues();
if (executor != null) {
executor.getPropertyValues().add("threadNamePrefix", name + "-");
@@ -247,6 +243,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
registerBeanDefByName(executorName, executor, context, source);
argValues.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName));
}
RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, argValues, null);
ManagedList<? super Object> interceptors = new ManagedList<Object>();
if (element != null) {
@@ -644,28 +641,29 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
return name;
}
private static void registerBeanDefByName(String name, RootBeanDefinition beanDef, ParserContext context, Object source) {
private static void registerBeanDefByName(
String name, RootBeanDefinition beanDef, ParserContext context, Object source) {
beanDef.setSource(source);
beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
context.getRegistry().registerBeanDefinition(name, beanDef);
context.registerComponent(new BeanComponentDefinition(beanDef, name));
}
private static class DecoratingFactoryBean implements FactoryBean<WebSocketHandler> {
private final WebSocketHandler handler;
private final List<WebSocketHandlerDecoratorFactory> factories;
@SuppressWarnings("unused")
private DecoratingFactoryBean(WebSocketHandler handler, List<WebSocketHandlerDecoratorFactory> factories) {
public DecoratingFactoryBean(WebSocketHandler handler, List<WebSocketHandlerDecoratorFactory> factories) {
this.handler = handler;
this.factories = factories;
}
@Override
public WebSocketHandler getObject() throws Exception {
public WebSocketHandler getObject() {
WebSocketHandler result = this.handler;
for (WebSocketHandlerDecoratorFactory factory : this.factories) {
result = factory.decorate(result);