Search in sources :

Example 16 with XClosure

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

the class ReorderedVarArgFeatureCallArgumentsTest 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.assertTrue(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 17 with XClosure

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

the class XtendHoverSignatureProviderTest method testSignatureForForXClosureVariable.

@Test
public void testSignatureForForXClosureVariable() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("\t");
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("def zonk(){");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("bar(s | s + \"42\")");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("def bar((String)=>String fun){");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        XtendMember _get = clazz.getMembers().get(0);
        final XtendFunction xtendFunction = ((XtendFunction) _get);
        XExpression _expression = xtendFunction.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        XExpression _get_2 = ((XFeatureCall) _get_1).getFeatureCallArguments().get(0);
        final XClosure closure = ((XClosure) _get_2);
        final JvmFormalParameter param = closure.getDeclaredFormalParameters().get(0);
        final String signature = this.signatureProvider.getSignature(param);
        Assert.assertEquals("String s", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XClosure(org.eclipse.xtext.xbase.XClosure) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 18 with XClosure

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

the class ErrorTest method testErrorModel_017.

@Test
public void testErrorModel_017() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static extension Throwables.*");
    _builder.newLine();
    _builder.append("import java.net.URI");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Throwables {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def static <T> T propagate(()=>T proc, (Exception)=>Exception handler) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("proc.apply");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} catch(Exception e) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("throw handler.apply(e)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class Client {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("valuri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration client = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
    XtendMember _head = IterableExtensions.<XtendMember>head(client.getMembers());
    final XtendField field = ((XtendField) _head);
    XExpression _initialValue = field.getInitialValue();
    final XMemberFeatureCall initializer = ((XMemberFeatureCall) _initialValue);
    XExpression _head_1 = IterableExtensions.<XExpression>head(initializer.getMemberCallArguments());
    final XClosure closure = ((XClosure) _head_1);
    final JvmFormalParameter implicit = IterableExtensions.<JvmFormalParameter>head(closure.getImplicitFormalParameters());
    Assert.assertNotNull(implicit);
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(implicit);
    Assert.assertNotNull(resolvedTypes.getActualType(implicit));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XClosure(org.eclipse.xtext.xbase.XClosure) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 19 with XClosure

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

the class ErrorTest method testErrorModel_019.

@Test
public void testErrorModel_019() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package x");
    _builder.newLine();
    _builder.append("import bug396879.*");
    _builder.newLine();
    _builder.append("class Z {");
    _builder.newLine();
    _builder.append("  \t");
    _builder.append("def addListeners(BooleanProperty prop) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val ChangeListenerBoolean> listener = [ p, oldValue, newValue | ]\t\tprop.addListener(listener)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration z = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _get = z.getMembers().get(1);
    final XtendField field = ((XtendField) _get);
    XExpression _initialValue = field.getInitialValue();
    final XClosure closure = ((XClosure) _initialValue);
    final JvmFormalParameter param = IterableExtensions.<JvmFormalParameter>head(closure.getDeclaredFormalParameters());
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(param);
    Assert.assertNotNull(resolvedTypes.getActualType(param));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XClosure(org.eclipse.xtext.xbase.XClosure) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 20 with XClosure

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

the class Oven method fireproof.

public void fireproof(final String input) throws Exception {
    try {
        final EObject file = this._parseHelper.parse(input);
        final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
        Assert.assertNotNull(resolvedTypes);
        if ((file != null)) {
            Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
            for (final EObject content : _iterable) {
                boolean _matched = false;
                if (content instanceof XAbstractFeatureCall) {
                    _matched = true;
                    this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
                    boolean _tripleNotEquals = (_implicitReceiver != null);
                    if (_tripleNotEquals) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
                    }
                    XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
                    boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
                    if (_tripleNotEquals_1) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof XClosure) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                        final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
                            this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
                        };
                        ((XClosure) content).getImplicitFormalParameters().forEach(_function);
                    }
                }
                if (!_matched) {
                    if (content instanceof XExpression) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof JvmIdentifiableElement) {
                        _matched = true;
                        this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
                    }
                }
            }
        }
    } catch (final Throwable _t) {
        if (_t instanceof Throwable) {
            final Throwable e = (Throwable) _t;
            String _message = e.getMessage();
            final ComparisonFailure error = new ComparisonFailure(_message, input, "");
            error.setStackTrace(e.getStackTrace());
            throw error;
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

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