[jboss-user] [JBoss Microcontainer Development] New message: "Re: JBREFLECT-5 - Implementing generics in JavassistClassInfo"

Kabir Khan do-not-reply at jboss.com
Tue Mar 9 12:31:52 EST 2010


User development,

A new message was posted in the thread "JBREFLECT-5 - Implementing generics in JavassistClassInfo":

http://community.jboss.org/message/530850#530850

Author  : Kabir Khan
Profile : http://community.jboss.org/people/kabir.khan@jboss.com

Message:
--------------------------------------------------------------
> mailto:kabir.khan at jboss.com wrote:
>  
>  
> 3) When accessing generics from the return type of a method, e.g.
>  
>      Collection<String> getStringCollection(){}
>  
> 
> 
> we get hold of this method using normal reflection (A) and construct the TypeInfo for that using the ParameterizedType (B1+2) for which I extended the Javassist TypeInfo factory:
> 
>    *private* *void* assertComponentType(String methodName, Class<?> expected) *throws* Exception
>    {
>       Method method = ClassInfoGenericClassTest.class.getMethod(methodName, (Class[]) *null*); //A
>       Type type = method.getGenericReturnType(); //B1
>       assertComponentType(type, expected);
>    }
>  
>    *private* *void* assertComponentType(Type type, Class<?> expected) *throws* Exception
>    {
>       TypeInfoFactory factory = getTypeInfoFactory();
>       TypeInfo typeInfo = factory.getTypeInfo(type); //B2
>       ClassInfo classInfo = assertInstanceOf(typeInfo, ClassInfo.class);
>       assertTrue(classInfo.isCollection());
>  
>       TypeInfo expectedInfo = factory.getTypeInfo(expected);
>       assertEquals(expectedInfo, classInfo.getComponentType());
>    }
> 
> 
> However, that is probably not what will happen in real life, we would have a ClassInfo, get hold of the MethodInfo in question, and then get the return type which should contain the actualTypeArguments. This needs implementing and is not being tested at the moment, and the same goes for parameters and field types.
Looking properly, I think what is there at the moment is correct. In reflect we have these additional methods:
 
 Type[] Method.getGenericExceptionTypes() 
 Type[] Constructor.getGenericExceptionTypes() 
 Type[] Method.getGenericParameterTypes() 
 Type[] Constructor.getGenericParameterTypes() 
 Type Method.getGenericReturnType() 
 Type Field.getGenericType() 
 
The normal non-generic methods (as getReturnType()) simply return a Class. So, I think that MethodInfo.getReturnType() should just return a plain TypeInfo as it does at the moment.
 
I'll concentrate on 1,2 and 4 for now, and see if 3 is needed, although I don't think so since it is not present in the reflect implementation either.

--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/530850#530850




More information about the jboss-user mailing list