use of org.eclipse.ceylon.model.typechecker.model.ClassAlias in project ceylon by eclipse.
the class GenerateJsVisitor method initParameters.
/**
* Initialize the sequenced, defaulted and captured parameters in a type declaration.
* @return The defaulted parameters that belong to a class, since their values have to be
* set later on.
*/
List<Tree.Parameter> initParameters(final Tree.ParameterList params, TypeDeclaration typeDecl, Functional m) {
List<Tree.Parameter> rparams = null;
for (final Tree.Parameter param : params.getParameters()) {
Parameter pd = param.getParameterModel();
String paramName = names.name(pd);
if (pd.isDefaulted() || pd.isSequenced()) {
out("if(", paramName, "===undefined){", paramName, "=");
if (pd.isDefaulted()) {
boolean done = false;
if (m instanceof Function) {
Function mf = (Function) m;
if (mf.getRefinedDeclaration() != mf) {
mf = (Function) mf.getRefinedDeclaration();
if (mf.isMember() || !mf.isImplemented()) {
qualify(params, mf);
out(names.name(mf), "$defs$", pd.getName(), "(");
boolean firstParam = true;
for (Parameter p : m.getFirstParameterList().getParameters()) {
if (firstParam) {
firstParam = false;
} else
out(",");
out(names.name(p));
}
out(")");
done = true;
}
}
} else if (pd.getDeclaration() instanceof Class) {
Class cdec = (Class) pd.getDeclaration().getRefinedDeclaration();
out(TypeGenerator.pathToType(params, cdec, this), ".$defs$", pd.getName(), "(", names.self(cdec));
for (Parameter p : ((Class) pd.getDeclaration()).getParameterList().getParameters()) {
if (!p.equals(pd)) {
out(",", names.name(p));
}
}
out(")");
if (rparams == null) {
rparams = new ArrayList<>(3);
}
rparams.add(param);
done = true;
}
if (!done) {
final SpecifierOrInitializerExpression expr = getDefaultExpression(param);
if (expr == null) {
param.addUnexpectedError("Default expression missing for " + pd.getName(), Backend.JavaScript);
out("undefined");
} else {
generateParameterExpression(param, expr, pd.getDeclaration() instanceof Scope ? (Scope) pd.getDeclaration() : null);
}
}
} else {
out(getClAlias(), "empty()");
}
out(";}");
endLine();
}
if (typeDecl != null && !(typeDecl instanceof ClassAlias) && (pd.getModel().isJsCaptured() || pd.getDeclaration() instanceof Class)) {
out(names.self(typeDecl), ".", names.valueName(pd.getModel()), "=", paramName);
if (!opts.isOptimize() && pd.isHidden()) {
// belt and suspenders...
out(";", names.self(typeDecl), ".", paramName, "=", paramName);
}
endLine(true);
}
}
return rparams;
}
use of org.eclipse.ceylon.model.typechecker.model.ClassAlias in project ceylon by eclipse.
the class GenerateJsVisitor method memberAccessBase.
String memberAccessBase(Node node, Declaration decl, boolean setter, String lhs) {
final StringBuilder sb = new StringBuilder(getMember(node, lhs));
final boolean isConstructor = decl instanceof Constructor;
if (sb.length() > 0) {
if (node instanceof Tree.BaseMemberOrTypeExpression) {
Declaration bmd = ((Tree.BaseMemberOrTypeExpression) node).getDeclaration();
if (bmd.isParameter() && bmd.getContainer() instanceof ClassAlias) {
return sb.toString();
}
}
sb.append(isConstructor ? names.constructorSeparator(decl) : ".");
}
boolean metaGetter = false;
Scope scope = getSuperMemberScope(node);
if (opts.isOptimize() && scope != null && !isConstructor) {
sb.append("getT$all()['").append(scope.getQualifiedNameString()).append("']");
if (AttributeGenerator.defineAsProperty(decl)) {
return getClAlias() + (setter ? "attrSetter(" : "attrGetter(") + sb.toString() + ",'" + names.name(decl) + "')";
}
sb.append(".$$.prototype.");
metaGetter = true;
}
final String member = accessThroughGetter(decl) && !accessDirectly(decl) ? (setter ? names.setter(decl) : names.getter(decl, metaGetter)) : names.name(decl);
if (!isConstructor && ModelUtil.isConstructor(decl)) {
sb.append(names.name((Declaration) decl.getContainer())).append(names.constructorSeparator(decl));
}
sb.append(member);
if (!opts.isOptimize() && (scope != null)) {
sb.append(names.scopeSuffix(scope));
}
return sb.toString();
}
Aggregations