Search in sources :

Example 31 with RichString

use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.

the class ParserTest method testRichStringFOR_01.

@Test
public void testRichStringFOR_01() throws Exception {
    XtendFunction function = function("def withForLoop() '''�FOR i: 1..10��i��ENDFOR�'''");
    final RichString richString = (RichString) function.getExpression();
    final RichStringForLoop rsFor = (RichStringForLoop) richString.getExpressions().get(1);
    assertTrue(rsFor.getForExpression() instanceof XBinaryOperation);
    assertEquals("i", rsFor.getDeclaredParam().getName());
    RichString eachRichString = (RichString) rsFor.getEachExpression();
    assertEquals(3, eachRichString.getExpressions().size());
    XExpression variableReference = eachRichString.getExpressions().get(1);
    assertTrue(variableReference instanceof XFeatureCall);
    assertSame(rsFor.getDeclaredParam(), ((XAbstractFeatureCall) variableReference).getFeature());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) RichString(org.eclipse.xtend.core.xtend.RichString) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) XExpression(org.eclipse.xtext.xbase.XExpression) RichStringForLoop(org.eclipse.xtend.core.xtend.RichStringForLoop) Test(org.junit.Test)

Example 32 with RichString

use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.

the class ParserTest method testRichStringFOR_02.

@Test
public void testRichStringFOR_02() throws Exception {
    XtendFunction function = function("def withForLoop() '''�FOR i: 1..10 BEFORE 'a' SEPARATOR '\t' AFTER i��ENDFOR�'''");
    final RichString richString = (RichString) function.getExpression();
    final RichStringForLoop rsFor = (RichStringForLoop) richString.getExpressions().get(1);
    assertTrue(rsFor.getForExpression() instanceof XBinaryOperation);
    assertEquals("i", rsFor.getDeclaredParam().getName());
    assertTrue(rsFor.getSeparator() instanceof XStringLiteral);
    assertTrue(rsFor.getBefore() instanceof XStringLiteral);
    assertTrue(rsFor.getAfter() instanceof XFeatureCall);
    assertTrue(((XAbstractFeatureCall) rsFor.getAfter()).getFeature().eIsProxy());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) RichString(org.eclipse.xtend.core.xtend.RichString) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) RichStringForLoop(org.eclipse.xtend.core.xtend.RichStringForLoop) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 33 with RichString

use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.

the class ParserTest method testRichStringWithComment_03.

@Test
public void testRichStringWithComment_03() throws Exception {
    XtendFunction function = function("def foo() '''first��� comment \nsecond� /* ml comment */ �third'''");
    assertTrue(function.getExpression() instanceof RichString);
    RichString richString = (RichString) function.getExpression();
    assertEquals(3, richString.getExpressions().size());
    RichStringLiteral first = (RichStringLiteral) richString.getExpressions().get(0);
    assertEquals("first", first.getValue());
    RichStringLiteral second = (RichStringLiteral) richString.getExpressions().get(1);
    assertEquals("second", second.getValue());
    RichStringLiteral third = (RichStringLiteral) richString.getExpressions().get(2);
    assertEquals("third", third.getValue());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) RichString(org.eclipse.xtend.core.xtend.RichString) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) Test(org.junit.Test)

Example 34 with RichString

use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.

the class RichStringEvaluationTest method richString.

protected RichString richString(String string) throws Exception {
    XtendClass clazz = clazz("class Foo { def foo() " + string + "}");
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    return (RichString) function.getExpression();
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) RichString(org.eclipse.xtend.core.xtend.RichString) XtendClass(org.eclipse.xtend.core.xtend.XtendClass)

Example 35 with RichString

use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.

the class RichStringProcessorTest method doTestStackIsConsistent.

protected void doTestStackIsConsistent(String string) throws Exception {
    RichString richString = richString(string);
    doCheckStackIsConsistent(richString);
}
Also used : RichString(org.eclipse.xtend.core.xtend.RichString)

Aggregations

RichString (org.eclipse.xtend.core.xtend.RichString)38 Test (org.junit.Test)18 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)15 RichStringLiteral (org.eclipse.xtend.core.xtend.RichStringLiteral)11 XExpression (org.eclipse.xtext.xbase.XExpression)11 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)6 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)5 XBinaryOperation (org.eclipse.xtext.xbase.XBinaryOperation)4 DefaultIndentationHandler (org.eclipse.xtend.core.richstring.DefaultIndentationHandler)3 RichStringForLoop (org.eclipse.xtend.core.xtend.RichStringForLoop)3 XBooleanLiteral (org.eclipse.xtext.xbase.XBooleanLiteral)3 XStringLiteral (org.eclipse.xtext.xbase.XStringLiteral)3 EObject (org.eclipse.emf.ecore.EObject)2 RichStringProcessor (org.eclipse.xtend.core.richstring.RichStringProcessor)2 AbstractRichStringTest (org.eclipse.xtend.core.tests.richstring.AbstractRichStringTest)2 RichStringIf (org.eclipse.xtend.core.xtend.RichStringIf)2 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)2 XtendInterface (org.eclipse.xtend.core.xtend.XtendInterface)2