use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl in project ceylon by eclipse.
the class ClassOrInterfaceDeclarationImpl method memberApply.
@SuppressWarnings("rawtypes")
@TypeInfo("ceylon.language.meta.model::Member<Container,ceylon.language.meta.model::ClassOrInterface<Type>>&ceylon.language.meta.model::ClassOrInterface<Type>")
@TypeParameters({ @TypeParameter("Container"), @TypeParameter("Type") })
@Override
public <Container, Type extends Object> java.lang.Object memberApply(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Name("containerType") ceylon.language.meta.model.Type<? extends Object> containerType, @Name("typeArguments") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
if (getToplevel())
throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a toplevel declaration to a container type: use apply");
ceylon.language.meta.model.Member<? extends Container, ceylon.language.meta.model.ClassOrInterface<?>> member = getAppliedClassOrInterface(null, null, typeArguments, containerType);
// This is all very ugly but we're trying to make it cheaper and friendlier than just checking the full type and showing
// implementation types to the user, such as AppliedMemberClass
TypeDescriptor actualReifiedContainer;
if (member instanceof MemberClassImpl)
actualReifiedContainer = ((MemberClassImpl) member).$reifiedContainer;
else
actualReifiedContainer = ((MemberInterfaceImpl) member).$reifiedContainer;
org.eclipse.ceylon.model.typechecker.model.Type actualType = Metamodel.getModel((ceylon.language.meta.model.Type<?>) member);
Metamodel.checkReifiedTypeArgument("memberApply", "Member<$1,ClassOrInterface<$2>>&ClassOrInterface<$2>", Variance.IN, Metamodel.getProducedType(actualReifiedContainer), $reifiedContainer, Variance.OUT, actualType, $reifiedType);
return member;
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl in project ceylon by eclipse.
the class PartialImpl method instantiate.
@Override
public java.lang.Object instantiate() {
final ClassModel<?, ?> classModel = getClazz();
if (classModel == null) {
throw new DeserializationException("no class specified for instance with id " + getId());
}
final java.lang.Class<?> clazz = getClassTypeDescriptor().getKlass();
final Class<?> outerClass;
Object outer;
if (classModel instanceof ClassImpl) {
// Class<Type, Arguments>
outerClass = null;
outer = null;
} else if (classModel instanceof MemberClassImpl) {
// MemberClass<Container, Type, Arguments>
// the algorithm in DeserializationContext
// should ensure the container exists by the point we're called.
outerClass = getOuterClassTypeDescriptor().getKlass();
outer = super.getContainer();
if (outer instanceof Partial) {
outer = ((Partial) outer).getInstance_();
}
if (outer == null) {
throw new DeserializationException("no containing instance specified for member instance with id" + 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((ceylon.language.meta.model.Type<?>) typeArgs.getFromFirst(jj));
}
try {
Constructor<?> 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
// Pass a null $Serialization$
java.lang.Object newInstance = ctor.newInstance(args);
if (newInstance instanceof Serializable) {
super.setInstance_(newInstance);
} else {
// we should never get here (a NoSuchMethodException should've been thrown and caught below)
throw new AssertionError("instance class " + classModel + " is not serializable for instance with id " + getId());
}
} catch (NoSuchMethodException e) {
throw new DeserializationException("instance class " + classModel + " is not serializable for instance with id " + getId());
} catch (InvocationTargetException e) {
// Should never happen: it's a compiler-generate constructor
rethrow_.rethrow(e);
} catch (SecurityException e) {
// Should never happen
rethrow_.rethrow(e);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
// Should never happen: it's a compiler-generate constructor
rethrow_.rethrow(e);
}
return null;
}
Aggregations