Search in sources :

Example 26 with TypeParameter

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.QualifiedType that) {
    super.visit(that);
    TypeDeclaration type = that.getDeclarationModel();
    if (type != null) {
        type = (TypeDeclaration) handleNativeHeader(type, that, true);
        if (!type.isVisible(that.getScope())) {
            if (type instanceof Constructor) {
                that.addError("constructor is not visible: " + qualifiedDescription(that), 400);
            } else {
                that.addError("member type is not visible: " + qualifiedDescription(that), 400);
            }
        } else if (type.isPackageVisibility() && !declaredInPackage(type, unit)) {
            that.addError("member type is not visible: " + qualifiedDescription(that) + " is package private");
        } else // in fact this restriction is OK
        if (type.isProtectedVisibility() && !declaredInPackage(type, unit)) {
            that.addError("member type is not visible: " + qualifiedDescription(that) + " is protected");
        }
        // Note: we should remove this check if we ever
        // make qualified member types like T.Member
        // into a sort of virtual type
        Tree.StaticType outerType = that.getOuterType();
        if (outerType instanceof Tree.SimpleType) {
            Tree.SimpleType st = (Tree.SimpleType) outerType;
            TypeDeclaration std = st.getDeclarationModel();
            if (std.isAlias()) {
                Type et = std.getExtendedType();
                if (et != null) {
                    std = et.resolveAliases().getDeclaration();
                }
            }
            if (std instanceof TypeParameter) {
                outerType.addError("type parameter should not occur as qualifying type: '" + std.getName(unit) + "' is a type parameter");
            }
        }
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) 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 27 with TypeParameter

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

the class ExpressionVisitor method getInvokedProducedReference.

private Reference getInvokedProducedReference(Declaration dec, Tree.MemberOrTypeExpression mte) {
    Tree.TypeArguments tas;
    if (mte instanceof Tree.StaticMemberOrTypeExpression) {
        Tree.StaticMemberOrTypeExpression smte = (Tree.StaticMemberOrTypeExpression) mte;
        tas = smte.getTypeArguments();
    } else {
        tas = null;
    }
    List<TypeParameter> tps = dec.getTypeParameters();
    if (isPackageQualified(mte)) {
        Tree.QualifiedMemberOrTypeExpression qmte = (Tree.QualifiedMemberOrTypeExpression) mte;
        Type invokedType = qmte.getPrimary().getTypeModel();
        if (invokedType != null) {
            invokedType = invokedType.resolveAliases();
        }
        Type receiverType = unwrap(invokedType, qmte);
        return receiverType.getTypedReference(dec, getTypeArguments(tas, receiverType, tps));
    } else {
        Type receiverType = mte.getScope().getDeclaringType(dec);
        return dec.appliedReference(receiverType, getTypeArguments(tas, receiverType, tps));
    }
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 28 with TypeParameter

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.BaseType that) {
    super.visit(that);
    final Scope scope = that.getScope();
    final String name = name(that.getIdentifier());
    if (inExtends) {
        final Tree.TypeArgumentList tal = that.getTypeArgumentList();
        final boolean packageQualified = that.getPackageQualified();
        Type t = new LazyType(unit) {

            @Override
            public TypeDeclaration initDeclaration() {
                return packageQualified ? getPackageTypeDeclaration(name, null, false, unit) : getTypeDeclaration(scope, name, null, false, unit);
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                TypeDeclaration dec = getDeclaration();
                List<TypeParameter> tps = dec.getTypeParameters();
                return getTypeArgumentMap(dec, null, AnalyzerUtil.getTypeArguments(tal, null, tps));
            }

            @Override
            public Map<TypeParameter, SiteVariance> initVarianceOverrides() {
                TypeDeclaration dec = getDeclaration();
                List<TypeParameter> tps = dec.getTypeParameters();
                return getVarianceMap(dec, null, AnalyzerUtil.getVariances(tal, tps));
            }
        };
        that.setTypeModel(t);
    }
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) SiteVariance(org.eclipse.ceylon.model.typechecker.model.SiteVariance) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) 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 29 with TypeParameter

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.QualifiedType that) {
    super.visit(that);
    final String name = name(that.getIdentifier());
    final Tree.StaticType outerType = that.getOuterType();
    if (inExtends) {
        final Tree.TypeArgumentList tal = that.getTypeArgumentList();
        Type t = new LazyType(unit) {

            @Override
            public TypeDeclaration initDeclaration() {
                if (outerType == null) {
                    return null;
                } else {
                    TypeDeclaration dec = outerType.getTypeModel().getDeclaration();
                    return AnalyzerUtil.getTypeMember(dec, name, null, false, unit, scope);
                }
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                if (outerType == null) {
                    return emptyMap();
                } else {
                    TypeDeclaration dec = getDeclaration();
                    List<TypeParameter> tps = dec.getTypeParameters();
                    Type ot = outerType.getTypeModel();
                    return getTypeArgumentMap(dec, ot, AnalyzerUtil.getTypeArguments(tal, ot, tps));
                }
            }

            @Override
            public Map<TypeParameter, SiteVariance> initVarianceOverrides() {
                TypeDeclaration dec = getDeclaration();
                List<TypeParameter> tps = dec.getTypeParameters();
                Type ot = outerType.getTypeModel();
                return getVarianceMap(dec, ot, AnalyzerUtil.getVariances(tal, tps));
            }
        };
        that.setTypeModel(t);
    }
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) SiteVariance(org.eclipse.ceylon.model.typechecker.model.SiteVariance) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) 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 30 with TypeParameter

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.TypeParameterDeclaration that) {
    Tree.TypeVariance tv = that.getTypeVariance();
    final TypeParameter p = new TypeParameter();
    defaultExtendedToAnything(p);
    p.setDeclaration(declaration);
    if (tv != null) {
        String v = tv.getText();
        p.setCovariant("out".equals(v));
        p.setContravariant("in".equals(v));
    }
    that.setDeclarationModel(p);
    visitDeclaration(that, p);
    super.visit(that);
    Tree.TypeSpecifier ts = that.getTypeSpecifier();
    if (ts != null) {
        p.setDefaulted(true);
        Tree.StaticType type = ts.getType();
        if (type != null) {
            Type dta = type.getTypeModel();
            p.setDefaultTypeArgument(dta);
        }
    }
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Aggregations

TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)181 Type (org.eclipse.ceylon.model.typechecker.model.Type)138 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)82 ArrayList (java.util.ArrayList)57 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)57 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)54 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)46 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)45 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)35 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)32 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)30 Function (org.eclipse.ceylon.model.typechecker.model.Function)29 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)28 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)28 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)28 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)27 JCTypeParameter (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter)26 Class (org.eclipse.ceylon.model.typechecker.model.Class)26 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)25 HashMap (java.util.HashMap)24