}
static void classDefinition(final Tree.ClassDefinition that, final GenerateJsVisitor gen) {
//Don't even bother with nodes that have errors
if (errVisitor.hasErrors(that))return;
final Class d = that.getDeclarationModel();
gen.comment(that);
if (gen.shouldStitch(d)) {
if (gen.stitchNative(d, that)) {
if (d.isShared()) {
gen.share(d);
}
initializeType(that, gen);
return;
}
}
gen.out(GenerateJsVisitor.function, gen.getNames().name(d));
final boolean withTargs = generateParameters(that, gen);
gen.beginBlock();
//This takes care of top-level attributes defined before the class definition
gen.out("$init$", gen.getNames().name(d), "()");
gen.endLine(true);
gen.declareSelf(d);
gen.referenceOuter(d);
if (withTargs) {
gen.out(gen.getClAlias(), "set_type_args(", gen.getNames().self(d), ",$$targs$$)");
gen.endLine(true);
} else {
//Check if any of the satisfied types have type arguments
if (that.getSatisfiedTypes() != null) {
for(Tree.StaticType sat : that.getSatisfiedTypes().getTypes()) {
boolean first = true;
Map<TypeParameter,ProducedType> targs = sat.getTypeModel().getTypeArguments();
if (targs != null && !targs.isEmpty()) {
if (first) {
gen.out(gen.getNames().self(d), ".$$targs$$=");
TypeUtils.printTypeArguments(that, targs, gen, false, null);
gen.endLine(true);
first = false;
} else {
gen.out("/*TODO: more type arguments*/");
}
}
}
}
}
if (!d.isToplevel() && d.getContainer() instanceof Method && !((Method)d.getContainer()).getTypeParameters().isEmpty()) {
gen.out(gen.getClAlias(), "set_type_args(", gen.getNames().self(d), ",$$$mptypes)");
gen.endLine(true);
}
gen.initParameters(that.getParameterList(), d, null);
final List<Declaration> superDecs = new ArrayList<Declaration>(3);
if (!gen.opts.isOptimize()) {
new SuperVisitor(superDecs).visit(that.getClassBody());
}
callSuperclass(that.getExtendedType(), d, that, superDecs, gen);
callInterfaces(that.getSatisfiedTypes(), d, that, superDecs, gen);
if (!gen.opts.isOptimize()) {
//Fix #231 for lexical scope
for (Tree.Parameter p : that.getParameterList().getParameters()) {
if (!p.getParameterModel().isHidden()){
gen.generateAttributeForParameter(that, d, p.getParameterModel());
}
}
}
if (d.isNative()) {
gen.stitchConstructorHelper(that, "_cons_before");
}
that.getClassBody().visit(gen);
if (d.isNative()) {
gen.stitchConstructorHelper(that, "_cons_after");
}
gen.out("return ", gen.getNames().self(d), ";");
gen.endBlockNewLine();
//Add reference to metamodel