Search in sources :

Example 11 with XClosure

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

the class XtendFormatter method builder.

@Override
protected XClosure builder(final List<XExpression> params) {
    XClosure _xifexpression = null;
    XExpression _last = IterableExtensions.<XExpression>last(params);
    boolean _tripleNotEquals = (_last != null);
    if (_tripleNotEquals) {
        XClosure _xblockexpression = null;
        {
            final EObject grammarElement = this.textRegionExtensions.grammarElement(IterableExtensions.<XExpression>last(params));
            XClosure _xifexpression_1 = null;
            if (((Objects.equal(grammarElement, this._xtendGrammarAccess.getXMemberFeatureCallAccess().getMemberCallArgumentsXClosureParserRuleCall_1_1_4_0()) || Objects.equal(grammarElement, this._xtendGrammarAccess.getXFeatureCallAccess().getFeatureCallArgumentsXClosureParserRuleCall_4_0())) || Objects.equal(grammarElement, this._xtendGrammarAccess.getXbaseConstructorCallAccess().getArgumentsXClosureParserRuleCall_5_0()))) {
                XExpression _last_1 = IterableExtensions.<XExpression>last(params);
                _xifexpression_1 = ((XClosure) _last_1);
            }
            _xblockexpression = _xifexpression_1;
        }
        _xifexpression = _xblockexpression;
    }
    return _xifexpression;
}
Also used : XClosure(org.eclipse.xtext.xbase.XClosure) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 12 with XClosure

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

the class ReorderedFeatureCallArgumentsTest method test_01.

@Test
public void test_01() {
    final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s, int i", "[], 1");
    Assert.assertEquals(2, 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 XNumberLiteral));
    Assert.assertEquals("int", firstSlot.getDeclaredType().getSimpleName());
    Assert.assertFalse(arguments.isProcessed(0));
    firstSlot.markProcessed();
    Assert.assertTrue(arguments.isProcessed(0));
    Assert.assertTrue(arguments.hasUnprocessedArguments());
    final IFeatureCallArgumentSlot secondSlot = arguments.getNextUnprocessedArgumentSlot();
    Assert.assertFalse(secondSlot.isVarArg());
    Assert.assertFalse(secondSlot.isSuperfluous());
    XExpression _argumentExpression_1 = secondSlot.getArgumentExpression();
    Assert.assertTrue((_argumentExpression_1 instanceof XClosure));
    Assert.assertEquals("String", secondSlot.getDeclaredType().getSimpleName());
    Assert.assertFalse(arguments.isProcessed(1));
    secondSlot.markProcessed();
    Assert.assertTrue(arguments.isProcessed(1));
    Assert.assertFalse(arguments.hasUnprocessedArguments());
}
Also used : XClosure(org.eclipse.xtext.xbase.XClosure) 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 13 with XClosure

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

the class ReorderedFeatureCallArgumentsTest method testBug457779_01.

@Test
public void testBug457779_01() {
    final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int i", "[], 1");
    final XExpression first = arguments.getArgument(0);
    Assert.assertNull(first);
    final LightweightTypeReference firstType = arguments.getDeclaredTypeForLambda(0);
    Assert.assertNull(firstType);
    final XExpression third = arguments.getArgument(1);
    Assert.assertTrue((third instanceof XNumberLiteral));
    final LightweightTypeReference thirdType = arguments.getDeclaredTypeForLambda(1);
    Assert.assertEquals("int", thirdType.getSimpleName());
    final XExpression second = arguments.getArgument(2);
    Assert.assertTrue((second instanceof XClosure));
    final LightweightTypeReference secondType = arguments.getDeclaredTypeForLambda(2);
    Assert.assertEquals("String", secondType.getSimpleName());
    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 : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XClosure(org.eclipse.xtext.xbase.XClosure) 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 14 with XClosure

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

the class ReorderedFeatureCallArgumentsTest method testBug457779_02.

@Test
public void testBug457779_02() {
    final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s, int i", "[], 1");
    final XExpression second = arguments.getArgument(0);
    Assert.assertTrue((second instanceof XNumberLiteral));
    final LightweightTypeReference secondType = arguments.getDeclaredTypeForLambda(0);
    Assert.assertEquals("int", secondType.getSimpleName());
    final XExpression first = arguments.getArgument(1);
    Assert.assertTrue((first instanceof XClosure));
    final LightweightTypeReference firstType = arguments.getDeclaredTypeForLambda(1);
    Assert.assertEquals("String", firstType.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 : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XClosure(org.eclipse.xtext.xbase.XClosure) 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 15 with XClosure

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

the class ReorderedVarArgFeatureCallArgumentsTest method testBug457779_01.

@Test
public void testBug457779_01() {
    final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, boolean b, int[] i", "[], 1, [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 XNumberLiteral));
    final LightweightTypeReference secondType = arguments.getDeclaredTypeForLambda(1);
    Assert.assertEquals("boolean", secondType.getSimpleName());
    final XExpression third = arguments.getArgument(2);
    Assert.assertTrue((third instanceof XClosure));
    XExpression _expression = ((XClosure) third).getExpression();
    Assert.assertFalse(((XBlockExpression) _expression).getExpressions().isEmpty());
    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());
    final XExpression fifth = arguments.getArgument(4);
    Assert.assertTrue((fifth instanceof XClosure));
    XExpression _expression_1 = ((XClosure) fifth).getExpression();
    Assert.assertTrue(((XBlockExpression) _expression_1).getExpressions().isEmpty());
    final LightweightTypeReference fifthType = arguments.getDeclaredTypeForLambda(4);
    Assert.assertEquals("String", fifthType.getSimpleName());
    try {
        arguments.getArgument(5);
        Assert.fail("Expected exception");
    } catch (final Throwable _t) {
        if (_t instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    try {
        arguments.getDeclaredTypeForLambda(5);
        Assert.fail("Expected exception");
    } catch (final Throwable _t_1) {
        if (_t_1 instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t_1);
        }
    }
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XBooleanLiteral(org.eclipse.xtext.xbase.XBooleanLiteral) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XClosure(org.eclipse.xtext.xbase.XClosure) XExpression(org.eclipse.xtext.xbase.XExpression) XNumberLiteral(org.eclipse.xtext.xbase.XNumberLiteral) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Aggregations

XClosure (org.eclipse.xtext.xbase.XClosure)21 Test (org.junit.Test)17 XExpression (org.eclipse.xtext.xbase.XExpression)16 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)8 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)6 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)4 IFeatureCallArgumentSlot (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot)4 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)4 EObject (org.eclipse.emf.ecore.EObject)3 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)3 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)3 XtendFormalParameter (org.eclipse.xtend.core.xtend.XtendFormalParameter)2