Search in sources :

Example 66 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class NamedArgumentInvocation method buildVars.

/**
 * Constructs the vars used in the Let expression
 */
private void buildVars() {
    if (getPrimaryDeclaration() == null) {
        return;
    }
    boolean prev = gen.expressionGen().withinInvocation(false);
    java.util.List<Tree.NamedArgument> namedArguments = namedArgumentList.getNamedArguments();
    SequencedArgument sequencedArgument = namedArgumentList.getSequencedArgument();
    java.util.List<ParameterList> paramLists = ((Functional) getPrimaryDeclaration()).getParameterLists();
    java.util.List<Parameter> declaredParams = paramLists.get(0).getParameters();
    appendVarsForNamedArguments(namedArguments, declaredParams);
    appendVarsForReifiedTypeArguments();
    if (sequencedArgument != null)
        appendVarsForSequencedArguments(sequencedArgument, declaredParams);
    boolean hasDefaulted = appendVarsForDefaulted(declaredParams);
    DefaultParameterMethodOwner owner = Strategy.defaultParameterMethodOwner(getPrimaryDeclaration());
    if (hasDefaulted && owner != DefaultParameterMethodOwner.STATIC && owner != DefaultParameterMethodOwner.OUTER && owner != DefaultParameterMethodOwner.OUTER_COMPANION) {
        vars.prepend(makeThis());
    }
    gen.expressionGen().withinInvocation(prev);
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) DefaultParameterMethodOwner(org.eclipse.ceylon.compiler.java.codegen.Strategy.DefaultParameterMethodOwner) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) SequencedArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)

Example 67 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class ClassOrPackageDoc method writeParameterList.

protected final void writeParameterList(Functional f, Referenceable scope) throws IOException {
    Unit unit = scope.getUnit();
    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 {
                if (!Decl.isDynamic(param.getModel())) {
                    Type type = param.getType();
                    if (param.isSequenced()) {
                        type = unit.getSequentialElementType(type);
                    }
                    linkRenderer().to(type).useScope(scope).write();
                    if (param.isSequenced()) {
                        write(param.isAtLeastOne() ? "+" : "*");
                    }
                } else {
                    around("span class='dynamic'", "dynamic");
                }
                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(org.eclipse.ceylon.model.typechecker.model.Function) Util.isAbbreviatedType(org.eclipse.ceylon.ceylondoc.Util.isAbbreviatedType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 68 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class ClassOrPackageDoc method writeParameters.

protected final void writeParameters(Declaration decl) throws IOException {
    if (decl instanceof Functional) {
        Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> parametersAssertions = getParametersAssertions(decl);
        boolean first = true;
        List<ParameterList> parameterLists = ((Functional) decl).getParameterLists();
        for (ParameterList parameterList : parameterLists) {
            for (Parameter parameter : parameterList.getParameters()) {
                ParameterDocData parameterDocData = getParameterDocData(parameter, parametersAssertions);
                if (!parameterDocData.isEmpty()) {
                    if (first) {
                        first = false;
                        open("div class='parameters section'");
                        around("span class='title'", "Parameters: ");
                        open("ul");
                    }
                    open("li");
                    open("code");
                    around("span class='parameter' id='" + decl.getName() + "-" + parameter.getName() + "'", parameter.getName());
                    // if parameter is function, we need to produce links to its parameters
                    if (parameter.getModel() instanceof Function) {
                        writeParameterLinksIfRequired((Function) parameter.getModel(), false, decl.getName() + "-");
                    }
                    if (!isEmpty(parameterDocData.defaultValue)) {
                        around("span class='parameter-default-value' title='Parameter default value'", " = " + parameterDocData.defaultValue);
                    }
                    close("code");
                    if (!isEmpty(parameterDocData.doc)) {
                        around("div class='doc section'", parameterDocData.doc);
                    }
                    writeParameterAssertions(decl, parameterDocData.parameterAssertions);
                    close("li");
                }
            }
        }
        if (!first) {
            close("ul");
            close("div");
        }
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Function(org.eclipse.ceylon.model.typechecker.model.Function) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 69 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class GenerateJsVisitor method addToPrototype.

void addToPrototype(Node node, ClassOrInterface d, List<Tree.Statement> statements) {
    final boolean isSerial = d instanceof Class && ((Class) d).isSerializable();
    boolean enter = opts.isOptimize();
    ArrayList<Parameter> plist = null;
    final boolean isAbstractNative = TypeUtils.makeAbstractNative(d);
    final String typename = names.name(d);
    final boolean overrideToString = d.getDirectMember("toString", null, true) == null;
    if (enter) {
        enter = !statements.isEmpty() | overrideToString;
        if (d instanceof Class) {
            ParameterList cpl = ((Class) d).getParameterList();
            if (cpl != null) {
                plist = new ArrayList<>(cpl.getParameters().size());
                plist.addAll(cpl.getParameters());
                enter |= !plist.isEmpty();
            }
        }
    }
    if (enter || isSerial) {
        final List<? extends Statement> prevStatements = currentStatements;
        currentStatements = statements;
        out("(function(", names.self(d), ")");
        beginBlock();
        if (enter) {
            // First of all, add an object to store statics only if needed
            for (Statement s : statements) {
            }
            // Generated attributes with corresponding parameters will remove them from the list
            if (plist != null) {
                for (Parameter p : plist) {
                    generateAttributeForParameter(node, (Class) d, p);
                }
            }
            boolean statics = false;
            InitDeferrer initDeferrer = new InitDeferrer();
            for (Statement s : statements) {
                if (!statics && s instanceof Tree.Declaration) {
                    Declaration sd = ((Tree.Declaration) s).getDeclarationModel();
                    if (sd.isStatic()) {
                        statics = true;
                        out(names.name(d), ".$st$={};");
                    }
                }
                if (!(s instanceof Tree.ClassOrInterface) && !(s instanceof Tree.AttributeDeclaration && ((Tree.AttributeDeclaration) s).getDeclarationModel().isParameter())) {
                    addToPrototype(d, s, plist, initDeferrer);
                }
            }
            for (Statement s : statements) {
                if (s instanceof Tree.ClassOrInterface) {
                    addToPrototype(d, s, plist, initDeferrer);
                } else if (s instanceof Tree.Enumerated) {
                    // Add a simple attribute which really returns the singleton from the class
                    final Tree.Enumerated vc = (Tree.Enumerated) s;
                    Value vcd = vc.getDeclarationModel();
                    defineAttribute(names.self(d), names.name(vcd));
                    out("{return ", typename, names.constructorSeparator(vcd), names.name(vcd), "();},undefined,");
                    TypeUtils.encodeForRuntime(vc, vcd, vc.getAnnotationList(), this);
                    out(");");
                }
            }
            for (String stmt : initDeferrer.deferred) {
                out(stmt);
                endLine();
            }
            if (d.isMember()) {
                ClassOrInterface coi = ModelUtil.getContainingClassOrInterface(d.getContainer());
                if (coi != null && d.inherits(coi)) {
                    out(names.self(d), ".", typename, "=", typename, ";");
                }
            }
        }
        if (isSerial && !isAbstractNative) {
            SerializationHelper.addSerializer(node, (Class) d, this);
        }
        if (overrideToString) {
            out(names.self(d), ".", "toString=function(){return this.string.valueOf();};");
        }
        endBlock();
        out(")(", typename, ".$$.prototype)");
        endLine(true);
        currentStatements = prevStatements;
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Statement(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Statement) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)

Aggregations

ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)69 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)47 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)25 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)24 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)24 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)23 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)22 Function (org.eclipse.ceylon.model.typechecker.model.Function)21 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)20 Value (org.eclipse.ceylon.model.typechecker.model.Value)20 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)19 ArrayList (java.util.ArrayList)16 AnalyzerUtil.getMatchingParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter)12 AnalyzerUtil.getUnspecifiedParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter)12 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)12 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)12 Class (org.eclipse.ceylon.model.typechecker.model.Class)11 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)10 HashMap (java.util.HashMap)9