Search in sources :

Example 6 with TransformationPlan

use of org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon by eclipse.

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.getDeclarationModel()))
            // 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(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) JCPrimitiveTypeTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) MethodDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 7 with TransformationPlan

use of org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon by eclipse.

the class ClassTransformer method transformClass.

// private void capturedReifiedTypeParameters(ClassOrInterface model,
// ClassDefinitionBuilder classBuilder) {
// if (model.isStatic()) {
// ClassOrInterface outer = (ClassOrInterface)model.getContainer();
// capturedReifiedTypeParameters(outer, classBuilder);
// classBuilder.reifiedTypeParameters(outer.getTypeParameters());
// }
// }
private void transformClass(Tree.AnyClass def, Class model, ClassDefinitionBuilder classBuilder, Tree.ParameterList paramList, boolean generateInstantiator, ClassDefinitionBuilder instantiatorDeclCb, ClassDefinitionBuilder instantiatorImplCb) {
    // do reified type params first
    // java.util.List<TypeParameter> typeParameters = typeParametersOfAllContainers(model, false);
    // for(TypeParameter tp : typeParameters){
    // classBuilder.typeParameter(tp, false);
    // }
    // capturedReifiedTypeParameters(model, classBuilder);
    classBuilder.reifiedTypeParameters(Strategy.getEffectiveTypeParameters(model));
    if (def.getParameterList() != null) {
        TransformationPlan error = errors().hasDeclarationAndMarkBrokenness(def);
        if (error instanceof ThrowerCatchallConstructor) {
            InitializerBuilder initBuilder = classBuilder.getInitBuilder();
            initBuilder.init(make().If(make().Literal(true), statementGen().makeThrowUnresolvedCompilationError(error.getErrorMessage().getMessage()), null));
        }
        for (Tree.Parameter param : def.getParameterList().getParameters()) {
            Tree.TypedDeclaration member = def != null ? Decl.getMemberDeclaration(def, param) : null;
            makeAttributeForValueParameter(classBuilder, param, member);
            makeMethodForFunctionalParameter(classBuilder, param, member);
        }
        transformClassOrCtorParameters(def, model, null, def, def.getParameterList(), false, classBuilder, classBuilder.getInitBuilder(), generateInstantiator, instantiatorDeclCb, instantiatorImplCb);
    }
    satisfaction(def.getSatisfiedTypes(), model, classBuilder);
    at(def);
    // Generate the inner members list for model loading
    addAtMembers(classBuilder, model, def);
    addAtLocalDeclarations(classBuilder, def);
    // Make sure top types satisfy reified type
    addReifiedTypeInterface(classBuilder, model);
}
Also used : ThrowerCatchallConstructor(org.eclipse.ceylon.compiler.java.codegen.recovery.ThrowerCatchallConstructor) JCPrimitiveTypeTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan)

Example 8 with TransformationPlan

use of org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon by eclipse.

the class CeylonVisitor method visit.

public void visit(Tree.ClassOrInterface decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    if (skipHeaderMergeLater(decl)) {
        return;
    }
    // To accept this class it is either not native or native for this backend
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    if (decl.getDeclarationModel().isClassOrInterfaceMember()) {
        if (decl.getDeclarationModel().isInterfaceMember()) {
            classBuilder.getCompanionBuilder((Interface) decl.getDeclarationModel().getContainer()).defs(gen.classGen().transform(decl));
        } else {
            classBuilder.defs(gen.classGen().transform(decl));
        }
    } else {
        appendList(gen.classGen().transform(decl));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 9 with TransformationPlan

use of org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon by eclipse.

the class CeylonVisitor method visit.

public void visit(Tree.AnyMethod decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    Function dec = decl.getDeclarationModel();
    if (dec.isClassOrInterfaceMember() && (!Decl.isDeferred(dec) || ModelUtil.isCaptured(dec))) {
        classBuilder.method(decl, plan);
    } else {
        appendList(gen.classGen().transformWrappedMethod(decl, plan));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 10 with TransformationPlan

use of org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon by eclipse.

the class CeylonVisitor method visit.

public void visit(Tree.AttributeGetterDefinition decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    Value dec = decl.getDeclarationModel();
    if (dec.isClassMember() && !ModelUtil.isLocalToInitializer(dec) || dec.isStatic()) {
        classBuilder.attribute(gen.classGen().transform(decl, false));
    } else if (dec.isInterfaceMember() && !ModelUtil.isLocalToInitializer(dec)) {
        classBuilder.attribute(gen.classGen().transform(decl, false));
        AttributeDefinitionBuilder adb = gen.classGen().transform(decl, true);
        if (dec.isShared()) {
            adb.ignoreAnnotations();
        }
        classBuilder.getCompanionBuilder((Interface) dec.getContainer()).attribute(adb);
    } else if (dec.isToplevel()) {
        topattrBuilder.add(decl);
    } else {
        appendList(gen.transform(decl));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Aggregations

TransformationPlan (org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan)11 Drop (org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)9 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)4 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)4 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)4 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)4 JCPrimitiveTypeTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree)3 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)3 ThrowerCatchallConstructor (org.eclipse.ceylon.compiler.java.codegen.recovery.ThrowerCatchallConstructor)2 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)2 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)2 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)2 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)2 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)2 Class (org.eclipse.ceylon.model.typechecker.model.Class)2 TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)2 Value (org.eclipse.ceylon.model.typechecker.model.Value)2 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)1 Generate (org.eclipse.ceylon.compiler.java.codegen.recovery.Generate)1 PrivateConstructorOnly (org.eclipse.ceylon.compiler.java.codegen.recovery.PrivateConstructorOnly)1