Search in sources :

Example 1 with FunctionImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.FunctionImpl 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);
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) OpenType(ceylon.language.meta.declaration.OpenType) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) FunctionImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.FunctionImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 2 with FunctionImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.FunctionImpl 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);
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) OpenType(ceylon.language.meta.declaration.OpenType) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) FunctionImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.FunctionImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)

Aggregations

OpenType (ceylon.language.meta.declaration.OpenType)2 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)2 FunctionImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.FunctionImpl)2 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)2 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)2 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)1 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)1