Search in sources :

Example 1 with IntersectionTypeImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.IntersectionTypeImpl in project ceylon by eclipse.

the class Metamodel method getAppliedMetamodel.

@SuppressWarnings({ "rawtypes", "unchecked" })
@NonNull
public static <T> ceylon.language.meta.model.Type<T> getAppliedMetamodel(Type pt) {
    TypeDeclaration declaration = pt.getDeclaration();
    if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
        org.eclipse.ceylon.model.typechecker.model.Constructor ctorDeclaration = (org.eclipse.ceylon.model.typechecker.model.Constructor) declaration;
        Type ctorType = pt;
        pt = pt.getExtendedType();
        declaration = pt.getDeclaration();
        TypeDescriptor reifiedArguments;
        if (!ModelUtil.isEnumeratedConstructor(ctorDeclaration) && !declaration.isAnonymous() && !isLocalType(declaration))
            reifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.getUnit(), (Functional) ctorDeclaration, ctorType);
        else
            reifiedArguments = TypeDescriptor.NothingType;
        TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
        if (declaration.isToplevel() || isLocalType(declaration))
            return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl(reifiedType, reifiedArguments, pt, Metamodel.getAppliedMetamodel(pt.getQualifyingType()), null);
        TypeDescriptor reifiedContainer = getTypeDescriptorForProducedType(pt.getQualifyingType());
        return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl(reifiedContainer, reifiedType, reifiedArguments, pt);
    }
    if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
        // anonymous classes don't have parameter lists
        TypeDescriptor reifiedArguments;
        if (!declaration.isAnonymous() && !isLocalType(declaration))
            reifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.getUnit(), (Functional) declaration, pt);
        else
            reifiedArguments = TypeDescriptor.NothingType;
        TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
        if (declaration.isToplevel() || isLocalType(declaration))
            return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl(reifiedType, reifiedArguments, pt, null, null);
        // Workaround for old binaries where static members could have some qualified TDs
        // but not always. If the qualifying type is missing treat it as a toplevel
        org.eclipse.ceylon.model.typechecker.model.Type qt = pt.getQualifyingType();
        if (qt == null && declaration.isStatic()) {
            qt = ((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) declaration.getContainer()).getType();
        }
        TypeDescriptor reifiedContainer = getTypeDescriptorForProducedType(qt);
        return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl(reifiedContainer, reifiedType, reifiedArguments, pt);
    }
    if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
        TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
        if (declaration.isToplevel() || isLocalType(declaration))
            return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.InterfaceImpl<T>(reifiedType, pt, null, null);
        // Workaround for old binaries where static members could have some qualified TDs
        // but not always. If the qualifying type is missing treat it as a toplevel
        org.eclipse.ceylon.model.typechecker.model.Type qt = pt.getQualifyingType();
        if (qt == null && declaration.isStatic()) {
            qt = ((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) declaration.getContainer()).getType();
        }
        TypeDescriptor reifiedContainer = getTypeDescriptorForProducedType(qt);
        return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberInterfaceImpl(reifiedContainer, reifiedType, pt);
    }
    if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.UnionType) {
        TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
        return new UnionTypeImpl<T>(reifiedType, (org.eclipse.ceylon.model.typechecker.model.UnionType) declaration);
    }
    if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.IntersectionType) {
        TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
        return new IntersectionTypeImpl<T>(reifiedType, (org.eclipse.ceylon.model.typechecker.model.IntersectionType) declaration);
    }
    if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.NothingType) {
        return (ceylon.language.meta.model.Type<T>) ceylon.language.meta.model.nothingType_.get_();
    }
    if (declaration instanceof UnknownType) {
        ((UnknownType) declaration).reportErrors();
    }
    throw Metamodel.newModelError("Declaration type not supported yet: " + declaration);
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) MemberClassImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) OpenUnionTypeImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.OpenUnionTypeImpl) UnionTypeImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.UnionTypeImpl) Constructor(java.lang.reflect.Constructor) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) 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) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) ClassImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) ReflectionClass(org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) OpenIntersectionTypeImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.OpenIntersectionTypeImpl) IntersectionTypeImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.IntersectionTypeImpl) FunctionOrValueInterface(org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface) ClassOrInterface(ceylon.language.meta.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) NonNull(org.eclipse.ceylon.common.NonNull)

Aggregations

OpenClassOrInterfaceType (ceylon.language.meta.declaration.OpenClassOrInterfaceType)1 OpenType (ceylon.language.meta.declaration.OpenType)1 ClassOrInterface (ceylon.language.meta.model.ClassOrInterface)1 Constructor (java.lang.reflect.Constructor)1 NonNull (org.eclipse.ceylon.common.NonNull)1 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)1 OpenIntersectionTypeImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.OpenIntersectionTypeImpl)1 OpenUnionTypeImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.OpenUnionTypeImpl)1 ClassImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl)1 IntersectionTypeImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.IntersectionTypeImpl)1 MemberClassImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl)1 UnionTypeImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.UnionTypeImpl)1 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)1 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)1 DeclarationType (org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType)1 ReflectionClass (org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass)1 AnnotationProxyClass (org.eclipse.ceylon.model.loader.model.AnnotationProxyClass)1 FunctionOrValueInterface (org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface)1 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)1 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)1