Search in sources :

Example 11 with ParameterList

use of com.redhat.ceylon.model.typechecker.model.ParameterList in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method writeParameterList.

protected final void writeParameterList(Functional f, Referenceable scope) throws IOException {
    for (ParameterList lists : f.getParameterLists()) {
        write("(");
        boolean first = true;
        for (Parameter param : lists.getParameters()) {
            if (!first) {
                write(", ");
            } else {
                first = false;
            }
            if (param.getModel() instanceof Function) {
                writeFunctionalParameter(param, scope);
            } else {
                linkRenderer().to(param.getType()).useScope(scope).write();
                write(" ");
                around("span class='parameter'", param.getName());
            }
            if (param.isDefaulted()) {
                String defaultValue = getParameterDefaultValue(param);
                if (defaultValue != null) {
                    around("span class='parameter-default-value'", " = ");
                    if (simpleDefaultValues.contains(defaultValue)) {
                        around("span class='parameter-default-value' title='Parameter default value'", defaultValue);
                    } else {
                        around("a class='parameter-default-value' href='#" + f.getName() + "-" + param.getName() + "' title='Go to parameter default value'", "...");
                    }
                }
            }
        }
        write(")");
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter)

Example 12 with ParameterList

use of com.redhat.ceylon.model.typechecker.model.ParameterList in project ceylon-compiler by ceylon.

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()));
}
Also used : ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList)

Example 13 with ParameterList

use of com.redhat.ceylon.model.typechecker.model.ParameterList in project ceylon-compiler by ceylon.

the class Strategy method hasNoRequiredParameters.

/**
 * Returns true if the given functional takes no parameters or accepts only defaulted params
 */
private static boolean hasNoRequiredParameters(Functional model) {
    List<ParameterList> parameterLists = model.getParameterLists();
    if (parameterLists == null || parameterLists.size() != 1)
        return false;
    ParameterList parameterList = parameterLists.get(0);
    if (parameterList == null)
        return false;
    List<Parameter> parameters = parameterList.getParameters();
    if (parameters == null)
        return false;
    if (parameters.isEmpty())
        return true;
    // if the first one is optional, all others have to be too
    return parameters.get(0).isDefaulted();
}
Also used : ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter)

Example 14 with ParameterList

use of com.redhat.ceylon.model.typechecker.model.ParameterList in project ceylon-compiler by ceylon.

the class ClassTransformer method transformMplBody.

/**
 * Constructs all but the outer-most method of a {@code Function} with
 * multiple parameter lists
 * @param model The {@code Function} model
 * @param body The inner-most body
 */
List<JCStatement> transformMplBody(java.util.List<Tree.ParameterList> parameterListsTree, Function model, List<JCStatement> body) {
    Type resultType = model.getType();
    for (int index = model.getParameterLists().size() - 1; index > 0; index--) {
        ParameterList pl = model.getParameterLists().get(index);
        resultType = gen().typeFact().getCallableType(List.of(resultType, typeFact().getParameterTypesAsTupleType(pl.getParameters(), model.getReference())));
        CallableBuilder cb = CallableBuilder.mpl(gen(), resultType, pl, parameterListsTree.get(index), body);
        body = List.<JCStatement>of(make().Return(cb.build()));
    }
    return body;
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList)

Example 15 with ParameterList

use of com.redhat.ceylon.model.typechecker.model.ParameterList in project ceylon-compiler by ceylon.

the class ClassTransformer method generateInstantiators.

private void generateInstantiators(ClassDefinitionBuilder classBuilder, Class cls, Constructor ctor, ClassDefinitionBuilder instantiatorDeclCb, ClassDefinitionBuilder instantiatorImplCb, Tree.Declaration node, Tree.ParameterList pl) {
    // TODO Instantiators on companion classes
    if (Decl.isEnumeratedConstructor(ctor)) {
        return;
    }
    ParameterList parameterList = ctor != null ? ctor.getFirstParameterList() : cls.getParameterList();
    if (Decl.withinInterface(cls)) {
        DefaultedArgumentOverload overloaded = new DefaultedArgumentInstantiator(daoAbstract, cls, ctor, instantiatorDeclCb.isCompanionBuilder());
        MethodDefinitionBuilder instBuilder = overloaded.makeOverload(parameterList, null, cls.getTypeParameters());
        instantiatorDeclCb.method(instBuilder);
    }
    if (!Decl.withinInterface(cls) || !cls.isFormal()) {
        DefaultedArgumentOverload overloaded = new DefaultedArgumentInstantiator(!cls.isFormal() ? new DaoThis(node, pl) : daoAbstract, cls, ctor, instantiatorImplCb.isCompanionBuilder());
        MethodDefinitionBuilder instBuilder = overloaded.makeOverload(parameterList, null, cls.getTypeParameters());
        instantiatorImplCb.method(instBuilder);
    }
}
Also used : ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList)

Aggregations

ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)19 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)13 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)11 Function (com.redhat.ceylon.model.typechecker.model.Function)8 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)7 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)7 Value (com.redhat.ceylon.model.typechecker.model.Value)7 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)6 Functional (com.redhat.ceylon.model.typechecker.model.Functional)6 Type (com.redhat.ceylon.model.typechecker.model.Type)6 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)6 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)5 Class (com.redhat.ceylon.model.typechecker.model.Class)5 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)5 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)5 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)5 ArrayList (java.util.ArrayList)5 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)4 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)4 FieldValue (com.redhat.ceylon.model.loader.model.FieldValue)3