Search in sources :

Example 31 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.

the class UnicodeEscapeLinkingTest method testIdentifiersWithUnicode_01.

@Test
public void testIdentifiersWithUnicode_01() throws Exception {
    XtendClass clazz = clazz("class A {\n" + " String a\n" + " def m() {\n" + "	    \\u0061\n" + "	}\n" + "}");
    XFeatureCall call = (XFeatureCall) ((XBlockExpression) ((XtendFunction) clazz.getMembers().get(1)).getExpression()).getExpressions().get(0);
    JvmIdentifiableElement feature = call.getFeature();
    assertFalse(feature.eIsProxy());
    assertSame(feature, associator.getJvmField((XtendField) clazz.getMembers().get(0)));
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 32 with XBlockExpression

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

Example 33 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression 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 34 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression 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 35 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression 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

XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)229 Test (org.junit.Test)209 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)198 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)169 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)126 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)82 XExpression (org.eclipse.xtext.xbase.XExpression)80 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)67 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)58 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)54 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)29 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)9 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)8 JvmType (org.eclipse.xtext.common.types.JvmType)7