Search in sources :

Example 51 with ParameterList

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

the class JsonPackage method parseParameters.

/**
 * Creates a parameter list from a list of maps where each map represents a parameter.
 * @param params The list of maps to create the parameters.
 * @param owner The declaration to assign to each parameter.
 * @param typeParameters The type parameters which can be referenced from the parameters.
 */
private ParameterList parseParameters(List<Map<String, Object>> params, Declaration owner, List<TypeParameter> typeParameters) {
    ParameterList plist = new ParameterList();
    if (params != null) {
        for (Map<String, Object> p : params) {
            Parameter param = new Parameter();
            final String paramtype = (String) p.get("$pt");
            param.setHidden(p.containsKey("$hdn"));
            param.setName((String) p.get(KEY_NAME));
            param.setDeclaration(owner);
            param.setDefaulted(p.containsKey(KEY_DEFAULT));
            param.setSequenced(p.containsKey("seq"));
            param.setAtLeastOne(p.containsKey("$min1"));
            if (paramtype == null || "v".equals(paramtype)) {
                Value _v = new Value();
                param.setModel(_v);
            } else if ("f".equals(paramtype)) {
                @SuppressWarnings("unchecked") List<List<Map<String, Object>>> paramLists = (List<List<Map<String, Object>>>) p.get(KEY_PARAMS);
                Function _m = new Function();
                param.setModel(_m);
                if (paramLists == null) {
                    _m.addParameterList(new ParameterList());
                } else {
                    boolean first = true;
                    for (List<Map<String, Object>> subplist : paramLists) {
                        ParameterList _params = parseParameters(subplist, _m, typeParameters);
                        if (first) {
                            first = false;
                        } else {
                            _params.setNamedParametersSupported(false);
                        }
                        _m.addParameterList(_params);
                    }
                }
            } else {
                throw new IllegalArgumentException("Unknown parameter type " + paramtype);
            }
            FunctionOrValue paramModel = param.getModel();
            if (paramModel != null) {
                paramModel.setInitializerParameter(param);
                paramModel.setName(param.getName());
                paramModel.setUnit(u2);
                if (owner instanceof Scope) {
                    Scope scope = (Scope) owner;
                    paramModel.setContainer(scope);
                    paramModel.setScope(scope);
                }
                if (p.get(KEY_TYPE) instanceof Map) {
                    @SuppressWarnings("unchecked") final Map<String, Object> ktype = (Map<String, Object>) p.get(KEY_TYPE);
                    paramModel.setType(getTypeFromJson(ktype, owner, typeParameters));
                } else {
                    // parameter type
                    for (TypeParameter tp : typeParameters) {
                        if (tp.getName().equals(p.get(KEY_TYPE))) {
                            paramModel.setType(tp.getType());
                        }
                    }
                }
                setAnnotations(paramModel, (Integer) p.remove(KEY_PACKED_ANNS), p.remove(KEY_ANNOTATIONS));
            }
            // owner.getMembers().add(param);
            plist.getParameters().add(param);
        }
    }
    return plist;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Function(org.eclipse.ceylon.model.typechecker.model.Function) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 52 with ParameterList

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

the class NpmPackage method getDirectMember.

public Declaration getDirectMember(String name, List<Type> signature, boolean variadic) {
    Declaration d = decs.get(name);
    if (d == null) {
        if (Character.isUpperCase(name.charAt(0))) {
            // TODO: it looks like this needs to be a special
            // class that can return any member in a fashion
            // similar to this package
            d = new Class();
            ParameterList plist = new ParameterList();
            plist.setNamedParametersSupported(true);
            plist.setFirst(true);
            for (int i = 0; i < 10; i++) {
                Parameter p = new Parameter();
                p.setName("arg" + i);
                Value v = new Value();
                v.setUnit(d.getUnit());
                v.setType(getUnit().getUnknownType());
                v.setDynamic(true);
                v.setDynamicallyTyped(true);
                v.setInitializerParameter(p);
                v.setContainer((Class) d);
                p.setModel(v);
                p.setDeclaration(d);
                p.setDefaulted(true);
                plist.getParameters().add(p);
            }
            ((Class) d).setParameterList(plist);
        } else {
            d = new Function();
            ((Function) d).setDynamicallyTyped(true);
        }
        d.setDynamic(true);
        d.setName(name);
        d.setUnit(getUnit());
        d.setShared(true);
        d.setContainer(this);
        d.setScope(this);
        decs.put(name, d);
    }
    return d;
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) Class(org.eclipse.ceylon.model.typechecker.model.Class) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 53 with ParameterList

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

the class UnknownTypeCollector method visit.

public void visit(Tree.BaseMemberOrTypeExpression that) {
    super.visit(that);
    Declaration declaration = that.getDeclaration();
    if (declaration == null)
        return;
    if (declaration instanceof Functional) {
        Functional m = (Functional) declaration;
        collectUnknownTypes(m.getType());
        for (ParameterList pl : m.getParameterLists()) {
            for (Parameter p : pl.getParameters()) {
                collectUnknownTypes(p.getType());
            }
        }
    } else if (declaration instanceof Value) {
        Value v = (Value) declaration;
        collectUnknownTypes(v.getType());
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Value(org.eclipse.ceylon.model.typechecker.model.Value) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 54 with ParameterList

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

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(org.eclipse.ceylon.model.typechecker.model.ParameterList)

Example 55 with ParameterList

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

the class AbstractModelLoader method getSignature.

private List<Type> getSignature(Declaration decl) {
    List<Type> result = null;
    if (decl instanceof Functional) {
        Functional func = (Functional) decl;
        ParameterList firstParameterList = func.getFirstParameterList();
        if (firstParameterList != null) {
            List<Parameter> params = firstParameterList.getParameters();
            result = new ArrayList<Type>(params.size());
            for (Parameter p : params) {
                result.add(p.getType());
            }
        }
    }
    return result;
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

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