use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class ParserTest method testExtensionOnLambdaParameter_01.
@Test
public void testExtensionOnLambdaParameter_01() throws Exception {
XtendClass clazz = clazz("class Foo { val x = [ extension String a, String b | 0 ] }");
assertEquals(1, clazz.getMembers().size());
XtendField f = (XtendField) clazz.getMembers().get(0);
XClosure initializer = (XClosure) f.getInitialValue();
List<JvmFormalParameter> parameters = initializer.getDeclaredFormalParameters();
assertEquals(2, parameters.size());
XtendFormalParameter firstParameter = (XtendFormalParameter) parameters.get(0);
assertTrue(firstParameter.isExtension());
XtendFormalParameter secondParameter = (XtendFormalParameter) parameters.get(1);
assertFalse(secondParameter.isExtension());
}
use of org.eclipse.xtend.core.xtend.XtendClass 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.XtendClass 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.XtendClass 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.XtendClass in project xtext-xtend by eclipse.
the class ParserTest method testMultiCatch_02.
@Test
public void testMultiCatch_02() throws Exception {
XtendClass clazz = clazz("class Foo { def void m() { try {} catch(extension NullPointerException | IllegalArgumentException | IllegalStateException 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());
JvmSynonymTypeReference parameterType = (JvmSynonymTypeReference) parameter.getParameterType();
assertEquals(3, parameterType.getReferences().size());
}
Aggregations