Search in sources :

Example 1 with AssignmentFeatureCallArguments

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

the class AssignmentFeatureCallArgumentsTest method test_02.

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

Example 2 with AssignmentFeatureCallArguments

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

the class AssignmentFeatureCallArgumentsTest method test_01.

@Test
public void test_01() {
    final AssignmentFeatureCallArguments arguments = this.toArguments("", "null");
    Assert.assertTrue(arguments.hasUnprocessedArguments());
    final IFeatureCallArgumentSlot singleSlot = arguments.getNextUnprocessedArgumentSlot();
    Assert.assertNull(singleSlot.getDeclaredType());
    Assert.assertFalse(singleSlot.isVarArg());
    Assert.assertFalse(singleSlot.isSuperfluous());
    XExpression _argumentExpression = singleSlot.getArgumentExpression();
    Assert.assertTrue((_argumentExpression instanceof XNullLiteral));
    singleSlot.markProcessed();
    Assert.assertFalse(arguments.hasUnprocessedArguments());
}
Also used : AssignmentFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.AssignmentFeatureCallArguments) XNullLiteral(org.eclipse.xtext.xbase.XNullLiteral) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureCallArgumentSlot(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot) Test(org.junit.Test)

Example 3 with AssignmentFeatureCallArguments

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

the class AssignmentFeatureCallArgumentsTest method toArguments.

protected AssignmentFeatureCallArguments toArguments(final String type, final String expression) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void m(");
        _builder.append(type);
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(expression, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("}");
        _builder.newLine();
        final String functionString = _builder.toString();
        final XtendFunction function = this.function(functionString);
        XExpression _expression = function.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        final XExpression value = IterableExtensions.<XExpression>head(body.getExpressions());
        JvmFormalParameter _head = IterableExtensions.<JvmFormalParameter>head(this._iXtendJvmAssociations.getDirectlyInferredOperation(function).getParameters());
        JvmTypeReference _parameterType = null;
        if (_head != null) {
            _parameterType = _head.getParameterType();
        }
        final JvmTypeReference declaredType = _parameterType;
        if ((declaredType != null)) {
            LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(declaredType);
            return new AssignmentFeatureCallArguments(value, _lightweightTypeReference);
        } else {
            return new AssignmentFeatureCallArguments(value, null);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AssignmentFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.AssignmentFeatureCallArguments) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

XExpression (org.eclipse.xtext.xbase.XExpression)3 AssignmentFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.AssignmentFeatureCallArguments)3 IFeatureCallArgumentSlot (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot)2 Test (org.junit.Test)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)1 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)1 XNullLiteral (org.eclipse.xtext.xbase.XNullLiteral)1 XStringLiteral (org.eclipse.xtext.xbase.XStringLiteral)1 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)1