Search in sources :

Example 1 with OpenType

use of ceylon.language.meta.declaration.OpenType in project ceylon by eclipse.

the class Metamodel method getMetamodelSequential.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Sequential<? extends ceylon.language.meta.declaration.OpenType> getMetamodelSequential(List<Type> types) {
    if (types.isEmpty())
        return (Sequential<? extends ceylon.language.meta.declaration.OpenType>) (Sequential) empty_.get_();
    ceylon.language.meta.declaration.OpenType[] ret = new ceylon.language.meta.declaration.OpenType[types.size()];
    int i = 0;
    TypeDescriptor td = TypeDescriptor.NothingType;
    for (Type pt : types) {
        OpenType mm = Metamodel.getMetamodel(pt);
        td = TypeDescriptor.union(((ReifiedType) mm).$getType$());
        ret[i++] = mm;
    }
    return Util.sequentialWrapper(td, ret);
}
Also used : OpenType(ceylon.language.meta.declaration.OpenType) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) OpenClassOrInterfaceType(ceylon.language.meta.declaration.OpenClassOrInterfaceType) OpenType(ceylon.language.meta.declaration.OpenType) DeclarationType(org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) Sequential(ceylon.language.Sequential) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)

Example 2 with OpenType

use of ceylon.language.meta.declaration.OpenType in project ceylon by eclipse.

the class OpenClassOrInterfaceTypeImpl method init.

protected void init() {
    org.eclipse.ceylon.model.typechecker.model.ClassOrInterface decl = (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) producedType.getDeclaration();
    this.declaration = (ClassOrInterfaceDeclarationImpl) Metamodel.getOrCreateMetamodel(decl);
    java.util.Map<ceylon.language.meta.declaration.TypeParameter, ceylon.language.meta.declaration.OpenType> typeArguments = new LinkedHashMap<ceylon.language.meta.declaration.TypeParameter, ceylon.language.meta.declaration.OpenType>();
    java.util.Map<ceylon.language.meta.declaration.TypeParameter, ceylon.language.Sequence<? extends Object>> typeArgumentWithVariances = new LinkedHashMap<ceylon.language.meta.declaration.TypeParameter, ceylon.language.Sequence<? extends Object>>();
    Iterator<? extends ceylon.language.meta.declaration.TypeParameter> typeParameters = declaration.getTypeParameterDeclarations().iterator();
    Object it;
    java.util.Map<org.eclipse.ceylon.model.typechecker.model.TypeParameter, org.eclipse.ceylon.model.typechecker.model.Type> ptArguments = producedType.getTypeArguments();
    java.util.Map<TypeParameter, SiteVariance> varianceOverrides = producedType.getVarianceOverrides();
    while ((it = typeParameters.next()) != finished_.get_()) {
        org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.TypeParameterImpl tp = (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.TypeParameterImpl) it;
        org.eclipse.ceylon.model.typechecker.model.TypeParameter tpDecl = (org.eclipse.ceylon.model.typechecker.model.TypeParameter) tp.declaration;
        org.eclipse.ceylon.model.typechecker.model.Type ptArg = ptArguments.get(tpDecl);
        OpenType ptArgWrapped = Metamodel.getMetamodel(ptArg);
        typeArguments.put(tp, ptArgWrapped);
        ceylon.language.meta.declaration.Variance variance = Metamodel.modelVarianceToMetaModel(varianceOverrides, tpDecl);
        ceylon.language.Sequence<? extends Object> tuple = ceylon.language.Tuple.instance(Metamodel.TD_OpenTypeArgumentElement, new Object[] { ptArgWrapped, variance });
        typeArgumentWithVariances.put(tp, tuple);
    }
    this.typeArguments = new InternalMap<ceylon.language.meta.declaration.TypeParameter, ceylon.language.meta.declaration.OpenType>(ceylon.language.meta.declaration.TypeParameter.$TypeDescriptor$, ceylon.language.meta.declaration.OpenType.$TypeDescriptor$, typeArguments);
    this.typeArgumentWithVariances = new InternalMap<ceylon.language.meta.declaration.TypeParameter, ceylon.language.Sequence<?>>(ceylon.language.meta.declaration.TypeParameter.$TypeDescriptor$, Metamodel.TD_OpenTypeArgument, typeArgumentWithVariances);
    org.eclipse.ceylon.model.typechecker.model.Type superType = decl.getExtendedType();
    if (superType != null) {
        org.eclipse.ceylon.model.typechecker.model.Type superTypeResolved = superType.substitute(producedType);
        this.superclass = (ceylon.language.meta.declaration.OpenClassType) Metamodel.getMetamodel(superTypeResolved);
    }
    List<org.eclipse.ceylon.model.typechecker.model.Type> satisfiedTypes = decl.getSatisfiedTypes();
    ceylon.language.meta.declaration.OpenInterfaceType[] interfaces = new ceylon.language.meta.declaration.OpenInterfaceType[satisfiedTypes.size()];
    int i = 0;
    for (org.eclipse.ceylon.model.typechecker.model.Type pt : satisfiedTypes) {
        org.eclipse.ceylon.model.typechecker.model.Type resolvedPt = pt.substitute(producedType);
        interfaces[i++] = (ceylon.language.meta.declaration.OpenInterfaceType) Metamodel.getMetamodel(resolvedPt);
    }
    this.interfaces = Util.sequentialWrapper(ceylon.language.meta.declaration.OpenInterfaceType.$TypeDescriptor$, interfaces);
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) OpenType(ceylon.language.meta.declaration.OpenType) LinkedHashMap(java.util.LinkedHashMap) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) Sequence(ceylon.language.Sequence) OpenType(ceylon.language.meta.declaration.OpenType) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) SiteVariance(org.eclipse.ceylon.model.typechecker.model.SiteVariance)

Aggregations

OpenType (ceylon.language.meta.declaration.OpenType)2 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)2 Sequence (ceylon.language.Sequence)1 Sequential (ceylon.language.Sequential)1 OpenClassOrInterfaceType (ceylon.language.meta.declaration.OpenClassOrInterfaceType)1 LinkedHashMap (java.util.LinkedHashMap)1 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)1 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)1 DeclarationType (org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType)1 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)1 SiteVariance (org.eclipse.ceylon.model.typechecker.model.SiteVariance)1 Type (org.eclipse.ceylon.model.typechecker.model.Type)1 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)1 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)1