Handle uncomplicated wildcard types.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2351 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -24,6 +24,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.WildcardType;
|
||||
|
||||
/**
|
||||
* Utility methods for code that generates code.
|
||||
@@ -67,6 +68,27 @@ public class GenUtil
|
||||
buf.append(simpleName(arg));
|
||||
}
|
||||
return simpleName(pt.getRawType()) + "<" + buf + ">";
|
||||
|
||||
} else if (type instanceof WildcardType) {
|
||||
WildcardType wt = (WildcardType)type;
|
||||
if (wt.getLowerBounds().length > 0) {
|
||||
String errmsg = "Generation of simple name for wildcard type with lower bounds " +
|
||||
"not implemented [type=" + type +
|
||||
", lbounds=" + StringUtil.toString(wt.getLowerBounds()) + "]";
|
||||
throw new IllegalArgumentException(errmsg);
|
||||
}
|
||||
if (wt.getUpperBounds().length > 1) {
|
||||
String errmsg = "Generation of simple name for wildcard type with multiple upper " +
|
||||
"bounds not implemented [type=" + type +
|
||||
", ubounds=" + StringUtil.toString(wt.getUpperBounds()) + "]";
|
||||
throw new IllegalArgumentException(errmsg);
|
||||
}
|
||||
StringBuilder buf = new StringBuilder("?");
|
||||
if (!Object.class.equals(wt.getUpperBounds()[0])) {
|
||||
buf.append(" extends ").append(simpleName(wt.getUpperBounds()[0]));
|
||||
}
|
||||
return buf.toString();
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("Can't generate simple name [type=" + type +
|
||||
", tclass=" + StringUtil.shortClassName(type) + "]");
|
||||
|
||||
Reference in New Issue
Block a user