Search in sources :

Example 91 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall 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 92 with XFeatureCall

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

the class LinkingTest method testImplicitFirstArgument_02.

@Test
public void testImplicitFirstArgument_02() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    toUpperCase\n" + "  }\n" + "  extension String" + "  def toUpperCase() { null }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall second = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation secondFeature = (JvmOperation) second.getFeature();
    assertEquals("MyXtendClass.toUpperCase()", secondFeature.getIdentifier());
    assertEquals(0, secondFeature.getParameters().size());
    assertNull(second.getImplicitFirstArgument());
    XFeatureCall secondReceiver = (XFeatureCall) second.getImplicitReceiver();
    assertTrue(secondReceiver.getFeature() instanceof JvmGenericType);
    assertNull(second.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) Test(org.junit.Test)

Example 93 with XFeatureCall

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

the class LinkingTest method testCreateExtension_01.

@Test
public void testCreateExtension_01() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  def create list: newArrayList(s) getListWithFooAnd(String s) {" + "	 s" + "  }" + "}");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall featureCall = (XFeatureCall) func.getCreateExtensionInfo().getCreateExpression();
    List<XExpression> arguments = featureCall.getActualArguments();
    XFeatureCall argument = (XFeatureCall) arguments.get(0);
    JvmFormalParameter parameter = (JvmFormalParameter) argument.getFeature();
    assertEquals("s", parameter.getIdentifier());
    JvmOperation operation = (JvmOperation) parameter.eContainer();
    assertEquals("Foo.getListWithFooAnd(java.lang.String)", operation.getIdentifier());
    XFeatureCall featureCallInInitializer = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmFormalParameter parameterInInitializer = (JvmFormalParameter) featureCallInInitializer.getFeature();
    assertEquals("s", parameterInInitializer.getIdentifier());
    JvmOperation initializer = (JvmOperation) parameterInInitializer.eContainer();
    assertEquals("Foo._init_getListWithFooAnd(java.util.ArrayList,java.lang.String)", initializer.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)93 Test (org.junit.Test)81 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)72 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)67 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)62 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)29 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)26 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)19 XExpression (org.eclipse.xtext.xbase.XExpression)14 RichString (org.eclipse.xtend.core.xtend.RichString)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)6 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)5 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)5 EObject (org.eclipse.emf.ecore.EObject)4 XtendField (org.eclipse.xtend.core.xtend.XtendField)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)3