use of org.eclipse.ceylon.model.typechecker.model.Parameter 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.Parameter in project ceylon by eclipse.
the class Metamodel method getTypeDescriptorForArguments.
public static TypeDescriptor getTypeDescriptorForArguments(org.eclipse.ceylon.model.typechecker.model.Unit unit, org.eclipse.ceylon.model.typechecker.model.Functional decl, Reference producedReference) {
if (!decl.getParameterLists().isEmpty()) {
List<Parameter> parameters = decl.getFirstParameterList().getParameters();
org.eclipse.ceylon.model.typechecker.model.Type tupleType = unit.getParameterTypesAsTupleType(parameters, producedReference);
return Metamodel.getTypeDescriptorForProducedType(tupleType);
} else {
return TypeDescriptor.NothingType;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class Metamodel method getParameterProducedTypes.
public static List<Type> getParameterProducedTypes(List<Parameter> parameters, Reference producedReference) {
List<Type> parameterProducedTypes = new ArrayList<Type>(parameters.size());
for (Parameter parameter : parameters) {
Type ft = producedReference.getTypedParameter(parameter).getFullType();
parameterProducedTypes.add(ft);
}
return parameterProducedTypes;
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class Metamodel method getJavaConstructors.
/**
* Return all the Java constructors for the given named Ceylon constructor,
* including the overloaded ones.
*/
public static List<java.lang.reflect.Constructor<?>> getJavaConstructors(org.eclipse.ceylon.model.typechecker.model.Constructor declaration) {
Class<?> javaClass = getJavaClass((org.eclipse.ceylon.model.typechecker.model.Class) declaration.getContainer());
ArrayList<java.lang.reflect.Constructor<?>> result = new ArrayList<java.lang.reflect.Constructor<?>>();
// find the appropriate ultimate constructor
java.lang.reflect.Constructor<?> ultimate = getJavaConstructor(declaration);
result.add(ultimate);
List<Parameter> parameters = declaration.getFirstParameterList().getParameters();
Class<?>[] javapl = ultimate.getParameterTypes();
// according to the parameter list
for (int ii = parameters.size() - 1, jj = javapl.length; ii >= 0; ii--, jj--) {
Parameter p = parameters.get(ii);
if (p.isDefaulted() || (p.isSequenced() && !p.isAtLeastOne())) {
Class<?>[] sig = Arrays.copyOfRange(javapl, 0, jj - 1);
try {
Constructor<?> overloaded = javaClass.getDeclaredConstructor(sig);
result.add(overloaded);
} catch (NoSuchMethodException e) {
throw Metamodel.newModelError("Could not find overloaded constructor with signature " + Arrays.toString(sig), e);
}
}
}
return result;
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter 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;
}
Aggregations