Search in sources :

Example 41 with ClassOrInterface

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.This that) {
    ClassOrInterface ci = getContainingClassOrInterface(that.getScope());
    if (inExtendsClause) {
        if (ci != null) {
            if (ci.isClassOrInterfaceMember()) {
                ClassOrInterface cci = (ClassOrInterface) ci.getContainer();
                that.setDeclarationModel(cci);
                that.setTypeModel(cci.getType());
            }
        }
    } else {
        if (ci == null) {
            that.addError("'this' occurs outside a class or interface definition");
        } else {
            that.setDeclarationModel(ci);
            that.setTypeModel(ci.getType());
        }
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) ModelUtil.getOuterClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getOuterClassOrInterface) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface)

Example 42 with ClassOrInterface

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

the class GenerateJsVisitor method addToPrototype.

private void addToPrototype(ClassOrInterface d, final Tree.Statement s, List<Parameter> params, InitDeferrer initDeferrer) {
    ClassOrInterface oldPrototypeOwner = prototypeOwner;
    prototypeOwner = d;
    if (s instanceof Tree.MethodDefinition) {
        addMethodToPrototype(d, (Tree.MethodDefinition) s);
    } else if (s instanceof Tree.MethodDeclaration) {
        // Don't even bother with nodes that have errors
        if (errVisitor.hasErrors(s))
            return;
        FunctionHelper.methodDeclaration(d, (Tree.MethodDeclaration) s, this, verboseStitcher);
    } else if (s instanceof Tree.AttributeGetterDefinition) {
        addGetterToPrototype(d, (Tree.AttributeGetterDefinition) s);
    } else if (s instanceof Tree.AttributeDeclaration) {
        AttributeGenerator.addGetterAndSetterToPrototype(d, (Tree.AttributeDeclaration) s, this, verboseStitcher);
    } else if (s instanceof Tree.ClassDefinition) {
        addClassToPrototype(d, (Tree.ClassDefinition) s, initDeferrer);
    } else if (s instanceof Tree.InterfaceDefinition) {
        addInterfaceToPrototype(d, (Tree.InterfaceDefinition) s, initDeferrer);
    } else if (s instanceof Tree.ObjectDefinition) {
        addObjectToPrototype(d, (Tree.ObjectDefinition) s, initDeferrer);
    } else if (s instanceof Tree.ClassDeclaration) {
        addClassDeclarationToPrototype(d, (Tree.ClassDeclaration) s);
    } else if (s instanceof Tree.InterfaceDeclaration) {
        addInterfaceDeclarationToPrototype(d, (Tree.InterfaceDeclaration) s);
    } else if (s instanceof Tree.SpecifierStatement) {
        addSpecifierToPrototype(d, (Tree.SpecifierStatement) s);
    } else if (s instanceof Tree.TypeAliasDeclaration) {
        addAliasDeclarationToPrototype(d, (Tree.TypeAliasDeclaration) s);
    }
    // This fixes #231 for prototype style
    if (params != null && s instanceof Tree.Declaration) {
        Declaration m = ((Tree.Declaration) s).getDeclarationModel();
        for (Iterator<Parameter> iter = params.iterator(); iter.hasNext(); ) {
            Parameter _p = iter.next();
            if (m.getName() != null && m.getName().equals(_p.getName())) {
                iter.remove();
                break;
            }
        }
    }
    prototypeOwner = oldPrototypeOwner;
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) ClassDefinition(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ClassDefinition) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)

Example 43 with ClassOrInterface

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

the class TypeGenerator method interfaceDefinition.

static void interfaceDefinition(final Tree.InterfaceDefinition that, final GenerateJsVisitor gen, InitDeferrer initDeferrer) {
    // Don't even bother with nodes that have errors
    if (errVisitor.hasErrors(that))
        return;
    final Interface d = that.getDeclarationModel();
    // If it's inside a dynamic interface, don't generate anything
    if (d.isClassOrInterfaceMember() && ((ClassOrInterface) d.getContainer()).isDynamic())
        return;
    final Interface natd = (Interface) ModelUtil.getNativeDeclaration(d, Backend.JavaScript);
    final boolean headerWithoutBackend = NativeUtil.isHeaderWithoutBackend(that, Backend.JavaScript);
    if (natd != null && (headerWithoutBackend || NativeUtil.isNativeHeader(that))) {
        // It's a native header, remember it for later when we deal with its implementation
        gen.saveNativeHeader(that);
        return;
    }
    if (!(NativeUtil.isForBackend(that, Backend.JavaScript) || headerWithoutBackend)) {
        return;
    }
    gen.comment(that);
    gen.out(GenerateJsVisitor.function, gen.getNames().name(d));
    final boolean withTargs = generateParameters(that.getTypeParameterList(), null, d, gen);
    gen.beginBlock();
    final List<Declaration> superDecs = new ArrayList<>(3);
    if (!gen.opts.isOptimize()) {
        new SuperVisitor(superDecs).visit(that.getInterfaceBody());
    }
    final Tree.SatisfiedTypes sats = that.getSatisfiedTypes();
    if (withTargs) {
        gen.out(gen.getClAlias(), "set_type_args(", gen.getNames().self(d), ",$$targs$$,", gen.getNames().name(d), ")");
        gen.endLine(true);
    }
    callSupertypes(sats == null ? null : TypeUtils.getTypes(sats.getTypes()), null, d, that, superDecs, null, null, gen);
    if (!d.isToplevel() && d.getContainer() instanceof Function && !((Function) d.getContainer()).getTypeParameters().isEmpty()) {
        gen.out(gen.getClAlias(), "set_type_args(", gen.getNames().self(d), ",", gen.getNames().typeArgsParamName((Function) d.getContainer()), ",", gen.getNames().name(d), ")");
        gen.endLine(true);
    }
    final List<Tree.Statement> stmts;
    if (NativeUtil.isForBackend(d, Backend.JavaScript)) {
        Tree.Declaration nh = gen.getNativeHeader(d);
        if (nh == null && NativeUtil.hasNativeMembers(d)) {
            nh = that;
        }
        stmts = NativeUtil.mergeStatements(that.getInterfaceBody(), nh, Backend.JavaScript);
    } else {
        stmts = that.getInterfaceBody().getStatements();
    }
    gen.visitStatements(stmts);
    // returnSelf(d);
    gen.endBlockNewLine();
    if (d.isDynamic()) {
        // Add the list of expected members here
        final List<Declaration> members = d.getMembers();
        gen.out(gen.getNames().name(d), ".dynmem$=[");
        if (members.isEmpty()) {
            gen.out("];");
        } else {
            gen.out("'");
            boolean first = true;
            for (Declaration m : members) {
                if (first)
                    first = false;
                else
                    gen.out("','");
                gen.out(gen.getNames().name(m));
            }
            gen.out("'];");
        }
    }
    // Add reference to metamodel
    gen.out(gen.getNames().name(d), ".$crtmm$=");
    TypeUtils.encodeForRuntime(that, d, that.getAnnotationList(), gen);
    gen.endLine(true);
    gen.share(d);
    initializeType(that, gen, initDeferrer);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) SuperVisitor(org.eclipse.ceylon.compiler.js.GenerateJsVisitor.SuperVisitor) ArrayList(java.util.ArrayList) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 44 with ClassOrInterface

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

the class BmeGenerator method generateStaticReference.

static void generateStaticReference(Node n, Declaration d, GenerateJsVisitor gen) {
    Declaration orig = d instanceof TypedDeclaration ? ((TypedDeclaration) d).getOriginalDeclaration() : d;
    ClassOrInterface coi = (ClassOrInterface) (orig == null ? d : orig).getContainer();
    gen.qualify(n, coi);
    gen.out(gen.getNames().name(coi), ".$st$.", gen.getNames().name(d));
    if (d instanceof Value && ((Value) d).getType().getDeclaration().isAnonymous()) {
        gen.out("()");
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Value(org.eclipse.ceylon.model.typechecker.model.Value) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 45 with ClassOrInterface

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

the class TypeParameterCaptureVisitor method visit.

@Override
public void visit(Tree.ClassOrInterface that) {
    ClassOrInterface model = that.getDeclarationModel();
    if (model != null && !model.isAlias() && !model.isToplevel() && !model.isMember()) {
        // it's a local type, capture!
        captureTypeParameters(model);
    }
    super.visit(that);
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Aggregations

ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)102 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)62 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)48 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)46 Type (org.eclipse.ceylon.model.typechecker.model.Type)44 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)27 Class (org.eclipse.ceylon.model.typechecker.model.Class)24 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)23 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)23 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)20 ModelUtil.getContainingClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface)19 Value (org.eclipse.ceylon.model.typechecker.model.Value)19 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)18 ArrayList (java.util.ArrayList)17 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)17 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)16 Function (org.eclipse.ceylon.model.typechecker.model.Function)14 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)13 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)12 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)12