Search in sources :

Example 21 with IFeatureCallArguments

use of org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments in project xtext-xtend by eclipse.

the class VarArgFeatureCallArgumentsTest method test_02.

@Test(expected = NoSuchElementException.class)
public void test_02() {
    final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("", "");
    arguments.getNextUnprocessedArgumentSlot();
}
Also used : IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Example 22 with IFeatureCallArguments

use of org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments in project xtext-xtend by eclipse.

the class VarArgFeatureCallArgumentsTest method testBug457779_01.

@Test
public void testBug457779_01() {
    final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int[] i", "\"\", 1, true");
    final XExpression first = arguments.getArgument(0);
    Assert.assertNull(first);
    final LightweightTypeReference firstType = arguments.getDeclaredTypeForLambda(0);
    Assert.assertNull(firstType);
    final XExpression second = arguments.getArgument(1);
    Assert.assertTrue((second instanceof XStringLiteral));
    final LightweightTypeReference secondType = arguments.getDeclaredTypeForLambda(1);
    Assert.assertEquals("String", secondType.getSimpleName());
    final XExpression third = arguments.getArgument(2);
    Assert.assertTrue((third instanceof XNumberLiteral));
    final LightweightTypeReference thirdType = arguments.getDeclaredTypeForLambda(2);
    Assert.assertEquals("int", thirdType.getSimpleName());
    final XExpression fourth = arguments.getArgument(3);
    Assert.assertTrue((fourth instanceof XBooleanLiteral));
    final LightweightTypeReference fourthType = arguments.getDeclaredTypeForLambda(3);
    Assert.assertEquals("int", fourthType.getSimpleName());
    try {
        arguments.getArgument(4);
        Assert.fail("Expected exception");
    } catch (final Throwable _t) {
        if (_t instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    try {
        arguments.getDeclaredTypeForLambda(4);
        Assert.fail("Expected exception");
    } catch (final Throwable _t_1) {
        if (_t_1 instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t_1);
        }
    }
}
Also used : XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) XBooleanLiteral(org.eclipse.xtext.xbase.XBooleanLiteral) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) XNumberLiteral(org.eclipse.xtext.xbase.XNumberLiteral) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Example 23 with IFeatureCallArguments

use of org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments in project xtext-xtend by eclipse.

the class VarArgFeatureCallArgumentsTest method test_10.

@Test
public void test_10() {
    final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s", "\"\", 1");
    Assert.assertTrue(arguments.hasUnprocessedArguments());
    Assert.assertEquals(3, arguments.getArgumentCount());
    final IFeatureCallArgumentSlot valid = arguments.getNextUnprocessedArgumentSlot();
    Assert.assertTrue(valid.isVarArg());
    Assert.assertFalse(valid.isSuperfluous());
    final List<XExpression> expressions = valid.getArgumentExpressions();
    Assert.assertEquals(2, expressions.size());
    XExpression _head = IterableExtensions.<XExpression>head(expressions);
    Assert.assertTrue((_head instanceof XStringLiteral));
    XExpression _last = IterableExtensions.<XExpression>last(expressions);
    Assert.assertTrue((_last instanceof XNumberLiteral));
    Assert.assertTrue(arguments.isProcessed(0));
    Assert.assertFalse(arguments.isProcessed(1));
    Assert.assertFalse(arguments.isProcessed(2));
    valid.markProcessed();
    Assert.assertTrue(arguments.isProcessed(0));
    Assert.assertTrue(arguments.isProcessed(1));
    Assert.assertTrue(arguments.isProcessed(2));
    Assert.assertFalse(arguments.hasUnprocessedArguments());
}
Also used : XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) XExpression(org.eclipse.xtext.xbase.XExpression) XNumberLiteral(org.eclipse.xtext.xbase.XNumberLiteral) IFeatureCallArgumentSlot(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Example 24 with IFeatureCallArguments

use of org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments in project xtext-xtend by eclipse.

the class VarArgFeatureCallArgumentsTest method test_03.

@Test
public void test_03() {
    final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s", "\"\"");
    Assert.assertTrue(arguments.hasUnprocessedArguments());
    Assert.assertEquals(1, arguments.getArgumentCount());
    final IFeatureCallArgumentSlot singleSlot = arguments.getNextUnprocessedArgumentSlot();
    Assert.assertTrue(singleSlot.isVarArg());
    Assert.assertFalse(singleSlot.isSuperfluous());
    XExpression _argumentExpression = singleSlot.getArgumentExpression();
    Assert.assertTrue((_argumentExpression instanceof XStringLiteral));
    Assert.assertEquals("String", singleSlot.getDeclaredType().getSimpleName());
    singleSlot.markProcessed();
    Assert.assertFalse(arguments.hasUnprocessedArguments());
}
Also used : XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureCallArgumentSlot(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Example 25 with IFeatureCallArguments

use of org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments in project xtext-xtend by eclipse.

the class VarArgFeatureCallArgumentsTest method test_08.

@Test
public void test_08() {
    final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int i", "\"\", 1");
    Assert.assertEquals(3, arguments.getArgumentCount());
    Assert.assertTrue(arguments.hasUnprocessedArguments());
    final IFeatureCallArgumentSlot firstSlot = arguments.getNextUnprocessedArgumentSlot();
    Assert.assertFalse(firstSlot.isVarArg());
    Assert.assertFalse(firstSlot.isSuperfluous());
    XExpression _argumentExpression = firstSlot.getArgumentExpression();
    Assert.assertTrue((_argumentExpression instanceof XStringLiteral));
    Assert.assertEquals("String", firstSlot.getDeclaredType().getSimpleName());
    Assert.assertTrue(arguments.isProcessed(0));
    Assert.assertFalse(arguments.isProcessed(1));
    firstSlot.markProcessed();
    Assert.assertTrue(arguments.isProcessed(1));
    Assert.assertTrue(arguments.hasUnprocessedArguments());
    final IFeatureCallArgumentSlot secondSlot = arguments.getNextUnprocessedArgumentSlot();
    Assert.assertTrue(secondSlot.isVarArg());
    Assert.assertFalse(secondSlot.isSuperfluous());
    XExpression _argumentExpression_1 = secondSlot.getArgumentExpression();
    Assert.assertTrue((_argumentExpression_1 instanceof XNumberLiteral));
    Assert.assertEquals("int", secondSlot.getDeclaredType().getSimpleName());
    Assert.assertFalse(arguments.isProcessed(2));
    secondSlot.markProcessed();
    Assert.assertTrue(arguments.isProcessed(2));
    Assert.assertFalse(arguments.hasUnprocessedArguments());
}
Also used : XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) XExpression(org.eclipse.xtext.xbase.XExpression) XNumberLiteral(org.eclipse.xtext.xbase.XNumberLiteral) IFeatureCallArgumentSlot(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Aggregations

IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)53 Test (org.junit.Test)49 XExpression (org.eclipse.xtext.xbase.XExpression)28 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)21 XStringLiteral (org.eclipse.xtext.xbase.XStringLiteral)16 IFeatureCallArgumentSlot (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot)14 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 XClosure (org.eclipse.xtext.xbase.XClosure)8 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)6 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)4 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)4 XBooleanLiteral (org.eclipse.xtext.xbase.XBooleanLiteral)3