Search in sources :

Example 26 with Parameter

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

the class AnnotationLoader method loadAnnotationConstructorDefaultedParameters.

private void loadAnnotationConstructorDefaultedParameters(LazyFunction method, MethodMirror meth, AnnotationInvocation ai) {
    for (Parameter ctorParam : method.getFirstParameterList().getParameters()) {
        AnnotationConstructorParameter acp = new AnnotationConstructorParameter();
        acp.setParameter(ctorParam);
        if (ctorParam.isDefaulted()) {
            acp.setDefaultArgument(loadAnnotationConstructorDefaultedParameter(method, meth, ctorParam, acp));
        }
        ai.getConstructorParameters().add(acp);
    }
}
Also used : AnnotationConstructorParameter(com.redhat.ceylon.compiler.java.codegen.AnnotationConstructorParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) AnnotationConstructorParameter(com.redhat.ceylon.compiler.java.codegen.AnnotationConstructorParameter)

Example 27 with Parameter

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

the class AnnotationLoader method makeInterorAnnotationConstructorInvocation.

public void makeInterorAnnotationConstructorInvocation(AnnotationProxyMethod ctor, AnnotationProxyClass klass, java.util.List<Parameter> ctorParams) {
    AnnotationInvocation ai = new AnnotationInvocation();
    ai.setConstructorDeclaration(ctor);
    ai.setPrimary(klass);
    ai.setInterop(true);
    ctor.setAnnotationConstructor(ai);
    java.util.List<AnnotationArgument> annotationArgs = new ArrayList<AnnotationArgument>();
    for (Parameter ctorParam : ctorParams) {
        boolean isValue = ctorParam.getName().equals("value");
        ParameterAnnotationTerm term = new ParameterAnnotationTerm();
        AnnotationArgument argument = new AnnotationArgument();
        argument.setTerm(term);
        argument.setParameter(klass.getParameter(ctorParam.getName()));
        term.setSourceParameter(ctorParam);
        AnnotationConstructorParameter acp = new AnnotationConstructorParameter();
        acp.setParameter(ctorParam);
        if (isValue)
            ai.getConstructorParameters().add(0, acp);
        else
            ai.getConstructorParameters().add(acp);
        annotationArgs.add(argument);
    }
    ai.getAnnotationArguments().addAll(annotationArgs);
}
Also used : ParameterAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.ParameterAnnotationTerm) AnnotationInvocation(com.redhat.ceylon.compiler.java.codegen.AnnotationInvocation) AnnotationConstructorParameter(com.redhat.ceylon.compiler.java.codegen.AnnotationConstructorParameter) ArrayList(java.util.ArrayList) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) AnnotationConstructorParameter(com.redhat.ceylon.compiler.java.codegen.AnnotationConstructorParameter) AnnotationArgument(com.redhat.ceylon.compiler.java.codegen.AnnotationArgument)

Example 28 with Parameter

use of com.redhat.ceylon.model.typechecker.model.Parameter 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 29 with Parameter

use of com.redhat.ceylon.model.typechecker.model.Parameter 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 30 with Parameter

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

the class ParameterDefinitionBuilder method functionalParameters.

static void functionalParameters(StringBuilder sb, ParameterList pl) {
    sb.append('(');
    Iterator<Parameter> parameters = pl.getParameters().iterator();
    while (parameters.hasNext()) {
        Parameter p = parameters.next();
        FunctionOrValue pm = p.getModel();
        sb.append(pm.getName());
        if (p.isSequenced()) {
            if (p.isAtLeastOne()) {
                sb.append('+');
            } else {
                sb.append('*');
            }
        }
        if (pm instanceof Function) {
            Function meth = (Function) pm;
            functionalName(sb, (Function) pm);
        }
        if (parameters.hasNext()) {
            sb.append(',');
        }
    }
    sb.append(')');
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)56 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)40 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)25 Type (com.redhat.ceylon.model.typechecker.model.Type)24 Function (com.redhat.ceylon.model.typechecker.model.Function)19 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)18 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)17 JCTree (com.sun.tools.javac.tree.JCTree)15 Class (com.redhat.ceylon.model.typechecker.model.Class)14 ArrayList (java.util.ArrayList)14 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)13 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)13 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)12 Value (com.redhat.ceylon.model.typechecker.model.Value)12 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)11 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)11 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)11 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)10 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)9 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)9