Search in sources :

Example 1 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 2 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 3 with XBlockExpression

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

the class UTF8ParserErrorTest method testInvalidReference_01.

@Test
public void testInvalidReference_01() throws Exception {
    XtendFunction func = function("def m() { \\u0020invalidStart }");
    XBlockExpression block = (XBlockExpression) func.getExpression();
    XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
    String featureName = featureCall.getConcreteSyntaxFeatureName();
    assertEquals("\\u0020invalidStart", featureName);
    assertTrue(featureCall.getFeature().eIsProxy());
    List<Diagnostic> errorList = func.eResource().getErrors();
    assertEquals(2, errorList.size());
    XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errorList.get(1);
    assertTrue(diagnostic.getMessage().contains("invalidStart"));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 4 with XBlockExpression

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

the class Bug409780Test method testConstraintsInfluenceFeatureScope_02.

@Test
public void testConstraintsInfluenceFeatureScope_02() throws Exception {
    XtendFile file = file("class C {\n" + "	def private a(Iterable<CharSequence> it) {\n" + "		map[ b.append('') ]\n" + "	}\n" + "	def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement method = featureCall.getFeature();
    assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
    assertTrue(featureCall.isStatic());
    assertTrue(featureCall.isExtension());
    assertFalse(featureCall.isTypeLiteral());
    LightweightTypeReference type = getType(featureCall);
    assertEquals("java.lang.Iterable<java.lang.Appendable>", type.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 5 with XBlockExpression

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

the class Bug409780Test method testMissingTypeArgumentInference.

@Test
public void testMissingTypeArgumentInference() throws Exception {
    XtendFile file = file("class C {\n" + "	def private <T extends Appendable> Iterable<T> a(Iterable<CharSequence> it) {\n" + "		map[ b ]\n" + "	}\n" + "	def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement method = featureCall.getFeature();
    assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
    assertTrue(featureCall.isStatic());
    assertTrue(featureCall.isExtension());
    assertFalse(featureCall.isTypeLiteral());
    LightweightTypeReference type = getType(featureCall);
    assertEquals("java.lang.Iterable<T>", type.getIdentifier());
    LightweightTypeReference expectedType = getExpectedType(featureCall);
    assertEquals("java.lang.Iterable<T>", expectedType.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Aggregations

XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)240 Test (org.junit.Test)213 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)201 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)169 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)126 XExpression (org.eclipse.xtext.xbase.XExpression)85 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)84 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)73 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)61 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)55 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 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)11 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)11 XTryCatchFinallyExpression (org.eclipse.xtext.xbase.XTryCatchFinallyExpression)10 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)9