提交 a2d40f3f 编写于 作者: J Juergen Hoeller

Polishing

上级 0de307bb
......@@ -219,12 +219,11 @@ class CglibAopProxy implements AopProxy, Serializable {
}
protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) {
enhancer.setInterceptDuringConstruction(false);
enhancer.setCallbacks(callbacks);
return this.constructorArgs == null ? enhancer.create() : enhancer.create(
this.constructorArgTypes, this.constructorArgs);
return (this.constructorArgs != null ?
enhancer.create(this.constructorArgTypes, this.constructorArgs) :
enhancer.create());
}
/**
......@@ -314,8 +313,7 @@ class CglibAopProxy implements AopProxy, Serializable {
Callback[] fixedCallbacks = new Callback[methods.length];
this.fixedInterceptorMap = new HashMap<String, Integer>(methods.length);
// TODO: small memory optimisation here (can skip creation for
// methods with no advice)
// TODO: small memory optimisation here (can skip creation for methods with no advice)
for (int x = 0; x < methods.length; x++) {
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(methods[x], rootClass);
fixedCallbacks[x] = new FixedChainStaticTargetInterceptor(
......@@ -342,16 +340,15 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private static Object processReturnType(Object proxy, Object target, Method method, Object retVal) {
// Massage return value if necessary
if (retVal != null && retVal == target &&
!RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
// Special case: it returned "this".
// Note that we can't help if the target sets a reference
// to itself in another returned object.
if (retVal != null && retVal == target && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
// Special case: it returned "this". Note that we can't help
// if the target sets a reference to itself in another returned object.
retVal = proxy;
}
Class<?> returnType = method.getReturnType();
if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) {
throw new AopInvocationException("Null return value from advice does not match primitive return type for: " + method);
throw new AopInvocationException(
"Null return value from advice does not match primitive return type for: " + method);
}
return retVal;
}
......@@ -864,7 +861,7 @@ class CglibAopProxy implements AopProxy, Serializable {
@Override
public boolean equals(Object other) {
if (other == this) {
if (this == other) {
return true;
}
if (!(other instanceof ProxyCallbackFilter)) {
......
......@@ -16,9 +16,9 @@
package org.springframework.aop.framework;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cglib.proxy.Callback;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.Factory;
......@@ -54,15 +54,14 @@ class ObjenesisCglibAopProxy extends CglibAopProxy {
@SuppressWarnings("unchecked")
protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) {
try {
Factory factory = (Factory) objenesis.newInstance(enhancer.createClass());
Factory factory = (Factory) this.objenesis.newInstance(enhancer.createClass());
factory.setCallbacks(callbacks);
return factory;
}
catch (ObjenesisException ex) {
// Fallback to Cglib on unsupported JVMs
// Fallback to regular proxy construction on unsupported JVMs
if (logger.isDebugEnabled()) {
logger.debug("Unable to instantiate proxy using Objenesis, falling back "
+ "to regular proxy construction", ex);
logger.debug("Unable to instantiate proxy using Objenesis, falling back to regular proxy construction", ex);
}
return super.createProxyClassAndInstance(enhancer, callbacks);
}
......
......@@ -64,7 +64,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
* @see #setPatterns
*/
public void setPattern(String pattern) {
setPatterns(new String[] {pattern});
setPatterns(pattern);
}
/**
......@@ -72,7 +72,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
* Matching will be the union of all these; if any match,
* the pointcut matches.
*/
public void setPatterns(String[] patterns) {
public void setPatterns(String... patterns) {
Assert.notEmpty(patterns, "'patterns' must not be empty");
this.patterns = new String[patterns.length];
for (int i = 0; i < patterns.length; i++) {
......@@ -94,7 +94,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
* @see #setExcludedPatterns
*/
public void setExcludedPattern(String excludedPattern) {
setExcludedPatterns(new String[] {excludedPattern});
setExcludedPatterns(excludedPattern);
}
/**
......@@ -102,7 +102,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
* Matching will be the union of all these; if any match,
* the pointcut matches.
*/
public void setExcludedPatterns(String[] excludedPatterns) {
public void setExcludedPatterns(String... excludedPatterns) {
Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
this.excludedPatterns = new String[excludedPatterns.length];
for (int i = 0; i < excludedPatterns.length; i++) {
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
......@@ -180,7 +180,6 @@ public class ComposablePointcut implements Pointcut, Serializable {
return this.methodMatcher;
}
@Override
public boolean equals(Object other) {
if (this == other) {
......@@ -189,7 +188,6 @@ public class ComposablePointcut implements Pointcut, Serializable {
if (!(other instanceof ComposablePointcut)) {
return false;
}
ComposablePointcut that = (ComposablePointcut) other;
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
......@@ -209,8 +207,7 @@ public class ComposablePointcut implements Pointcut, Serializable {
@Override
public String toString() {
return "ComposablePointcut: ClassFilter [" + this.classFilter +
"], MethodMatcher [" + this.methodMatcher + "]";
return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册