Search in sources :

Example 96 with XtendClass

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());
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) XtendFormalParameter(org.eclipse.xtend.core.xtend.XtendFormalParameter) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 97 with XtendClass

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 98 with XtendClass

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());
}
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 99 with XtendClass

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XCatchClause(org.eclipse.xtext.xbase.XCatchClause) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XTryCatchFinallyExpression(org.eclipse.xtext.xbase.XTryCatchFinallyExpression) XtendFormalParameter(org.eclipse.xtend.core.xtend.XtendFormalParameter) Test(org.junit.Test)

Example 100 with XtendClass

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XCatchClause(org.eclipse.xtext.xbase.XCatchClause) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmSynonymTypeReference(org.eclipse.xtext.common.types.JvmSynonymTypeReference) XTryCatchFinallyExpression(org.eclipse.xtext.xbase.XTryCatchFinallyExpression) XtendFormalParameter(org.eclipse.xtend.core.xtend.XtendFormalParameter) Test(org.junit.Test)

Aggregations

XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1017 Test (org.junit.Test)988 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)249 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)229 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)169 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)129 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)104 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)101 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)74 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)73 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)63 XExpression (org.eclipse.xtext.xbase.XExpression)62 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)62 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)56 XtendField (org.eclipse.xtend.core.xtend.XtendField)37 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)36 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)35 XAssignment (org.eclipse.xtext.xbase.XAssignment)19 EObject (org.eclipse.emf.ecore.EObject)18 RichString (org.eclipse.xtend.core.xtend.RichString)17