use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class NamedArgumentInvocation method buildVars.
/**
* Constructs the vars used in the Let expression
*/
private void buildVars() {
if (getPrimaryDeclaration() == null) {
return;
}
boolean prev = gen.expressionGen().withinInvocation(false);
java.util.List<Tree.NamedArgument> namedArguments = namedArgumentList.getNamedArguments();
SequencedArgument sequencedArgument = namedArgumentList.getSequencedArgument();
java.util.List<ParameterList> paramLists = ((Functional) getPrimaryDeclaration()).getParameterLists();
java.util.List<Parameter> declaredParams = paramLists.get(0).getParameters();
appendVarsForNamedArguments(namedArguments, declaredParams);
appendVarsForReifiedTypeArguments();
if (sequencedArgument != null)
appendVarsForSequencedArguments(sequencedArgument, declaredParams);
boolean hasDefaulted = appendVarsForDefaulted(declaredParams);
DefaultParameterMethodOwner owner = Strategy.defaultParameterMethodOwner(getPrimaryDeclaration());
if (hasDefaulted && owner != DefaultParameterMethodOwner.STATIC && owner != DefaultParameterMethodOwner.OUTER && owner != DefaultParameterMethodOwner.OUTER_COMPANION) {
vars.prepend(makeThis());
}
gen.expressionGen().withinInvocation(prev);
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ClassOrPackageDoc method writeParameterList.
protected final void writeParameterList(Functional f, Referenceable scope) throws IOException {
Unit unit = scope.getUnit();
for (ParameterList lists : f.getParameterLists()) {
write("(");
boolean first = true;
for (Parameter param : lists.getParameters()) {
if (!first) {
write(", ");
} else {
first = false;
}
if (param.getModel() instanceof Function) {
writeFunctionalParameter(param, scope);
} else {
if (!Decl.isDynamic(param.getModel())) {
Type type = param.getType();
if (param.isSequenced()) {
type = unit.getSequentialElementType(type);
}
linkRenderer().to(type).useScope(scope).write();
if (param.isSequenced()) {
write(param.isAtLeastOne() ? "+" : "*");
}
} else {
around("span class='dynamic'", "dynamic");
}
write(" ");
around("span class='parameter'", param.getName());
}
if (param.isDefaulted()) {
String defaultValue = getParameterDefaultValue(param);
if (defaultValue != null) {
around("span class='parameter-default-value'", " = ");
if (simpleDefaultValues.contains(defaultValue)) {
around("span class='parameter-default-value' title='Parameter default value'", defaultValue);
} else {
around("a class='parameter-default-value' href='#" + f.getName() + "-" + param.getName() + "' title='Go to parameter default value'", "...");
}
}
}
}
write(")");
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ClassOrPackageDoc method writeParameters.
protected final void writeParameters(Declaration decl) throws IOException {
if (decl instanceof Functional) {
Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> parametersAssertions = getParametersAssertions(decl);
boolean first = true;
List<ParameterList> parameterLists = ((Functional) decl).getParameterLists();
for (ParameterList parameterList : parameterLists) {
for (Parameter parameter : parameterList.getParameters()) {
ParameterDocData parameterDocData = getParameterDocData(parameter, parametersAssertions);
if (!parameterDocData.isEmpty()) {
if (first) {
first = false;
open("div class='parameters section'");
around("span class='title'", "Parameters: ");
open("ul");
}
open("li");
open("code");
around("span class='parameter' id='" + decl.getName() + "-" + parameter.getName() + "'", parameter.getName());
// if parameter is function, we need to produce links to its parameters
if (parameter.getModel() instanceof Function) {
writeParameterLinksIfRequired((Function) parameter.getModel(), false, decl.getName() + "-");
}
if (!isEmpty(parameterDocData.defaultValue)) {
around("span class='parameter-default-value' title='Parameter default value'", " = " + parameterDocData.defaultValue);
}
close("code");
if (!isEmpty(parameterDocData.doc)) {
around("div class='doc section'", parameterDocData.doc);
}
writeParameterAssertions(decl, parameterDocData.parameterAssertions);
close("li");
}
}
}
if (!first) {
close("ul");
close("div");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class GenerateJsVisitor method addToPrototype.
void addToPrototype(Node node, ClassOrInterface d, List<Tree.Statement> statements) {
final boolean isSerial = d instanceof Class && ((Class) d).isSerializable();
boolean enter = opts.isOptimize();
ArrayList<Parameter> plist = null;
final boolean isAbstractNative = TypeUtils.makeAbstractNative(d);
final String typename = names.name(d);
final boolean overrideToString = d.getDirectMember("toString", null, true) == null;
if (enter) {
enter = !statements.isEmpty() | overrideToString;
if (d instanceof Class) {
ParameterList cpl = ((Class) d).getParameterList();
if (cpl != null) {
plist = new ArrayList<>(cpl.getParameters().size());
plist.addAll(cpl.getParameters());
enter |= !plist.isEmpty();
}
}
}
if (enter || isSerial) {
final List<? extends Statement> prevStatements = currentStatements;
currentStatements = statements;
out("(function(", names.self(d), ")");
beginBlock();
if (enter) {
// First of all, add an object to store statics only if needed
for (Statement s : statements) {
}
// Generated attributes with corresponding parameters will remove them from the list
if (plist != null) {
for (Parameter p : plist) {
generateAttributeForParameter(node, (Class) d, p);
}
}
boolean statics = false;
InitDeferrer initDeferrer = new InitDeferrer();
for (Statement s : statements) {
if (!statics && s instanceof Tree.Declaration) {
Declaration sd = ((Tree.Declaration) s).getDeclarationModel();
if (sd.isStatic()) {
statics = true;
out(names.name(d), ".$st$={};");
}
}
if (!(s instanceof Tree.ClassOrInterface) && !(s instanceof Tree.AttributeDeclaration && ((Tree.AttributeDeclaration) s).getDeclarationModel().isParameter())) {
addToPrototype(d, s, plist, initDeferrer);
}
}
for (Statement s : statements) {
if (s instanceof Tree.ClassOrInterface) {
addToPrototype(d, s, plist, initDeferrer);
} else if (s instanceof Tree.Enumerated) {
// Add a simple attribute which really returns the singleton from the class
final Tree.Enumerated vc = (Tree.Enumerated) s;
Value vcd = vc.getDeclarationModel();
defineAttribute(names.self(d), names.name(vcd));
out("{return ", typename, names.constructorSeparator(vcd), names.name(vcd), "();},undefined,");
TypeUtils.encodeForRuntime(vc, vcd, vc.getAnnotationList(), this);
out(");");
}
}
for (String stmt : initDeferrer.deferred) {
out(stmt);
endLine();
}
if (d.isMember()) {
ClassOrInterface coi = ModelUtil.getContainingClassOrInterface(d.getContainer());
if (coi != null && d.inherits(coi)) {
out(names.self(d), ".", typename, "=", typename, ";");
}
}
}
if (isSerial && !isAbstractNative) {
SerializationHelper.addSerializer(node, (Class) d, this);
}
if (overrideToString) {
out(names.self(d), ".", "toString=function(){return this.string.valueOf();};");
}
endBlock();
out(")(", typename, ".$$.prototype)");
endLine(true);
currentStatements = prevStatements;
}
}
Aggregations