Search in sources :

Example 56 with Class

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

the class TypeHierarchyVisitor method visit.

@Override
public void visit(Tree.ObjectExpression that) {
    super.visit(that);
    Class anonymousClass = that.getAnonymousClass();
    // an object definition is always concrete
    List<Type> orderedTypes = sortDAGAndBuildMetadata(anonymousClass, that);
    checkForFormalsNotImplemented(that, orderedTypes, anonymousClass);
    checkForDoubleMemberInheritanceNotOverridden(that, orderedTypes, anonymousClass);
    checkForDoubleMemberInheritanceWoCommonAncestor(that, orderedTypes, anonymousClass);
    validateMemberRefinement(that, anonymousClass);
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 57 with Class

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

the class TypeHierarchyVisitor method visit.

@Override
public void visit(Tree.ObjectDefinition that) {
    super.visit(that);
    Value value = that.getDeclarationModel();
    Class anonymousClass = that.getAnonymousClass();
    // an object definition is always concrete
    List<Type> orderedTypes = sortDAGAndBuildMetadata(value.getTypeDeclaration(), that);
    checkForFormalsNotImplemented(that, orderedTypes, anonymousClass);
    checkForDoubleMemberInheritanceNotOverridden(that, orderedTypes, anonymousClass);
    checkForDoubleMemberInheritanceWoCommonAncestor(that, orderedTypes, anonymousClass);
    validateMemberRefinement(that, anonymousClass);
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 58 with Class

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

the class TypeVisitor method visit.

@Override
public void visit(Tree.SequenceType that) {
    super.visit(that);
    Tree.StaticType elementType = that.getElementType();
    Tree.NaturalLiteral length = that.getLength();
    Type et = elementType.getTypeModel();
    if (et != null) {
        Type t;
        if (length == null) {
            t = unit.getSequentialType(et);
        } else {
            final int len;
            try {
                len = parseInt(length.getText());
            } catch (NumberFormatException nfe) {
                length.addError("must be a positive decimal integer");
                return;
            }
            if (len < 1) {
                length.addError("must be positive");
                return;
            }
            if (len > 1000) {
                length.addError("may not be greater than 1000");
                return;
            }
            Class td = unit.getTupleDeclaration();
            t = unit.getEmptyType();
            for (int i = 0; i < len; i++) {
                t = appliedType(td, et, et, t);
            }
        }
        that.setTypeModel(t);
    }
}
Also used : NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) 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) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass)

Example 59 with Class

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

the class TypeVisitor method visit.

/* private boolean hasSharedConstructors(Class cd) {
        for (Declaration m: cd.getMembers()) {
            if (m instanceof Constructor &&
                    m.isShared()) {
                return true;
            }
        }
        return false;
    }*/
@Override
public void visit(Tree.InterfaceDefinition that) {
    Interface id = that.getDeclarationModel();
    id.setExtendedType(null);
    id.getSatisfiedTypes().clear();
    Class od = unit.getObjectDeclaration();
    if (od != null) {
        id.setExtendedType(od.getType());
    }
    super.visit(that);
}
Also used : Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) 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 60 with Class

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

the class TypeVisitor method visit.

@Override
public void visit(Tree.SatisfiedTypes that) {
    super.visit(that);
    TypeDeclaration td = (TypeDeclaration) that.getScope();
    if (td.isAlias()) {
        return;
    }
    List<Tree.StaticType> types = that.getTypes();
    List<Type> list = new ArrayList<Type>(types.size());
    if (types.isEmpty()) {
        that.addError("missing types in satisfies");
    }
    boolean foundTypeParam = false;
    boolean foundClass = false;
    boolean foundInterface = false;
    for (Tree.StaticType st : types) {
        inheritedType(st);
        Type type = st.getTypeModel();
        if (type != null) {
            TypeDeclaration std = type.getDeclaration();
            if (std != null && !(std instanceof UnknownType)) {
                if (std == td) {
                // unnecessary, handled by SupertypeVisitor
                // st.addError("directly extends itself: '" +
                // td.getName() + "'");
                } else if (std instanceof NothingType) {
                    st.addError("satisfies the bottom type 'Nothing'");
                } else if (std instanceof TypeAlias) {
                    st.addError("satisfies a type alias: '" + type.getDeclaration().getName(unit) + "'");
                } else if (std instanceof Constructor) {
                // nothing to do
                } else if (td instanceof TypeParameter) {
                    if (foundTypeParam) {
                        st.addUnsupportedError("type parameter upper bounds are not yet supported in combination with other bounds");
                    } else if (std instanceof TypeParameter) {
                        if (foundClass || foundInterface) {
                            st.addUnsupportedError("type parameter upper bounds are not yet supported in combination with other bounds");
                        }
                        foundTypeParam = true;
                        list.add(type);
                    } else if (std instanceof Class) {
                        if (foundClass) {
                            st.addUnsupportedError("multiple class upper bounds are not yet supported");
                        }
                        foundClass = true;
                        list.add(type);
                    } else if (std instanceof Interface) {
                        foundInterface = true;
                        list.add(type);
                    } else {
                        st.addError("upper bound must be a class, interface, or type parameter");
                    }
                } else {
                    if (std instanceof TypeParameter) {
                        st.addError("directly satisfies type parameter: '" + std.getName(unit) + "'");
                    } else if (std instanceof Class) {
                        st.addError("satisfies a class: '" + std.getName(unit) + "'");
                    } else if (std instanceof Interface) {
                        if (td.isDynamic() && !std.isDynamic()) {
                            st.addError("dynamic interface satisfies a non-dynamic interface: '" + std.getName(unit) + "'");
                        } else {
                            list.add(type);
                        }
                    } else {
                        st.addError("satisfied type must be an interface");
                    }
                }
            }
        }
    }
    td.setSatisfiedTypes(list);
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.setTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.setTypeConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) ArrayList(java.util.ArrayList) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) 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) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) 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)

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