use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypesDirectly.
/**
* Infer parameter types of anonymous function arguments
* in a direct invocation with positional arguments.
*/
private boolean[] inferParameterTypesDirectly(Tree.PositionalArgumentList pal, Tree.MemberOrTypeExpression mte, Declaration dec, boolean error) {
List<Tree.PositionalArgument> args = pal.getPositionalArguments();
int argCount = args.size();
boolean[] delayed = new boolean[argCount];
Functional fun = (Functional) dec;
List<ParameterList> pls = fun.getParameterLists();
if (!pls.isEmpty()) {
List<Parameter> params = pls.get(0).getParameters();
Reference reference = getInvokedProducedReference(dec, mte);
int paramsSize = params.size();
for (int i = 0, j = 0; i < argCount && j < paramsSize; i++) {
Parameter param = params.get(j);
Tree.PositionalArgument arg = args.get(i);
arg.setParameter(param);
if (arg instanceof Tree.ListedArgument) {
Tree.ListedArgument la = (Tree.ListedArgument) arg;
delayed[i] = !inferParameterTypes(reference, param, la.getExpression(), param.isSequenced(), error);
}
if (!param.isSequenced()) {
j++;
}
}
}
return delayed;
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class Metamodel method getConstructors.
public static <Type> Sequential getConstructors(ClassOrInterfaceImpl<Type> cls, boolean justShared, boolean callableConstructors, TypeDescriptor $reified$Arguments, ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
ArrayList<Object> ctors = new ArrayList<>();
org.eclipse.ceylon.model.typechecker.model.Type reifiedArguments = $reified$Arguments == null ? null : Metamodel.getProducedType($reified$Arguments);
TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
if (cls.declaration instanceof ClassWithInitializerDeclarationImpl) {
Reference producedReference = cls.declaration.declaration.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(cls.declaration.declaration.getUnit(), (Functional) cls.declaration.declaration, producedReference);
if (reifiedArguments == null || reifiedArguments.isSubtypeOf(argumentsType)) {
if (hasAllAnnotations(((ClassWithInitializerDeclarationImpl) cls.declaration).getDefaultConstructor(), annotationTypeDescriptors)) {
// TODO test for arguments too
// ctors.add(new AppliedInitializer((AppliedClass)cls));
ctors.add(((ClassModel<?, ?>) cls).getDefaultConstructor());
}
}
} else {
for (ceylon.language.meta.declaration.Declaration d : ((ClassDeclarationImpl) cls.declaration).constructors()) {
Declaration dd = null;
AnnotatedDeclaration annotated;
if (d instanceof CallableConstructorDeclarationImpl && callableConstructors) {
dd = ((CallableConstructorDeclarationImpl) d).declaration;
annotated = (CallableConstructorDeclaration) d;
} else if (d instanceof ValueConstructorDeclarationImpl && !callableConstructors) {
dd = ((ValueConstructorDeclarationImpl) d).declaration;
annotated = (ValueConstructorDeclaration) d;
} else {
continue;
}
// ATM this is an AND WRT annotation types: all must be present
if (!hasAllAnnotations(annotated, annotationTypeDescriptors))
continue;
if (dd instanceof Functional && reifiedArguments != null) {
// CallableConstructor need a check on the <Arguments>
Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
if (!reifiedArguments.isSubtypeOf(argumentsType))
continue;
}
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations((AnnotatedDeclaration) d, annotationTypeDescriptors))
continue;
if (dd instanceof Functional && reifiedArguments != null) {
// CallableConstructor need a check on the <Arguments>
Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
if (!reifiedArguments.isSubtypeOf(argumentsType))
continue;
}
if (!justShared || (d instanceof NestableDeclaration && ((NestableDeclaration) d).getShared())) {
Object ctor;
if (cls instanceof ClassImpl<?, ?>) {
ctor = ((ClassImpl<?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
} else {
// if (cls instanceof AppliedMemberClass<?,?,?>) {
ctor = ((MemberClassImpl<?, ?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
}
ctors.add(ctor);
}
}
}
Object[] array = ctors.toArray(new Object[ctors.size()]);
ObjectArrayIterable<ceylon.language.meta.declaration.Declaration> iterable = new ObjectArrayIterable<ceylon.language.meta.declaration.Declaration>(TypeDescriptor.union(TypeDescriptor.klass(FunctionModel.class, cls.$reifiedType, TypeDescriptor.NothingType), TypeDescriptor.klass(ValueModel.class, cls.$reifiedType, TypeDescriptor.NothingType)), (Object[]) array);
return (ceylon.language.Sequential) iterable.sequence();
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class FunctionalUtil method getParameters.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Sequential<FunctionOrValueDeclaration> getParameters(Functional declaration) {
ParameterList parameterList = ((Functional) declaration).getFirstParameterList();
if (parameterList == null)
return (Sequential) empty_.get_();
List<Parameter> modelParameters = parameterList.getParameters();
ceylon.language.meta.declaration.FunctionOrValueDeclaration[] parameters = new ceylon.language.meta.declaration.FunctionOrValueDeclaration[modelParameters.size()];
int i = 0;
for (Parameter modelParameter : modelParameters) {
parameters[i] = (ceylon.language.meta.declaration.FunctionOrValueDeclaration) Metamodel.getOrCreateMetamodel(modelParameter.getModel());
i++;
}
return Util.sequentialWrapper(ceylon.language.meta.declaration.FunctionOrValueDeclaration.$TypeDescriptor$, parameters);
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class FunctionDeclarationImpl method apply.
@Override
@TypeInfo("ceylon.language.meta.model::Function<Return,Arguments>")
@TypeParameters({ @TypeParameter("Return"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
public <Return extends Object, Arguments extends Sequential<? extends Object>> ceylon.language.meta.model.Function<Return, Arguments> apply(@Ignore TypeDescriptor $reifiedReturn, @Ignore TypeDescriptor $reifiedArguments, @Name("typeArguments") @TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::Type<ceylon.language::Anything>>") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
if (!getToplevel()) {
String msg;
if (getStatic()) {
msg = "Cannot apply a static declaration with no container type: use staticApply";
} else {
msg = "Cannot apply a member declaration with no container type: use memberApply";
}
throw new ceylon.language.meta.model.TypeApplicationException(msg);
}
List<org.eclipse.ceylon.model.typechecker.model.Type> producedTypes = Metamodel.getProducedTypes(typeArguments);
Metamodel.checkTypeArguments(null, declaration, producedTypes);
org.eclipse.ceylon.model.typechecker.model.Reference appliedFunction = declaration.appliedReference(null, producedTypes);
TypeDescriptor reifiedType = Metamodel.getTypeDescriptorForFunction(appliedFunction);
TypeDescriptor reifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.getUnit(), (Functional) declaration, appliedFunction);
Metamodel.checkReifiedTypeArgument("apply", "Function<$1,$2>", Variance.OUT, declaration.getUnit().getCallableReturnType(appliedFunction.getFullType()), $reifiedReturn, Variance.IN, Metamodel.getProducedTypeForArguments(declaration.getUnit(), (Functional) declaration, appliedFunction), $reifiedArguments);
return new FunctionImpl<Return, Arguments>(reifiedType, reifiedArguments, appliedFunction, this, null, null);
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class FunctionDeclarationImpl method staticApply.
@Override
public <Return extends Object, Arguments extends Sequential<? extends Object>> ceylon.language.meta.model.Function<Return, Arguments> staticApply(@Ignore TypeDescriptor $reifiedReturn, @Ignore TypeDescriptor $reifiedArguments, @Name("containerType") ceylon.language.meta.model.Type<? extends Object> containerType, @Name("typeArguments") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
if (!getStatic())
throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a " + (getToplevel() ? "toplevel" : "member") + " declaration to a container type: use " + (getToplevel() ? "apply" : "memberApply"));
List<org.eclipse.ceylon.model.typechecker.model.Type> producedTypes = Metamodel.getProducedTypes(typeArguments);
Metamodel.checkTypeArguments(null, declaration, producedTypes);
org.eclipse.ceylon.model.typechecker.model.Reference appliedFunction = declaration.appliedReference(((ClassOrInterfaceImpl<?>) containerType).producedType, producedTypes);
TypeDescriptor reifiedType = Metamodel.getTypeDescriptorForFunction(appliedFunction);
TypeDescriptor reifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.getUnit(), (Functional) declaration, appliedFunction);
if (getStatic()) {
producedTypes.addAll(0, Metamodel.getModel(containerType).getTypeArgumentList());
}
Metamodel.checkReifiedTypeArgument("apply", "Function<$1,$2>", Variance.OUT, declaration.getUnit().getCallableReturnType(appliedFunction.getFullType()), $reifiedReturn, Variance.IN, Metamodel.getProducedTypeForArguments(declaration.getUnit(), (Functional) declaration, appliedFunction), $reifiedArguments);
return new FunctionImpl<Return, Arguments>(reifiedType, reifiedArguments, appliedFunction, this, containerType, null);
}
Aggregations