Search in sources :

Example 31 with TypeParameter

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

the class DeclarationVisitor method visit.

public void visit(Tree.IterableType that) {
    super.visit(that);
    if (inExtends) {
        final Tree.Type elem = that.getElementType();
        Type t = new LazyType(unit) {

            Type iterableType() {
                final Type elementType;
                final boolean atLeastOne;
                if (elem == null) {
                    elementType = unit.getNothingType();
                    atLeastOne = false;
                } else if (elem instanceof Tree.SequencedType) {
                    Tree.SequencedType set = (Tree.SequencedType) elem;
                    elementType = set.getType().getTypeModel();
                    atLeastOne = set.getAtLeastOne();
                } else {
                    elementType = null;
                    atLeastOne = false;
                }
                if (elementType != null) {
                    return atLeastOne ? unit.getNonemptyIterableType(elementType) : unit.getIterableType(elementType);
                } else {
                    Type ut = new UnknownType(unit).getType();
                    return unit.getIterableType(ut);
                }
            }

            @Override
            public boolean isUnknown() {
                return false;
            }

            @Override
            public TypeDeclaration initDeclaration() {
                return iterableType().getDeclaration();
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                return iterableType().getTypeArguments();
            }
        };
        that.setTypeModel(t);
    }
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) 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) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 32 with TypeParameter

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

the class DeclarationVisitor method visit.

public void visit(final Tree.UnionType that) {
    super.visit(that);
    final List<Tree.StaticType> sts = that.getStaticTypes();
    if (inExtends) {
        Type t = new LazyType(unit) {

            @Override
            public TypeDeclaration initDeclaration() {
                List<Type> types = new ArrayList<Type>(sts.size());
                for (Tree.StaticType st : sts) {
                    Type t = st.getTypeModel();
                    if (t != null) {
                        types.add(t);
                    }
                }
                UnionType ut = new UnionType(unit);
                ut.setCaseTypes(types);
                return ut;
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                return emptyMap();
            }
        };
        that.setTypeModel(t);
    }
}
Also used : UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) 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) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) ArrayList(java.util.ArrayList) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 33 with TypeParameter

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

the class DeclarationVisitor method visit.

public void visit(Tree.FunctionType that) {
    super.visit(that);
    if (inExtends) {
        final Tree.StaticType rt = that.getReturnType();
        if (rt != null) {
            final List<Tree.Type> args = that.getArgumentTypes();
            Type t = new LazyType(unit) {

                @Override
                public boolean isUnknown() {
                    return false;
                }

                @Override
                public TypeDeclaration initDeclaration() {
                    return unit.getCallableDeclaration();
                }

                @Override
                public Map<TypeParameter, Type> initTypeArguments() {
                    HashMap<TypeParameter, Type> map = new HashMap<TypeParameter, Type>();
                    List<TypeParameter> ctps = unit.getCallableDeclaration().getTypeParameters();
                    map.put(ctps.get(0), rt.getTypeModel());
                    map.put(ctps.get(1), getTupleType(args, unit));
                    return map;
                }
            };
            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) HashMap(java.util.HashMap) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 34 with TypeParameter

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

the class DeclarationVisitor method visit.

public void visit(Tree.SuperType that) {
    super.visit(that);
    if (inExtends) {
        final Scope scope = that.getScope();
        Type t = new LazyType(unit) {

            @Override
            public TypeDeclaration initDeclaration() {
                ClassOrInterface ci = getContainingClassOrInterface(scope);
                if (ci == null) {
                    return null;
                } else {
                    if (ci.isClassOrInterfaceMember()) {
                        ClassOrInterface oci = (ClassOrInterface) ci.getContainer();
                        return intersectionOfSupertypes(oci).getDeclaration();
                    } else {
                        return null;
                    }
                }
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                return emptyMap();
            }
        };
        that.setTypeModel(t);
    }
}
Also used : ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) 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) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType)

Example 35 with TypeParameter

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

the class DeclarationVisitor method visit.

public void visit(Tree.SequencedType that) {
    super.visit(that);
    if (inExtends) {
        final Type type = that.getType().getTypeModel();
        final boolean atLeastOne = that.getAtLeastOne();
        Type t = new LazyType(unit) {

            @Override
            public boolean isUnknown() {
                return false;
            }

            @Override
            public TypeDeclaration initDeclaration() {
                return atLeastOne ? unit.getSequenceDeclaration() : unit.getSequentialDeclaration();
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                Interface dec = atLeastOne ? unit.getSequenceDeclaration() : unit.getSequentialDeclaration();
                List<TypeParameter> stps = dec.getTypeParameters();
                return singletonMap(stps.get(0), type);
            }
        };
        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) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

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