use lang3 TypeUtils in commons-proxy core
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/proxy/branches/version-2.0-work@979754 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/pom.xml b/core/pom.xml
index 059e673..8d652cf 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -73,10 +73,10 @@
<optional>true</optional>
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.3</version>
- <scope>test</scope>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>jmock</groupId>
diff --git a/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java b/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
index b4a1751..f34c2d4 100644
--- a/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
+++ b/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
@@ -17,15 +17,14 @@
package org.apache.commons.proxy2.invoker.recorder;
+import org.apache.commons.lang3.reflect.TypeUtils;
import org.apache.commons.proxy2.Invoker;
import org.apache.commons.proxy2.ProxyFactory;
import org.apache.commons.proxy2.ProxyUtils;
import org.apache.commons.proxy2.invoker.RecordedInvocation;
import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
import java.util.LinkedList;
import java.util.List;
@@ -103,7 +102,8 @@
public Object invoke( Object o, Method method, Object[] args ) throws Throwable
{
recordedInvocations.add(new RecordedInvocation(method, args));
- final Class<?> returnType = getReturnType(targetType, method);
+ final Class<?> returnType = TypeUtils.getRawType(method.getGenericReturnType(), targetType);
+ //what to do if returnType is null?
return proxy(method.getGenericReturnType(), returnType);
}
}
@@ -116,58 +116,4 @@
recordedInvocations.clear();
}
- /**
- * Get the raw return type of a method qualified with regard to a particular target type.
- * @param enclosingType
- * @param method
- * @return {@link Class} instance
- * @throws Exception
- */
- public static Class<?> getReturnType( Type enclosingType, Method method ) throws Exception
- {
- Type returnType = method.getGenericReturnType();
- if( returnType instanceof Class<?> )
- {
- return ( Class<?> ) returnType;
- }
- else if( returnType instanceof TypeVariable<?> )
- {
- return resolveVariable(enclosingType, ( TypeVariable<?> ) returnType);
- }
- else if( returnType instanceof ParameterizedType )
- {
- return ( Class<?> ) ( ( ParameterizedType ) returnType ).getRawType();
- }
- return null;
- }
-
- /**
- * Resolve the raw type of a type variable against a particular owning/inheriting type.
- * @param enclosingType
- * @param typeVar
- * @return {@link Class} instance
- * @throws Exception
- */
- public static Class<?> resolveVariable( Type enclosingType, TypeVariable<?> typeVar ) throws Exception
- {
- if( enclosingType instanceof ParameterizedType )
- {
- ParameterizedType pt = ( ParameterizedType ) enclosingType;
- final Class<?> rawType = ( Class<?> ) pt.getRawType();
- TypeVariable<?>[] typeParameters = rawType.getTypeParameters();
- for( int i = 0; i < typeParameters.length; i++ )
- {
- TypeVariable<?> typeParameter = typeParameters[i];
- if( typeParameter == typeVar )
- {
- return ( Class<?> ) pt.getActualTypeArguments()[i];
- }
- }
- }
- else if( enclosingType instanceof Class<?> )
- {
- return resolveVariable(( ( Class<?> ) enclosingType ).getGenericSuperclass(), typeVar);
- }
- return null;
- }
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java b/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
index c2cdbec..7e2f282 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
@@ -1,10 +1,11 @@
package org.apache.commons.proxy2.util;
import junit.framework.TestCase;
-import org.apache.commons.lang.SerializationUtils;
import java.io.Serializable;
+import org.apache.commons.lang3.SerializationUtils;
+
/**
* @author James Carman
* @since 1.1