Search in sources :

Example 56 with ParameterList

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

the class AbstractModelLoader method loadFunctionalParameter.

private Function loadFunctionalParameter(Declaration decl, String paramName, Type type, String parameterNames) {
    Function method = new Function();
    method.setName(paramName);
    method.setUnit(decl.getUnit());
    if (parameterNames == null || parameterNames.isEmpty()) {
        // This branch is broken, but it deals with old code which lacked
        // the encoding of parameter names of functional parameters, so we'll keep it until 1.2
        method.setType(getSimpleCallableReturnType(type));
        ParameterList pl = new ParameterList();
        int count = 0;
        for (Type pt : getSimpleCallableArgumentTypes(type)) {
            Parameter p = new Parameter();
            Value v = new Value();
            String name = "arg" + count++;
            p.setName(name);
            v.setName(name);
            v.setType(pt);
            v.setContainer(method);
            v.setScope(method);
            p.setModel(v);
            v.setInitializerParameter(p);
            pl.getParameters().add(p);
            method.addMember(v);
        }
        method.addParameterList(pl);
    } else {
        try {
            parameterNameParser.parse(parameterNames, type, method);
        } catch (Exception x) {
            logError(x.getClass().getSimpleName() + " while parsing parameter names of " + decl + ": " + x.getMessage());
            return method;
        }
    }
    return method;
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException)

Example 57 with ParameterList

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

the class AbstractModelLoader method setEqualsParameters.

private void setEqualsParameters(Function decl, MethodMirror methodMirror) {
    ParameterList parameters = new ParameterList();
    decl.addParameterList(parameters);
    Parameter parameter = new Parameter();
    Value value = new Value();
    parameter.setModel(value);
    value.setInitializerParameter(parameter);
    value.setUnit(decl.getUnit());
    Scope scope = (Scope) decl;
    value.setContainer(scope);
    value.setScope(scope);
    parameter.setName("that");
    value.setName("that");
    value.setType(getNonPrimitiveType(getLanguageModule(), CEYLON_OBJECT_TYPE, decl));
    parameter.setDeclaration((Declaration) decl);
    parameters.getParameters().add(parameter);
    decl.addMember(value);
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Example 58 with ParameterList

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

the class AbstractModelLoader method complete.

private void complete(AnnotationProxyClass klass, LazyInterface iface) {
    ParameterList classpl = new ParameterList();
    klass.addParameterList(classpl);
    for (Declaration member : iface.getMembers()) {
        boolean isValue = member.getName().equals("value");
        if (member instanceof JavaMethod) {
            JavaMethod m = (JavaMethod) member;
            Parameter klassParam = new Parameter();
            Value value = new Value();
            klassParam.setModel(value);
            value.setInitializerParameter(klassParam);
            klassParam.setDeclaration(klass);
            value.setContainer(klass);
            value.setScope(klass);
            value.setName(member.getName());
            klassParam.setName(member.getName());
            value.setType(annotationParameterType(iface.getUnit(), m));
            value.setUnboxed(true);
            value.setUnit(iface.getUnit());
            if (isValue)
                classpl.getParameters().add(0, klassParam);
            else
                classpl.getParameters().add(klassParam);
            klass.addMember(value);
        }
    }
}
Also used : JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) JavaMethod(org.eclipse.ceylon.model.loader.model.JavaMethod) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 59 with ParameterList

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

the class ParameterNameParser method parse.

public void parse(String input, Type type, Function method) {
    lexer.setup(input);
    this.unit = method.getUnit();
    boolean declaredVoid = false;
    ArrayList<ParameterList> lists = new ArrayList<>();
    if (lexer.lookingAt(BANG)) {
        lexer.eat();
        declaredVoid = true;
    }
    lists.add(parseNameList(type, method));
    while (lexer.lookingAt(LEFT_PAREN)) {
        // mpl
        type = loader.getSimpleCallableReturnType(type);
        lists.add(parseNameList(type, method));
    }
    for (ParameterList parameterList : lists) {
        method.addParameterList(parameterList);
    }
    method.setDeclaredVoid(declaredVoid);
    method.setType(loader.getSimpleCallableReturnType(type));
    if (!lexer.lookingAt(EOI)) {
        throw new ParameterNameParserException("Expected end of input" + System.lineSeparator() + input);
    }
}
Also used : ArrayList(java.util.ArrayList) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList)

Example 60 with ParameterList

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

the class ExpressionTransformer method transformFunctionalInterfaceBridge.

public JCExpression transformFunctionalInterfaceBridge(Tree.InvocationExpression expr, JCExpression primaryExpr, Type expectedType) {
    ParameterList paramList = new ParameterList();
    int i = 0;
    Type callableType = expr.getTypeModel().getSupertype(typeFact().getCallableDeclaration());
    for (Type type : typeFact().getCallableArgumentTypes(callableType)) {
        Parameter param = new Parameter();
        Value paramModel = new Value();
        param.setModel(paramModel);
        param.setName("arg" + i);
        paramModel.setName("arg" + i);
        paramModel.setType(type);
        paramList.getParameters().add(param);
        i++;
    }
    return CallableBuilder.callableToFunctionalInterface(gen(), expr, paramList, expectedType, expr.getTypeModel(), false, primaryExpr);
}
Also used : UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) 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)

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