Search in sources :

Example 31 with XExpression

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

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

Example 33 with XExpression

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

the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference.

@Test
public void testOverriddenMethodTypeArgumentInference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new Iterable<String>() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override iterator() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFunction function = this.function(_builder.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
        Assert.assertEquals("Iterable<String>", resolvedTypes.getActualType(operation).toString());
        XExpression _expression = function.getExpression();
        XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
        final AnonymousClass anonymousClass = ((AnonymousClass) _head);
        XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
        final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
        Assert.assertEquals("Iterator<String>", resolvedTypes.getActualType(overriding).toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 34 with XExpression

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

the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference_2.

@Test
public void testOverriddenMethodTypeArgumentInference_2() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def <T> foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new Iterable<T>() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override iterator() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFunction function = this.function(_builder.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
        Assert.assertEquals("Iterable<T>", resolvedTypes.getActualType(operation).toString());
        XExpression _expression = function.getExpression();
        XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
        final AnonymousClass anonymousClass = ((AnonymousClass) _head);
        XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
        final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
        Assert.assertEquals("Iterator<T>", resolvedTypes.getActualType(overriding).toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 35 with XExpression

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

the class AmbiguityValidationTest method assertAmbiguous.

protected void assertAmbiguous(final CharSequence contents, final String... messageParts) {
    final XtendFile file = this.getParsedXtendFile(contents);
    final EList<Resource.Diagnostic> errors = file.eResource().getErrors();
    Assert.assertEquals(errors.toString(), 1, errors.size());
    Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(errors);
    final AbstractDiagnostic singleError = ((AbstractDiagnostic) _head);
    Assert.assertEquals(singleError.getMessage(), IssueCodes.AMBIGUOUS_FEATURE_CALL, singleError.getCode());
    final Function1<String, String> _function = (String it) -> {
        return Strings.toUnixLineSeparator(it);
    };
    final Consumer<String> _function_1 = (String it) -> {
        final String message = singleError.getMessage();
        boolean _contains = message.contains(it);
        boolean _not = (!_contains);
        if (_not) {
            Assert.assertEquals(it, message);
        }
    };
    ListExtensions.<String, String>map(((List<String>) Conversions.doWrapArray(messageParts)), _function).forEach(_function_1);
    final XtendTypeDeclaration firstType = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _head_1 = IterableExtensions.<XtendMember>head(firstType.getMembers());
    final XtendFunction firstMember = ((XtendFunction) _head_1);
    XExpression _expression = firstMember.getExpression();
    final XBlockExpression block = ((XBlockExpression) _expression);
    XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions());
    final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
    final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
    Assert.assertTrue((linkingCandidate instanceof IAmbiguousLinkingCandidate));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Resource(org.eclipse.emf.ecore.resource.Resource) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) IAmbiguousLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)

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