Search in sources :

Example 61 with XMemberFeatureCall

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

the class LinkingTest method testImplicitFirstArgument_00_a.

@Test
public void testImplicitFirstArgument_00_a() 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" + "  }\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());
}
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 62 with XMemberFeatureCall

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

the class LinkingTest method testOverloadedMethods_03.

@Test
public void testOverloadedMethods_03() throws Exception {
    XtendFile file = file("import java.util.List\n" + "class X {\n" + "  def foo() {\n" + "    var List<String> strings = null\n" + "    var testdata.OverloadedMethods<Object> receiver = null\n" + "    receiver.overloaded(strings, strings)\n" + "  }\n" + "}");
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(2);
    JvmIdentifiableElement overloaded = featureCall.getFeature();
    assertNotNull(overloaded);
    assertFalse(overloaded.eIsProxy());
    assertEquals("testdata.OverloadedMethods.overloaded(java.util.List,java.util.List)", overloaded.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 63 with XMemberFeatureCall

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

the class Bug409780Test method testConstraintsInfluenceFeatureScope.

@Test
public void testConstraintsInfluenceFeatureScope() throws Exception {
    XtendFile file = file("class C {\n" + "	def private a(Iterable<CharSequence> it) {\n" + "		map[ b ].map[ 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();
    XMemberFeatureCall featureCall = (XMemberFeatureCall) 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) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 64 with XMemberFeatureCall

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

the class TypeProviderTest method testExpectationRelevantExpressionType_05.

@Test
public void testExpectationRelevantExpressionType_05() throws Exception {
    String clazzString = "class C<T> {\n" + "  def String m(String s, Class<? super T>[] types) {\n" + "    this.m('', newArrayList)\n" + "  }\n" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
    assertEquals("Class<? super T>[]", getExpectedType(newArrayList).getSimpleName());
    assertEquals("ArrayList<Class<? super T>>", getType(newArrayList).getSimpleName());
}
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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 65 with XMemberFeatureCall

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

the class TypeProviderTest method testExpectationRelevantExpressionType_03.

@Test
public void testExpectationRelevantExpressionType_03() throws Exception {
    String clazzString = "class C {\n" + "  def m() {\n" + "    typeof(C).getMethod('', newArrayList)\n" + "  }\n" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
    assertEquals("Class<?>[]", getExpectedType(newArrayList).getSimpleName());
    assertEquals("ArrayList<Class<?>>", getType(newArrayList).getSimpleName());
}
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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) 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