Search in sources :

Example 26 with XBlockExpression

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

the class LinkingTest method testBug400807.

@Test
public void testBug400807() throws Exception {
    XtendFile file = file("package testPackage\n" + "import bug400807.Bug400807\n" + "class C {\n" + "	def Bug400807 m() {\n" + "		[ string ]\n" + "	}\n" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XClosure lambda = (XClosure) body.getExpressions().get(0);
    XBlockExpression innerBody = (XBlockExpression) lambda.getExpression();
    XAbstractFeatureCall string = (XAbstractFeatureCall) innerBody.getExpressions().get(0);
    assertEquals("bug400807.Bug400807Param.getString()", string.getFeature().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 27 with XBlockExpression

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

the class LinkingTest method testOverloadedMethods_18.

@Test
public void testOverloadedMethods_18() throws Exception {
    XtendFile file = file("import java.util.Collection\n" + "class X {\n" + "  def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" + "    collection.addAll(elements.head)\n" + "  }\n" + "}");
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmIdentifiableElement addAll = featureCall.getFeature();
    assertNotNull(addAll);
    assertFalse(addAll.eIsProxy());
    assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,T[])", addAll.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 28 with XBlockExpression

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

the class LinkingTest method testStaticImports_09.

@Test
public void testStaticImports_09() throws Exception {
    String fileAsText = "import static java.util.Collections.* class Clazz { def void method() {singletonList('').findFirst(String e|e!=null)} }";
    XtendFile file = file(fileAsText, true);
    XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
    XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) function.getExpression()).getExpressions().get(0);
    String identifier = featureCall.getFeature().getIdentifier();
    assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.findFirst(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", identifier);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 29 with XBlockExpression

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

the class LinkingTest method testImplicitFirstArgument_05.

@Test
public void testImplicitFirstArgument_05() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    withObject\n" + "  }\n" + "  extension String" + "  def withObject(Object obj) { null }" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall fifth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation fifthFeature = (JvmOperation) fifth.getFeature();
    assertEquals("MyXtendClass.withObject(java.lang.Object)", fifthFeature.getIdentifier());
    assertEquals(1, fifthFeature.getParameters().size());
    assertNotNull(fifth.getImplicitFirstArgument());
    assertEquals("it", ((XAbstractFeatureCall) fifth.getImplicitFirstArgument()).getFeature().getSimpleName());
    XFeatureCall fifthReceiver = (XFeatureCall) fifth.getImplicitReceiver();
    assertTrue(fifthReceiver.getFeature() instanceof JvmGenericType);
    assertNull(fifth.getInvalidFeatureIssueCode(), fifth.getInvalidFeatureIssueCode());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 30 with XBlockExpression

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

the class LinkingTest method testFeatureScope_3.

@Test
public void testFeatureScope_3() throws Exception {
    XtendFile file = file("import java.lang.String class X { def String foo(String foo) {[String foo|foo]}}");
    XtendClass xClass = ((XtendClass) file.getXtendTypes().get(0));
    XtendFunction func = (XtendFunction) xClass.getMembers().get(0);
    XClosure closure = (XClosure) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    XAbstractFeatureCall featureCall1 = (XAbstractFeatureCall) (((XBlockExpression) closure.getExpression()).getExpressions().get(0));
    assertEquals(closure.getFormalParameters().get(0), featureCall1.getFeature());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) 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