Support array types in JavassistTypeParameterMatcherGenerator

This commit is contained in:
Trustin Lee 2013-02-28 10:37:55 -08:00
parent b712b030fa
commit 881bd8eea3

View File

@ -40,7 +40,8 @@ final class JavassistTypeParameterMatcherGenerator {
}
static TypeParameterMatcher generate(Class<?> type, ClassLoader classLoader) {
final String className = "io.netty.util.internal.__matchers__." + type.getName() + "Matcher";
final String typeName = typeName(type);
final String className = "io.netty.util.internal.__matchers__." + typeName + "Matcher";
try {
try {
return (TypeParameterMatcher) Class.forName(className, true, classLoader).newInstance();
@ -50,7 +51,7 @@ final class JavassistTypeParameterMatcherGenerator {
CtClass c = classPool.getAndRename(NoOpTypeParameterMatcher.class.getName(), className);
c.setModifiers(c.getModifiers() | Modifier.FINAL);
c.getDeclaredMethod("match").setBody("{ return $1 instanceof " + type.getName() + "; }");
c.getDeclaredMethod("match").setBody("{ return $1 instanceof " + typeName + "; }");
byte[] byteCode = c.toBytecode();
c.detach();
Method method = ClassLoader.class.getDeclaredMethod(
@ -67,5 +68,13 @@ final class JavassistTypeParameterMatcherGenerator {
}
}
private static String typeName(Class<?> type) {
if (type.isArray()) {
return typeName(type.getComponentType()) + "[]";
}
return type.getName();
}
private JavassistTypeParameterMatcherGenerator() { }
}