use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.ValueLiteral in project ceylon by eclipse.
the class MetamodelHelper method generateMemberLiteral.
static void generateMemberLiteral(final Tree.MemberLiteral that, final GenerateJsVisitor gen) {
final org.eclipse.ceylon.model.typechecker.model.Reference ref = that.getTarget();
Type ltype = that.getType() == null ? null : that.getType().getTypeModel().resolveAliases();
final Declaration d = ref.getDeclaration();
final Class anonClass = d.isMember() && d.getContainer() instanceof Class && ((Class) d.getContainer()).isAnonymous() ? (Class) d.getContainer() : null;
if (that instanceof Tree.FunctionLiteral || d instanceof Function) {
if (ModelUtil.isConstructor(d)) {
constructorLiteral(ref.getType(), TypeUtils.getConstructor(d), that, gen);
return;
}
gen.out(gen.getClAlias(), d.isMember() ? "AppliedMethod$jsint(" : "AppliedFunction$jsint(");
if (anonClass != null) {
gen.qualify(that, anonClass);
gen.out(gen.getNames().objectName(anonClass), ".");
} else if (ltype == null) {
gen.qualify(that, d);
} else {
if (ltype.isUnion() || ltype.isIntersection()) {
if (d.getContainer() instanceof TypeDeclaration) {
ltype = ((TypeDeclaration) d.getContainer()).getType();
} else if (d.getContainer() instanceof TypedDeclaration) {
ltype = ((TypedDeclaration) d.getContainer()).getType();
}
}
if (ltype.getDeclaration().isMember()) {
outputPathToDeclaration(that, ltype.getDeclaration(), gen);
} else {
gen.qualify(that, ltype.getDeclaration());
}
gen.out(gen.getNames().name(ltype.getDeclaration()));
gen.out(d.isStatic() ? ".$st$." : ".$$.prototype.");
}
if (d instanceof Value) {
gen.out(gen.getNames().getter(d, true), ",");
} else {
gen.out(gen.getNames().name(d), ",");
}
if (d.isMember()) {
if (that.getTypeArgumentList() != null) {
List<Type> typeModels = that.getTypeArgumentList().getTypeModels();
if (typeModels != null) {
gen.out("[");
boolean first = true;
for (Type targ : typeModels) {
if (first)
first = false;
else
gen.out(",");
gen.out(gen.getClAlias(), "typeLiteral$meta({Type$typeLiteral:");
TypeUtils.typeNameOrList(that, targ, gen, false);
gen.out("})");
}
gen.out("]");
gen.out(",");
} else {
gen.out("undefined,");
}
} else {
gen.out("undefined,");
}
TypeUtils.printTypeArguments(that, that.getTypeModel().getTypeArguments(), gen, false, that.getTypeModel().getVarianceOverrides());
} else {
TypeUtils.printTypeArguments(that, that.getTypeModel().getTypeArguments(), gen, false, that.getTypeModel().getVarianceOverrides());
if (ref.getTypeArguments() != null && !ref.getTypeArguments().isEmpty()) {
gen.out(",undefined,");
TypeUtils.printTypeArguments(that, ref.getTypeArguments(), gen, false, ref.getType().getVarianceOverrides());
}
}
gen.out(")");
} else if (that instanceof ValueLiteral || d instanceof Value) {
if (ModelUtil.isConstructor(d)) {
constructorLiteral(ref.getType(), TypeUtils.getConstructor(d), that, gen);
return;
}
Value vd = (Value) d;
if (vd.isMember()) {
gen.out(gen.getClAlias(), "$init$AppliedAttribute$meta$model()('");
gen.out(d.getName(), "',");
} else {
gen.out(gen.getClAlias(), "$init$AppliedValue$jsint()(undefined,");
}
if (anonClass != null) {
gen.qualify(that, anonClass);
gen.out(gen.getNames().objectName(anonClass), ".");
} else if (ltype == null) {
gen.qualify(that, d);
} else {
gen.qualify(that, ltype.getDeclaration());
gen.out(gen.getNames().name(ltype.getDeclaration()));
gen.out(d.isStatic() ? ".$st$." : ".$$.prototype.");
}
gen.out(gen.getNames().getter(vd, true), ",");
TypeUtils.printTypeArguments(that, that.getTypeModel().getTypeArguments(), gen, false, that.getTypeModel().getVarianceOverrides());
gen.out(")");
} else {
gen.out(gen.getClAlias(), "/*TODO:closed member literal*/typeLiteral$meta({Type$typeLiteral:");
gen.out("{t:");
if (ltype == null) {
gen.qualify(that, d);
} else {
gen.qualify(that, ltype.getDeclaration());
gen.out(gen.getNames().name(ltype.getDeclaration()));
gen.out(d.isStatic() ? ".$st$." : ".$$.prototype.");
}
gen.out(gen.getNames().name(d));
if (ltype != null && ltype.getTypeArguments() != null && !ltype.getTypeArguments().isEmpty()) {
gen.out(",a:");
TypeUtils.printTypeArguments(that, ltype.getTypeArguments(), gen, false, ltype.getVarianceOverrides());
}
gen.out("}})");
}
}
Aggregations