use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ParserTest method testUnambiguity_01.
@Test
public void testUnambiguity_01() throws Exception {
XtendClass clazz = clazz("package x\n" + "class Foo {\n" + " def String x(Foo bar) {String}\n" + " def String x(Baz x) {baz}\n" + "}");
XtendFunction f1 = (XtendFunction) clazz.getMembers().get(0);
XtendFunction f2 = (XtendFunction) clazz.getMembers().get(1);
assertEquals("String", ((XFeatureCall) ((XBlockExpression) f1.getExpression()).getExpressions().get(0)).getConcreteSyntaxFeatureName());
assertNotNull(f2.getReturnType());
}
use of org.eclipse.xtend.core.xtend.XtendFunction 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());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ParserTest method testExtensionOnCatchClause_01.
@Test
public void testExtensionOnCatchClause_01() throws Exception {
XtendClass clazz = clazz("class Foo { def void m() { try {} catch(extension NullPointerException e) {} } }");
assertEquals(1, clazz.getMembers().size());
XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
assertEquals(1, body.getExpressions().size());
XTryCatchFinallyExpression tryCatch = (XTryCatchFinallyExpression) body.getExpressions().get(0);
XCatchClause singleCatchClause = tryCatch.getCatchClauses().get(0);
XtendFormalParameter parameter = (XtendFormalParameter) singleCatchClause.getDeclaredParam();
assertTrue(parameter.isExtension());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ParserTest method testRichStringIF_01.
@Test
public void testRichStringIF_01() throws Exception {
XtendFunction function = function("def foo() ''' foo �IF true� wurst �IF false� brot �ELSE� machine �ENDIF� bar �ENDIF�'''");
final RichString richString = (RichString) function.getExpression();
assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
final RichStringIf rsIf = (RichStringIf) richString.getExpressions().get(1);
assertTrue(rsIf.getIf() instanceof XBooleanLiteral);
final RichString then = (RichString) rsIf.getThen();
assertEquals(3, then.getExpressions().size());
RichStringIf innerIf = (RichStringIf) then.getExpressions().get(1);
assertTrue(innerIf.getIf() instanceof XBooleanLiteral);
assertTrue(innerIf.getElse() instanceof RichString);
assertTrue(rsIf.getElse() == null);
assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ParserTest method testFunction_6.
@Test
public void testFunction_6() throws Exception {
XtendFunction func = function("override dispatch foo(String s) { foo('x')}");
assertEquals("foo", func.getName());
assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
assertEquals(1, func.getParameters().size());
assertNull(func.getReturnType());
assertTrue(func.isOverride());
assertTrue(func.isDispatch());
assertEquals(0, func.getTypeParameters().size());
}
Aggregations