Search in sources :

Example 1 with XExpression

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

Example 2 with XExpression

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

the class AbstractXbaseContentAssistTest method expression.

protected XExpression expression(String string) throws Exception {
    XtextResource resource = getResourceFor(new StringInputStream(string));
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    XExpression result = (XExpression) resource.getContents().get(0);
    return result;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 3 with XExpression

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

the class AbstractXbaseUITestCase method expression.

protected XExpression expression(String string) throws Exception {
    XtextResource resource = getResourceFor(new StringInputStream(string));
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    XExpression result = (XExpression) resource.getContents().get(0);
    return result;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 4 with XExpression

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

the class AbstractXbaseContentAssistTest method expression.

protected XExpression expression(String string) throws Exception {
    XtextResource resource = getResourceFor(new StringInputStream(string));
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    XExpression result = (XExpression) resource.getContents().get(0);
    return result;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 5 with XExpression

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

the class RuleEngineFormatter method _format.

@Override
protected void _format(final XSwitchExpression expr, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    document.set(this.textRegionExtensions.previousHiddenRegion(expr.getSwitch()), this.textRegionExtensions.nextHiddenRegion(expr), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.append(this.textRegionExtensions.regionFor(expr).keyword("switch"), _function_1);
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.<XExpression>format(document.<XExpression>append(expr.getSwitch(), _function_2));
    EList<XCasePart> _cases = expr.getCases();
    for (final XCasePart c : _cases) {
        {
            if (((c.getTypeGuard() != null) && (c.getCase() != null))) {
                final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                    it.oneSpace();
                };
                document.<JvmTypeReference>append(c.getTypeGuard(), _function_3);
                final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                document.<XExpression>append(c.getCase(), _function_4);
            } else {
                JvmTypeReference _typeGuard = c.getTypeGuard();
                boolean _tripleNotEquals = (_typeGuard != null);
                if (_tripleNotEquals) {
                    final Procedure1<IHiddenRegionFormatter> _function_5 = (IHiddenRegionFormatter it) -> {
                        it.noSpace();
                    };
                    document.<JvmTypeReference>append(c.getTypeGuard(), _function_5);
                } else {
                    XExpression _case = c.getCase();
                    boolean _tripleNotEquals_1 = (_case != null);
                    if (_tripleNotEquals_1) {
                        final Procedure1<IHiddenRegionFormatter> _function_6 = (IHiddenRegionFormatter it) -> {
                            it.oneSpace();
                        };
                        final Procedure1<IHiddenRegionFormatter> _function_7 = (IHiddenRegionFormatter it) -> {
                            it.noSpace();
                        };
                        document.<XExpression>append(document.<XExpression>prepend(c.getCase(), _function_6), _function_7);
                    }
                }
            }
            final Procedure1<IHiddenRegionFormatter> _function_8 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            final Procedure1<IHiddenRegionFormatter> _function_9 = (IHiddenRegionFormatter it) -> {
                it.newLine();
            };
            document.append(document.prepend(this.textRegionExtensions.regionFor(c).feature(XbasePackage.Literals.XCASE_PART__FALL_THROUGH), _function_8), _function_9);
            document.<XExpression>format(c.getCase());
            if ((Objects.equal(c, IterableExtensions.<XCasePart>last(expr.getCases())) && (expr.getDefault() == null))) {
                this.formatBody(c.getThen(), true, document);
            } else {
                this.formatBodyParagraph(c.getThen(), document);
            }
        }
    }
    XExpression _default = expr.getDefault();
    boolean _tripleNotEquals = (_default != null);
    if (_tripleNotEquals) {
        final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        document.append(this.textRegionExtensions.regionFor(expr).keyword("default"), _function_3);
        this.formatBody(expr.getDefault(), true, document);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XCasePart(org.eclipse.xtext.xbase.XCasePart) XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

XExpression (org.eclipse.xtext.xbase.XExpression)262 Test (org.junit.Test)134 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)96 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)84 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)84 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)84 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)82 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)63 EObject (org.eclipse.emf.ecore.EObject)37 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)36 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)28 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)28 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)25 XtendField (org.eclipse.xtend.core.xtend.XtendField)23 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)22 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)22 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)21 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 XClosure (org.eclipse.xtext.xbase.XClosure)18 XStringLiteral (org.eclipse.xtext.xbase.XStringLiteral)18