package com.redhat.ceylon.compiler.js;

import java.util.Map;

import com.redhat.ceylon.compiler.loader.MetamodelGenerator;
import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.compiler.typechecker.tree.Visitor;

/** Generates the metamodel for all objects in a module.
 * 
 * @author Enrique Zamudio
 */
public class MetamodelVisitor extends Visitor {

    private final MetamodelGenerator gen;

    public MetamodelVisitor(Module module) {
        this.gen = new MetamodelGenerator(module);
    }

    /** Returns the in-memory model as a collection of maps.
     * The top-level map represents the module. */
    public Map<String, Object> getModel() {
        return gen.getModel();
    }

    @Override public void visit(Tree.MethodDeclaration that) {
        gen.encodeMethod(that.getDeclarationModel());
    }

    /** Create and store the model of a method definition. */
    @Override public void visit(Tree.MethodDefinition that) {
        gen.encodeMethod(that.getDeclarationModel());
    }

    /** Create and store the metamodel info for an attribute. */
    @Override public void visit(Tree.AttributeDeclaration that) {
        gen.encodeAttribute(that.getDeclarationModel());
    }

    @Override
    public void visit(Tree.ClassDefinition that) {
        gen.encodeClass(that.getDeclarationModel());
        super.visit(that);
    }

    @Override
    public void visit(Tree.InterfaceDefinition that) {
        gen.encodeInterface(that.getDeclarationModel());
        super.visit(that);
    }

    @Override
    public void visit(Tree.ObjectDefinition that) {
        gen.encodeObject(that.getDeclarationModel());
        super.visit(that);
    }

    @Override
    public void visit(Tree.AttributeGetterDefinition that) {
        gen.encodeGetter(that.getDeclarationModel());
    }

    @Override
    public void visit(Tree.TypeAliasDeclaration that) {
        gen.encodeTypeAlias(that.getDeclarationModel());
    }
    @Override
    public void visit(Tree.ClassDeclaration that) {
        gen.encodeClass(that.getDeclarationModel());
    }
    @Override
    public void visit(Tree.InterfaceDeclaration that) {
        gen.encodeInterface(that.getDeclarationModel());
    }

}

@@ -885,38 +885,65 @@
 rationModel());%0A
+        super.visit(that);%0A
     %7D%0A
-
 %0A    /** Create 
@@ -1097,32 +1097,59 @@
 rationModel());%0A
+        super.visit(that);%0A
     %7D%0A%0A    /** C
@@ -1262,32 +1262,32 @@
 aration that) %7B%0A
-
         gen.enco
@@ -1319,32 +1319,59 @@
 rationModel());%0A
+        super.visit(that);%0A
     %7D%0A%0A    @Over
@@ -1952,24 +1952,51 @@
 onModel());%0A
+        super.visit(that);%0A
     %7D%0A%0A    @

call super.visit