Search in sources :

Example 31 with XFeatureCall

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

the class LinkingTest method testCreateExtension_00.

@Test
public void testCreateExtension_00() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  def create list: newArrayList('foo') getListWithFooAnd(String s) {" + "	list" + "   this.getListWithFooAnd('')" + "  }" + "}");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    Set<EObject> elements = associator.getJvmElements(func);
    Iterable<JvmOperation> filter = filter(elements, JvmOperation.class);
    JvmOperation initializer = filter(filter, new Predicate<JvmOperation>() {

        @Override
        public boolean apply(JvmOperation input) {
            return input.getSimpleName().startsWith("_init_");
        }
    }).iterator().next();
    assertEquals(initializer.getParameters().get(0), featureCall.getFeature());
    XAbstractFeatureCall recursiveFeatureCall = (XAbstractFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(1);
    assertEquals("Foo.getListWithFooAnd(java.lang.String)", recursiveFeatureCall.getFeature().getIdentifier());
}
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) EObject(org.eclipse.emf.ecore.EObject) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 32 with XFeatureCall

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

the class LinkingTest method testImplicitFirstArgument_00_b.

@Test
public void testImplicitFirstArgument_00_b() throws Exception {
    XtendClass clazz = clazz("class MyXtendClass {\n" + "  def prependHello(String myString) {\n" + "  }\n" + "  def testExtensionMethods(String it) {\n" + "    prependHello\n" + "  }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(1);
    XFeatureCall first = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation firstFeature = (JvmOperation) first.getFeature();
    assertEquals("prependHello", firstFeature.getSimpleName());
    assertNull(first.getInvalidFeatureIssueCode(), first.getInvalidFeatureIssueCode());
    assertNotNull(first.getImplicitFirstArgument());
}
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) Test(org.junit.Test)

Example 33 with XFeatureCall

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

the class LinkingTest method testImplicitFirstArgument_06.

@Test
public void testImplicitFirstArgument_06() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    contains\n" + "  }\n" + "  extension String" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall sixth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation sixthFeature = (JvmOperation) sixth.getFeature();
    assertEquals("java.lang.String.contains(java.lang.CharSequence)", sixthFeature.getIdentifier());
    assertEquals("java.lang.String", sixthFeature.getDeclaringType().getQualifiedName());
    assertNotNull(sixth.getImplicitFirstArgument());
    assertEquals("it", ((XAbstractFeatureCall) sixth.getImplicitFirstArgument()).getFeature().getSimpleName());
    XMemberFeatureCall sixthReceiver = (XMemberFeatureCall) sixth.getImplicitReceiver();
    assertTrue(sixthReceiver.getFeature() instanceof JvmField);
    assertNull(sixth.getInvalidFeatureIssueCode(), sixth.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) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) JvmField(org.eclipse.xtext.common.types.JvmField) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 34 with XFeatureCall

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

the class LinkingTest method testBug403580_05.

@Test
public void testBug403580_05() throws Exception {
    XtendFile file = file("abstract class C {\n" + "	def void m() {\n" + "		overloaded [ String s | s ]\n" + "	}\n" + "	def void overloaded((String)=>String s)" + "	def void overloaded(Object o)" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement method = featureCall.getFeature();
    assertEquals("C.overloaded(org.eclipse.xtext.xbase.lib.Functions$Function1)", method.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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 35 with XFeatureCall

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

the class LinkingTest method testExplicitTypeOverSugar_02.

@Test
public void testExplicitTypeOverSugar_02() 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.appendFragment(\"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.appendFragment(java.lang.String)", method.getIdentifier());
    assertFalse(featureCall.isStaticWithDeclaringType());
    XFeatureCall target = (XFeatureCall) featureCall.getMemberCallTarget();
    assertFalse(target.isTypeLiteral());
    assertEquals("org.eclipse.emf.ecore.util.EcoreUtil.getURI(org.eclipse.emf.ecore.EObject)", 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)

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