use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ParameterNameParser method parseMpl.
public void parseMpl(String input, Type type, Function method) {
lexer.setup(input);
this.unit = method.getUnit();
ArrayList<ParameterList> lists = new ArrayList<>();
lists.add(parseNameList(type, method));
while (lexer.lookingAt(LEFT_PAREN)) {
// mpl
type = loader.getSimpleCallableReturnType(type);
lists.add(parseNameList(type, method));
}
for (ParameterList parameterList : lists) {
method.addParameterList(parameterList);
}
method.setType(loader.getSimpleCallableReturnType(type));
if (!lexer.lookingAt(EOI)) {
throw new ParameterNameParserException("Expected end of input" + System.lineSeparator() + input);
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ParameterNameParser method parseNameList.
private ParameterList parseNameList(Type type, Function method) {
ParameterList pl = new ParameterList();
List<Parameter> parameters = pl.getParameters();
// startParameterList();
lexer.eat(LEFT_PAREN);
if (!lexer.lookingAt(RIGHT_PAREN)) {
Iterator<Type> ct = loader.getSimpleCallableArgumentTypes(type).iterator();
if (!ct.hasNext()) {
throw new ParameterNameParserException("Too few parameter types");
}
parameters.add(parseName(ct.next(), method));
// addParameter()
while (lexer.lookingAt(COMMA)) {
lexer.eat();
if (!ct.hasNext()) {
throw new ParameterNameParserException("Too few parameter types");
}
parameters.add(parseName(ct.next(), method));
}
if (ct.hasNext()) {
throw new ParameterNameParserException("Too many parameter types");
}
}
lexer.eat(RIGHT_PAREN);
// endParameterList();
return pl;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ExpressionVisitor method inferrableAnyway.
private static boolean inferrableAnyway(Declaration dec) {
if (dec != null && dec.isParameterized() && dec instanceof Functional) {
Functional fd = (Functional) dec;
ParameterList list = fd.getFirstParameterList();
return list != null && list.getParameters().isEmpty();
} else {
return false;
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypesFromCallableParameter.
private boolean inferParameterTypesFromCallableParameter(Reference pr, Parameter param, Tree.FunctionArgument anon, boolean error) {
boolean result = true;
Declaration declaration = param.getDeclaration();
Functional fun = (Functional) param.getModel();
List<ParameterList> fpls = fun.getParameterLists();
List<Tree.ParameterList> apls = anon.getParameterLists();
if (!fpls.isEmpty() && !apls.isEmpty()) {
List<Parameter> fps = fpls.get(0).getParameters();
List<Tree.Parameter> aps = apls.get(0).getParameters();
for (int j = 0; j < fps.size() && j < aps.size(); j++) {
Parameter fp = fps.get(j);
Tree.Parameter ap = aps.get(j);
if (isInferrableParameter(ap)) {
result = result & createInferredParameter(anon, declaration, ap, ap.getParameterModel(), pr.getTypedParameter(fp).getType(), fp.getModel(), error);
}
}
}
return result;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ExpressionVisitor method inferrableParameters.
/**
* Get the parameters of a callable parameter, or, if
* the given parameter is a value parameter of type
* X(Y), a single faked parameter with the name 'it'.
*/
private List<Parameter> inferrableParameters(Parameter param) {
FunctionOrValue model = param.getModel();
if (model instanceof Function) {
Function fun = (Function) model;
ParameterList fpl = fun.getFirstParameterList();
return fpl == null ? null : fpl.getParameters();
} else if (model instanceof Value) {
Type type = param.getType();
if (type != null) {
Type callable = intersectionType(type.resolveAliases(), appliedType(unit.getCallableDeclaration(), unit.getAnythingType(), unit.getNothingType()), unit);
if (callable.isCallable()) {
Type tup = unit.getCallableTuple(callable);
int min = unit.getTupleMinimumLength(tup);
int max = unit.getTupleMaximumLength(tup);
if (min == 1 || max == 1) {
Parameter p = new Parameter();
p.setName("it");
return Collections.<Parameter>singletonList(p);
} else if (min == 0) {
return Collections.<Parameter>emptyList();
}
}
}
return null;
} else {
return null;
}
}
Aggregations