updated for JDK 1.5+

This commit is contained in:
Juergen Hoeller 2010-03-24 13:58:45 +00:00
parent 6fb49f1de7
commit bc2440ea16
2 changed files with 8 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -139,9 +140,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
private boolean argumentsIntrospected = false; private boolean argumentsIntrospected = false;
// The actual type is java.lang.reflect.Type, private Type discoveredReturningGenericType;
// but for JDK 1.4 compatibility we use Object as the static type.
private Object discoveredReturningGenericType;
// Note: Unlike return type, no such generic information is needed for the throwing type, // Note: Unlike return type, no such generic information is needed for the throwing type,
// since Java doesn't allow exception types to be parameterized. // since Java doesn't allow exception types to be parameterized.
@ -295,7 +294,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
return this.discoveredReturningType; return this.discoveredReturningType;
} }
protected Object getDiscoveredReturningGenericType() { protected Type getDiscoveredReturningGenericType() {
return this.discoveredReturningGenericType; return this.discoveredReturningGenericType;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,21 +69,11 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice implement
*/ */
private boolean shouldInvokeOnReturnValueOf(Method method, Object returnValue) { private boolean shouldInvokeOnReturnValueOf(Method method, Object returnValue) {
Class type = getDiscoveredReturningType(); Class type = getDiscoveredReturningType();
Object genericType = getDiscoveredReturningGenericType(); Type genericType = getDiscoveredReturningGenericType();
// If we aren't dealing with a raw type, check if generic parameters are assignable. // If we aren't dealing with a raw type, check if generic parameters are assignable.
return (ClassUtils.isAssignableValue(type, returnValue) && return (ClassUtils.isAssignableValue(type, returnValue) &&
(genericType == null || genericType == type || GenericTypeMatcher.isAssignable(genericType, method))); (genericType == null || genericType == type ||
} TypeUtils.isAssignable(genericType, method.getGenericReturnType())));
/**
* Inner class to avoid a static JDK 1.5 dependency for generic type matching.
*/
private static class GenericTypeMatcher {
public static boolean isAssignable(Object genericType, Method method) {
return TypeUtils.isAssignable((Type) genericType, method.getGenericReturnType());
}
} }
} }