Search in sources :

Example 1 with MemberImpl

use of ceylon.language.impl.MemberImpl in project ceylon by eclipse.

the class PartialImpl method initializeTuple.

protected <Id> void initializeTuple(TypeDescriptor $reified$Id, DeserializationContextImpl<Id> context, ceylon.language.Tuple<?, ?, ?> instance) {
    NativeMap<ReachableReference, Id> state = (NativeMap<ReachableReference, Id>) getState();
    ValueDeclaration firstAttribute = Util.assertExists((ValueDeclaration) ((ClassDeclaration) Metamodel.getOrCreateMetamodel(Tuple.class)).getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, "first"));
    MemberImpl firstMember = new MemberImpl(firstAttribute);
    java.lang.Object first = getReferredInstance(context, state, firstMember);
    ValueDeclaration restAttribute = Util.assertExists((ValueDeclaration) ((ClassDeclaration) Metamodel.getOrCreateMetamodel(Tuple.class)).getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, "rest"));
    MemberImpl restMember = new MemberImpl(restAttribute);
    Id restId = state.get(restMember);
    java.lang.Object referredRest = context.leakInstance(restId);
    if (referredRest instanceof Partial && !((PartialImpl) referredRest).getInitialized()) {
        // Safe because tuples are immutable => no cycles
        ((PartialImpl) referredRest).initialize($reified$Id, context);
    }
    java.lang.Object rest = getReferredInstance(context, state, restMember);
    ((Tuple<?, ?, ?>) instance).$completeInit$(first, rest);
    // now check compatibility (do this after initialization
    // because Tuple$getType$ requires the tuple is initialized!
    Type firstMemberType = Metamodel.getModuleManager().getCachedType(getClassTypeDescriptor().getTypeArgument(1));
    Type firstInstanceType = Metamodel.getModuleManager().getCachedType(Metamodel.getTypeDescriptor(first));
    if (!firstInstanceType.isSubtypeOf(firstMemberType)) {
        throw notAssignable(firstMember, firstMemberType, firstInstanceType);
    }
    Type restInstanceType = Metamodel.getModuleManager().getCachedType(Metamodel.getTypeDescriptor(rest));
    Type restMemberType = Metamodel.getModuleManager().getCachedType(getClassTypeDescriptor().getTypeArgument(2));
    if (!restInstanceType.isSubtypeOf(restMemberType)) {
        throw notAssignable(restMember, restMemberType, restInstanceType);
    }
}
Also used : MemberImpl(ceylon.language.impl.MemberImpl) ValueDeclaration(ceylon.language.meta.declaration.ValueDeclaration) Type(org.eclipse.ceylon.model.typechecker.model.Type) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) Tuple(ceylon.language.Tuple)

Example 2 with MemberImpl

use of ceylon.language.impl.MemberImpl in project ceylon by eclipse.

the class Tuple method $references$.

@Ignore
@Override
public java.util.Collection<ReachableReference> $references$() {
    // could put the elements with int indexes and the rest as a String!
    ArrayList<ReachableReference> s = new ArrayList<ReachableReference>(2);
    ClassDeclaration cd = (ClassDeclaration) Metamodel.getOrCreateMetamodel(Tuple.class);
    s.add(new MemberImpl(Util.assertExists(cd.<ValueDeclaration>getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, "first"))));
    s.add(new MemberImpl(Util.assertExists(cd.<ValueDeclaration>getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, "rest"))));
    return s;
}
Also used : ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) MemberImpl(ceylon.language.impl.MemberImpl) ArrayList(java.util.ArrayList) ReachableReference(ceylon.language.serialization.ReachableReference) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Aggregations

MemberImpl (ceylon.language.impl.MemberImpl)2 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)2 Tuple (ceylon.language.Tuple)1 ValueDeclaration (ceylon.language.meta.declaration.ValueDeclaration)1 ReachableReference (ceylon.language.serialization.ReachableReference)1 ArrayList (java.util.ArrayList)1 Ignore (org.eclipse.ceylon.compiler.java.metadata.Ignore)1 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)1 Type (org.eclipse.ceylon.model.typechecker.model.Type)1