// MemberClass<Container, Type, Arguments>
clazz = (java.lang.Class)((TypeDescriptor.Class)typeArguments[1]).getKlass();
outerClass = ((TypeDescriptor.Class)typeArguments[0]).getKlass();
outer = context.leakReferred(outerReference.getId());
} else {
throw new AssertionError("unexpected class model: "
+ (classModel != null ? classModel.getClass().getName() : "null"));
}
// Construct arrays for types and arguments for reflective instantiation
// of the serialization constructor
Collection<?> typeArgs = classModel.getTypeArguments().getItems();
Class<?>[] types = new Class[(outerClass != null ? 2 : 1) + Util.toInt(typeArgs.getSize())];
Object[] args = new Object[(outer != null ? 2 : 1) + Util.toInt(typeArgs.getSize())];
int ii = 0;
if (outerClass != null) {
types[ii] = outerClass;
args[ii] = outer;
ii++;
}
types[ii] = $Serialization$.class;
args[ii] = null;
ii++;
for (int jj = 0 ; jj < typeArgs.getSize(); ii++, jj++) {
types[ii] = TypeDescriptor.class;
args[ii] = Metamodel.getTypeDescriptor((Type)typeArgs.getFromFirst(jj));
}
try {
Constructor<Instance> ctor = clazz.getDeclaredConstructor(types);
ctor.setAccessible(true);
// Actually we need to pass something equivalent to the type descriptors here
// because the companion instances can require those. But we don't have the deconstructed yet!
// This means we have to obtain the type descriptors from the class model
return ctor.newInstance(args);// Pass a null $Serialization$
} catch (NoSuchMethodException e) {
throw new AssertionError("class is not serializable " + classModel);
} catch (InvocationTargetException e) {
throw new AssertionError("error thrown during instantiation of " + classModel+ (e.getMessage() != null ? ": " + e.getMessage() : ""));
} catch (SecurityException e) {
// Should never happen
throw new RuntimeException(e);
} catch (InstantiationException|IllegalAccessException|IllegalArgumentException e) {
// Should never happen