use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class JsonPackage method parseParameters.
/**
* Creates a parameter list from a list of maps where each map represents a parameter.
* @param params The list of maps to create the parameters.
* @param owner The declaration to assign to each parameter.
* @param typeParameters The type parameters which can be referenced from the parameters.
*/
private ParameterList parseParameters(List<Map<String, Object>> params, Declaration owner, List<TypeParameter> typeParameters) {
ParameterList plist = new ParameterList();
if (params != null) {
for (Map<String, Object> p : params) {
Parameter param = new Parameter();
final String paramtype = (String) p.get("$pt");
param.setHidden(p.containsKey("$hdn"));
param.setName((String) p.get(KEY_NAME));
param.setDeclaration(owner);
param.setDefaulted(p.containsKey(KEY_DEFAULT));
param.setSequenced(p.containsKey("seq"));
param.setAtLeastOne(p.containsKey("$min1"));
if (paramtype == null || "v".equals(paramtype)) {
Value _v = new Value();
param.setModel(_v);
} else if ("f".equals(paramtype)) {
@SuppressWarnings("unchecked") List<List<Map<String, Object>>> paramLists = (List<List<Map<String, Object>>>) p.get(KEY_PARAMS);
Function _m = new Function();
param.setModel(_m);
if (paramLists == null) {
_m.addParameterList(new ParameterList());
} else {
boolean first = true;
for (List<Map<String, Object>> subplist : paramLists) {
ParameterList _params = parseParameters(subplist, _m, typeParameters);
if (first) {
first = false;
} else {
_params.setNamedParametersSupported(false);
}
_m.addParameterList(_params);
}
}
} else {
throw new IllegalArgumentException("Unknown parameter type " + paramtype);
}
FunctionOrValue paramModel = param.getModel();
if (paramModel != null) {
paramModel.setInitializerParameter(param);
paramModel.setName(param.getName());
paramModel.setUnit(u2);
if (owner instanceof Scope) {
Scope scope = (Scope) owner;
paramModel.setContainer(scope);
paramModel.setScope(scope);
}
if (p.get(KEY_TYPE) instanceof Map) {
@SuppressWarnings("unchecked") final Map<String, Object> ktype = (Map<String, Object>) p.get(KEY_TYPE);
paramModel.setType(getTypeFromJson(ktype, owner, typeParameters));
} else {
// parameter type
for (TypeParameter tp : typeParameters) {
if (tp.getName().equals(p.get(KEY_TYPE))) {
paramModel.setType(tp.getType());
}
}
}
setAnnotations(paramModel, (Integer) p.remove(KEY_PACKED_ANNS), p.remove(KEY_ANNOTATIONS));
}
// owner.getMembers().add(param);
plist.getParameters().add(param);
}
}
return plist;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class NpmPackage method getDirectMember.
public Declaration getDirectMember(String name, List<Type> signature, boolean variadic) {
Declaration d = decs.get(name);
if (d == null) {
if (Character.isUpperCase(name.charAt(0))) {
// TODO: it looks like this needs to be a special
// class that can return any member in a fashion
// similar to this package
d = new Class();
ParameterList plist = new ParameterList();
plist.setNamedParametersSupported(true);
plist.setFirst(true);
for (int i = 0; i < 10; i++) {
Parameter p = new Parameter();
p.setName("arg" + i);
Value v = new Value();
v.setUnit(d.getUnit());
v.setType(getUnit().getUnknownType());
v.setDynamic(true);
v.setDynamicallyTyped(true);
v.setInitializerParameter(p);
v.setContainer((Class) d);
p.setModel(v);
p.setDeclaration(d);
p.setDefaulted(true);
plist.getParameters().add(p);
}
((Class) d).setParameterList(plist);
} else {
d = new Function();
((Function) d).setDynamicallyTyped(true);
}
d.setDynamic(true);
d.setName(name);
d.setUnit(getUnit());
d.setShared(true);
d.setContainer(this);
d.setScope(this);
decs.put(name, d);
}
return d;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class UnknownTypeCollector method visit.
public void visit(Tree.BaseMemberOrTypeExpression that) {
super.visit(that);
Declaration declaration = that.getDeclaration();
if (declaration == null)
return;
if (declaration instanceof Functional) {
Functional m = (Functional) declaration;
collectUnknownTypes(m.getType());
for (ParameterList pl : m.getParameterLists()) {
for (Parameter p : pl.getParameters()) {
collectUnknownTypes(p.getType());
}
}
} else if (declaration instanceof Value) {
Value v = (Value) declaration;
collectUnknownTypes(v.getType());
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class MethodDefinitionBuilder method mpl.
public void mpl(java.util.List<ParameterList> parameterLists) {
StringBuilder sb = new StringBuilder();
for (int ii = 1; ii < parameterLists.size(); ii++) {
ParameterList parameterList = parameterLists.get(ii);
ParameterDefinitionBuilder.functionalParameters(sb, parameterList);
}
modelAnnotations(gen.makeAtFunctionalParameter(sb.toString()));
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class AbstractModelLoader method getSignature.
private List<Type> getSignature(Declaration decl) {
List<Type> result = null;
if (decl instanceof Functional) {
Functional func = (Functional) decl;
ParameterList firstParameterList = func.getFirstParameterList();
if (firstParameterList != null) {
List<Parameter> params = firstParameterList.getParameters();
result = new ArrayList<Type>(params.size());
for (Parameter p : params) {
result.add(p.getType());
}
}
}
return result;
}
Aggregations