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

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


            for (int i=0; i<params.size(); i++) {
                TypeParameter param = params.get(i);
                if ( param.isSelfType() && args.size()>i ) {
                    ProducedType arg = args.get(i);
                    if (arg==null) arg = new UnknownType(unit).getType();
                    TypeDeclaration std = param.getSelfTypedDeclaration();
                    ProducedType at;
                    TypeDeclaration mtd;
                    if (param.getContainer().equals(std)) {
                        at = td.getType();
                        mtd = td;
                    }
                    else {
                        //TODO: lots wrong here?
                        mtd = (TypeDeclaration) td.getMember(std.getName(), null, false);
                        at = mtd==null ? null : mtd.getType();
                    }
                    if (at!=null && !at.isSubtypeOf(arg) &&
                            !(mtd.getSelfType()!=null &&
                                mtd.getSelfType().isExactly(arg))) {
                        String help;
                        TypeDeclaration ad = arg.getDeclaration();
                        if (ad instanceof TypeParameter &&
                                ((TypeParameter) ad).getDeclaration().equals(td)) {
                            help = " (try making " + ad.getName() + " a self type of " + td.getName() + ")";
                        }
                        else if (ad instanceof Interface) {
                            help = " (try making " + td.getName() + " satisfy " + ad.getName() + ")";
                        }
                        else if (ad instanceof Class && td instanceof Class) {
                            help = " (try making " + td.getName() + " extend " + ad.getName() + ")";
                        }
                        else {
                            help = "";
                        }
                        that.addError("type argument does not satisfy self type constraint on type parameter '" +
View Full Code Here


    private void validateEnumeratedSupertypes(Node that, ClassOrInterface d) {
        ProducedType type = d.getType();
        for (ProducedType supertype: type.getSupertypes()) {
            if (!type.isExactly(supertype)) {
                TypeDeclaration std = supertype.getDeclaration();
                if (std.getCaseTypes()!=null && !std.getCaseTypes().isEmpty()) {
                    if (std.getCaseTypes().size()==1 &&
                            std.getCaseTypeDeclarations().get(0).isSelfType()) {
                        continue;
                    }
                    List<ProducedType> types =
                            new ArrayList<ProducedType>(std.getCaseTypes().size());
                    for (ProducedType ct: std.getCaseTypes()) {
                        ProducedType cst = type.getSupertype(ct.resolveAliases().getDeclaration());
                        if (cst!=null) {
                            types.add(cst);
                        }
                    }
                    if (types.isEmpty()) {
                        that.addError("not a subtype of any case of enumerated supertype: '" +
                                d.getName(unit) + "' is a subtype of '" + std.getName(unit) + "'");
                    }
                    else if (types.size()>1) {
                        StringBuilder sb = new StringBuilder();
                        for (ProducedType pt: types) {
                            sb.append("'").append(pt.getProducedTypeName(unit)).append("' and ");
                        }
                        sb.setLength(sb.length()-5);
                        that.addError("concrete type is a subtype of multiple cases of enumerated supertype '" +
                                std.getName(unit) + "': '" + d.getName(unit) + "' is a subtype of " + sb);
                    }
                }
            }
        }
    }
View Full Code Here

        }
    }

    private void validateEnumeratedSupertypeArgument(Node that, TypeDeclaration d,
            ProducedType supertype, TypeParameter p, ProducedType arg) {
        TypeDeclaration td = arg.getDeclaration();
        if (td instanceof TypeParameter) {
            TypeParameter tp = (TypeParameter) td;
            if (tp.getDeclaration().equals(d)) { //the argument is a type parameter of the declaration
                //check that the variance of the argument type parameter is
                //the same as the type parameter of the enumerated supertype
View Full Code Here

            that.setTypeModel( defaultType() );
        }
    }

    private ProducedType defaultType() {
        TypeDeclaration ut = new UnknownType(unit);
        Class ad = unit.getAnythingDeclaration();
        if (ad!=null) {
            ut.setExtendedType(ad.getType());
        }
        return ut.getType();
    }
View Full Code Here

        }
        finally {
            declarationLiteral = false;
        }
        ProducedType t;
        TypeDeclaration d;
        Tree.StaticType type = that.getType();
        Tree.BaseMemberExpression oe = that.getObjectExpression();
        Node errorNode;
    if (type != null) {
          t = type.getTypeModel();
          d = t.getDeclaration();
          errorNode = type;
        }
    else if (oe != null ) {
          t = oe.getTypeModel();
          d = t.getDeclaration();
          if (!d.isAnonymous()) {
            oe.addError("must be a reference to an anonymous class");
          }
          errorNode = oe;
        }
    else {
View Full Code Here

        }
        Tree.Identifier id = that.getIdentifier();
        if (id!=null) {
            String name = name(id);
            ProducedType qt = null;
            TypeDeclaration qtd = null;
            Tree.StaticType type = that.getType();
            Tree.BaseMemberExpression oe = that.getObjectExpression();
      if (type != null) {
              qt = type.getTypeModel();
              qtd = qt.getDeclaration();
            }
      else if (oe != null) {
              qt = oe.getTypeModel();
              qtd = qt.getDeclaration();
              if (!qtd.isAnonymous()) {
                oe.addError("must be a reference to an anonymous class");
              }
            }
            if (qt != null) {
              qt = qt.resolveAliases();
              if (qtd instanceof UnknownType) {
                // let it go, we already logged an error for the missing type
                return;
              }
              //checkNonlocalType(that.getType(), qtd);
              String container = "type '" + qtd.getName(unit) + "'";
              TypedDeclaration member =
                      getTypedMember(qtd, name, null, false, unit);
              if (member==null) {
                if (qtd.isMemberAmbiguous(name, unit, null, false)) {
                  that.addError("method or attribute is ambiguous: '" +
                      name + "' for " + container);
                }
                else {
                  that.addError("method or attribute does not exist: '" +
View Full Code Here

                            !currentTypeMembers.shared.isEmpty();
                    if (superMemberIsShared && currentMemberIsShared) {
                        boolean isMemberNameOnAncestor =
                                isMemberNameOnAncestor(currentType, name);
                        if (!isMemberNameOnAncestor) {
                            TypeDeclaration otherType =
                                    getTypeDeclarationFor(aggregateMembers);
                          if (!mixedInBySupertype(currentType.declaration,
                                  otherType, classOrInterface)) {
                            StringBuilder sb = new StringBuilder("may not inherit two declarations with the same name that do not share a common supertype: '");
                                sb.append(name)
                                  .append("' is defined by supertypes '")
                              .append(currentType.declaration.getName())
                              .append("' and '")
                              .append(otherType.getName())
                              .append("'");
                            that.addError(sb.toString());
                          }
                        }
                    }
View Full Code Here

                        boolean isMemberRefined =
                                isMemberRefined(orderedTypes,index,name,currentTypeMembers);
                        boolean isMemberNameOnAncestor =
                                isMemberNameOnAncestor(currentType, name);
                        if (!isMemberRefined && isMemberNameOnAncestor) {
                            TypeDeclaration otherType =
                                    getTypeDeclarationFor(aggregateMembers);
                          if (!mixedInBySupertype(currentType.declaration,
                                  otherType, classOrInterface)) {
                            StringBuilder sb = new StringBuilder("may not inherit two declarations with the same name unless redefined in subclass: '");
                                sb.append(name)
                                  .append("' is defined by supertypes '")
                              .append(currentType.declaration.getName())
                              .append("' and '")
                              .append(otherType.getName())
                              .append("'");
                            that.addError(sb.toString());
                          }
                        }
                    }
View Full Code Here

        return !currentType.declaration.getInheritedMembers(name).isEmpty();
    }

    private boolean mixedInBySupertype(TypeDeclaration currentType,
            TypeDeclaration otherType, ClassOrInterface classOrInterface) {
        TypeDeclaration et = classOrInterface.getExtendedTypeDeclaration();
        if (et!=null &&
                et.inherits(currentType) &&
                et.inherits(otherType)) {
            return true;
        }
        for (TypeDeclaration st:
                classOrInterface.getSatisfiedTypeDeclarations()) {
            if (st!=null &&
View Full Code Here

    private static final String DOC_LINK_VALUE = "value ";
    private static final String DOC_LINK_ALIAS = "alias ";

    private static boolean isIllegalAnnotationParameterType(ProducedType pt) {
        if (pt!=null) {
            TypeDeclaration ptd = pt.getDeclaration();
            if (ptd instanceof IntersectionType || ptd instanceof UnionType) {
                return true;
            }
            Unit unit = pt.getDeclaration().getUnit();
            if (!ptd.isAnnotation() && !isEnum(ptd) &&
                    !ptd.equals(unit.getBooleanDeclaration()) &&
                    !ptd.equals(unit.getStringDeclaration()) &&
                    !ptd.equals(unit.getIntegerDeclaration()) &&
                    !ptd.equals(unit.getFloatDeclaration()) &&
                    !ptd.equals(unit.getCharacterDeclaration()) &&
                    !ptd.equals(unit.getIterableDeclaration()) &&
                    !ptd.equals(unit.getSequentialDeclaration()) &&
                    !pt.isSubtypeOf(unit.getType(unit.getDeclarationDeclaration()))) {
                return true;
            }
            if (ptd.equals(unit.getIterableDeclaration()) ||
                    ptd.equals(unit.getSequentialDeclaration())) {
                if (isIllegalAnnotationParameterType(unit.getIteratedType(pt))) {
                    return true;
                }
            }
        }
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.