Search in sources :

Example 56 with TypeDeclaration

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

the class ClassTransformer method addAtMembers.

private void addAtMembers(ClassDefinitionBuilder classBuilder, ClassOrInterface model, Tree.ClassOrInterface def) {
    List<JCExpression> members = List.nil();
    for (Declaration member : model.getMembers()) {
        if (member instanceof ClassOrInterface == false && member instanceof TypeAlias == false) {
            continue;
        }
        TypeDeclaration innerType = (TypeDeclaration) member;
        Tree.Declaration innerTypeTree = findInnerType(def, innerType.getName());
        if (innerTypeTree != null) {
            TransformationPlan plan = errors().hasDeclarationAndMarkBrokenness(innerTypeTree);
            if (plan instanceof Drop) {
                continue;
            }
        }
        if (innerType.isAlias() && innerTypeTree != null && Decl.isAncestorLocal(innerTypeTree))
            // for the same reason we do not generate aliases in transform(ClassOrInterface def) let's not list them
            continue;
        JCAnnotation atMember;
        // interfaces are moved to toplevel so they can lose visibility of member types if they are local
        if (Decl.isLocal(model) && model instanceof Interface)
            atMember = makeAtMember(innerType.getName());
        else
            atMember = makeAtMember(innerType.getType());
        members = members.prepend(atMember);
    }
    classBuilder.annotations(makeAtMembers(members));
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCPrimitiveTypeTree(com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) TypeAlias(com.redhat.ceylon.model.typechecker.model.TypeAlias) 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) TransformationPlan(com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(com.redhat.ceylon.model.loader.model.LazyInterface) Interface(com.redhat.ceylon.model.typechecker.model.Interface) Drop(com.redhat.ceylon.compiler.java.codegen.recovery.Drop)

Example 57 with TypeDeclaration

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

the class ClassTransformer method transformClassAlias.

private void transformClassAlias(final Tree.ClassDeclaration def, ClassDefinitionBuilder classBuilder) {
    ClassAlias model = (ClassAlias) def.getDeclarationModel();
    Type aliasedClass = model.getExtendedType();
    TypeDeclaration classOrCtor = def.getClassSpecifier().getType().getDeclarationModel();
    while (classOrCtor instanceof ClassAlias) {
        classOrCtor = ((ClassAlias) classOrCtor).getConstructor();
    }
    classBuilder.annotations(makeAtAlias(aliasedClass, classOrCtor instanceof Constructor ? (Constructor) classOrCtor : null));
    classBuilder.isAlias(true);
    MethodDefinitionBuilder instantiator = transformClassAliasInstantiator(def, model, aliasedClass);
    ClassDefinitionBuilder cbInstantiator = null;
    switch(Strategy.defaultParameterMethodOwner(model)) {
        case STATIC:
            cbInstantiator = classBuilder;
            break;
        case OUTER:
            cbInstantiator = classBuilder.getContainingClassBuilder();
            break;
        case OUTER_COMPANION:
            cbInstantiator = classBuilder.getContainingClassBuilder().getCompanionBuilder(Decl.getClassOrInterfaceContainer(model, true));
            break;
        default:
            throw BugException.unhandledEnumCase(Strategy.defaultParameterMethodOwner(model));
    }
    cbInstantiator.method(instantiator);
}
Also used : ClassAlias(com.redhat.ceylon.model.typechecker.model.ClassAlias) Type(com.redhat.ceylon.model.typechecker.model.Type) ThrowerCatchallConstructor(com.redhat.ceylon.compiler.java.codegen.recovery.ThrowerCatchallConstructor) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 58 with TypeDeclaration

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

the class ClassTransformer method addAtContainer.

private void addAtContainer(ClassDefinitionBuilder classBuilder, TypeDeclaration model) {
    Scope scope = Decl.getNonSkippedContainer((Scope) model);
    Scope declarationScope = Decl.getFirstDeclarationContainer((Scope) model);
    boolean inlineObjectInToplevelAttr = Decl.isTopLevelObjectExpressionType(model);
    if (scope == null || (scope instanceof Package && !inlineObjectInToplevelAttr) && scope == declarationScope)
        return;
    if (scope instanceof ClassOrInterface && scope == declarationScope && !inlineObjectInToplevelAttr && // we do not check for types inside initialiser section which are private and not captured because we treat them as members
    !(model instanceof Interface && Decl.hasLocalNotInitializerAncestor(model))) {
        ClassOrInterface container = (ClassOrInterface) scope;
        List<JCAnnotation> atContainer = makeAtContainer(container.getType());
        classBuilder.annotations(atContainer);
    } else {
        if (model instanceof Interface)
            classBuilder.annotations(makeLocalContainerPath((Interface) model));
        Declaration declarationContainer = getDeclarationContainer(model);
        classBuilder.annotations(makeAtLocalDeclaration(model.getQualifier(), declarationContainer == null));
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Package(com.redhat.ceylon.model.typechecker.model.Package) 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) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(com.redhat.ceylon.model.loader.model.LazyInterface) Interface(com.redhat.ceylon.model.typechecker.model.Interface) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 59 with TypeDeclaration

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

the class CeylonVisitor method visit.

// FIXME: also support Tree.SequencedTypeParameter
public void visit(Tree.TypeParameterDeclaration param) {
    TypeDeclaration container = (TypeDeclaration) param.getDeclarationModel().getContainer();
    classBuilder.typeParameter(param);
    ClassDefinitionBuilder companionBuilder = classBuilder.getCompanionBuilder(container);
    if (companionBuilder != null)
        companionBuilder.typeParameter(param);
}
Also used : TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 60 with TypeDeclaration

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

the class ClassTransformer method getFirstSatisfiedType.

private Type getFirstSatisfiedType(Type currentType, Interface iface) {
    Type found = null;
    TypeDeclaration currentDecl = currentType.getDeclaration();
    if (Decl.equal(currentDecl, iface)) {
        return currentType;
    }
    if (currentType.getExtendedType() != null) {
        Type supertype = currentType.getSupertype(currentType.getExtendedType().getDeclaration());
        found = getFirstSatisfiedType(supertype, iface);
        if (found != null)
            return found;
    }
    for (Type superInterfaceType : currentType.getSatisfiedTypes()) {
        found = getFirstSatisfiedType(superInterfaceType, iface);
        if (found != null)
            return found;
    }
    return null;
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)140 Type (com.redhat.ceylon.model.typechecker.model.Type)85 Test (org.junit.Test)51 Class (com.redhat.ceylon.model.typechecker.model.Class)40 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)37 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)36 IntersectionType (com.redhat.ceylon.model.typechecker.model.IntersectionType)33 UnionType (com.redhat.ceylon.model.typechecker.model.UnionType)33 TypeParser (com.redhat.ceylon.model.loader.TypeParser)32 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)32 Interface (com.redhat.ceylon.model.typechecker.model.Interface)27 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)24 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)20 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)19 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)19 Function (com.redhat.ceylon.model.typechecker.model.Function)18 ArrayList (java.util.ArrayList)17 JCTree (com.sun.tools.javac.tree.JCTree)16 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)14 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)14