Search in sources :

Example 86 with XMemberFeatureCall

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

the class LinkingTest method testInjectedExtensionMethodCall.

@Test
public void testInjectedExtensionMethodCall() throws Exception {
    XtendClass clazz = clazz("" + "class Foo {" + "  @com.google.inject.Inject extension String string" + "  def foo() " + "    {(1 as int).indexOf()}" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(1);
    final XMemberFeatureCall call = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    assertEquals("java.lang.String.indexOf(int)", call.getFeature().getIdentifier());
    assertEquals("Foo.string", ((XMemberFeatureCall) call.getImplicitReceiver()).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 87 with XMemberFeatureCall

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

the class LinkingTest method testImplicitFirstArgument_00.

@Test
public void testImplicitFirstArgument_00() throws Exception {
    XtendClass clazz = clazz("class MyXtendClass {\n" + "  def prependHello(String myString) {\n" + "    'Hello '+myString\n" + "  }\n" + "  def testExtensionMethods(String it) {\n" + "    it.prependHello\n" + "    prependHello\n" + "  }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(1);
    XMemberFeatureCall first = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation firstFeature = (JvmOperation) first.getFeature();
    assertEquals("prependHello", firstFeature.getSimpleName());
    assertNull(first.getInvalidFeatureIssueCode(), first.getInvalidFeatureIssueCode());
    XFeatureCall firstReceiver = (XFeatureCall) first.getImplicitReceiver();
    assertEquals("MyXtendClass", firstReceiver.getFeature().getSimpleName());
    XFeatureCall second = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(1);
    JvmOperation secondFeature = (JvmOperation) second.getFeature();
    assertEquals("prependHello", secondFeature.getSimpleName());
    assertNull(second.getInvalidFeatureIssueCode(), second.getInvalidFeatureIssueCode());
    assertFalse(secondFeature.eIsProxy());
    XFeatureCall secondReceiver = (XFeatureCall) second.getImplicitReceiver();
    assertEquals("MyXtendClass", secondReceiver.getFeature().getSimpleName());
    XFeatureCall implicitArgument = (XFeatureCall) second.getImplicitFirstArgument();
    assertNotNull(implicitArgument);
    assertEquals("it", implicitArgument.getFeature().getSimpleName());
}
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) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 88 with XMemberFeatureCall

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

the class LinkingTest method testSuper.

@Test
public void testSuper() throws Exception {
    XtendFile file = file("class B<T> { def T m1() {} }\n" + "class C extends B<String> {\n" + "  def void m2() { super.m1.subSequence(1,1) }\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(1);
    XtendFunction n = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) n.getExpression();
    XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("java.lang.String.subSequence(int,int)", 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) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Aggregations

XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)88 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)82 Test (org.junit.Test)82 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)78 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)74 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)46 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)19 XExpression (org.eclipse.xtext.xbase.XExpression)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)5 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)4 XIfExpression (org.eclipse.xtext.xbase.XIfExpression)4 XSwitchExpression (org.eclipse.xtext.xbase.XSwitchExpression)4 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)3 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)2 RichString (org.eclipse.xtend.core.xtend.RichString)2