[jboss-user] [JBoss Microcontainer Development] New message: "Re: JBREFLECT-5 - Implementing generics in JavassistClassInfo"
Kabir Khan
do-not-reply at jboss.com
Mon Mar 15 14:33:34 EDT 2010
User development,
A new message was posted in the thread "JBREFLECT-5 - Implementing generics in JavassistClassInfo":
http://community.jboss.org/message/532084#532084
Author : Kabir Khan
Profile : http://community.jboss.org/people/kabir.khan@jboss.com
Message:
--------------------------------------------------------------
One thing I have been doing which might be unnecessary is to wrap things with wildcards with a delegating class, e.g.:
/**
* Type info for a wildcard type
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
public class WildcardTypeInfo extends DelegateClassInfo
{
private static final long serialVersionUID = 1L;
private final String name;
public WildcardTypeInfo(String name, ClassInfo delegate)
{
super(delegate);
this.name = name;
}
@Override
public void toShortString(JBossStringBuilder buffer)
{
buffer.append(name);
}
@Override
protected void toString(JBossStringBuilder buffer)
{
buffer.append("name=").append(name);
}
}
So if you try to get the typeInfo for Class<? extends some.Thing> we end up with a ParameterizedClassInfo for Class which contains one type argument. This type argument is for some.Thing. The original introspection implemetation would just use that directly. What I am doing now is to
get the TypeInfo for some.Thing (1) and decorate that with a WildcardTypeInfo that delegates to 1, but has the name '? extends some.Thing' which is ONLY used in these two cases:
* invoking toString().
* looking up the WildcardTypeInfo in the cache
This has been done for both implementations.
The reason I am unsure if this is needed after all is that I am currently implementing TypeVariables, e.g.:
public <T extends some.Thing> T signatureMethod()
If I were to wrap it, I would end up with 1 and wrapping that with a TypeVariableTypeInfo which overrides toString with 'T extends some.Thing'. The problem is that if we also have
public <U extends some.Thing> T signatureMethod2()
public <V extends some.Thing> T signatureMethod3()
We end up with 3 different cached versions with a different name used for toString(), which all delegate to 1.
The only reason I did this was to have nice output when calling toString(), so I am wondering if that is really necessary?
--------------------------------------------------------------
To reply to this message visit the message page: http://community.jboss.org/message/532084#532084
More information about the jboss-user
mailing list