Search in sources :

Example 6 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.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 7 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.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 8 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.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)

Example 9 with LazyType

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

the class RefinementVisitor method createRefiningParameter.

private void createRefiningParameter(final Reference rm, Function method, final Parameter p, ParameterList l, Tree.ParameterList tpl, int j, final Map<TypeParameter, Type> subs, Unit unit) {
    if (tpl == null || tpl.getParameters().size() <= j) {
        Parameter vp = new Parameter();
        Value v = new Value();
        vp.setModel(v);
        v.setInitializerParameter(vp);
        vp.setSequenced(p.isSequenced());
        vp.setAtLeastOne(p.isAtLeastOne());
        // vp.setDefaulted(p.isDefaulted());
        vp.setName(p.getName());
        v.setName(p.getName());
        vp.setDeclaration(method);
        v.setContainer(method);
        v.setScope(method);
        l.getParameters().add(vp);
        v.setType(new LazyType(unit) {

            private Type type() {
                return rm.getTypedParameter(p).getFullType().substitute(subs, null);
            }

            @Override
            public Type initQualifyingType() {
                Type type = type();
                return type == null ? null : type.getQualifyingType();
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                Type type = type();
                return type == null ? null : type.getTypeArguments();
            }

            @Override
            public TypeDeclaration initDeclaration() {
                Type type = type();
                return type == null ? null : type.getDeclaration();
            }

            @Override
            public Map<TypeParameter, SiteVariance> getVarianceOverrides() {
                Type type = type();
                return type == null ? null : type.getVarianceOverrides();
            }
        });
    } else {
        Tree.Parameter tp = tpl.getParameters().get(j);
        Parameter rp = tp.getParameterModel();
        rp.setDefaulted(p.isDefaulted());
        rp.setDeclaration(method);
        l.getParameters().add(rp);
    }
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.erasedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.erasedType) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 10 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.OptionalType that) {
    super.visit(that);
    final Tree.StaticType definiteType = that.getDefiniteType();
    if (inExtends) {
        Type t = new LazyType(unit) {

            @Override
            public TypeDeclaration initDeclaration() {
                List<Type> types = new ArrayList<Type>(2);
                types.add(unit.getNullType());
                if (definiteType != null) {
                    types.add(definiteType.getTypeModel());
                }
                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