use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class LinkingTest method testBug345433_01.
@Test
public void testBug345433_01() throws Exception {
String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + " org.eclipse.xtext.Grammar grammar\n" + " def function1() {\n" + " grammar.containedRuleCalls.filter(e | " + " !e.isAssigned() && !e.isEObjectRuleCall()" + " ).map(e | e.rule)\n" + " }\n" + " def function2() {\n" + " newArrayList(function1().head())\n" + " }\n" + "}";
XtendClass clazz = clazz(classAsString);
IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
XtendFunction function1 = (XtendFunction) clazz.getMembers().get(1);
JvmOperation operation1 = associator.getDirectlyInferredOperation(function1);
assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", operation1.getReturnType().getIdentifier());
XtendFunction function2 = (XtendFunction) clazz.getMembers().get(2);
JvmOperation operation2 = associator.getDirectlyInferredOperation(function2);
assertEquals("java.util.ArrayList<org.eclipse.xtext.AbstractRule>", operation2.getReturnType().getIdentifier());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ParserTest method testRichStringIF_00.
@Test
public void testRichStringIF_00() throws Exception {
XtendFunction function = function("def foo() ''' foo �IF true� wurst �ELSEIF null==3� brot �ELSE� machine �ENDIF� bar '''");
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);
assertTrue(rsIf.getThen() instanceof RichString);
assertEquals(1, rsIf.getElseIfs().size());
RichStringElseIf elseIf = rsIf.getElseIfs().get(0);
assertTrue(elseIf.getIf() instanceof XBinaryOperation);
assertTrue(elseIf.getThen() instanceof RichString);
assertTrue(rsIf.getElse() instanceof RichString);
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_0.
@Test
public void testFunction_0() throws Exception {
XtendFunction func = function("def foo() {foo}");
assertEquals("foo", func.getName());
assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
assertEquals(0, func.getParameters().size());
assertNull(func.getReturnType());
assertEquals(0, func.getTypeParameters().size());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ParserTest method testRichStringWithComment_01.
@Test
public void testRichStringWithComment_01() throws Exception {
XtendFunction function = function("def foo() '''first� /* ml comment\n */ �� sl_comment \nsecond'''");
assertTrue(function.getExpression() instanceof RichString);
RichString richString = (RichString) function.getExpression();
assertEquals(2, 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());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ParserTest method testCreateExtension_00.
@Test
public void testCreateExtension_00() throws Exception {
XtendClass clazz = clazz("class Foo { " + " def create list: newArrayList('foo') getListWithFooAnd(String s) {" + " list.add(s)" + " }" + "}");
assertEquals(1, clazz.getMembers().size());
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
assertNotNull(func.getCreateExtensionInfo().getCreateExpression());
assertEquals("list", func.getCreateExtensionInfo().getName());
}
Aggregations