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

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


                pt!=null &&
                //account for dynamic blocks
                (!pt.isUnknown() ||
                        that.getMemberOperator() instanceof Tree.SpreadOp);
        if (check) {
            TypeDeclaration type;
            String name = name(that.getIdentifier());
            String container;
            boolean ambiguous;
            List<ProducedType> signature = that.getSignature();
            boolean ellipsis = that.getEllipsis();
            if (packageQualified) {
                container = "package '" + unit.getPackage().getNameAsString() + "'";
                Declaration pm = unit.getPackage()
                        .getMember(name, signature, ellipsis);
                if (pm instanceof TypeDeclaration) {
                    type = (TypeDeclaration) pm;
                }
                else {
                    type = null;
                }
                ambiguous = false;
            }
            else {
                pt = pt.resolveAliases(); //needed for aliases like "alias Id<T> => T"
                TypeDeclaration d = getDeclaration(that, pt);
                container = "type '" + d.getName(unit) + "'";
                ClassOrInterface ci =
                        getContainingClassOrInterface(that.getScope());
                if (ci!=null && d.inherits(ci) && !(d instanceof NothingType)) {
                    Declaration direct =
                            ci.getDirectMember(name, signature, ellipsis);
                    if (direct instanceof TypeDeclaration) {
                        type = (TypeDeclaration) direct;
                    }
                    else {
                        type = getTypeMember(d, name, signature, ellipsis, unit);
                    }
                }
                else {
                    type = getTypeMember(d, name, signature, ellipsis, unit);
                }
                ambiguous = type==null && d.isMemberAmbiguous(name, unit,
                        signature, ellipsis);
            }
            if (type==null) {
                if (error) {
                    if (ambiguous) {
View Full Code Here


    }
   
    private TypeDeclaration getDeclaration(Tree.QualifiedMemberOrTypeExpression that,
            ProducedType pt) {
        if (that.getStaticMethodReference()) {
            TypeDeclaration td = (TypeDeclaration)
                    ((Tree.MemberOrTypeExpression) that.getPrimary()).getDeclaration();
            return td==null ? new UnknownType(unit) : td;
        }
        else {
            return unwrap(pt, that).getDeclaration();
View Full Code Here

        //this one is a declaration, not an expression!
        //we are only validating type arguments here
        super.visit(that);
        ProducedType pt = that.getTypeModel();
        if (pt!=null) {
            TypeDeclaration type = that.getDeclarationModel();//pt.getDeclaration()
            Tree.TypeArgumentList tal = that.getTypeArgumentList();
            //No type inference for declarations
            if (type!=null) {
                List<TypeParameter> params = type.getTypeParameters();
                List<ProducedType> ta = getTypeArguments(tal,
                        params, pt.getQualifyingType());
                acceptsTypeArguments(type, ta, tal, that, that.getMetamodel());
                //the type has already been set by TypeVisitor
                if (tal!=null) {
                    List<Tree.Type> args = tal.getTypes();
                    for (int i = 0; i<args.size(); i++) {
                        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

                        }
                    }
                    else if (term instanceof Tree.MemberOrTypeExpression) {
                        ProducedType ut = unionType(unit.getType(unit.getNullDeclaration()),
                                unit.getType(unit.getIdentifiableDeclaration()), unit);
                        TypeDeclaration dec = t.getDeclaration();
                        if ((!dec.isToplevel() && !dec.isStaticallyImportable()) || !dec.isAnonymous()) {
                            e.addError("case must refer to a toplevel object declaration or literal value");
                        }
                        else {
                            checkAssignable(t, ut, e, "case must be identifiable or null");
                        }
View Full Code Here

            return etv;
        }
    }

    private boolean isNullCase(ProducedType ct) {
        TypeDeclaration d = ct.getDeclaration();
        return d!=null && d instanceof Class &&
                d.equals(unit.getNullDeclaration());
    }
View Full Code Here

       
        inExtendsClause = true;
        super.visit(that);
        inExtendsClause = false;
               
        TypeDeclaration td = (TypeDeclaration) that.getScope();
        if (td.isAlias()) {
            return;
        }
        Tree.SimpleType et = that.getType();
        if (et!=null) {
            ProducedType type = et.getTypeModel();
            if (type!=null) {
                checkSelfTypes(et, td, type);
                checkExtensionOfMemberType(et, td, type);
                //checkCaseOfSupertype(et, td, type);
                if (!td.isAlias()) {
                    TypeDeclaration etd = td.getExtendedTypeDeclaration();
                    while (etd!=null && etd.isAlias()) {
                        etd = etd.getExtendedTypeDeclaration();
                    }
                    if (etd!=null) {
                        if (etd.isFinal()) {
                            et.addError("extends a final class: '" +
                                    etd.getName(unit) + "'");
                        }
                      if (etd.isSealed() && !inSameModule(etd)) {
                        et.addError("extends a sealed class in a different module: '" +
                            etd.getName(unit) + "' in '" +
                            etd.getUnit().getPackage().getModule().getNameAsString() + "'");
                      }
                    }
                }
//                if (td.isParameterized() &&
//                        type.getDeclaration().inherits(unit.getExceptionDeclaration())) {
View Full Code Here

    }

    @Override
    public void visit(Tree.SatisfiedTypes that) {
        super.visit(that);
        TypeDeclaration td = (TypeDeclaration) that.getScope();
        if (td.isAlias()) {
            return;
        }
        Set<TypeDeclaration> set = new HashSet<TypeDeclaration>();
        if (td.getSatisfiedTypes().isEmpty()) return; //handle undecidability case
        for (Tree.StaticType t: that.getTypes()) {
            ProducedType type = t.getTypeModel();
            if (type!=null && type.getDeclaration()!=null) {
                type = type.resolveAliases();
                TypeDeclaration std = type.getDeclaration();
                if (td instanceof ClassOrInterface &&
                        !inLanguageModule(that.getUnit())) {
                    if (unit.isCallableType(type)) {
                        t.addError("satisfies 'Callable'");
                    }
                    if (type.getDeclaration().equals(unit.getConstrainedAnnotationDeclaration())) {
                        t.addError("directly satisfies 'ConstrainedAnnotation'");
                    }
                }
                if (!set.add(type.getDeclaration())) {
                    //this error is not really truly necessary
                    //but the spec says it is an error, and
                    //the backend doesn't like it
                    t.addError("duplicate satisfied type: '" +
                            type.getDeclaration().getName(unit) +
                            "' of '" + td.getName() + "'");
                }
              if (td instanceof ClassOrInterface &&
                  std.isSealed() && !inSameModule(std)) {
              t.addError("satisfies a sealed interface in a different module: '" +
                  std.getName(unit) + "' in '" +
                  std.getUnit().getPackage().getModule().getNameAsString() + "'");
              }
                checkSelfTypes(t, td, type);
                checkExtensionOfMemberType(t, td, type);
                /*if (!(td instanceof TypeParameter)) {
                    checkCaseOfSupertype(t, td, type);
View Full Code Here

    public void visit(Tree.CaseTypes that) {
        super.visit(that);
        //this forces every case to be a subtype of the
        //enumerated type, so that we can make use of the
        //enumerated type is equivalent to its cases
        TypeDeclaration td = (TypeDeclaration) that.getScope();
       
        //TODO: get rid of this awful hack:
        List<ProducedType> cases = td.getCaseTypes();
        td.setCaseTypes(null);
       
        if (td instanceof TypeParameter) {
            for (Tree.StaticType t: that.getTypes()) {
                for (Tree.StaticType ot: that.getTypes()) {
                    if (t==ot) break;
                    checkCasesDisjoint(t.getTypeModel(), ot.getTypeModel(), ot);
                }
            }
        }
        else {
            Set<TypeDeclaration> typeSet = new HashSet<TypeDeclaration>();
            for (Tree.StaticType st: that.getTypes()) {
                ProducedType type = st.getTypeModel();
                TypeDeclaration ctd = type.getDeclaration();
                if (type!=null && ctd!=null) {
                    type = type.resolveAliases();
                    ctd = type.getDeclaration();
                    if (!typeSet.add(ctd)) {
                        //this error is not really truly necessary
                        st.addError("duplicate case type: '" +
                                ctd.getName(unit) +
                                "' of '" + td.getName() + "'");
                    }
                    if (!(ctd instanceof TypeParameter)) {
                        //it's not a self type
                        if (checkDirectSubtype(td, st, type)) {
                            checkAssignable(type, td.getType(), st,
                                    getCaseTypeExplanation(td, type));
                        }
                        //note: this is a better, faster way to call
                        //      validateEnumeratedSupertypeArguments()
                        //      but unfortunately it winds up displaying
                        //      the error on the wrong node, confusing
                        //      the user
                        /*ProducedType supertype = type.getDeclaration().getType().getSupertype(td);
                        validateEnumeratedSupertypeArguments(t, type.getDeclaration(), supertype);*/
                    }
                    if (ctd instanceof ClassOrInterface && st instanceof Tree.SimpleType) {
                        Tree.TypeArgumentList tal = ((Tree.SimpleType) st).getTypeArgumentList();
                        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

    }

    private static boolean checkDirectSubtype(TypeDeclaration td, Node node,
            ProducedType type) {
        boolean found = false;
        TypeDeclaration ctd = type.getDeclaration();
        if (td instanceof Interface) {
            for (ProducedType st: ctd.getSatisfiedTypes()) {
                if (st!=null &&
                        st.resolveAliases().getDeclaration().equals(td)) {
                    found = true;
                }
            }
        }
        else if (td instanceof Class) {
            ProducedType et = ctd.getExtendedType();
            if (et!=null &&
                    et.resolveAliases().getDeclaration().equals(td)) {
                found = true;
            }
        }
        if (!found) {
            node.addError("case type is not a direct subtype of enumerated type: " +
                    ctd.getName(node.getUnit()));
        }
        return found;
    }
View Full Code Here

            !type.getDeclaration().isStaticallyImportable()) {
            Scope s = td;
            while (s!=null) {
                s = s.getContainer();
                if (s instanceof TypeDeclaration) {
                  TypeDeclaration otd = (TypeDeclaration) s;
                    if (otd.getType().isSubtypeOf(qt)) {
                        return;
                    }
                }
            }
            that.addError("qualifying type '" + qt.getProducedTypeName(unit) +
View Full Code Here

TOP

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

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.