Search in sources :

Example 61 with XFeatureCall

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

the class LinkingTest method testExplicitTypeOverSugar_01.

@Test
public void testExplicitTypeOverSugar_01() throws Exception {
    XtendFile file = file("import static extension org.eclipse.emf.ecore.util.EcoreUtil.*\n" + "import org.eclipse.emf.ecore.EObject\n" + "import org.eclipse.emf.common.util.URI\n" + "\n" + "class C {\n" + "  def m(EObject it) {\n" + "    URI::createURI(\"someString\")\n" + "  }\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.emf.common.util.URI.createURI(java.lang.String)", method.getIdentifier());
    assertTrue(featureCall.isStaticWithDeclaringType());
    XFeatureCall target = (XFeatureCall) featureCall.getMemberCallTarget();
    assertTrue(target.isTypeLiteral());
    assertEquals("org.eclipse.emf.common.util.URI", target.getFeature().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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 62 with XFeatureCall

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

the class LinkingTest method testImplicitFirstArgument_01.

@Test
public void testImplicitFirstArgument_01() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    length\n" + "  }\n" + "  extension String" + "  def length() { null }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall first = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation firstFeature = (JvmOperation) first.getFeature();
    assertEquals("java.lang.CharSequence.length()", firstFeature.getIdentifier());
    assertEquals("java.lang.CharSequence", firstFeature.getDeclaringType().getQualifiedName());
    assertNull(first.getImplicitFirstArgument());
    XFeatureCall firstReceiver = (XFeatureCall) first.getImplicitReceiver();
    assertTrue(firstReceiver.getFeature() instanceof JvmFormalParameter);
    assertNull(first.getInvalidFeatureIssueCode());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 63 with XFeatureCall

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

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

the class UnicodeEscapeLinkingTest method testIdentifiersWithUnicode_02.

@Test
public void testIdentifiersWithUnicode_02() throws Exception {
    XtendClass clazz = clazz("class A {\n" + " String \\u0061\n" + " def m() {\n" + "	    a\n" + "	}\n" + "}");
    XFeatureCall call = (XFeatureCall) ((XBlockExpression) ((XtendFunction) clazz.getMembers().get(1)).getExpression()).getExpressions().get(0);
    JvmIdentifiableElement feature = call.getFeature();
    assertFalse(feature.eIsProxy());
    assertSame(feature, associator.getJvmField((XtendField) clazz.getMembers().get(0)));
}
Also used : 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) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 65 with XFeatureCall

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

the class ParserTest method testFunction_2.

@Test
public void testFunction_2() throws Exception {
    XtendFunction func = function("def foo(String s) {s}");
    assertEquals("foo", func.getName());
    assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
    assertEquals(1, func.getParameters().size());
    assertEquals("s", func.getParameters().get(0).getName());
    assertNotNull(func.getParameters().get(0).getParameterType());
    assertNull(func.getReturnType());
    assertEquals(0, func.getTypeParameters().size());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) 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