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

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


        }
        if (inExtends) {
            ProducedType t = new LazyProducedType(unit) {
                @Override
                public TypeDeclaration initDeclaration() {
                    UnionType ut = new UnionType(unit);
                    ut.setCaseTypes(types);
                    return ut;
                }
                @Override
                public Map<TypeParameter, ProducedType> initTypeArguments() {
                    return emptyMap();
View Full Code Here


        for (Tree.StaticType st: that.getStaticTypes()) {
            //addToUnion( types, st.getTypeModel() );
            ProducedType t = st.getTypeModel();
            if (t!=null) types.add(t);
        }
        UnionType ut = new UnionType(unit);
        ut.setCaseTypes(types);
        that.setTypeModel(ut.getType());
        //that.setTarget(pt);
    }
View Full Code Here

        super.visit(that);
        List<ProducedType> types = new ArrayList<ProducedType>(2);
        types.add(unit.getType(unit.getNullDeclaration()));
        ProducedType dt = that.getDefiniteType().getTypeModel();
        if (dt!=null) types.add(dt);
        UnionType ut = new UnionType(unit);
        ut.setCaseTypes(types);
        that.setTypeModel(ut.getType());
    }
View Full Code Here

        for (int i=last; i>=0; i--) {
            ProducedType elemType = elemTypes.get(i);
            List<ProducedType> pair = new ArrayList<ProducedType>();
            pair.add(elemType);
            pair.add(union);
            UnionType ut = new UnionType(unit);
            ut.setCaseTypes(pair);
            union = ut.getType();
            if (variadic && i==last) {
                result = atLeastOne ?
                        unit.getSequenceType(elemType) :
                        unit.getSequentialType(elemType);
            }
            else {
                result = producedType(unit.getTupleDeclaration(),
                        union, elemType, result);
                if (firstDefaulted>=0 && i>=firstDefaulted) {
                    pair = new ArrayList<ProducedType>();
                    pair.add(unit.getType(unit.getEmptyDeclaration()));
                    pair.add(result);
                    ut = new UnionType(unit);
                    ut.setCaseTypes(pair);
                    result = ut.getType();
                }
            }
        }
        return result;
    }
View Full Code Here

            return false;
        TypeDeclaration declaration = type.getDeclaration();
        if(declaration == null)
            return false;
        if(declaration instanceof UnionType){
            UnionType ut = (UnionType) declaration;
            java.util.List<ProducedType> caseTypes = ut.getCaseTypes();
            for(ProducedType pt : caseTypes){
                if(hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
                    return true;
            }
            return false;
        }
        if(declaration instanceof IntersectionType){
            IntersectionType ut = (IntersectionType) declaration;
            java.util.List<ProducedType> satisfiedTypes = ut.getSatisfiedTypes();
            for(ProducedType pt : satisfiedTypes){
                if(hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
                    return true;
            }
            return false;
View Full Code Here

        // we do not use Unit.getOptionalType because it causes lots of lazy loading that ultimately triggers the typechecker's
        // infinite recursion loop
        List<ProducedType> list = new ArrayList<ProducedType>(2);
        list.add(typeFactory.getNullDeclaration().getType());
        list.add(type);
        UnionType ut = new UnionType(getUnitForModule(moduleScope));
        ut.setCaseTypes(list);
        return ut.getType();
    }
View Full Code Here

            return false;
        TypeDeclaration declaration = type.getDeclaration();
        if(declaration == null)
            return false;
        if(declaration instanceof UnionType){
            UnionType ut = (UnionType) declaration;
            java.util.List<ProducedType> caseTypes = ut.getCaseTypes();
            // special case for optional types
            if(caseTypes.size() == 2){
                if(isOptional(caseTypes.get(0)))
                    return hasErasureResolved(caseTypes.get(1));
                if(isOptional(caseTypes.get(1)))
                    return hasErasureResolved(caseTypes.get(0));
            }
            // must be erased
            return true;
        }
        if(declaration instanceof IntersectionType){
            IntersectionType ut = (IntersectionType) declaration;
            java.util.List<ProducedType> satisfiedTypes = ut.getSatisfiedTypes();
            // special case for non-optional types
            if(satisfiedTypes.size() == 2){
                if(isObject(satisfiedTypes.get(0)))
                    return hasErasureResolved(satisfiedTypes.get(1));
                if(isObject(satisfiedTypes.get(1)))
View Full Code Here

    }

    private boolean isErasedUnionOrIntersection(ProducedType producedType) {
        TypeDeclaration typeDeclaration = producedType.getDeclaration();
        if(typeDeclaration instanceof UnionType){
            UnionType ut = (UnionType) typeDeclaration;
            java.util.List<ProducedType> caseTypes = ut.getCaseTypes();
            // special case for optional types
            if(caseTypes.size() == 2){
                if(isNull(caseTypes.get(0))){
                    return isErasedUnionOrIntersection(caseTypes.get(1));
                }else if(isNull(caseTypes.get(1))){
                    return isErasedUnionOrIntersection(caseTypes.get(0));
                }
            }
            // it is erased
            return true;
        }
        if(typeDeclaration instanceof IntersectionType){
            IntersectionType ut = (IntersectionType) typeDeclaration;
            java.util.List<ProducedType> satisfiedTypes = ut.getSatisfiedTypes();
            // special case for non-optional types
            if(satisfiedTypes.size() == 2){
                if(isObject(satisfiedTypes.get(0))){
                    return isErasedUnionOrIntersection(satisfiedTypes.get(1));
                }else if(isObject(satisfiedTypes.get(1))){
View Full Code Here

                        return typeTester.isReified(varExpr, testedType);
                    }
                }
            }
        } else if (typeFact().isUnion(testedType)) {
            UnionType union = (UnionType)declaration;
            for (ProducedType pt : union.getCaseTypes()) {
                R partExpr = makeTypeTest(typeTester, firstTimeExpr, varName, pt, expressionType);
                firstTimeExpr = null;
                if (result == null) {
                    result = partExpr;
                } else {
                    result = typeTester.andOr(result, partExpr, JCTree.OR);
                }
            }
            return result;
        } else if (typeFact().isIntersection(testedType)) {
            IntersectionType union = (IntersectionType)declaration;
            for (ProducedType pt : union.getSatisfiedTypes()) {
                R partExpr = makeTypeTest(typeTester, firstTimeExpr, varName, pt, expressionType);
                firstTimeExpr = null;
                if (result == null) {
                    result = partExpr;
                } else {
View Full Code Here

        ProducedType type = new TypeParser(MockLoader.instance).decodeType("a|b|c", null, mockModule, mockUnit);
        Assert.assertNotNull(type);
        TypeDeclaration declaration = type.getDeclaration();
        Assert.assertNotNull(declaration);
        Assert.assertTrue(declaration instanceof UnionType);
        UnionType union = (UnionType) declaration;
        List<ProducedType> types = union.getCaseTypes();
        Assert.assertEquals(3, types.size());
        Assert.assertEquals("a", types.get(0).getDeclaration().getName());
        Assert.assertTrue(types.get(0).getDeclaration() instanceof Class);
        Assert.assertEquals("b", types.get(1).getDeclaration().getName());
        Assert.assertTrue(types.get(1).getDeclaration() instanceof Class);
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.