}
return new JsObjectLiteral(SourceOrigin.UNKNOWN);
}
private void maybeGenerateClassLiteral(JType type, JsVars vars) {
JDeclarationStatement decl = classLiteralDeclarationsByType.get(type);
if (decl == null) {
return;
}
JField field = (JField) decl.getVariableRef().getTarget();
// TODO(rluble): refactor so that all output related to a class is decided together.
if (type != null && type instanceof JDeclaredType
&& program.isReferenceOnly((JDeclaredType) type)) {
// Only generate class literals for classes in the current module.
// TODO(rluble): In separate compilation some class literals will be duplicated, which if
// not done with care might violate java semantics of getClass(). There are class literals
// for primitives and arrays. Currently, because they will be assigned to the same field
// the one defined later will be the one used and Java semantics are preserved.
return;
}
JsName jsName = names.get(field);
this.accept(decl.getInitializer());
JsExpression classObjectAlloc = pop();
JsVar var = new JsVar(decl.getSourceInfo(), jsName);
var.setInitExpr(classObjectAlloc);
vars.add(var);
}