Search in sources :

Example 11 with Class

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

the class AnalyzerUtil method getTupleType.

public static Type getTupleType(List<Tree.PositionalArgument> es, Unit unit, boolean requireSequential) {
    Type result = unit.getEmptyType();
    Type ut = unit.getNothingType();
    Class td = unit.getTupleDeclaration();
    Interface id = unit.getIterableDeclaration();
    for (int i = es.size() - 1; i >= 0; i--) {
        Tree.PositionalArgument a = es.get(i);
        Type t = a.getTypeModel();
        if (t != null) {
            // unit.denotableType(t);
            Type et = t;
            if (a instanceof Tree.SpreadArgument) {
                /*if (requireSequential) { 
                        checkSpreadArgumentSequential((Tree.SpreadArgument) a, et);
                    }*/
                if (unit.isIterableType(et)) {
                    ut = unit.getIteratedType(et);
                    result = spreadType(et, unit, requireSequential);
                } else if (unit.isJavaIterableType(et)) {
                    ut = unit.getJavaIteratedType(et);
                    result = unit.getSequentialType(ut);
                } else if (unit.isJavaArrayType(et)) {
                    ut = unit.getJavaArrayElementType(et);
                    result = unit.getSequentialType(ut);
                } else {
                    result = unit.getUnknownType();
                }
            } else if (a instanceof Tree.Comprehension) {
                ut = et;
                Tree.Comprehension c = (Tree.Comprehension) a;
                Tree.InitialComprehensionClause icc = c.getInitialComprehensionClause();
                result = icc.getPossiblyEmpty() ? unit.getSequentialType(et) : unit.getSequenceType(et);
                if (!requireSequential) {
                    Type it = appliedType(id, et, icc.getFirstTypeModel());
                    result = intersectionType(result, it, unit);
                }
            } else {
                ut = unionType(ut, et, unit);
                result = appliedType(td, ut, et, result);
            }
        }
    }
    return result;
}
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) Class(org.eclipse.ceylon.model.typechecker.model.Class) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 12 with Class

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

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.Enumerated that) {
    Constructor e = new Constructor();
    that.setEnumerated(e);
    visitDeclaration(that, e, false);
    Type at;
    if (scope instanceof Class) {
        Class clazz = (Class) scope;
        Type ot = clazz.getType();
        e.setExtendedType(ot);
        at = e.appliedType(ot, NO_TYPE_ARGS);
        clazz.setEnumerated(true);
        if (clazz.isAnonymous()) {
            that.addError("anonymous class may not have a value constructor: '" + clazz.getName() + "' is an anonymous class");
        } else if (clazz.isAbstract()) {
            that.addError("abstract class may not have a value constructor: '" + clazz.getName() + "' is abstract");
        } else if (!clazz.getTypeParameters().isEmpty()) {
            that.addError("generic class may not have a value constructor: '" + clazz.getName() + "' is generic");
        } else if (scope.getContainer() instanceof Interface) {
            that.addError("class nested inside an interface may not have a value constructor: '" + clazz.getName() + "' belongs to an interface");
        }
    } else {
        at = null;
        that.addError("value constructor declaration must occur directly in the body of a class");
    }
    Value v = new Value();
    v.setType(at);
    that.setDeclarationModel(v);
    visitDeclaration(that, v);
    Scope o = enterScope(e);
    super.visit(that);
    exitScope(o);
    v.setImplemented(that.getBlock() != null);
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) ModelUtil.isDefaultConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isDefaultConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) ModelUtil.isAnonymousClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isAnonymousClass) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 14 with Class

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.ObjectExpression that) {
    Class c = new Class();
    c.setName("anonymous#" + fid++);
    c.setNamed(false);
    defaultExtendedToBasic(c);
    c.setAnonymous(true);
    that.setAnonymousClass(c);
    visitArgument(that, c);
    Scope o = enterScope(c);
    super.visit(that);
    exitScope(o);
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) ModelUtil.isAnonymousClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isAnonymousClass)

Example 15 with Class

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.ObjectArgument that) {
    Class c = new Class();
    defaultExtendedToBasic(c);
    c.setAnonymous(true);
    that.setAnonymousClass(c);
    visitArgument(that, c);
    Value v = new Value();
    that.setDeclarationModel(v);
    visitArgument(that, v);
    Type t = c.getType();
    that.getType().setTypeModel(t);
    v.setType(t);
    Scope o = enterScope(c);
    super.visit(that);
    exitScope(o);
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) ModelUtil.isAnonymousClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isAnonymousClass)

Aggregations

Class (org.eclipse.ceylon.model.typechecker.model.Class)184 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)110 Type (org.eclipse.ceylon.model.typechecker.model.Type)87 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)78 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)72 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)55 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)46 Value (org.eclipse.ceylon.model.typechecker.model.Value)46 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)42 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)39 Function (org.eclipse.ceylon.model.typechecker.model.Function)38 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)36 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)35 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)33 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)33 ArrayList (java.util.ArrayList)32 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)32 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)31 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)27 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)23