use of org.eclipse.xtend.core.xtend.XtendClass 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());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class ParserTest method testExtensionOnForLoopParam_01.
@Test
public void testExtensionOnForLoopParam_01() throws Exception {
XtendClass clazz = clazz("class Foo { def void m() { for(extension i: 1..2) {} } }");
assertEquals(1, clazz.getMembers().size());
XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
assertEquals(1, body.getExpressions().size());
XForLoopExpression forLoop = (XForLoopExpression) body.getExpressions().get(0);
XtendFormalParameter parameter = (XtendFormalParameter) forLoop.getDeclaredParam();
assertTrue(parameter.isExtension());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class ParserTest method testCreateExtension_01.
@Test
public void testCreateExtension_01() throws Exception {
XtendClass clazz = clazz("class Foo { " + " def create foo : newArrayList('foo') getListWithFooAnd(String s) {" + " foo.add(s)" + " }" + "}");
assertEquals(1, clazz.getMembers().size());
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
assertNotNull(func.getCreateExtensionInfo().getCreateExpression());
assertEquals("foo", func.getCreateExtensionInfo().getName());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class ParserTest method testAllGrammarElementsUniqueAfterReparse.
@Test
public void testAllGrammarElementsUniqueAfterReparse() throws Exception {
String text = "class Foo { def m() { newArrayList() } }";
XtendClass clazz = clazz(text);
XtextResource resource = (XtextResource) clazz.eResource();
resource.update(text.indexOf('m'), 0, "m");
ICompositeNode root = resource.getParseResult().getRootNode();
assertSame(root, root.getRootNode());
Set<EObject> grammarElements = Sets.newHashSet();
for (INode node : root.getAsTreeIterable()) {
if (node instanceof ICompositeNode) {
if (node.getGrammarElement() == null) {
fail("node without grammar element");
}
if (!grammarElements.add(node.getGrammarElement())) {
fail(node.getGrammarElement().toString());
}
}
}
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class ParserTest method testAllGrammarElementsUnique.
@Test
public void testAllGrammarElementsUnique() throws Exception {
XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }");
XtextResource resource = (XtextResource) clazz.eResource();
ICompositeNode root = resource.getParseResult().getRootNode();
new InvariantChecker().checkInvariant(root);
assertSame(root, root.getRootNode());
Set<EObject> grammarElements = Sets.newHashSet();
for (INode node : root.getAsTreeIterable()) {
if (node instanceof ICompositeNode) {
if (node.getGrammarElement() == null) {
fail("node without grammar element");
}
if (!grammarElements.add(node.getGrammarElement())) {
fail(node.getGrammarElement().toString());
}
}
}
}
Aggregations