Search in sources :

Example 96 with Type

use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.

the class AnalyzerUtil method spreadType.

static Type spreadType(Type et, Unit unit, boolean requireSequential) {
    if (et == null)
        return null;
    if (requireSequential) {
        if (unit.isSequentialType(et)) {
            // if (et.isTypeParameter()) {
            return et;
        /*}
                else {
                    // if it's already a subtype of Sequential, erase 
                    // out extraneous information, like that it is a
                    // String, just keeping information about what
                    // kind of tuple it is
                    List<Type> elementTypes = unit.getTupleElementTypes(et);
                    boolean variadic = unit.isTupleLengthUnbounded(et);
                    boolean atLeastOne = unit.isTupleVariantAtLeastOne(et);
                    int minimumLength = unit.getTupleMinimumLength(et);
                    if (variadic) {
                        Type spt = elementTypes.get(elementTypes.size()-1);
                        elementTypes.set(elementTypes.size()-1, unit.getIteratedType(spt));
                    }
                    return unit.getTupleType(elementTypes, variadic, 
                            atLeastOne, minimumLength);
                }*/
        } else {
            // transform any Iterable into a Sequence without
            // losing the information that it is nonempty, in
            // the case that we know that for sure
            Type it = unit.getElementType(et);
            Type st = unit.isNonemptyIterableType(et) ? unit.getSequenceType(it) : unit.getSequentialType(it);
            // for now, just return the sequential type:
            return st;
        }
    } else {
        return et;
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)

Example 97 with Type

use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.

the class AnalyzerUtil method checkCasesDisjoint.

static boolean checkCasesDisjoint(Type later, Type earlier, Node node, String hint) {
    if (!isTypeUnknown(later) && !isTypeUnknown(earlier)) {
        Unit unit = node.getUnit();
        Type it = intersectionType(later.resolveAliases(), earlier.resolveAliases(), unit);
        if (!it.isNothing()) {
            if (earlier.isExactly(later)) {
                node.addError("case is not disjoint: there is another case of type '" + earlier.asString(unit) + "'" + hint);
            } else if (earlier.isSubtypeOf(later)) {
                node.addError("case is not disjoint: '" + later.asString(unit) + "' contains '" + earlier.asString(unit) + "'" + hint);
            } else {
                node.addError("case is not disjoint: '" + later.asString(unit) + "' and '" + earlier.asString(unit) + "' have intersection '" + it.asString(unit) + "'" + hint);
            }
            return false;
        }
    }
    return true;
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 98 with Type

use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.

the class AnalyzerUtil method unwrapAliasedTypeConstructor.

static TypeDeclaration unwrapAliasedTypeConstructor(TypeDeclaration dec) {
    TypeDeclaration d = dec;
    while (!d.isParameterized() && d.isAlias()) {
        Type et = d.getExtendedType();
        if (et == null)
            break;
        et = et.resolveAliases();
        d = et.getDeclaration();
        if (et.isTypeConstructor() && d.isParameterized()) {
            return d;
        }
    }
    return dec;
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 99 with Type

use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.

the class AnalyzerUtil method isAlwaysSatisfied.

public static boolean isAlwaysSatisfied(Tree.ConditionList cl) {
    if (cl == null)
        return false;
    for (Tree.Condition c : cl.getConditions()) {
        if (c instanceof Tree.BooleanCondition) {
            Tree.BooleanCondition bc = (Tree.BooleanCondition) c;
            Tree.Expression ex = bc.getExpression();
            if (ex != null) {
                Type type = ex.getTypeModel();
                if (type != null && type.getDeclaration().isTrueValue()) {
                    continue;
                }
            }
        }
        return false;
    }
    return true;
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 100 with Type

use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.

the class AnnotationVisitor method checkAnnotationType.

private void checkAnnotationType(Tree.AnyClass that, Class c) {
    if (c.isParameterized()) {
        that.addError("annotation class may not be a parameterized type");
    }
    /*if (c.isAbstract()) {
            that.addError("annotation class may not be abstract");
        }*/
    if (!c.isFinal()) {
        that.addError("annotation class must be final");
    }
    Type et = c.getExtendedType();
    if (et != null) {
        if (!et.isBasic()) {
            that.addError("annotation class must directly extend 'Basic'");
        }
    }
    for (Tree.Parameter pn : that.getParameterList().getParameters()) {
        checkAnnotationParameter(c, pn);
    }
    if (that instanceof Tree.ClassDefinition) {
        Tree.ClassDefinition cd = (Tree.ClassDefinition) that;
        Tree.ClassBody body = cd.getClassBody();
        if (body != null && !getExecutableStatements(body).isEmpty()) {
            that.addError("annotation class body may not contain executable statements");
        }
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Aggregations

Type (org.eclipse.ceylon.model.typechecker.model.Type)692 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)270 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)263 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)244 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)225 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)207 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)182 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)176 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)176 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)169 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)153 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)130 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)125 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)114 ArrayList (java.util.ArrayList)106 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)100 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)96 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)95 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)94 Class (org.eclipse.ceylon.model.typechecker.model.Class)87