Skip to content

Commit dd7ddc0

Browse files
committed
Polishing
1 parent 3564616 commit dd7ddc0

File tree

7 files changed

+71
-70
lines changed

7 files changed

+71
-70
lines changed

spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.context.weaving;
1818

19-
2019
import java.lang.instrument.ClassFileTransformer;
2120
import java.lang.instrument.IllegalClassFormatException;
2221
import java.security.ProtectionDomain;
@@ -44,12 +43,13 @@
4443
public class AspectJWeavingEnabler
4544
implements BeanFactoryPostProcessor, BeanClassLoaderAware, LoadTimeWeaverAware, Ordered {
4645

46+
public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml";
47+
48+
4749
private ClassLoader beanClassLoader;
4850

4951
private LoadTimeWeaver loadTimeWeaver;
5052

51-
public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml";
52-
5353

5454
@Override
5555
public void setBeanClassLoader(ClassLoader classLoader) {
@@ -71,6 +71,12 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
7171
enableAspectJWeaving(this.loadTimeWeaver, this.beanClassLoader);
7272
}
7373

74+
75+
/**
76+
* Enable AspectJ weaving with the given {@link LoadTimeWeaver}.
77+
* @param weaverToUse the LoadTimeWeaver to apply to (or {@code null} for a default weaver)
78+
* @param beanClassLoader the class loader to create a default weaver for (if necessary)
79+
*/
7480
public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) {
7581
if (weaverToUse == null) {
7682
if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
@@ -80,8 +86,8 @@ public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader
8086
throw new IllegalStateException("No LoadTimeWeaver available");
8187
}
8288
}
83-
weaverToUse.addTransformer(new AspectJClassBypassingClassFileTransformer(
84-
new ClassPreProcessorAgentAdapter()));
89+
weaverToUse.addTransformer(
90+
new AspectJClassBypassingClassFileTransformer(new ClassPreProcessorAgentAdapter()));
8591
}
8692

8793

@@ -108,4 +114,5 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
108114
return this.delegate.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
109115
}
110116
}
117+
111118
}

spring-core/src/main/java/org/springframework/core/MethodParameter.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -29,15 +29,13 @@
2929
import org.springframework.util.Assert;
3030

3131
/**
32-
* Helper class that encapsulates the specification of a method parameter, i.e.
33-
* a {@link Method} or {@link Constructor} plus a parameter index and a nested
34-
* type index for a declared generic type. Useful as a specification object to
35-
* pass along.
32+
* Helper class that encapsulates the specification of a method parameter, i.e. a {@link Method}
33+
* or {@link Constructor} plus a parameter index and a nested type index for a declared generic
34+
* type. Useful as a specification object to pass along.
3635
*
37-
* <p>As of 4.2, there is a {@link org.springframework.core.annotation.SynthesizingMethodParameter
38-
* SynthesizingMethodParameter} subclass available which synthesizes annotations
39-
* with attribute aliases. That subclass is used for web and message endpoint
40-
* processing, in particular.
36+
* <p>As of 4.2, there is a {@link org.springframework.core.annotation.SynthesizingMethodParameter}
37+
* subclass available which synthesizes annotations with attribute aliases. That subclass is used
38+
* for web and message endpoint processing, in particular.
4139
*
4240
* @author Juergen Hoeller
4341
* @author Rob Harrop
@@ -167,7 +165,14 @@ public Constructor<?> getConstructor() {
167165
}
168166

169167
/**
170-
* Returns the wrapped member.
168+
* Return the class that declares the underlying Method or Constructor.
169+
*/
170+
public Class<?> getDeclaringClass() {
171+
return getMember().getDeclaringClass();
172+
}
173+
174+
/**
175+
* Return the wrapped member.
171176
* @return the Method or Constructor as Member
172177
*/
173178
public Member getMember() {
@@ -183,7 +188,9 @@ public Member getMember() {
183188
}
184189

185190
/**
186-
* Returns the wrapped annotated element.
191+
* Return the wrapped annotated element.
192+
* <p>Note: This method exposes the annotations declared on the method/constructor
193+
* itself (i.e. at the method/constructor level, not at the parameter level).
187194
* @return the Method or Constructor as AnnotatedElement
188195
*/
189196
public AnnotatedElement getAnnotatedElement() {
@@ -198,13 +205,6 @@ public AnnotatedElement getAnnotatedElement() {
198205
}
199206
}
200207

201-
/**
202-
* Return the class that declares the underlying Method or Constructor.
203-
*/
204-
public Class<?> getDeclaringClass() {
205-
return getMember().getDeclaringClass();
206-
}
207-
208208
/**
209209
* Return the index of the method/constructor parameter.
210210
* @return the parameter index (-1 in case of the return type)
@@ -338,8 +338,8 @@ public Type getGenericParameterType() {
338338
/**
339339
* Return the nested type of the method/constructor parameter.
340340
* @return the parameter type (never {@code null})
341-
* @see #getNestingLevel()
342341
* @since 3.1
342+
* @see #getNestingLevel()
343343
*/
344344
public Class<?> getNestedParameterType() {
345345
if (this.nestingLevel > 1) {
@@ -370,8 +370,8 @@ else if (type instanceof ParameterizedType) {
370370
/**
371371
* Return the nested generic type of the method/constructor parameter.
372372
* @return the parameter type (never {@code null})
373-
* @see #getNestingLevel()
374373
* @since 4.2
374+
* @see #getNestingLevel()
375375
*/
376376
public Type getNestedGenericParameterType() {
377377
if (this.nestingLevel > 1) {
@@ -423,33 +423,37 @@ public Annotation[] getParameterAnnotations() {
423423
return this.parameterAnnotations;
424424
}
425425

426+
/**
427+
* Return {@code true} if the parameter has at least one annotation,
428+
* {@code false} if it has none.
429+
* @see #getParameterAnnotations()
430+
*/
431+
public boolean hasParameterAnnotations() {
432+
return (getParameterAnnotations().length != 0);
433+
}
434+
426435
/**
427436
* Return the parameter annotation of the given type, if available.
428437
* @param annotationType the annotation type to look for
429438
* @return the annotation object, or {@code null} if not found
430439
*/
431440
@SuppressWarnings("unchecked")
432-
public <T extends Annotation> T getParameterAnnotation(Class<T> annotationType) {
441+
public <A extends Annotation> A getParameterAnnotation(Class<A> annotationType) {
433442
Annotation[] anns = getParameterAnnotations();
434443
for (Annotation ann : anns) {
435444
if (annotationType.isInstance(ann)) {
436-
return (T) ann;
445+
return (A) ann;
437446
}
438447
}
439448
return null;
440449
}
441450

442451
/**
443-
* Return true if the parameter has at least one annotation, false if it has none.
444-
*/
445-
public boolean hasParameterAnnotations() {
446-
return (getParameterAnnotations().length != 0);
447-
}
448-
449-
/**
450-
* Return true if the parameter has the given annotation type, and false if it doesn't.
452+
* Return whether the parameter is declared with the given annotation type.
453+
* @param annotationType the annotation type to look for
454+
* @see #getParameterAnnotation(Class)
451455
*/
452-
public <T extends Annotation> boolean hasParameterAnnotation(Class<T> annotationType) {
456+
public <A extends Annotation> boolean hasParameterAnnotation(Class<A> annotationType) {
453457
return (getParameterAnnotation(annotationType) != null);
454458
}
455459

spring-core/src/main/java/org/springframework/core/convert/ConversionService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -64,19 +64,19 @@ public interface ConversionService {
6464

6565
/**
6666
* Convert the given {@code source} to the specified {@code targetType}.
67-
* @param source the source object to convert (may be null)
67+
* @param source the source object to convert (may be {@code null})
6868
* @param targetType the target type to convert to (required)
6969
* @return the converted object, an instance of targetType
7070
* @throws ConversionException if a conversion exception occurred
71-
* @throws IllegalArgumentException if targetType is null
71+
* @throws IllegalArgumentException if targetType is {@code null}
7272
*/
7373
<T> T convert(Object source, Class<T> targetType);
7474

7575
/**
7676
* Convert the given {@code source} to the specified {@code targetType}.
7777
* The TypeDescriptors provide additional context about the source and target locations
7878
* where conversion will occur, often object fields or property locations.
79-
* @param source the source object to convert (may be null)
79+
* @param source the source object to convert (may be {@code null})
8080
* @param sourceType context about the source type to convert from
8181
* (may be {@code null} if source is {@code null})
8282
* @param targetType context about the target type to convert to (required)

spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
* and services which use plain JDBC (without being aware of Hibernate)!
7070
* Application code needs to stick to the same simple Connection lookup pattern as
7171
* with {@link org.springframework.jdbc.datasource.DataSourceTransactionManager}
72-
* (i.e. {@link DataSourceUtils#getConnection}
72+
* (i.e. {@link org.springframework.jdbc.datasource.DataSourceUtils#getConnection}
7373
* or going through a
74-
* {@link TransactionAwareDataSourceProxy}).
74+
* {@link org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy}).
7575
*
7676
* <p>Note: To be able to register a DataSource's Connection for plain JDBC code,
7777
* this instance needs to be aware of the DataSource ({@link #setDataSource}).
@@ -235,7 +235,6 @@ public void setPrepareConnection(boolean prepareConnection) {
235235
* <p>Default is "false". Turning this flag on enforces over-commit holdability on the
236236
* underlying JDBC Connection (if {@link #prepareConnection "prepareConnection"} is on)
237237
* and skips the disconnect-on-completion step.
238-
* @since 4.2
239238
* @see Connection#setHoldability
240239
* @see ResultSet#HOLD_CURSORS_OVER_COMMIT
241240
* @see #disconnectOnCompletion(Session)
@@ -687,7 +686,6 @@ protected void doCleanupAfterCompletion(Object transaction) {
687686
* <p>The default implementation simply calls {@link Session#disconnect()}.
688687
* Subclasses may override this with a no-op or with fine-tuned disconnection logic.
689688
* @param session the Hibernate Session to disconnect
690-
* @since 4.2
691689
* @see Session#disconnect()
692690
*/
693691
protected void disconnectOnCompletion(Session session) {

spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerInterceptor.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -33,8 +33,8 @@
3333
* or common handler behavior like locale or theme changes. Its main purpose
3434
* is to allow for factoring out repetitive handler code.
3535
*
36-
* <p>In an async processing scenario, the handler may be executed in a separate
37-
* thread while the main thread exits without rendering or invoking the
36+
* <p>In an asynchronous processing scenario, the handler may be executed in a
37+
* separate thread while the main thread exits without rendering or invoking the
3838
* {@code postHandle} and {@code afterCompletion} callbacks. When concurrent
3939
* handler execution completes, the request is dispatched back in order to
4040
* proceed with rendering the model and all methods of this contract are invoked
@@ -77,16 +77,13 @@ public interface HandlerInterceptor {
7777
/**
7878
* Intercept the execution of a handler. Called after HandlerMapping determined
7979
* an appropriate handler object, but before HandlerAdapter invokes the handler.
80-
*
8180
* <p>DispatcherServlet processes a handler in an execution chain, consisting
8281
* of any number of interceptors, with the handler itself at the end.
8382
* With this method, each interceptor can decide to abort the execution chain,
8483
* typically sending a HTTP error or writing a custom response.
85-
*
8684
* <p><strong>Note:</strong> special considerations apply for asynchronous
8785
* request processing. For more details see
8886
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
89-
*
9087
* @param request current HTTP request
9188
* @param response current HTTP response
9289
* @param handler chosen handler to execute, for type and/or instance evaluation
@@ -102,19 +99,16 @@ boolean preHandle(HttpServletRequest request, HttpServletResponse response, Obje
10299
* Intercept the execution of a handler. Called after HandlerAdapter actually
103100
* invoked the handler, but before the DispatcherServlet renders the view.
104101
* Can expose additional model objects to the view via the given ModelAndView.
105-
*
106102
* <p>DispatcherServlet processes a handler in an execution chain, consisting
107103
* of any number of interceptors, with the handler itself at the end.
108104
* With this method, each interceptor can post-process an execution,
109105
* getting applied in inverse order of the execution chain.
110-
*
111106
* <p><strong>Note:</strong> special considerations apply for asynchronous
112107
* request processing. For more details see
113108
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
114-
*
115109
* @param request current HTTP request
116110
* @param response current HTTP response
117-
* @param handler handler (or {@link HandlerMethod}) that started async
111+
* @param handler handler (or {@link HandlerMethod}) that started asynchronous
118112
* execution, for type and/or instance examination
119113
* @param modelAndView the {@code ModelAndView} that the handler returned
120114
* (can also be {@code null})
@@ -127,21 +121,17 @@ void postHandle(HttpServletRequest request, HttpServletResponse response, Object
127121
* Callback after completion of request processing, that is, after rendering
128122
* the view. Will be called on any outcome of handler execution, thus allows
129123
* for proper resource cleanup.
130-
*
131124
* <p>Note: Will only be called if this interceptor's {@code preHandle}
132125
* method has successfully completed and returned {@code true}!
133-
*
134126
* <p>As with the {@code postHandle} method, the method will be invoked on each
135127
* interceptor in the chain in reverse order, so the first interceptor will be
136128
* the last to be invoked.
137-
*
138129
* <p><strong>Note:</strong> special considerations apply for asynchronous
139130
* request processing. For more details see
140131
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
141-
*
142132
* @param request current HTTP request
143133
* @param response current HTTP response
144-
* @param handler handler (or {@link HandlerMethod}) that started async
134+
* @param handler handler (or {@link HandlerMethod}) that started asynchronous
145135
* execution, for type and/or instance examination
146136
* @param ex exception thrown on handler execution, if any
147137
* @throws Exception in case of errors

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodExceptionResolver.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -34,7 +34,7 @@ public abstract class AbstractHandlerMethodExceptionResolver extends AbstractHan
3434

3535
/**
3636
* Checks if the handler is a {@link HandlerMethod} and then delegates to the
37-
* base class implementation of {@link #shouldApplyTo(HttpServletRequest, Object)}
37+
* base class implementation of {@code #shouldApplyTo(HttpServletRequest, Object)}
3838
* passing the bean of the {@code HandlerMethod}. Otherwise returns {@code false}.
3939
*/
4040
@Override
@@ -54,8 +54,7 @@ else if (handler instanceof HandlerMethod) {
5454

5555
@Override
5656
protected final ModelAndView doResolveException(
57-
HttpServletRequest request, HttpServletResponse response,
58-
Object handler, Exception ex) {
57+
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
5958

6059
return doResolveHandlerMethodException(request, response, (HandlerMethod) handler, ex);
6160
}
@@ -75,7 +74,6 @@ protected final ModelAndView doResolveException(
7574
* @return a corresponding ModelAndView to forward to, or {@code null} for default processing
7675
*/
7776
protected abstract ModelAndView doResolveHandlerMethodException(
78-
HttpServletRequest request, HttpServletResponse response,
79-
HandlerMethod handlerMethod, Exception ex);
77+
HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception ex);
8078

8179
}

0 commit comments

Comments
 (0)