Skip to content

Commit a2d40f3

Browse files
committed
Polishing
1 parent 0de307b commit a2d40f3

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,11 @@ public Object getProxy(ClassLoader classLoader) {
219219
}
220220

221221
protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) {
222-
223222
enhancer.setInterceptDuringConstruction(false);
224223
enhancer.setCallbacks(callbacks);
225-
226-
return this.constructorArgs == null ? enhancer.create() : enhancer.create(
227-
this.constructorArgTypes, this.constructorArgs);
224+
return (this.constructorArgs != null ?
225+
enhancer.create(this.constructorArgTypes, this.constructorArgs) :
226+
enhancer.create());
228227
}
229228

230229
/**
@@ -314,8 +313,7 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
314313
Callback[] fixedCallbacks = new Callback[methods.length];
315314
this.fixedInterceptorMap = new HashMap<String, Integer>(methods.length);
316315

317-
// TODO: small memory optimisation here (can skip creation for
318-
// methods with no advice)
316+
// TODO: small memory optimisation here (can skip creation for methods with no advice)
319317
for (int x = 0; x < methods.length; x++) {
320318
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(methods[x], rootClass);
321319
fixedCallbacks[x] = new FixedChainStaticTargetInterceptor(
@@ -342,16 +340,15 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
342340
*/
343341
private static Object processReturnType(Object proxy, Object target, Method method, Object retVal) {
344342
// Massage return value if necessary
345-
if (retVal != null && retVal == target &&
346-
!RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
347-
// Special case: it returned "this".
348-
// Note that we can't help if the target sets a reference
349-
// to itself in another returned object.
343+
if (retVal != null && retVal == target && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
344+
// Special case: it returned "this". Note that we can't help
345+
// if the target sets a reference to itself in another returned object.
350346
retVal = proxy;
351347
}
352348
Class<?> returnType = method.getReturnType();
353349
if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) {
354-
throw new AopInvocationException("Null return value from advice does not match primitive return type for: " + method);
350+
throw new AopInvocationException(
351+
"Null return value from advice does not match primitive return type for: " + method);
355352
}
356353
return retVal;
357354
}
@@ -864,7 +861,7 @@ else if (returnType.isPrimitive() || !returnType.isAssignableFrom(targetClass))
864861

865862
@Override
866863
public boolean equals(Object other) {
867-
if (other == this) {
864+
if (this == other) {
868865
return true;
869866
}
870867
if (!(other instanceof ProxyCallbackFilter)) {

spring-aop/src/main/java/org/springframework/aop/framework/ObjenesisCglibAopProxy.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.springframework.aop.framework;
1818

19-
2019
import org.apache.commons.logging.Log;
2120
import org.apache.commons.logging.LogFactory;
21+
2222
import org.springframework.cglib.proxy.Callback;
2323
import org.springframework.cglib.proxy.Enhancer;
2424
import org.springframework.cglib.proxy.Factory;
@@ -54,15 +54,14 @@ public ObjenesisCglibAopProxy(AdvisedSupport config) {
5454
@SuppressWarnings("unchecked")
5555
protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) {
5656
try {
57-
Factory factory = (Factory) objenesis.newInstance(enhancer.createClass());
57+
Factory factory = (Factory) this.objenesis.newInstance(enhancer.createClass());
5858
factory.setCallbacks(callbacks);
5959
return factory;
6060
}
6161
catch (ObjenesisException ex) {
62-
// Fallback to Cglib on unsupported JVMs
62+
// Fallback to regular proxy construction on unsupported JVMs
6363
if (logger.isDebugEnabled()) {
64-
logger.debug("Unable to instantiate proxy using Objenesis, falling back "
65-
+ "to regular proxy construction", ex);
64+
logger.debug("Unable to instantiate proxy using Objenesis, falling back to regular proxy construction", ex);
6665
}
6766
return super.createProxyClassAndInstance(enhancer, callbacks);
6867
}

spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
6464
* @see #setPatterns
6565
*/
6666
public void setPattern(String pattern) {
67-
setPatterns(new String[] {pattern});
67+
setPatterns(pattern);
6868
}
6969

7070
/**
7171
* Set the regular expressions defining methods to match.
7272
* Matching will be the union of all these; if any match,
7373
* the pointcut matches.
7474
*/
75-
public void setPatterns(String[] patterns) {
75+
public void setPatterns(String... patterns) {
7676
Assert.notEmpty(patterns, "'patterns' must not be empty");
7777
this.patterns = new String[patterns.length];
7878
for (int i = 0; i < patterns.length; i++) {
@@ -94,15 +94,15 @@ public String[] getPatterns() {
9494
* @see #setExcludedPatterns
9595
*/
9696
public void setExcludedPattern(String excludedPattern) {
97-
setExcludedPatterns(new String[] {excludedPattern});
97+
setExcludedPatterns(excludedPattern);
9898
}
9999

100100
/**
101101
* Set the regular expressions defining methods to match for exclusion.
102102
* Matching will be the union of all these; if any match,
103103
* the pointcut matches.
104104
*/
105-
public void setExcludedPatterns(String[] excludedPatterns) {
105+
public void setExcludedPatterns(String... excludedPatterns) {
106106
Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
107107
this.excludedPatterns = new String[excludedPatterns.length];
108108
for (int i = 0; i < excludedPatterns.length; i++) {

spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java

Lines changed: 2 additions & 5 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-2013 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.
@@ -180,7 +180,6 @@ public MethodMatcher getMethodMatcher() {
180180
return this.methodMatcher;
181181
}
182182

183-
184183
@Override
185184
public boolean equals(Object other) {
186185
if (this == other) {
@@ -189,7 +188,6 @@ public boolean equals(Object other) {
189188
if (!(other instanceof ComposablePointcut)) {
190189
return false;
191190
}
192-
193191
ComposablePointcut that = (ComposablePointcut) other;
194192
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
195193
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
@@ -209,8 +207,7 @@ public int hashCode() {
209207

210208
@Override
211209
public String toString() {
212-
return "ComposablePointcut: ClassFilter [" + this.classFilter +
213-
"], MethodMatcher [" + this.methodMatcher + "]";
210+
return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher;
214211
}
215212

216213
}

0 commit comments

Comments
 (0)