use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class MetamodelGenerator method parameterListMap.
/**
* Create a list of maps for the parameter list. Each map will be a parameter, including
* name, type, default value (if any), and whether it's sequenced.
*/
private List<Map<String, Object>> parameterListMap(ParameterList plist, Declaration from) {
if (plist == null) {
// Possibly an anonymous class for an anonymous object
return null;
}
List<Parameter> parms = plist.getParameters();
if (parms.size() > 0) {
List<Map<String, Object>> p = new ArrayList<>(parms.size());
for (Parameter parm : parms) {
Map<String, Object> pm = new HashMap<>();
pm.put(KEY_NAME, parm.getName());
pm.put(KEY_METATYPE, METATYPE_PARAMETER);
if (parm.isSequenced()) {
pm.put("seq", 1);
}
if (parm.isDefaulted()) {
pm.put(KEY_DEFAULT, 1);
}
if (parm.isAtLeastOne()) {
pm.put("$min1", 1);
}
final FunctionOrValue parmtype = parm.getModel();
if (parmtype != null && parmtype.getDeclarationKind() == DeclarationKind.TYPE_PARAMETER) {
pm.put(KEY_TYPE, parmtype.getName());
} else {
pm.put(KEY_TYPE, typeMap(parm.getType(), from));
}
if (parm.isHidden()) {
pm.put("$hdn", 1);
}
if (parmtype instanceof Function) {
pm.put("$pt", "f");
List<List<Map<String, Object>>> _paramLists = new ArrayList<>(((Function) parmtype).getParameterLists().size());
for (ParameterList subplist : ((Function) parmtype).getParameterLists()) {
List<Map<String, Object>> params = parameterListMap(subplist, from);
if (params == null) {
params = Collections.emptyList();
}
_paramLists.add(params);
}
if (_paramLists.size() > 1 || !_paramLists.get(0).isEmpty()) {
pm.put(KEY_PARAMS, _paramLists);
}
}
// TODO do these guys need anything else?
/*if (parm.getDefaultArgument() != null) {
//This could be compiled to JS...
pm.put(ANN_DEFAULT, parm.getDefaultArgument().getSpecifierExpression().getExpression().getTerm().getText());
}*/
encodeAnnotations(parm.getModel().getAnnotations(), parm.getModel(), pm);
p.add(pm);
}
return p;
}
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class RefinementVisitor method inheritDefaultedArguments.
private void inheritDefaultedArguments(Declaration d) {
Declaration rd = d.getRefinedDeclaration();
if (rd != d && rd instanceof Functional && d instanceof Functional) {
Functional fd = (Functional) d;
Functional frd = (Functional) rd;
List<ParameterList> tdpls = fd.getParameterLists();
List<ParameterList> rdpls = frd.getParameterLists();
if (!tdpls.isEmpty() && !rdpls.isEmpty()) {
List<Parameter> tdps = tdpls.get(0).getParameters();
List<Parameter> rdps = rdpls.get(0).getParameters();
for (int i = 0; i < tdps.size() && i < rdps.size(); i++) {
Parameter tdp = tdps.get(i);
Parameter rdp = rdps.get(i);
if (tdp != null && rdp != null) {
tdp.setDefaulted(rdp.isDefaulted());
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class RefinementVisitor method checkRefiningMemberParameters.
private void checkRefiningMemberParameters(Tree.Declaration that, Declaration refining, Declaration refined, Reference refinedMember, Reference refiningMember, boolean forNative) {
Functional refiningFun = (Functional) refining;
Functional refinedFun = (Functional) refined;
List<ParameterList> refiningParamLists = refiningFun.getParameterLists();
List<ParameterList> refinedParamLists = refinedFun.getParameterLists();
if (refinedParamLists.size() != refiningParamLists.size()) {
String subject = forNative ? "native header" : "refined member";
String current = forNative ? "native implementation" : "refining member";
StringBuilder message = new StringBuilder();
message.append(current).append(" must have the same number of parameter lists as ").append(subject).append(": ").append(message(refining));
if (!forNative) {
message.append(" refines ").append(message(refined));
}
that.addError(message.toString());
}
for (int i = 0; i < refinedParamLists.size() && i < refiningParamLists.size(); i++) {
checkParameterTypes(that, getParameterList(that, i), refiningMember, refinedMember, refiningParamLists.get(i), refinedParamLists.get(i), forNative);
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class RefinementVisitor method visit.
@Override
public void visit(Tree.ParameterList that) {
super.visit(that);
boolean foundSequenced = false;
boolean foundDefault = false;
ParameterList pl = that.getModel();
for (Tree.Parameter p : that.getParameters()) {
if (p != null) {
Parameter pm = p.getParameterModel();
if (pm != null) {
if (pm.isDefaulted()) {
if (foundSequenced) {
p.addError("defaulted parameter must occur before variadic parameter");
}
foundDefault = true;
if (!pl.isFirst()) {
p.addError("only the first parameter list may have defaulted parameters");
}
} else if (pm.isSequenced()) {
if (foundSequenced) {
p.addError("parameter list may have at most one variadic parameter");
}
foundSequenced = true;
if (!pl.isFirst()) {
p.addError("only the first parameter list may have a variadic parameter");
}
if (foundDefault && pm.isAtLeastOne()) {
p.addError("parameter list with defaulted parameters may not have a nonempty variadic parameter");
}
} else {
if (foundDefault) {
p.addError("required parameter must occur before defaulted parameters");
}
if (foundSequenced) {
p.addError("required parameter must occur before variadic parameter");
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class RefinementVisitor method createRefiningParameterList.
private void createRefiningParameterList(Reference rm, Function method, Tree.ParameterList params, Unit unit, Map<TypeParameter, Type> subs, ParameterList pl) {
ParameterList list = new ParameterList();
int j = 0;
for (Parameter p : pl.getParameters()) {
// TODO: meaningful errors when parameters don't line up
// currently this is handled elsewhere, but we can
// probably do it better right here
createRefiningParameter(rm, method, p, list, params, j++, subs, unit);
}
method.getParameterLists().add(list);
}
Aggregations