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());
    }

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

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

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

}

@@ -1390,38 +1390,65 @@
 rationModel());%0A
+        super.visit(that);%0A
     %7D%0A
-
 %0A    @Override%0A 
@@ -1550,32 +1550,59 @@
 rationModel());%0A
+        super.visit(that);%0A
     %7D%0A%0A    @Over
@@ -1650,32 +1650,32 @@
 inition that) %7B%0A
-
         gen.enco
@@ -1704,32 +1704,59 @@
 rationModel());%0A
+        super.visit(that);%0A
     %7D%0A%0A    @Over

call super.visit