Search in sources :

Example 1 with XtendVariableDeclaration

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

the class ParserTest method testExtensionOnLocalVar_01.

@Test
public void testExtensionOnLocalVar_01() throws Exception {
    XtendClass clazz = clazz("class Foo { def m() { extension var s = '' } }");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    assertEquals(1, body.getExpressions().size());
    XtendVariableDeclaration variableDeclaration = (XtendVariableDeclaration) body.getExpressions().get(0);
    assertTrue(variableDeclaration.isWriteable());
    assertTrue(variableDeclaration.isExtension());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendVariableDeclaration(org.eclipse.xtend.core.xtend.XtendVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 2 with XtendVariableDeclaration

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

the class ParserTest method testExtensionOnLocalVar_02.

@Test
public void testExtensionOnLocalVar_02() throws Exception {
    XtendClass clazz = clazz("class Foo { def m() { val extension Object s = '' } }");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    assertEquals(1, body.getExpressions().size());
    XtendVariableDeclaration variableDeclaration = (XtendVariableDeclaration) body.getExpressions().get(0);
    assertFalse(variableDeclaration.isWriteable());
    assertTrue(variableDeclaration.isExtension());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendVariableDeclaration(org.eclipse.xtend.core.xtend.XtendVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Aggregations

XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 XtendVariableDeclaration (org.eclipse.xtend.core.xtend.XtendVariableDeclaration)2 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)2 Test (org.junit.Test)2