Search in sources :

Example 41 with XAbstractFeatureCall

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

the class LinkingTest method testParameterizedExtension_06.

@Test
public void testParameterizedExtension_06() throws Exception {
    XtendFile file = file("package testPackage\n" + "import org.eclipse.xtext.testing.util.ParseHelper\n" + "import org.eclipse.xtend.core.xtend.XtendFile\n" + "class C<F extends XtendFile, T extends ParseHelper<F>> {\n" + "	extension T\n" + "	def m() {" + "		parse('').xtendTypes\n" + "	}\n" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XAbstractFeatureCall substring = findSingleFeatureCall(c);
    assertEquals("org.eclipse.xtend.core.xtend.XtendFile.getXtendTypes()", substring.getFeature().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 42 with XAbstractFeatureCall

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

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

the class LinkingTest method testOverloadedMethod_01.

@Test
public void testOverloadedMethod_01() throws Exception {
    XtendFile file = file("package testPackage\n" + "class C {\n" + "	def String m(String s) {\n" + "		return null\n" + "	}\n" + "	def String m() {" + "		this.m\n" + "	}\n" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XAbstractFeatureCall substring = findSingleFeatureCall(c);
    assertEquals("testPackage.C.m()", substring.getFeature().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 44 with XAbstractFeatureCall

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

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

the class TypeProviderTest method testTypeOfRichStringWithNoExpectedString_1.

@Test
public void testTypeOfRichStringWithNoExpectedString_1() throws Exception {
    XtendFunction function = function("def foo(String x) {" + "println('''someString''')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XAbstractFeatureCall call = (XAbstractFeatureCall) block.getExpressions().get(0);
    XExpression expression = call.getExplicitArguments().get(0);
    // TODO propagate the expectation better via unbound type parameters
    // could still be a charsequence, here
    assertEquals("java.lang.String", getType(expression).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Aggregations

XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)122 Test (org.junit.Test)105 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)104 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)42 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)21 XExpression (org.eclipse.xtext.xbase.XExpression)17 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)11 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)9 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)6 EObject (org.eclipse.emf.ecore.EObject)5 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)4 IFeatureLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)3 AbstractDiagnostic (org.eclipse.xtext.diagnostics.AbstractDiagnostic)3 XClosure (org.eclipse.xtext.xbase.XClosure)3