Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.UnionType


                        } else {
                            ArrayList<ProducedType> cases = new ArrayList<ProducedType>(2);
                            Util.addToUnion(cases, sequencedType);
                            Util.addToUnion(cases, exprType);
                            if (cases.size() > 1) {
                                UnionType ut = new UnionType(that.getUnit());
                                ut.setCaseTypes(cases);
                                sequencedType = ut.getType();
                            } else {
                                sequencedType = cases.get(0);
                            }
                        }
                        if (!opened) {
View Full Code Here


            subs = node.getUnit().getTupleElementTypes(pt);
            final ProducedType lastType = subs.get(subs.size()-1);
            if (node.getUnit().getSequenceDeclaration().equals(lastType.getDeclaration())
                    || node.getUnit().getSequentialDeclaration().equals(lastType.getDeclaration())) {
                //Non-empty, non-tuple tail; union it with its type parameter
                UnionType utail = new UnionType(node.getUnit());
                utail.setCaseTypes(Arrays.asList(lastType.getTypeArgumentList().get(0), lastType));
                subs.remove(subs.size()-1);
                subs.add(utail.getType());
            }
        } else {
            return false;
        }
        gen.out("',l:[");
View Full Code Here

        if (td == null && m.containsKey("comp")) {
            @SuppressWarnings("unchecked")
            final List<Map<String,Object>> tmaps = (List<Map<String,Object>>)m.get(MetamodelGenerator.KEY_TYPES);
            final ArrayList<ProducedType> types = new ArrayList<ProducedType>(tmaps.size());
            if ("u".equals(m.get("comp"))) {
                UnionType ut = new UnionType(u2);
                for (Map<String, Object> tmap : tmaps) {
                    Util.addToUnion(types, getTypeFromJson(tmap, container, typeParams));
                }
                ut.setCaseTypes(types);
                td = ut;
            } else if ("i".equals(m.get("comp"))) {
                IntersectionType it = new IntersectionType(u2);
                for (Map<String, Object> tmap : tmaps) {
                    Util.addToIntersection(types, getTypeFromJson(tmap, container, typeParams), u2);
View Full Code Here

            if (et==null || et.isSubtypeOf(at)) {
                returnType.setTypeModel(at);
            }
            else {
                if (!at.isSubtypeOf(et)) {
                    UnionType ut = new UnionType(unit);
                    List<ProducedType> list =
                            new ArrayList<ProducedType>(2);
                    addToUnion(list, et);
                    addToUnion(list, at);
                    ut.setCaseTypes(list);
                    returnType.setTypeModel( ut.getType() );
                }
            }
        }
    }
View Full Code Here

        }
        return formIntersection(types);
    }

    private ProducedType formUnion(List<ProducedType> types) {
        UnionType ut = new UnionType(unit);
        ut.setCaseTypes(types);
        return ut.getType();
    }
View Full Code Here

        if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
            checkOptional(lhst, that.getLeftTerm(), that.getLeftTerm());
            List<ProducedType> list = new ArrayList<ProducedType>(2);
            addToUnion(list, unit.denotableType(rhst));
            addToUnion(list, unit.getDefiniteType(unit.denotableType(lhst)));
            UnionType ut = new UnionType(unit);
            ut.setCaseTypes(list);
            ProducedType rt = ut.getType();
            that.setTypeModel(rt);
            /*that.setTypeModel(rhst);
            ProducedType ot;
            if (isOptionalType(rhst)) {
                ot = rhst;
View Full Code Here

                }
                else {
                    addToUnion(list, ct);
                }
            }
            UnionType ut = new UnionType(unit);
            ut.setCaseTypes(list);
            //if the union of the case types covers
            //the switch expression type then the
            //switch is exhaustive
            if (!ut.getType().covers(st)) {
                switchClause.addError("case types must cover all cases of the switch type or an else clause must appear: '" +
                                ut.getType().getProducedTypeName(unit) + "' does not cover '" +
                                st.getProducedTypeName(unit) + "'");
            }
        }
        /*else if (dynamic) {
            that.addError("else clause must appear: static type not known");
View Full Code Here

    }

    public static boolean abbreviateOptional(ProducedType pt) {
        if (pt.getDeclaration() instanceof UnionType) {
            Unit unit = pt.getDeclaration().getUnit();
            UnionType ut = (UnionType) pt.getDeclaration();
            return ut.getCaseTypes().size()==2 &&
                    isElementOfUnion(ut, unit.getNullDeclaration()); /*&&
                    minus(unit.getNullDeclaration()).isPrimitiveAbbreviatedType();*/
        }
        else {
            return false;
View Full Code Here

            elemtypes.set(lastIndex, u.getSequentialElementType(last));
        }
        if (elemtypes==null) {
            return false;
        }
        UnionType ut = new UnionType(u);
        ut.setCaseTypes(elemtypes);
        ProducedType t = ut.getType();
        ProducedType typeArg =
                args.getTypeArgumentList().get(0);
        if (typeArg==null) {
            return false;
        }
View Full Code Here

                public TypeDeclaration initDeclaration() {
                    List<ProducedType> types =
                            new ArrayList<ProducedType>(2);
                    types.add(unit.getType(unit.getNullDeclaration()));
                    if (definiteType!=null) types.add(definiteType);
                    UnionType ut = new UnionType(unit);
                    ut.setCaseTypes(types);
                    return ut;
                }
                @Override
                public Map<TypeParameter, ProducedType> initTypeArguments() {
                    return emptyMap();
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.UnionType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.