protected Expression instantiate(Object oldInstance,
Encoder out) {
Class c = (Class)oldInstance;
// As of 1.3 it is not possible to call Class.forName("int"),
// so we have to generate different code for primitive types.
// This is needed for arrays whose subtype may be primitive.
if (c.isPrimitive()) {
Field field = null;
try {
field = ReflectionUtils.typeToClass(c).getDeclaredField("TYPE");
} catch (NoSuchFieldException ex) {
System.err.println("Unknown primitive type: " + c);
}
return new Expression(oldInstance, field, "get", new Object[]{null});
}
else if (oldInstance == String.class) {
return new Expression(oldInstance, "", "getClass", new Object[]{});
}
else if (oldInstance == Class.class) {
return new Expression(oldInstance, String.class, "getClass", new Object[]{});
}
else {
return new Expression(oldInstance, Class.class, "forName", new Object[]{c.getName()});
}
}
|