Search in sources :

Example 6 with UnknownType

use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.

the class ExpressionVisitor method defaultType.

private Type defaultType() {
    TypeDeclaration ut = new UnknownType(unit);
    Class ad = unit.getAnythingDeclaration();
    if (ad != null) {
        ut.setExtendedType(ad.getType());
    }
    return ut.getType();
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.findMatchingOverloadedClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.findMatchingOverloadedClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 7 with UnknownType

use of org.eclipse.ceylon.model.typechecker.model.UnknownType 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)

Example 8 with UnknownType

use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.

the class Metamodel method getTypeDescriptorForProducedType.

public static TypeDescriptor getTypeDescriptorForProducedType(org.eclipse.ceylon.model.typechecker.model.Type type) {
    TypeDeclaration declaration = type.getDeclaration();
    if (type.isNothing()) {
        return TypeDescriptor.NothingType;
    }
    if (type.isUnion()) {
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getCaseTypes());
        return TypeDescriptor.union(tdArgs);
    }
    if (type.isIntersection()) {
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getSatisfiedTypes());
        return TypeDescriptor.intersection(tdArgs);
    }
    if (declaration instanceof LazyClass) {
        ReflectionClass classMirror = (ReflectionClass) ((LazyClass) declaration).classMirror;
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
        TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
        if (type.getQualifyingType() != null)
            return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
        return ret;
    }
    if (declaration instanceof LazyInterface) {
        ReflectionClass classMirror = (ReflectionClass) ((LazyInterface) declaration).classMirror;
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
        TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
        if (type.getQualifyingType() != null)
            return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
        return ret;
    }
    if (declaration instanceof FunctionOrValueInterface) {
        TypedDeclaration underlyingDeclaration = ((FunctionOrValueInterface) declaration).getUnderlyingDeclaration();
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
        TypeDescriptor ret;
        if (underlyingDeclaration.isToplevel()) {
            ReflectionClass classMirror;
            // type arguments
            if (underlyingDeclaration instanceof Setter)
                underlyingDeclaration = ((Setter) underlyingDeclaration).getGetter();
            if (underlyingDeclaration instanceof LazyValue)
                classMirror = (ReflectionClass) ((LazyValue) underlyingDeclaration).classMirror;
            else if (underlyingDeclaration instanceof LazyFunction)
                classMirror = (ReflectionClass) ((LazyFunction) underlyingDeclaration).classMirror;
            else
                throw Metamodel.newModelError("Unsupported underlying declaration type: " + underlyingDeclaration);
            ret = TypeDescriptor.functionOrValue(classMirror.klass, tdArgs);
        } else
            ret = TypeDescriptor.functionOrValue(underlyingDeclaration.getPrefixedName(), tdArgs);
        if (type.getQualifyingType() != null)
            return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
        return ret;
    }
    if (declaration instanceof UnknownType) {
        ((UnknownType) declaration).reportErrors();
    }
    throw Metamodel.newModelError("Unsupported declaration type: " + (declaration == null ? "null" : declaration.getClass()));
}
Also used : FunctionOrValueInterface(org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) ReflectionClass(org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 9 with UnknownType

use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.

the class UnknownTypeCollector method collectUnknownTypes.

private void collectUnknownTypes(Type type, Map<Declaration, Declaration> visited) {
    if (type != null) {
        type = type.resolveAliases();
        if (type.isUnknown()) {
            UnknownType ut = (UnknownType) type.getDeclaration();
            ut.reportErrors();
            // don't report it twice
            ut.setErrorReporter(null);
        } else if (type.isUnion()) {
            for (Type t : type.getCaseTypes()) {
                collectUnknownTypesResolved(t, visited);
            }
        } else if (type.isIntersection()) {
            for (Type t : type.getSatisfiedTypes()) {
                collectUnknownTypesResolved(t, visited);
            }
        } else if (type.isUnknown() || type.isTypeParameter()) {
        // do nothing
        } else {
            TypeDeclaration declaration = type.getDeclaration();
            if (visited.put(declaration, declaration) != null)
                return;
            if (type.isClassOrInterface()) {
                // these are not resolved
                if (type.getExtendedType() != null)
                    collectUnknownTypes(type.getExtendedType(), visited);
                for (Type t : type.getSatisfiedTypes()) collectUnknownTypes(t, visited);
            }
        }
    }
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) Type(org.eclipse.ceylon.model.typechecker.model.Type) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 10 with UnknownType

use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.

the class AbstractModelLoader method logModelResolutionException.

private Type logModelResolutionException(final String exceptionMessage, Module module, final String message) {
    UnknownType.ErrorReporter errorReporter;
    if (module != null && !module.isDefaultModule()) {
        final StringBuilder sb = new StringBuilder();
        sb.append("Error while loading the ").append(module.getNameAsString()).append("/").append(module.getVersion());
        sb.append(" module:\n ");
        sb.append(message);
        if (exceptionMessage != null)
            sb.append(":\n ").append(exceptionMessage);
        errorReporter = makeModelErrorReporter(module, sb.toString());
    } else if (exceptionMessage == null) {
        errorReporter = makeModelErrorReporter(message);
    } else {
        errorReporter = makeModelErrorReporter(message + ": " + exceptionMessage);
    }
    UnknownType ret = new UnknownType(typeFactory);
    ret.setErrorReporter(errorReporter);
    return ret.getType();
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType)

Aggregations

UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)15 Type (org.eclipse.ceylon.model.typechecker.model.Type)10 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)9 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)6 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)5 ArrayList (java.util.ArrayList)4 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)4 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)4 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)4 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)3 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)3 Class (org.eclipse.ceylon.model.typechecker.model.Class)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)3 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)3 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)2 AnalyzerUtil.setTypeConstructor (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.setTypeConstructor)2 AnalyzerUtil.unwrapAliasedTypeConstructor (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor)2 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)2 ReflectionClass (org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass)2