Search in sources :

Example 11 with FunctionOrValue

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

the class MethodDefinitionBuilder method parameter.

public MethodDefinitionBuilder parameter(Node node, Parameter param, TypedReference typedRef, List<JCAnnotation> userAnnotations, int flags, WideningRules wideningRules) {
    String paramName = param.getName();
    String aliasedName = Naming.getAliasedParameterName(param);
    FunctionOrValue mov = CodegenUtil.findMethodOrValueForParam(param);
    if (typedRef == null)
        typedRef = gen.getTypedReference(mov);
    long mods = 0;
    if (!Decl.isNonTransientValue(mov) || !mov.isVariable() || mov.isCaptured()) {
        mods |= FINAL;
    }
    NonWideningParam nonWideningParam = getNonWideningParam(typedRef, wideningRules);
    flags |= nonWideningParam.flags;
    mods |= nonWideningParam.modifiers;
    return parameter(node, mods, param.getModel().getAnnotations(), userAnnotations, paramName, aliasedName, param, nonWideningParam.nonWideningDecl, nonWideningParam.nonWideningType, flags);
}
Also used : FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 12 with FunctionOrValue

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

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) {
            functionalName(sb, (Function) pm);
        }
        if (parameters.hasNext()) {
            sb.append(',');
        }
    }
    sb.append(')');
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 13 with FunctionOrValue

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

the class SmallDeclarationVisitor method setSmallType.

protected static void setSmallType(FunctionOrValue f) {
    Type t = smallUnderlyingType(f.getType());
    f.setType(t);
    if (f instanceof Value) {
        Setter s = ((Value) f).getSetter();
        if (s != null) {
            s.getParameter().getModel().setType(t);
        }
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter)

Example 14 with FunctionOrValue

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

the class JsonPackage method loadAttribute.

FunctionOrValue loadAttribute(String name, Map<String, Object> m, Scope parent, List<TypeParameter> typeParameters) {
    String metatype = (String) m.get(KEY_METATYPE);
    Value d = new Value();
    d.setTransient(METATYPE_GETTER.equals(metatype));
    d.setName(name);
    d.setContainer(parent);
    d.setScope(parent);
    d.setUnit(u2);
    if (parent == this) {
        u2.addDeclaration(d);
        addMember(null);
    }
    setAnnotations(d, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
    d.setDynamic(m.remove(KEY_DYNAMIC) != null);
    if (m.containsKey("var")) {
        d.setVariable(true);
    }
    @SuppressWarnings("unchecked") final Map<String, Object> ktype = (Map<String, Object>) m.get(KEY_TYPE);
    d.setType(getTypeFromJson(ktype, parent instanceof Declaration ? (Declaration) parent : null, typeParameters));
    @SuppressWarnings("unchecked") final Map<String, Object> smap = (Map<String, Object>) m.remove("$set");
    if (smap != null) {
        Setter s = new Setter();
        s.setName(name);
        s.setContainer(parent);
        s.setScope(parent);
        s.setUnit(u2);
        s.setGetter(d);
        d.setSetter(s);
        if (parent == this) {
            u2.addDeclaration(s);
            addMember(null);
        }
        setAnnotations(s, (Integer) smap.remove(KEY_PACKED_ANNS), smap.remove(KEY_ANNOTATIONS));
        s.setType(d.getType());
    }
    return d;
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with FunctionOrValue

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

the class MetamodelGenerator method parameterListMap.

/**
 * Create a list of maps for the parameter list. Each map will be a parameter, including
 * name, type, default value (if any), and whether it's sequenced.
 */
private List<Map<String, Object>> parameterListMap(ParameterList plist, Declaration from) {
    if (plist == null) {
        // Possibly an anonymous class for an anonymous object
        return null;
    }
    List<Parameter> parms = plist.getParameters();
    if (parms.size() > 0) {
        List<Map<String, Object>> p = new ArrayList<>(parms.size());
        for (Parameter parm : parms) {
            Map<String, Object> pm = new HashMap<>();
            pm.put(KEY_NAME, parm.getName());
            pm.put(KEY_METATYPE, METATYPE_PARAMETER);
            if (parm.isSequenced()) {
                pm.put("seq", 1);
            }
            if (parm.isDefaulted()) {
                pm.put(KEY_DEFAULT, 1);
            }
            if (parm.isAtLeastOne()) {
                pm.put("$min1", 1);
            }
            final FunctionOrValue parmtype = parm.getModel();
            if (parmtype != null && parmtype.getDeclarationKind() == DeclarationKind.TYPE_PARAMETER) {
                pm.put(KEY_TYPE, parmtype.getName());
            } else {
                pm.put(KEY_TYPE, typeMap(parm.getType(), from));
            }
            if (parm.isHidden()) {
                pm.put("$hdn", 1);
            }
            if (parmtype instanceof Function) {
                pm.put("$pt", "f");
                List<List<Map<String, Object>>> _paramLists = new ArrayList<>(((Function) parmtype).getParameterLists().size());
                for (ParameterList subplist : ((Function) parmtype).getParameterLists()) {
                    List<Map<String, Object>> params = parameterListMap(subplist, from);
                    if (params == null) {
                        params = Collections.emptyList();
                    }
                    _paramLists.add(params);
                }
                if (_paramLists.size() > 1 || !_paramLists.get(0).isEmpty()) {
                    pm.put(KEY_PARAMS, _paramLists);
                }
            }
            // TODO do these guys need anything else?
            /*if (parm.getDefaultArgument() != null) {
                    //This could be compiled to JS...
                    pm.put(ANN_DEFAULT, parm.getDefaultArgument().getSpecifierExpression().getExpression().getTerm().getText());
                }*/
            encodeAnnotations(parm.getModel().getAnnotations(), parm.getModel(), pm);
            p.add(pm);
        }
        return p;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Function(org.eclipse.ceylon.model.typechecker.model.Function) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)65 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)28 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)27 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)26 Type (org.eclipse.ceylon.model.typechecker.model.Type)25 Value (org.eclipse.ceylon.model.typechecker.model.Value)24 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)22 Function (org.eclipse.ceylon.model.typechecker.model.Function)22 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)21 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)19 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)13 ArrayList (java.util.ArrayList)12 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)11 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)10 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)9 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)9 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)9 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)9 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)9 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)9