Search in sources :

Example 1 with LazyClass

use of com.redhat.ceylon.model.loader.model.LazyClass in project ceylon-compiler by ceylon.

the class Strategy method generateJpaCtor.

static boolean generateJpaCtor(ClassOrInterface declarationModel) {
    if (declarationModel instanceof Class && !(declarationModel instanceof ClassAlias) && declarationModel.isToplevel()) {
        Class cls = (Class) declarationModel;
        if (cls.getCaseValues() != null && !cls.getCaseValues().isEmpty()) {
            return false;
        }
        if (hasNullaryNonJpaConstructor(cls)) {
            // The class will already have a nullary ctor
            return false;
        }
        boolean hasDelegatableSuper = false;
        Class superClass = (Class) cls.getExtendedType().getDeclaration();
        if (superClass instanceof LazyClass && !((LazyClass) superClass).isCeylon()) {
            if (superClass.isAbstraction()) {
                for (Declaration s : superClass.getOverloads()) {
                    if (s instanceof Class && isNullary((Class) s)) {
                        hasDelegatableSuper = true;
                        break;
                    }
                }
            } else {
                // If the superclass is Java then generate a Jpa constructor
                // if there's a nullary superclass constructor we can call
                hasDelegatableSuper = isNullary(superClass);
            }
        } else {
            hasDelegatableSuper = hasNullaryNonJpaConstructor(superClass) || hasJpaConstructor(superClass);
        }
        boolean constrained = (cls.getCaseValues() != null && !cls.getCaseValues().isEmpty()) || cls.hasEnumerated() && Decl.hasOnlyValueConstructors(cls);
        return hasDelegatableSuper && !constrained;
    } else {
        return false;
    }
}
Also used : ClassAlias(com.redhat.ceylon.model.typechecker.model.ClassAlias) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) MethodDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass)

Example 2 with LazyClass

use of com.redhat.ceylon.model.loader.model.LazyClass in project ceylon-compiler by ceylon.

the class DeclarationErrorVisitor method visit.

public void visit(Tree.ExtendedType that) {
    that.getType().visit(this);
    // error if we tried to generate a ctor for this class.
    if (that.getType().getDeclarationModel() instanceof LazyClass && !((LazyClass) that.getType().getDeclarationModel()).isCeylon()) {
        boolean hasPrivateCtor = false;
        List<Declaration> overloads = ((LazyClass) that.getType().getDeclarationModel()).getOverloads();
        if (overloads != null) {
            for (Declaration ctor : overloads) {
                if (!ctor.isShared()) {
                    hasPrivateCtor = true;
                    break;
                }
            }
        }
        if (hasPrivateCtor) {
            that.getInvocationExpression().visit(this);
        }
    }
}
Also used : Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass)

Aggregations

LazyClass (com.redhat.ceylon.model.loader.model.LazyClass)2 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)2 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)1 Class (com.redhat.ceylon.model.typechecker.model.Class)1 ClassAlias (com.redhat.ceylon.model.typechecker.model.ClassAlias)1 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)1