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

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


        if (otherType == null) {
            expr.addUnexpectedError("Right term of intersection operator should have type parameter named " + rightTpName);
            return null;
        }
        targs = new HashMap<>();
        TypeParameter mtp = null;
        for (TypeParameter tp : md.getTypeParameters()) {
            if (tp.getName().equals(leftTpName)) {
                mtp = tp;
                break;
            }
View Full Code Here


                //we already had it (from partial loading elsewhere)
                allparms.add((TypeParameter)maybe);
                tparms.add((TypeParameter)maybe);
                tp.put(MetamodelGenerator.KEY_METATYPE, maybe);
            } else {
                TypeParameter tparm = new TypeParameter();
                tparm.setUnit(u2);
                tparm.setDeclaration(container);
                container.getMembers().add(tparm);
                if (tp.containsKey(MetamodelGenerator.KEY_NAME)) {
                    tparm.setName((String)tp.get(MetamodelGenerator.KEY_NAME));
                } else if (!tp.containsKey(MetamodelGenerator.KEY_TYPES)) {
                    throw new IllegalArgumentException("Invalid type parameter map " + tp);
                }
                String variance = (String)tp.get(MetamodelGenerator.KEY_DS_VARIANCE);
                if ("out".equals(variance)) {
                    tparm.setCovariant(true);
                } else if ("in".equals(variance)) {
                    tparm.setContravariant(true);
                }
                if (container instanceof Scope) {
                    tparm.setContainer((Scope)container);
                }
                tparm.setDefaulted(tp.containsKey(MetamodelGenerator.KEY_DEFAULT));
                tparms.add(tparm);
                allparms.add(tparm);
                tp.put(MetamodelGenerator.KEY_METATYPE, tparm);
            }
        }
        if (container instanceof TypeDeclaration) {
            ((TypeDeclaration) container).setTypeParameters(tparms);
        } else if (container instanceof Method) {
            ((Method) container).setTypeParameters(tparms);
        }
        //Second, add defaults and heritage
        for (Map<String,Object> tp : typeParams) {
            TypeParameter tparm = (TypeParameter)tp.get(MetamodelGenerator.KEY_METATYPE);
            if (tparm.getExtendedType() == null) {
                if (tp.containsKey(MetamodelGenerator.KEY_PACKAGE)) {
                    //Looks like this never happens but...
                    ProducedType subtype = getTypeFromJson(tp, container, allparms);
                    tparm.setExtendedType(subtype);
                } else if (tp.containsKey(MetamodelGenerator.KEY_TYPES)) {
                    if (!("u".equals(tp.get("comp")) || "i".equals(tp.get("comp")))) {
                        throw new IllegalArgumentException("Only union or intersection types are allowed as 'comp'");
                    }
                    ProducedType subtype = getTypeFromJson(tp, container, allparms);
                    tparm.setName(subtype.getProducedTypeName());
                    tparm.setExtendedType(subtype);
                } else {
                    tparm.setExtendedType(getTypeFromJson(voidclass, container, null));
                }
            }
            if (tparm.isDefaulted()) {
                @SuppressWarnings("unchecked")
                final Map<String,Object> deftype = (Map<String,Object>)tp.get(MetamodelGenerator.KEY_DEFAULT);
                tparm.setDefaultTypeArgument(getTypeFromJson(deftype, container, existing));
            }
            if (tp.containsKey(MetamodelGenerator.KEY_SATISFIES)) {
                @SuppressWarnings("unchecked")
                final List<Map<String,Object>> stypes = (List<Map<String,Object>>)tp.get(MetamodelGenerator.KEY_SATISFIES);
                for (ProducedType sat : parseTypeList(stypes, allparms)) {
                    Util.addToIntersection(tparm.getSatisfiedTypes(), sat, u2);
                }
                tparm.setConstrained(true);
            } else if (tp.containsKey("of")) {
                @SuppressWarnings("unchecked")
                final List<Map<String,Object>> oftype = (List<Map<String,Object>>)tp.get("of");
                tparm.setCaseTypes(parseTypeList(oftype, allparms));
                tparm.setConstrained(true);
            }
        }
        return tparms;
    }
View Full Code Here

                    parseTypeParameters(modelParms, td, null);
                }
            }
            final Iterator<TypeParameter> viter = td.getTypeParameters().iterator();
            for (Map<String,Object> ptparm : modelParms) {
                TypeParameter _cparm = viter.next();
                if (ptparm.containsKey(MetamodelGenerator.KEY_PACKAGE) || ptparm.containsKey(MetamodelGenerator.KEY_TYPES)) {
                    //Substitute for proper type
                    final ProducedType _pt = getTypeFromJson(ptparm, container, typeParams);
                    if (ptparm.containsKey(MetamodelGenerator.KEY_US_VARIANCE)) {
                        if (variances == null) {
View Full Code Here

            final Map<TypeParameter, SiteVariance> usv = pt.getVarianceOverrides();
            final Iterator<TypeParameter> typeParameters = usv == null || usv.isEmpty() ?
                    null : pt.getDeclaration().getTypeParameters().iterator();
            for (ProducedType targ : pt.getTypeArgumentList()) {
                final Map<String, Object> tpmap = typeParameterMap(targ, from);
                final TypeParameter typeParam = typeParameters == null ? null : typeParameters.next();
                final SiteVariance variance = typeParam == null ? null : usv.get(typeParam);
                if (variance != null) {
                    tpmap.put(MetamodelGenerator.KEY_US_VARIANCE, variance.ordinal());
                }
                list.add(tpmap);
View Full Code Here

        }
    }
   
    @Override public void visit(Tree.TypeParameterDeclaration that) {
        super.visit(that);
        TypeParameter tpd = that.getDeclarationModel();
        ProducedType dta = tpd.getDefaultTypeArgument();
        if (dta!=null) {
            for (ProducedType st: tpd.getSatisfiedTypes()) {
                checkAssignable(dta, st,
                        that.getTypeSpecifier().getType(),
                        "default type argument does not satisfy type constraint");
            }
        }
View Full Code Here

                else {
                    return unit.denotableType(argType);
                }
            }
            else if (paramTypeDec instanceof TypeParameter) {
                TypeParameter tp2 =
                        (TypeParameter) paramTypeDec;
                if (!visited.contains(tp2)) {
                    visited.add(tp2);
                    List<ProducedType> list = new ArrayList<ProducedType>();
                    for (ProducedType upperBound: tp2.getSatisfiedTypes()) {
                        addToUnionOrIntersection(tp, list,
                                inferTypeArg(tp, tp2, upperBound, argType,
                                        covariant, contravariant,
                                        visited));
                        ProducedType supertype =
View Full Code Here

                j<superTypeArgs.size() &&
                j<typeParameters.size();
                j++) {
            ProducedType paramTypeArg = paramTypeArgs.get(j);
            ProducedType argTypeArg = superTypeArgs.get(j);
            TypeParameter typeParameter = typeParameters.get(j);
            boolean co;
            boolean contra;
            if (paramType.isCovariant(typeParameter)) {
                //leave them alone
                co = covariant;
View Full Code Here

                        Tree.Type t = args.get(i);
                        if (t instanceof Tree.StaticType) {
                            TypeVariance variance =
                                    ((Tree.StaticType) t).getTypeVariance();
                            if (variance!=null) {
                                TypeParameter p = params.get(i);
                                if (p.isInvariant()) {
                                    if (variance.getText().equals("out")) {
                                        pt.setVariance(p, OUT);
                                    }
                                    else if (variance.getText().equals("in")) {
                                        pt.setVariance(p, IN);
                                    }
                                }
                                else {
                                    variance.addError("type parameter is not declared invariant: '" +
                                            p.getName() + "' of '" + type.getName(unit) + "'");
                                }
                            }
                        }
                    }
                }
View Full Code Here

            }
            int max = params.size();
            int args = typeArguments.size();
            if (args<=max && args>=min) {
                for (int i=0; i<args; i++) {
                    TypeParameter param = params.get(i);
                    ProducedType argType = typeArguments.get(i);
                    //Map<TypeParameter, ProducedType> self = Collections.singletonMap(param, arg);
                    boolean argTypeMeaningful = argType!=null &&
                            !(argType.getDeclaration() instanceof UnknownType);
                    for (ProducedType st: param.getSatisfiedTypes()) {
                        //sts = sts.substitute(self);
                        ProducedType sts = st.getProducedType(receiver, dec, typeArguments);
                        if (argType!=null) {
                            if (!isCondition && !argType.isSubtypeOf(sts)) {
                                if (argTypeMeaningful) {
                                    if (tal instanceof Tree.InferredTypeArguments) {
                                        parent.addError("inferred type argument '" + argType.getProducedTypeName(unit)
                                                + "' to type parameter '" + param.getName()
                                                + "' of declaration '" + dec.getName(unit)
                                                + "' is not assignable to upper bound '" + sts.getProducedTypeName(unit)
                                                + "' of '" + param.getName() + "'");
                                    }
                                    else {
                                        ((Tree.TypeArgumentList) tal).getTypes()
                                                .get(i).addError("type parameter '" + param.getName()
                                                        + "' of declaration '" + dec.getName(unit)
                                                        + "' has argument '" + argType.getProducedTypeName(unit)
                                                        + "' is not assignable to upper bound '" + sts.getProducedTypeName(unit)
                                                        + "' of '" + param.getName() + "'", 2102);
                                    }
                                }
                                return false;
                            }
                        }
                    }
                    if (!isCondition &&
                            !argumentSatisfiesEnumeratedConstraint(receiver, dec,
                                    typeArguments, argType, param)) {
                        if (argTypeMeaningful) {
                            if (tal instanceof Tree.InferredTypeArguments) {
                                parent.addError("inferred type argument '" + argType.getProducedTypeName(unit)
                                        + "' to type parameter '" + param.getName()
                                        + "' of declaration '" + dec.getName(unit)
                                        + "' is not one of the enumerated cases of '" + param.getName() + "'");
                            }
                            else {
                                ((Tree.TypeArgumentList) tal).getTypes()
                                        .get(i).addError("type parameter '" + param.getName()
                                                + "' of declaration '" + dec.getName(unit)
                                                + "' has argument '" + argType.getProducedTypeName(unit)
                                                + "' is not one of the enumerated cases of '" + param.getName() + "'");
                            }
                        }
                        return false;
                    }
                }
View Full Code Here

                        if (tal!=null) {
                            List<Tree.Type> args = tal.getTypes();
                            List<TypeParameter> typeParameters = ctd.getTypeParameters();
                            for (int i=0; i<args.size() && i<typeParameters.size(); i++) {
                                Tree.Type arg = args.get(i);
                                TypeParameter typeParameter = ctd.getTypeParameters().get(i);
                                ProducedType argType = arg.getTypeModel();
                                if (argType!=null) {
                                    TypeDeclaration argTypeDec = argType.getDeclaration();
                                    if (argTypeDec instanceof TypeParameter) {
                                        if (!((TypeParameter) argTypeDec).getDeclaration().equals(td)) {
                                            arg.addError("type argument is not a type parameter of the enumerated type: '" +
                                                    argTypeDec.getName() + "' is not a type parameter of '" + td.getName());
                                        }
                                    }
                                    else if (typeParameter.isCovariant()) {
                                        checkAssignable(typeParameter.getType(), argType, arg,
                                                "type argument not an upper bound of the type parameter");
                                    }
                                    else if (typeParameter.isContravariant()) {
                                        checkAssignable(argType, typeParameter.getType(), arg,
                                                "type argument not a lower bound of the type parameter");
                                    }
                                    else {
                                        arg.addError("type argument is not a type parameter of the enumerated type: '" +
                                                argTypeDec.getName() + "'");
View Full Code Here

TOP

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

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.