Search in sources :

Example 66 with XMemberFeatureCall

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

the class TypeProviderTest method testReturnTypeInConstructor_02.

@Test
public void testReturnTypeInConstructor_02() throws Exception {
    XtendConstructor constructor = constructor("new() {\n" + "	return ''.toString\n" + "}\n", false);
    XBlockExpression body = (XBlockExpression) constructor.getExpression();
    assertEquals("void", getExpectedType(body).getIdentifier());
    assertEquals("void", getExpectedReturnType(body).getIdentifier());
    XReturnExpression returnExpression = (XReturnExpression) body.getExpressions().get(0);
    XMemberFeatureCall toString = (XMemberFeatureCall) returnExpression.getExpression();
    assertEquals("void", getExpectedType(toString).getIdentifier());
    assertEquals("void", getExpectedReturnType(toString).getIdentifier());
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XReturnExpression(org.eclipse.xtext.xbase.XReturnExpression) Test(org.junit.Test)

Example 67 with XMemberFeatureCall

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

the class TypeProviderTest method testBug380063NoException.

@Test
public void testBug380063NoException() throws Exception {
    XtendClass clazz = clazz("class Foo<T> { " + "def foo(java.util.List<? extends T> l) { " + "	l.add(null)" + "}}");
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XtendParameter xtendParameter = function.getParameters().get(0);
    XBlockExpression expr = (XBlockExpression) function.getExpression();
    XMemberFeatureCall call = (XMemberFeatureCall) expr.getExpressions().get(0);
    LightweightTypeReference type = getType(call.getMemberCallTarget());
    assertEquals("List<? extends T>", type.getSimpleName());
    assertEquals("List<? extends T>", xtendParameter.getParameterType().getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 68 with XMemberFeatureCall

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

the class InferredJvmModelShadowingJavaLinkingTests method testLinkJavaMethod.

@Test
public void testLinkJavaMethod() throws Exception {
    XtendClass bar = classFile("test/Bar", "package test class Bar { def bar(Foo foo) {foo.foo()} }");
    final XExpression block = ((XtendFunction) bar.getMembers().get(0)).getExpression();
    XMemberFeatureCall methodCall = (XMemberFeatureCall) ((XBlockExpression) block).getExpressions().get(0);
    assertTrue(isJavaElement(methodCall.getFeature()));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 69 with XMemberFeatureCall

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

the class InferredJvmModelShadowingJavaLinkingTests method testLinkInferredJvmOperationWithSyntaxError.

@Test
public void testLinkInferredJvmOperationWithSyntaxError() throws Exception {
    // syntax error is intentional
    XtendClass foo = classFile("test/Foo", "package test class Foo { def foo() :this; }");
    XtendClass bar = classFile("test/Bar", "package test class Bar { def bar(Foo foo) {foo.foo()} }");
    final XBlockExpression block = (XBlockExpression) ((XtendFunction) bar.getMembers().get(0)).getExpression();
    XMemberFeatureCall methodCall = (XMemberFeatureCall) block.getExpressions().get(0);
    assertEquals(associations.getDirectlyInferredOperation((XtendFunction) foo.getMembers().get(0)), methodCall.getFeature());
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 70 with XMemberFeatureCall

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

the class LinkingErrorTest method testFieldsAreNotSugared_01.

@Test
public void testFieldsAreNotSugared_01() throws Exception {
    XtendClass clazz = clazz("class A {\n" + " String getFoo\n" + " def String doStuff() {\n" + "	    this.foo\n" + "	}");
    XMemberFeatureCall call = (XMemberFeatureCall) ((XBlockExpression) ((XtendFunction) clazz.getMembers().get(1)).getExpression()).getExpressions().get(0);
    JvmIdentifiableElement feature = call.getFeature();
    assertTrue(feature.eIsProxy());
}
Also used : 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) Test(org.junit.Test)

Aggregations

XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)88 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)82 Test (org.junit.Test)82 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)78 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)74 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)46 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)19 XExpression (org.eclipse.xtext.xbase.XExpression)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)5 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)4 XIfExpression (org.eclipse.xtext.xbase.XIfExpression)4 XSwitchExpression (org.eclipse.xtext.xbase.XSwitchExpression)4 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)3 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)2 RichString (org.eclipse.xtend.core.xtend.RichString)2