Search in sources :

Example 41 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class Decl method isPrivateAccessRequiringCompanion.

public static boolean isPrivateAccessRequiringCompanion(Tree.StaticMemberOrTypeExpression qual) {
    if (qual instanceof Tree.QualifiedMemberOrTypeExpression) {
        Tree.Primary primary = ((Tree.QualifiedMemberOrTypeExpression) qual).getPrimary();
        Declaration decl = qual.getDeclaration();
        return decl.isMember() && !decl.isShared() && decl.getContainer() instanceof Interface && !Decl.equalScopeDecl(decl.getContainer(), primary.getTypeModel().getDeclaration());
    }
    return false;
}
Also used : Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) LazyInterface(com.redhat.ceylon.model.loader.model.LazyInterface) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Example 42 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class ClassTransformer method addMissingUnrefinedMembers.

/** 
     * Recover from members not being refined in the class hierarchy 
     * by generating a stub method that throws.
     */
private void addMissingUnrefinedMembers(Node def, Class classModel, ClassDefinitionBuilder classBuilder) {
    for (Reference unrefined : classModel.getUnimplementedFormals()) {
        //classModel.getMember(memberName, null, false);
        Declaration formalMember = unrefined.getDeclaration();
        String errorMessage = "formal member '" + formalMember.getName() + "' of '" + ((TypeDeclaration) formalMember.getContainer()).getName() + "' not implemented in class hierarchy";
        java.util.List<Type> params = new java.util.ArrayList<Type>();
        if (formalMember instanceof Generic) {
            for (TypeParameter tp : ((Generic) formalMember).getTypeParameters()) {
                params.add(tp.getType());
            }
        }
        if (formalMember instanceof Value) {
            addRefinedThrowerAttribute(classBuilder, errorMessage, classModel, (Value) formalMember);
        } else if (formalMember instanceof Function) {
            addRefinedThrowerMethod(classBuilder, errorMessage, classModel, (Function) formalMember);
        } else if (formalMember instanceof Class && formalMember.isClassMember()) {
            addRefinedThrowerInstantiatorMethod(classBuilder, errorMessage, classModel, (Class) formalMember, unrefined);
        }
    // formal member class of interface handled in
    // makeDelegateToCompanion()
    }
}
Also used : TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Reference(com.redhat.ceylon.model.typechecker.model.Reference) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) Generic(com.redhat.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(com.redhat.ceylon.model.loader.model.JavaBeanValue) Value(com.redhat.ceylon.model.typechecker.model.Value) Class(com.redhat.ceylon.model.typechecker.model.Class) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) 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) AttributeDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 43 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class Decl method isPrivateAccessRequiringUpcast.

/**
     * Is the member private and not visible from the primary (i.e. is an 
     * upcast required to be able to see that member) 
     */
public static boolean isPrivateAccessRequiringUpcast(Tree.StaticMemberOrTypeExpression qual) {
    if (qual instanceof Tree.QualifiedMemberOrTypeExpression) {
        Tree.Primary primary = ((Tree.QualifiedMemberOrTypeExpression) qual).getPrimary();
        Declaration decl = qual.getDeclaration();
        return decl.isMember() && !decl.isShared() && !(decl instanceof Constructor) && decl.getContainer() instanceof Class && !Decl.equalScopeDecl(decl.getContainer(), primary.getTypeModel().getDeclaration());
    }
    return false;
}
Also used : Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 44 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class DefiniteAssignmentVisitor method visit.

public void visit(Tree.SpecifierStatement stmt) {
    Tree.Term bme = stmt.getBaseMemberExpression();
    if (bme instanceof Tree.MemberOrTypeExpression) {
        Declaration decl = ((Tree.MemberOrTypeExpression) bme).getDeclaration();
        if (// non-variable and deferred
        tracked.containsKey(decl) && // specification is in a for/else
        forBlock != null && !forBlock.equals(tracked.get(decl))) {
            // not declared in *this* for/else
            if (elseBlock == null) {
                ((Value) decl).setSpecifiedInForElse(true);
            }
            ControlBlock assigningBlock = elseBlock != null ? elseBlock : forBlock;
            Set<Value> assigned = assigningBlock.getSpecifiedValues();
            if (assigned == null) {
                assigned = new HashSet<Value>(1);
                assigningBlock.setSpecifiedValues(assigned);
            }
            assigned.add((Value) decl);
        }
    }
    super.visit(stmt);
}
Also used : ControlBlock(com.redhat.ceylon.model.typechecker.model.ControlBlock) Value(com.redhat.ceylon.model.typechecker.model.Value) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration)

Example 45 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration 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)

Aggregations

Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)107 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)95 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)80 Type (com.redhat.ceylon.model.typechecker.model.Type)34 Function (com.redhat.ceylon.model.typechecker.model.Function)33 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)30 Class (com.redhat.ceylon.model.typechecker.model.Class)28 Value (com.redhat.ceylon.model.typechecker.model.Value)28 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)27 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)27 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)24 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)22 JCTree (com.sun.tools.javac.tree.JCTree)22 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)21 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)20 Interface (com.redhat.ceylon.model.typechecker.model.Interface)20 Scope (com.redhat.ceylon.model.typechecker.model.Scope)20 Package (com.redhat.ceylon.model.typechecker.model.Package)17 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)17 ArrayList (java.util.ArrayList)16