Search in sources :

Example 1 with LazyType

use of org.eclipse.ceylon.model.typechecker.model.LazyType 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 2 with LazyType

use of org.eclipse.ceylon.model.typechecker.model.LazyType 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 3 with LazyType

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

the class DeclarationVisitor method visit.

public void visit(Tree.SequenceType that) {
    super.visit(that);
    if (inExtends) {
        final Tree.StaticType elementType = that.getElementType();
        final Tree.NaturalLiteral length = that.getLength();
        Type t;
        if (length == null) {
            t = new LazyType(unit) {

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

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

                @Override
                public Map<TypeParameter, Type> initTypeArguments() {
                    List<TypeParameter> stps = unit.getSequentialDeclaration().getTypeParameters();
                    return singletonMap(stps.get(0), elementType.getTypeModel());
                }
            };
        } else {
            final int len;
            try {
                len = parseInt(length.getText());
            } catch (NumberFormatException nfe) {
                return;
            }
            if (len < 1 || len > 1000) {
                return;
            } else {
                t = new StaticLengthSequenceType(elementType, len);
            }
        }
        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) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) NamedArgumentList(org.eclipse.ceylon.model.typechecker.model.NamedArgumentList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImportList(org.eclipse.ceylon.model.typechecker.model.ImportList) ModuleImportList(org.eclipse.ceylon.model.typechecker.model.ModuleImportList) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) 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) ModelUtil.getTypeArgumentMap(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getTypeArgumentMap) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ModelUtil.getVarianceMap(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getVarianceMap)

Example 4 with LazyType

use of org.eclipse.ceylon.model.typechecker.model.LazyType 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 5 with LazyType

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

Aggregations

IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)13 LazyType (org.eclipse.ceylon.model.typechecker.model.LazyType)13 Type (org.eclipse.ceylon.model.typechecker.model.Type)13 TypeVisitor.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType)12 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)12 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)12 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)12 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)10 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)9 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)4 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)3 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)3 Collections.emptyMap (java.util.Collections.emptyMap)2 Map (java.util.Map)2 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)2 ConditionScope (org.eclipse.ceylon.model.typechecker.model.ConditionScope)2 ModelUtil.getContainingClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface)2 ModelUtil.getRealScope (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope)2