Search in sources :

Example 11 with Unit

use of org.eclipse.ceylon.model.typechecker.model.Unit 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 12 with Unit

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

the class AnnotationVisitor method getExecutableStatements.

private static List<Tree.Statement> getExecutableStatements(Tree.Body block) {
    List<Tree.Statement> list = new ArrayList<Tree.Statement>();
    Unit unit = block.getUnit();
    for (Tree.Statement s : block.getStatements()) {
        if (isExecutableStatement(unit, s)) {
            list.add(s);
        }
    }
    return list;
}
Also used : AnalyzerUtil.isExecutableStatement(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isExecutableStatement) ArrayList(java.util.ArrayList) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 13 with Unit

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

the class AnnotationVisitor method isIllegalAnnotationParameterType.

private static boolean isIllegalAnnotationParameterType(Type pt) {
    if (pt != null) {
        if (pt.isIntersection() || pt.isUnion()) {
            return true;
        }
        TypeDeclaration ptd = pt.getDeclaration();
        Unit unit = ptd.getUnit();
        if (!ptd.isAnnotation() && !isEnum(ptd) && !pt.isBoolean() && !pt.isString() && !pt.isInteger() && !pt.isFloat() && !pt.isCharacter() && !pt.isIterable() && !pt.isSequential() && !pt.isSequence() && !pt.isSubtypeOf(unit.getType(unit.getDeclarationDeclaration()))) {
            return true;
        }
        if (pt.isIterable() || pt.isSequential() || pt.isSequence()) {
            Type elementType = unit.getIteratedType(pt);
            if (isIllegalAnnotationParameterType(elementType)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 14 with Unit

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

the class AnnotationVisitor method visit.

@Override
public void visit(Tree.AnyClass that) {
    super.visit(that);
    Class c = that.getDeclarationModel();
    if (c.isAnnotation()) {
        checkAnnotationType(that, c);
    }
    Unit unit = that.getUnit();
    checkAnnotations(that.getAnnotationList(), unit.getClassDeclarationType(c), unit.getClassMetatype(c.getType()), that);
    checkServiceAnnotations(c, that.getAnnotationList());
}
Also used : Class(org.eclipse.ceylon.model.typechecker.model.Class) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 15 with Unit

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

the class AnnotationVisitor method visit.

@Override
public void visit(Tree.Enumerated that) {
    super.visit(that);
    Value v = that.getDeclarationModel();
    Unit unit = that.getUnit();
    // TODO: metamodel types for Enumerated!!
    checkAnnotations(that.getAnnotationList(), unit.getValueConstructorDeclarationType(), unit.getValueMetatype(v.getTypedReference()), that);
}
Also used : FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Aggregations

Unit (org.eclipse.ceylon.model.typechecker.model.Unit)82 Type (org.eclipse.ceylon.model.typechecker.model.Type)41 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)31 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)25 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)23 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)16 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)11 ArrayList (java.util.ArrayList)10 Class (org.eclipse.ceylon.model.typechecker.model.Class)10 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)10 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)9 Function (org.eclipse.ceylon.model.typechecker.model.Function)9 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)9 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)9 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)9 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)7 Module (org.eclipse.ceylon.model.typechecker.model.Module)7 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)6 LazyType (org.eclipse.ceylon.model.typechecker.model.LazyType)6