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

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


        System.out.println("-----------------------");
        ClassOrInterface d0 = (ClassOrInterface)srclang.getDirectMember("Iterable", null, false);
        Assert.assertNotNull("ContainerWithFirstElement from srclang", d0);
        ClassOrInterface d1 = (ClassOrInterface)jslang.getDirectMember("Iterable", null, false);
        Assert.assertNotNull("ContainerWithFirstElement from jslang", d1);
        ProducedType seq0 = null, seq1 = null;
        for (ProducedType pt : d0.getSatisfiedTypes()) {
            System.out.println(d0 + " satisfies " + pt);
            if (pt.getProducedTypeName().startsWith("Null[]")) {
                seq0 = pt;
                break;
View Full Code Here


        if (t0.getTypeArguments() == null) {
            Assert.assertNull(t1.getTypeArguments());
        } else {
            Map<TypeParameter, ProducedType> parms1 = t1.getTypeArguments();
            for (Map.Entry<TypeParameter, ProducedType> e : t0.getTypeArguments().entrySet()) {
                ProducedType tparm = parms1.get(e.getKey());
                Assert.assertNotNull(tparm);
                final String s0ppp = e.getValue().getProducedTypeQualifiedName();
                if (stack.contains(s0ppp)) {
                    Assert.assertEquals(s0ppp, tparm.getProducedTypeQualifiedName());
                } else {
                    compareTypes(e.getValue(), tparm, stack);
                }
            }
        }
        //Case types
        if (t0.getCaseTypes() == null) {
            Assert.assertNull(t1.getCaseTypes());
        } else {
            Iterator<ProducedType> cases = t1.getCaseTypes().iterator();
            for (ProducedType c0 : t0.getCaseTypes()) {
                ProducedType c1 = cases.next();
                compareTypes(c0, c1, stack);
            }
        }
        if (t0.getDeclaration().getSelfType() == null) {
            Assert.assertNull(t1.getDeclaration().getSelfType());
        } else {
            compareTypes(t0.getDeclaration().getSelfType(), t1.getDeclaration().getSelfType(), stack);
        }
        if (t0.getSupertypes() == null) {
            Assert.assertNull(t1.getSupertypes());
        } else {
            if (t0.getSupertypes().size() != t1.getSupertypes().size()) {
                System.out.println("SRC " + t0ptqn + "(" + t0.getDeclaration().getContainer().getQualifiedNameString() + ") supers " + t0.getSupertypes());
                System.out.println("JS  " + t1.getProducedTypeQualifiedName() + "(" + t1.getDeclaration().getContainer().getQualifiedNameString() + ") supers " + t1.getSupertypes());
            }
            Assert.assertEquals("supertypes differ for " + t0 + ": " + t0.getSupertypes() + " vs " + t1.getSupertypes(),
                    t0.getSupertypes().size(), t1.getSupertypes().size());
            Iterator<ProducedType> supers = t1.getSupertypes().iterator();
            for (ProducedType s0 : t0.getSupertypes()) {
                ProducedType s1 = supers.next();
                if (s0 == t0) {
                    Assert.assertTrue(s1 == t1);
                } else {
                    final String s0ppp = s0.getProducedTypeQualifiedName();
                    if (stack.contains(s0ppp)) {
                        Assert.assertEquals(s0ppp, s1.getProducedTypeQualifiedName());
                    } else {
                        compareTypes(s0, s1, stack);
                    }
                }
            }
View Full Code Here

        return node;
    }

    @Test
    public void testCollection_vs_Range() {
        final ProducedType d_coll = getType("Collection", getType("Integer"));
        final ProducedType d_ranged = getType("Ranged", getType("Integer"), getType("Integer"), getType("List", getType("Integer")));
        List<Tree.StaticType> types = Arrays.asList(staticType(d_coll), staticType(d_ranged));
        Collections.sort(types, new TypeGenerator.StaticTypeComparator());
        Assert.assertTrue(d_ranged == types.get(0).getTypeModel());
        types = Arrays.asList(staticType(d_ranged), staticType(d_coll));
        Collections.sort(types, new TypeGenerator.StaticTypeComparator());
        Assert.assertTrue(d_ranged == types.get(0).getTypeModel());
        final ProducedType d_iterable = getType("Iterable", getType("Integer"), getType("Null"));
        types = Arrays.asList(staticType(d_coll), staticType(d_ranged), staticType(d_iterable));
        Collections.sort(types, new TypeGenerator.StaticTypeComparator());
        Assert.assertTrue(d_iterable == types.get(0).getTypeModel());
        Assert.assertTrue(d_ranged == types.get(1).getTypeModel());
        Assert.assertTrue(d_coll == types.get(2).getTypeModel());
View Full Code Here

        }
        //This is to avoid circularity
        if (!(getModule().getLanguageModule()==getModule() && ("Nothing".equals(name) || "Anything".equals(name)))) {
            if (cls.getExtendedType() == null) {
                if (m.containsKey("super")) {
                    ProducedType father = getTypeFromJson((Map<String,Object>)m.get("super"),
                            parent instanceof Declaration ? (Declaration)parent : null, allparms);
                    if (father != null) {
                        m.remove("super");
                        cls.setExtendedType(father);
                    }
View Full Code Here

        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));
                }
            }
View Full Code Here

            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) {
                            variances = new HashMap<>();
                        }
                        variances.put(_cparm, SiteVariance.values()[(int)ptparm.get(MetamodelGenerator.KEY_US_VARIANCE)]);
                    }
                    concretes.put(_cparm, _pt);
                } else if (ptparm.containsKey(MetamodelGenerator.KEY_NAME)) {
                    //Look for type parameter with same name
                    for (TypeParameter typeParam : typeParams) {
                        if (typeParam.getName().equals(ptparm.get(MetamodelGenerator.KEY_NAME))) {
                            concretes.put(_cparm, typeParam.getType());
                        }
                    }
                }
            }
            if (!concretes.isEmpty()) {
                ProducedType rval = td.getType().substitute(concretes);
                if (variances != null) {
                    rval.setVarianceOverrides(variances);
                }
                return rval;
            }
        }
        if (td == null) {
View Full Code Here

        if (t!=null) {
            t.visit(this);
        }
        Tree.Variable v = that.getVariable();
        if (switchExpression!=null) {
            ProducedType st = switchExpression.getTypeModel();
            if (v!=null) {
                if (dynamic || !isTypeUnknown(st)) { //eliminate dupe errors
                    v.visit(this);
                }
                initOriginalDeclaration(v);
            }
            if (t!=null) {
                ProducedType pt = t.getTypeModel();
                ProducedType it = intersectionType(pt, st, unit);
                if (!hasUncheckedNulls(switchExpression.getTerm()) || !isNullCase(pt)) {
                    if (it.isExactly(unit.getNothingDeclaration().getType())) {
                        that.addError("narrows to bottom type 'Nothing': '" +
                                pt.getProducedTypeName(unit) + "' has empty intersection with '" +
                                st.getProducedTypeName(unit) + "'");
                    }
                    /*checkAssignable(ct, switchType, cc.getCaseItem(),
View Full Code Here

        }  
    }
   
    private void checkCasesExhaustive(Tree.SwitchCaseList switchCaseList,
            Tree.SwitchClause switchClause) {
        ProducedType st = switchExpression.getTypeModel();
        if (!isTypeUnknown(st)) {
            //form the union of all the case types
            List<Tree.CaseClause> caseClauses = switchCaseList.getCaseClauses();
            List<ProducedType> list = new ArrayList<ProducedType>(caseClauses.size());
            for (Tree.CaseClause cc: caseClauses) {
                ProducedType ct = getTypeIgnoringLiterals(cc);
                if (isTypeUnknown(ct)) {
                    return; //Note: early exit!
                }
                else {
                    addToUnion(list, ct);
View Full Code Here

    public void visit(Tree.TryCatchStatement that) {
        super.visit(that);
        for (Tree.CatchClause cc: that.getCatchClauses()) {
            if (cc.getCatchVariable()!=null &&
                    cc.getCatchVariable().getVariable()!=null) {
                ProducedType ct = cc.getCatchVariable()
                        .getVariable().getType().getTypeModel();
                if (ct!=null) {
                    for (Tree.CatchClause ecc: that.getCatchClauses()) {
                        if (ecc.getCatchVariable()!=null &&
                                ecc.getCatchVariable().getVariable()!=null) {
                            if (cc==ecc) break;
                            ProducedType ect = ecc.getCatchVariable()
                                    .getVariable().getType().getTypeModel();
                            if (ect!=null) {
                                if (ct.isSubtypeOf(ect)) {
                                    cc.getCatchVariable().getVariable().getType()
                                            .addError("exception type is already handled by earlier catch clause: '"
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;
                            }
View Full Code Here

TOP

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

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.