Search in sources :

Example 36 with Function

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

the class NamedArgumentInvocation method bindMethodArgument.

private void bindMethodArgument(Tree.MethodArgument methodArg, Parameter declaredParam, Naming.SyntheticName argName) {
    ListBuffer<JCStatement> statements;
    Function model = methodArg.getDeclarationModel();
    List<JCStatement> body;
    boolean prevNoExpressionlessReturn = gen.statementGen().noExpressionlessReturn;
    boolean prevSyntheticClassBody = gen.expressionGen().withinSyntheticClassBody(Decl.isMpl(model) || gen.expressionGen().isWithinSyntheticClassBody());
    try {
        gen.statementGen().noExpressionlessReturn = gen.isAnything(model.getType());
        if (methodArg.getBlock() != null) {
            body = gen.statementGen().transformBlock(methodArg.getBlock());
            if (!methodArg.getBlock().getDefinitelyReturns()) {
                if (gen.isAnything(model.getType())) {
                    body = body.append(gen.make().Return(gen.makeNull()));
                } else {
                    body = body.append(gen.make().Return(gen.makeErroneous(methodArg.getBlock(), "compiler bug: non-void method does not definitely return")));
                }
            }
        } else {
            Expression expr = methodArg.getSpecifierExpression().getExpression();
            BoxingStrategy boxing = CodegenUtil.getBoxingStrategy(model);
            Type type = model.getType();
            JCExpression transExpr = gen.expressionGen().transformExpression(expr, boxing, type);
            JCReturn returnStat = gen.make().Return(transExpr);
            body = List.<JCStatement>of(returnStat);
        }
    } finally {
        gen.expressionGen().withinSyntheticClassBody(prevSyntheticClassBody);
        gen.statementGen().noExpressionlessReturn = prevNoExpressionlessReturn;
    }
    Type callableType = model.appliedReference(null, Collections.<Type>emptyList()).getFullType();
    CallableBuilder callableBuilder = CallableBuilder.methodArgument(gen.gen(), methodArg, model, callableType, Collections.singletonList(methodArg.getParameterLists().get(0)), gen.classGen().transformMplBody(methodArg.getParameterLists(), model, body));
    JCExpression callable = callableBuilder.build();
    JCExpression typeExpr = gen.makeJavaType(callableType, JT_RAW);
    JCVariableDecl varDecl = gen.makeVar(argName, typeExpr, callable);
    statements = ListBuffer.<JCStatement>of(varDecl);
    bind(declaredParam, argName, gen.makeJavaType(callableType), statements.toList());
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) JCReturn(com.sun.tools.javac.tree.JCTree.JCReturn) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) QualifiedTypeExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.QualifiedTypeExpression) Expression(com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) BoxingStrategy(com.redhat.ceylon.compiler.java.codegen.AbstractTransformer.BoxingStrategy) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl)

Example 37 with Function

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

the class LocalTypeVisitor method visit.

@Override
public void visit(Tree.BaseMemberOrTypeExpression that) {
    Declaration model = that.getDeclaration();
    if (model != null && (model instanceof Function || model instanceof Class) && // if it's a parameter we don't need to wrap it in a class
    !model.isParameter() && !that.getDirectlyInvoked()) {
        String prefix = this.prefix;
        enterAnonymousClass();
        super.visit(that);
        exitAnonymousClass();
        this.prefix = prefix;
    } else {
        super.visit(that);
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Class(com.redhat.ceylon.model.typechecker.model.Class) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration)

Example 38 with Function

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

the class LocalTypeVisitor method startFrom.

public void startFrom(Node tree) {
    int mpl = 0;
    String prefix = null;
    // make sure we start with the right number of anonymous classes for methods with MPL before we visit the children
    if (tree instanceof Tree.AnyMethod) {
        Function model = ((Tree.AnyMethod) tree).getDeclarationModel();
        mpl = model.getParameterLists().size();
        if (mpl > 1) {
            prefix = this.prefix;
            for (int i = 1; i < mpl; i++) enterAnonymousClass();
        }
    }
    tree.visitChildren(this);
    if (mpl > 1) {
        for (int i = 1; i < mpl; i++) exitAnonymousClass();
        this.prefix = prefix;
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function)

Example 39 with Function

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

the class LocalTypeVisitor method visit.

@Override
public void visit(Tree.AnyMethod that) {
    Function model = that.getDeclarationModel();
    int mpl = model.getParameterLists().size();
    String prefix = null;
    if (mpl > 1) {
        prefix = this.prefix;
        for (int i = 1; i < mpl; i++) enterAnonymousClass();
    }
    collect(that, model);
    // stop at locals, who get a type generated for them
    if (model.isMember())
        super.visit(that);
    if (mpl > 1) {
        for (int i = 1; i < mpl; i++) exitAnonymousClass();
        this.prefix = prefix;
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function)

Example 40 with Function

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

the class ModelLoaderTests method functionalParameterParameterNames.

@Test
public void functionalParameterParameterNames() {
    compile("FunctionalParameterParameterNames.ceylon");
    try {
        verifyCompilerClassLoading("functionalparameterparameternamestest.ceylon", new RunnableTest() {

            @Override
            public void test(ModelLoader loader) {
                Module mod = loader.getLoadedModule(moduleForJavaModelLoading(), moduleVersionForJavaModelLoading());
                Assert.assertNotNull(mod);
                Package p = mod.getDirectPackage(packageForJavaModelLoading());
                Assert.assertNotNull(p);
                Declaration fpClass = p.getDirectMember("FunctionalParameterParameterNames", Collections.<Type>emptyList(), false);
                Assert.assertNotNull(fpClass);
                {
                    // functionalParameter
                    Function fp = (Function) fpClass.getDirectMember("functionalParameter", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(String)", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                }
                {
                    // callableValueParameter
                    Function fp = (Function) fpClass.getDirectMember("callableValueParameter", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertFalse(paramF.isDeclaredAnything());
                    Assert.assertTrue(paramF.getModel() instanceof Value);
                    Value modelF = (Value) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything(String)", typeName(modelF));
                }
                {
                    // functionalParameterNested
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterNested", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(Anything(String)))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("Anything(Anything(String))", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramF2 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF2.isDeclaredAnything());
                    Assert.assertEquals("f2", paramF2.getName());
                    Assert.assertTrue(paramF2.getModel() instanceof Function);
                    Function modelF2 = (Function) paramF2.getModel();
                    Assert.assertEquals("Anything(String)", typeName(modelF2));
                    Assert.assertEquals("f2", modelF2.getName());
                    Assert.assertTrue(modelF2.isDeclaredVoid());
                    Assert.assertEquals(1, modelF2.getParameterLists().size());
                    Assert.assertEquals(1, modelF2.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF2.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                }
                {
                    // functionalParameterNested2
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterNested2", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(Anything(String, Anything(Boolean, Integer))))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything(Anything(String, Anything(Boolean, Integer)))", typeName(modelF));
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramF2 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f2", paramF2.getName());
                    Assert.assertTrue(paramF2.getModel() instanceof Function);
                    Function modelF2 = (Function) paramF2.getModel();
                    Assert.assertEquals("Anything(String, Anything(Boolean, Integer))", typeName(modelF2));
                    Assert.assertEquals("f2", modelF2.getName());
                    Assert.assertEquals(1, modelF2.getParameterLists().size());
                    Assert.assertEquals(2, modelF2.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF2.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("String", typeName(modelS));
                    Assert.assertEquals("s", modelS.getName());
                    Parameter paramF3 = modelF2.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("f3", paramF3.getName());
                    Assert.assertTrue(paramF3.getModel() instanceof Function);
                    Function modelF3 = (Function) paramF3.getModel();
                    Assert.assertEquals("Anything(Boolean, Integer)", typeName(modelF3));
                    Assert.assertEquals("f3", modelF3.getName());
                    Assert.assertEquals(1, modelF3.getParameterLists().size());
                    Assert.assertEquals(2, modelF3.getParameterLists().get(0).getParameters().size());
                    Parameter paramB1 = modelF3.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("b1", paramB1.getName());
                    Assert.assertTrue(paramB1.getModel() instanceof Value);
                    Value modelB1 = (Value) paramB1.getModel();
                    Assert.assertEquals("Boolean", typeName(modelB1));
                    Assert.assertEquals("b1", modelB1.getName());
                    Parameter paramI2 = modelF3.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("i2", paramI2.getName());
                    Assert.assertTrue(paramI2.getModel() instanceof Value);
                    Value modelI2 = (Value) paramI2.getModel();
                    Assert.assertEquals("i2", modelI2.getName());
                    Assert.assertEquals("Integer", typeName(modelI2));
                }
                {
                    // functionalParameterMpl
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterMpl", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(Integer)(String))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("mpl", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(Integer)(String)", typeName(modelF));
                    Assert.assertEquals("mpl", modelF.getName());
                    Assert.assertEquals(2, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(1).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                    Parameter paramS2 = modelF.getParameterLists().get(1).getParameters().get(0);
                    Assert.assertEquals("i2", paramS2.getName());
                    Assert.assertTrue(paramS2.getModel() instanceof Value);
                    Value modelS2 = (Value) paramS2.getModel();
                    Assert.assertEquals("i2", modelS2.getName());
                    Assert.assertEquals("Integer", typeName(modelS2));
                }
                {
                    // functionalParameterMpl2
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterMpl2", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramMpl = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("mpl", paramMpl.getName());
                    Assert.assertTrue(paramMpl.getModel() instanceof Function);
                    Function modelMpl = (Function) paramMpl.getModel();
                    Assert.assertEquals("mpl", modelMpl.getName());
                    Assert.assertEquals(2, modelMpl.getParameterLists().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(1).getParameters().size());
                    Parameter paramS = modelMpl.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                    Parameter paramF = modelMpl.getParameterLists().get(1).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(2, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramB1 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("b1", paramB1.getName());
                    Assert.assertTrue(paramB1.getModel() instanceof Value);
                    Value modelB1 = (Value) paramB1.getModel();
                    Assert.assertEquals("b1", modelB1.getName());
                    Assert.assertEquals("Boolean", typeName(modelB1));
                    Parameter paramI2 = modelF.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("i2", paramI2.getName());
                    Assert.assertTrue(paramI2.getModel() instanceof Value);
                    Value modelI2 = (Value) paramI2.getModel();
                    Assert.assertEquals("i2", modelI2.getName());
                    Assert.assertEquals("Integer", typeName(modelI2));
                }
                {
                    // functionalParameterMpl3
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterMpl3", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramMpl = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("mpl", paramMpl.getName());
                    Assert.assertTrue(paramMpl.getModel() instanceof Function);
                    Function modelMpl = (Function) paramMpl.getModel();
                    Assert.assertEquals("mpl", modelMpl.getName());
                    Assert.assertEquals(2, modelMpl.getParameterLists().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals(1, modelMpl.getParameterLists().get(1).getParameters().size());
                    Parameter paramF = modelMpl.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(2, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramB1 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("b1", paramB1.getName());
                    Assert.assertTrue(paramB1.getModel() instanceof Value);
                    Value modelB1 = (Value) paramB1.getModel();
                    Assert.assertEquals("b1", modelB1.getName());
                    Assert.assertEquals("Boolean", typeName(modelB1));
                    Parameter paramI2 = modelF.getParameterLists().get(0).getParameters().get(1);
                    Assert.assertEquals("i2", paramI2.getName());
                    Assert.assertTrue(paramI2.getModel() instanceof Value);
                    Value modelI2 = (Value) paramI2.getModel();
                    Assert.assertEquals("i2", modelI2.getName());
                    Assert.assertEquals("Integer", typeName(modelI2));
                    Parameter paramS = modelMpl.getParameterLists().get(1).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", typeName(modelS));
                }
                {
                    // functionalParameterReturningCallable
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterReturningCallable", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything()", modelF.getType().asString());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String", modelS.getType().asString());
                }
                {
                    // functionalParameterReturningCallable
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterTakingCallable", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals("Anything", modelF.getType().asString());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramF2 = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("f2", paramF2.getName());
                    Assert.assertTrue(paramF2.getModel() instanceof Value);
                    Value modelF2 = (Value) paramF2.getModel();
                    Assert.assertEquals("f2", modelF2.getName());
                    Assert.assertEquals("Anything(String)", modelF2.getType().asString());
                }
                {
                    // functionalParameterVariadicStar
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterVariadicStar", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String*))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(String*)", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.isSequenced());
                    Assert.assertFalse(paramS.isAtLeastOne());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("String[]", typeName(modelS));
                }
                {
                    // functionalParameterVariadicPlus
                    Function fp = (Function) fpClass.getDirectMember("functionalParameterVariadicPlus", null, false);
                    Assert.assertNotNull(fp);
                    Assert.assertEquals(1, fp.getParameterLists().size());
                    Assert.assertEquals(1, fp.getParameterLists().get(0).getParameters().size());
                    Assert.assertEquals("Anything(Anything(String+))", typeName(fp));
                    Parameter paramF = fp.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertTrue(paramF.isDeclaredAnything());
                    Assert.assertEquals("f", paramF.getName());
                    Assert.assertTrue(paramF.getModel() instanceof Function);
                    Function modelF = (Function) paramF.getModel();
                    Assert.assertTrue(modelF.isDeclaredVoid());
                    Assert.assertEquals("Anything(String+)", typeName(modelF));
                    Assert.assertEquals("f", modelF.getName());
                    Assert.assertEquals(1, modelF.getParameterLists().size());
                    Assert.assertEquals(1, modelF.getParameterLists().get(0).getParameters().size());
                    Parameter paramS = modelF.getParameterLists().get(0).getParameters().get(0);
                    Assert.assertEquals("s", paramS.getName());
                    Assert.assertTrue(paramS.isSequenced());
                    Assert.assertTrue(paramS.isAtLeastOne());
                    Assert.assertTrue(paramS.getModel() instanceof Value);
                    Value modelS = (Value) paramS.getModel();
                    Assert.assertEquals("s", modelS.getName());
                    Assert.assertEquals("[String+]", typeName(modelS));
                }
            }

            private String typeName(FunctionOrValue fp) {
                if (fp instanceof Function) {
                    return fp.appliedTypedReference(null, Collections.<Type>emptyList()).getFullType().asString();
                } else if (fp instanceof Value) {
                    return fp.getType().asString();
                }
                return null;
            }
        });
    } catch (RuntimeException e) {
        if (e.getCause() instanceof org.junit.ComparisonFailure) {
            throw (org.junit.ComparisonFailure) e.getCause();
        } else if (e.getCause() instanceof java.lang.AssertionError) {
            throw (java.lang.AssertionError) e.getCause();
        }
        throw e;
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) AbstractModelLoader(com.redhat.ceylon.model.loader.AbstractModelLoader) ModelLoader(com.redhat.ceylon.model.loader.ModelLoader) RuntimeModelLoader(com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader) CeylonModelLoader(com.redhat.ceylon.compiler.java.loader.CeylonModelLoader) DeclarationType(com.redhat.ceylon.model.loader.ModelLoader.DeclarationType) Type(com.redhat.ceylon.model.typechecker.model.Type) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) Package(com.redhat.ceylon.model.typechecker.model.Package) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Module(com.redhat.ceylon.model.typechecker.model.Module) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Test(org.junit.Test)

Aggregations

Function (com.redhat.ceylon.model.typechecker.model.Function)74 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)35 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)35 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)33 Type (com.redhat.ceylon.model.typechecker.model.Type)33 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)26 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)26 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)25 Value (com.redhat.ceylon.model.typechecker.model.Value)25 Class (com.redhat.ceylon.model.typechecker.model.Class)23 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)22 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)20 JCTree (com.sun.tools.javac.tree.JCTree)18 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)17 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)17 ArrayList (java.util.ArrayList)14 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)13 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)12 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)11 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)11