Skip to content

Commit ae6d778

Browse files
committed
Polishing
1 parent e24ac55 commit ae6d778

File tree

4 files changed

+46
-47
lines changed

4 files changed

+46
-47
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,12 @@ public static <A extends Annotation> Set<A> getAllMergedAnnotations(AnnotatedEle
479479
* @param annotationType the annotation type to find (never {@code null})
480480
* @return the set of all merged repeatable {@code Annotations} found,
481481
* or an empty set if none were found
482+
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
483+
* is {@code null}, or if the container type cannot be resolved
482484
* @since 4.3
483485
* @see #getMergedAnnotation(AnnotatedElement, Class)
484486
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
485487
* @see #getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
486-
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
487-
* is {@code null}, or if the container type cannot be resolved
488488
*/
489489
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element,
490490
Class<A> annotationType) {
@@ -510,13 +510,13 @@ public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(Annot
510510
* {@link java.lang.annotation.Repeatable}
511511
* @return the set of all merged repeatable {@code Annotations} found,
512512
* or an empty set if none were found
513-
* @since 4.3
514-
* @see #getMergedAnnotation(AnnotatedElement, Class)
515-
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
516513
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
517514
* is {@code null}, or if the container type cannot be resolved
518515
* @throws AnnotationConfigurationException if the supplied {@code containerType}
519516
* is not a valid container annotation for the supplied {@code annotationType}
517+
* @since 4.3
518+
* @see #getMergedAnnotation(AnnotatedElement, Class)
519+
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
520520
*/
521521
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element,
522522
Class<A> annotationType, Class<? extends Annotation> containerType) {
@@ -803,12 +803,12 @@ public static <A extends Annotation> Set<A> findAllMergedAnnotations(AnnotatedEl
803803
* @param annotationType the annotation type to find (never {@code null})
804804
* @return the set of all merged repeatable {@code Annotations} found,
805805
* or an empty set if none were found
806+
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
807+
* is {@code null}, or if the container type cannot be resolved
806808
* @since 4.3
807809
* @see #findMergedAnnotation(AnnotatedElement, Class)
808810
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
809811
* @see #findMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
810-
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
811-
* is {@code null}, or if the container type cannot be resolved
812812
*/
813813
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element,
814814
Class<A> annotationType) {
@@ -834,13 +834,13 @@ public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(Anno
834834
* {@link java.lang.annotation.Repeatable}
835835
* @return the set of all merged repeatable {@code Annotations} found,
836836
* or an empty set if none were found
837-
* @since 4.3
838-
* @see #findMergedAnnotation(AnnotatedElement, Class)
839-
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
840837
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
841838
* is {@code null}, or if the container type cannot be resolved
842839
* @throws AnnotationConfigurationException if the supplied {@code containerType}
843840
* is not a valid container annotation for the supplied {@code annotationType}
841+
* @since 4.3
842+
* @see #findMergedAnnotation(AnnotatedElement, Class)
843+
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
844844
*/
845845
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element,
846846
Class<A> annotationType, Class<? extends Annotation> containerType) {
@@ -1326,9 +1326,9 @@ private static Class<? extends Annotation> resolveContainerType(Class<? extends
13261326
* annotation for the supplied repeatable {@code annotationType} (i.e.,
13271327
* that it declares a {@code value} attribute that holds an array of the
13281328
* {@code annotationType}).
1329-
* @since 4.3
13301329
* @throws AnnotationConfigurationException if the supplied {@code containerType}
13311330
* is not a valid container annotation for the supplied {@code annotationType}
1331+
* @since 4.3
13321332
*/
13331333
private static void validateContainerType(Class<? extends Annotation> annotationType,
13341334
Class<? extends Annotation> containerType) {
@@ -1351,9 +1351,6 @@ private static void validateContainerType(Class<? extends Annotation> annotation
13511351
}
13521352
}
13531353

1354-
/**
1355-
* @since 4.3
1356-
*/
13571354
private static <A extends Annotation> Set<A> postProcessAndSynthesizeAggregatedResults(AnnotatedElement element,
13581355
Class<A> annotationType, List<AnnotationAttributes> aggregatedResults) {
13591356

spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@ public AnnotationAttributesReadingVisitor(String annotationType,
6363
public void visitEnd() {
6464
super.visitEnd();
6565

66-
Class<?> annotationClass = this.attributes.annotationType();
66+
Class<? extends Annotation> annotationClass = this.attributes.annotationType();
6767
if (annotationClass != null) {
6868
List<AnnotationAttributes> attributeList = this.attributesMap.get(this.annotationType);
6969
if (attributeList == null) {
@@ -72,21 +72,23 @@ public void visitEnd() {
7272
else {
7373
attributeList.add(0, this.attributes);
7474
}
75-
Set<Annotation> visited = new LinkedHashSet<Annotation>();
76-
Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
77-
if (!ObjectUtils.isEmpty(metaAnnotations)) {
78-
for (Annotation metaAnnotation : metaAnnotations) {
79-
if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
80-
recursivelyCollectMetaAnnotations(visited, metaAnnotation);
75+
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationClass.getName())) {
76+
Set<Annotation> visited = new LinkedHashSet<Annotation>();
77+
Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
78+
if (!ObjectUtils.isEmpty(metaAnnotations)) {
79+
for (Annotation metaAnnotation : metaAnnotations) {
80+
if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
81+
recursivelyCollectMetaAnnotations(visited, metaAnnotation);
82+
}
8183
}
8284
}
83-
}
84-
if (this.metaAnnotationMap != null) {
85-
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>(visited.size());
86-
for (Annotation ann : visited) {
87-
metaAnnotationTypeNames.add(ann.annotationType().getName());
85+
if (this.metaAnnotationMap != null) {
86+
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>(visited.size());
87+
for (Annotation ann : visited) {
88+
metaAnnotationTypeNames.add(ann.annotationType().getName());
89+
}
90+
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
8891
}
89-
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
9092
}
9193
}
9294
}

spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,22 @@ public Object getAsyncResult(long timeToWait) {
136136
" was not set during the specified timeToWait=" + timeToWait);
137137
}
138138
Object result = this.asyncResult.get();
139-
Assert.state(result != RESULT_NONE, "Async result for handler [" + this.handler + "] was not set");
139+
if (result == RESULT_NONE) {
140+
throw new IllegalStateException("Async result for handler [" + this.handler + "] was not set");
141+
}
140142
return this.asyncResult.get();
141143
}
142144

143145
/**
144-
* True if is there a latch was not set, or the latch count reached 0.
146+
* True if the latch count reached 0 within the specified timeout.
145147
*/
146148
private boolean awaitAsyncDispatch(long timeout) {
147149
Assert.state(this.asyncDispatchLatch != null,
148-
"The asynDispatch CountDownLatch was not set by the TestDispatcherServlet.\n");
150+
"The asyncDispatch CountDownLatch was not set by the TestDispatcherServlet.");
149151
try {
150152
return this.asyncDispatchLatch.await(timeout, TimeUnit.MILLISECONDS);
151153
}
152-
catch (InterruptedException e) {
154+
catch (InterruptedException ex) {
153155
return false;
154156
}
155157
}

spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
119119

120120
@Override
121121
public BeanDefinition parse(Element element, ParserContext context) {
122-
123122
Object source = context.extractSource(element);
124123
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
125124
context.pushContainingComponent(compDefinition);
@@ -150,13 +149,12 @@ public BeanDefinition parse(Element element, ParserContext context) {
150149
for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
151150
RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
152151
String pathAttribute = endpointElem.getAttribute("path");
153-
Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
154-
List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
155-
for (String path : paths) {
152+
Assert.hasText(pathAttribute, "Invalid <stomp-endpoint> (no path mapping)");
153+
for (String path : StringUtils.tokenizeToStringArray(pathAttribute, ",")) {
156154
path = path.trim();
157-
Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
155+
Assert.hasText(path, "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
158156
if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
159-
path = path.endsWith("/") ? path + "**" : path + "/**";
157+
path = (path.endsWith("/") ? path + "**" : path + "/**");
160158
}
161159
urlMap.put(path, requestHandler);
162160
}
@@ -174,7 +172,6 @@ public BeanDefinition parse(Element element, ParserContext context) {
174172
}
175173

176174
private RuntimeBeanReference registerUserRegistry(Element element, ParserContext context, Object source) {
177-
178175
Element relayElement = DomUtils.getChildElementByTagName(element, "stomp-broker-relay");
179176
boolean multiServer = (relayElement != null && relayElement.hasAttribute("user-registry-broadcast"));
180177

@@ -192,9 +189,7 @@ private RuntimeBeanReference registerUserRegistry(Element element, ParserContext
192189
}
193190
}
194191

195-
private ManagedMap<String, Object> registerHandlerMapping(Element element,
196-
ParserContext context, Object source) {
197-
192+
private ManagedMap<String, Object> registerHandlerMapping(Element element, ParserContext context, Object source) {
198193
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
199194

200195
String orderAttribute = element.getAttribute("order");
@@ -240,13 +235,15 @@ private RuntimeBeanReference getMessageChannel(String name, Element element, Par
240235
}
241236
}
242237
}
238+
243239
ConstructorArgumentValues argValues = new ConstructorArgumentValues();
244240
if (executor != null) {
245241
executor.getPropertyValues().add("threadNamePrefix", name + "-");
246242
String executorName = name + "Executor";
247243
registerBeanDefByName(executorName, executor, context, source);
248244
argValues.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName));
249245
}
246+
250247
RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, argValues, null);
251248
ManagedList<? super Object> interceptors = new ManagedList<Object>();
252249
if (element != null) {
@@ -644,28 +641,29 @@ private static String registerBeanDef(RootBeanDefinition beanDef, ParserContext
644641
return name;
645642
}
646643

647-
private static void registerBeanDefByName(String name, RootBeanDefinition beanDef, ParserContext context, Object source) {
644+
private static void registerBeanDefByName(
645+
String name, RootBeanDefinition beanDef, ParserContext context, Object source) {
646+
648647
beanDef.setSource(source);
649648
beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
650649
context.getRegistry().registerBeanDefinition(name, beanDef);
651650
context.registerComponent(new BeanComponentDefinition(beanDef, name));
652651
}
653652

653+
654654
private static class DecoratingFactoryBean implements FactoryBean<WebSocketHandler> {
655655

656656
private final WebSocketHandler handler;
657657

658658
private final List<WebSocketHandlerDecoratorFactory> factories;
659659

660-
661-
@SuppressWarnings("unused")
662-
private DecoratingFactoryBean(WebSocketHandler handler, List<WebSocketHandlerDecoratorFactory> factories) {
660+
public DecoratingFactoryBean(WebSocketHandler handler, List<WebSocketHandlerDecoratorFactory> factories) {
663661
this.handler = handler;
664662
this.factories = factories;
665663
}
666664

667665
@Override
668-
public WebSocketHandler getObject() throws Exception {
666+
public WebSocketHandler getObject() {
669667
WebSocketHandler result = this.handler;
670668
for (WebSocketHandlerDecoratorFactory factory : this.factories) {
671669
result = factory.decorate(result);

0 commit comments

Comments
 (0)