Search in sources :

Example 46 with XBlockExpression

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

the class LinkingTest method testBug345827_06.

@Test
public void testBug345827_06() throws Exception {
    XtendFunction function = function("def String name(String param) {\n" + "  name('param')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
    assertSame(associator.getDirectlyInferredOperation(function), featureCall.getFeature());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 47 with XBlockExpression

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

the class LinkingTest method testExtensionMethodCall_Bug351827_04.

@Test
public void testExtensionMethodCall_Bug351827_04() throws Exception {
    XtendClass clazz = clazz("" + "class Foo {" + "  extension testdata.Properties1 p\n" + "  def setProp1(String s) { s }" + "  def foo(String s) {\n" + "    s.setProp1()\n" + "  }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(2);
    final XMemberFeatureCall call = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    assertEquals("Foo.setProp1(java.lang.String)", call.getFeature().getIdentifier());
}
Also used : 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 48 with XBlockExpression

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

the class LinkingTest method testImplicitFirstArgument_03.

@Test
public void testImplicitFirstArgument_03() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    toLowerCase\n" + "  }\n" + "  extension String" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall third = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation thirdFeature = (JvmOperation) third.getFeature();
    assertEquals("java.lang.String.toLowerCase()", thirdFeature.getIdentifier());
    assertNull(third.getImplicitFirstArgument());
    XMemberFeatureCall thirdReceiver = (XMemberFeatureCall) third.getImplicitReceiver();
    assertTrue(thirdReceiver.getFeature() instanceof JvmField);
    assertNull(third.getInvalidFeatureIssueCode(), third.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) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 49 with XBlockExpression

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

the class LinkingTest method testStaticImports_07.

@Test
public void testStaticImports_07() throws Exception {
    String fileAsText = "import static extension com.google.common.collect.Iterables.*\n" + "import static java.util.Collections.*\n" + "class Clazz { def void method() {find(singletonList(''), [e|e!=null])} }";
    XtendFile file = file(fileAsText, true);
    XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
    XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression) function.getExpression()).getExpressions().get(0);
    String identifier = featureCall.getFeature().getIdentifier();
    assertEquals("com.google.common.collect.Iterables.find(java.lang.Iterable,com.google.common.base.Predicate)", 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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 50 with XBlockExpression

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

the class LinkingTest method testStaticNestedClass_02.

@Test
public void testStaticNestedClass_02() throws Exception {
    XtendFile file = file("class C {\n" + "  static class D {\n" + "    def static void m(CharSequence c) { m('') }\n" + "  }\n" + "  def static void m(String s) {}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendClass d = (XtendClass) c.getMembers().get(0);
    XtendFunction m = (XtendFunction) d.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("C.m(java.lang.String)", feature.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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Aggregations

XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)236 Test (org.junit.Test)210 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)198 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)169 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)126 XExpression (org.eclipse.xtext.xbase.XExpression)84 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)84 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)70 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)58 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)10 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)10 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