Search in sources :

Example 26 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class StandardFeatureCallArgumentsTest 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.assertFalse(valid.isVarArg());
    Assert.assertFalse(valid.isSuperfluous());
    XExpression _argumentExpression = valid.getArgumentExpression();
    Assert.assertTrue((_argumentExpression instanceof XStringLiteral));
    valid.markProcessed();
    Assert.assertTrue(arguments.hasUnprocessedArguments());
    Assert.assertTrue(arguments.isProcessed(1));
    final IFeatureCallArgumentSlot superfluous = arguments.getNextUnprocessedArgumentSlot();
    Assert.assertFalse(superfluous.isVarArg());
    Assert.assertTrue(superfluous.isSuperfluous());
    XExpression _argumentExpression_1 = superfluous.getArgumentExpression();
    Assert.assertTrue((_argumentExpression_1 instanceof XNumberLiteral));
    Assert.assertFalse(arguments.isProcessed(2));
    superfluous.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)

Example 27 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class StandardFeatureCallArgumentsTest method testBug457779_03.

@Test
public void testBug457779_03() {
    final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s, int i", "\"\", 1, true");
    final XExpression first = arguments.getArgument(0);
    Assert.assertTrue((first instanceof XStringLiteral));
    final LightweightTypeReference firstType = arguments.getDeclaredTypeForLambda(0);
    Assert.assertEquals("String", firstType.getSimpleName());
    final XExpression second = arguments.getArgument(1);
    Assert.assertTrue((second instanceof XNumberLiteral));
    final LightweightTypeReference secondType = arguments.getDeclaredTypeForLambda(1);
    Assert.assertEquals("int", secondType.getSimpleName());
    final XExpression third = arguments.getArgument(2);
    Assert.assertTrue((third instanceof XBooleanLiteral));
    final LightweightTypeReference thirdType = arguments.getDeclaredTypeForLambda(2);
    Assert.assertNull("int", thirdType);
    try {
        arguments.getArgument(3);
        Assert.fail("Expected exception");
    } catch (final Throwable _t) {
        if (_t instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    try {
        arguments.getDeclaredTypeForLambda(3);
        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 28 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class VarArgFeatureCallArgumentsTest method testBug457779_03.

@Test
public void testBug457779_03() {
    final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int[] i", "\"\"");
    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());
    try {
        arguments.getArgument(2);
        Assert.fail("Expected exception");
    } catch (final Throwable _t) {
        if (_t instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    try {
        arguments.getDeclaredTypeForLambda(2);
        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) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Example 29 with XExpression

use of org.eclipse.xtext.xbase.XExpression 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 30 with XExpression

use of org.eclipse.xtext.xbase.XExpression 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)

Aggregations

XExpression (org.eclipse.xtext.xbase.XExpression)215 Test (org.junit.Test)133 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)96 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)84 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)82 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)82 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)80 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)63 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)36 EObject (org.eclipse.emf.ecore.EObject)28 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)28 XtendField (org.eclipse.xtend.core.xtend.XtendField)23 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)23 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)21 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)18 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)17 XStringLiteral (org.eclipse.xtext.xbase.XStringLiteral)17 XClosure (org.eclipse.xtext.xbase.XClosure)16 IFeatureCallArgumentSlot (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot)16