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());
}
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());
}
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());
}
Aggregations