Search in sources :

Example 81 with XBlockExpression

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

the class TypeProviderTest method testTypeOfRichStringWithExpectedString_2.

@Ignore("TODO improve expectation if the expected type is an unresolved type parameter")
@Test
public void testTypeOfRichStringWithExpectedString_2() throws Exception {
    XtendFunction function = function("def String foo(String x) {" + "println('''someString''')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XAbstractFeatureCall call = (XAbstractFeatureCall) block.getExpressions().get(0);
    XExpression expression = call.getExplicitArguments().get(0);
    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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 82 with XBlockExpression

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

the class TypeProviderTest method testReturnTypeInConstructor_01.

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

Example 83 with XBlockExpression

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

the class TypeProviderTest method testTypeOfRichStringWithExpectedString_1.

@Test
public void testTypeOfRichStringWithExpectedString_1() throws Exception {
    XtendFunction function = function("def String foo(String x) {" + "foo('''someString''')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XAbstractFeatureCall call = (XAbstractFeatureCall) block.getExpressions().get(0);
    XExpression expression = call.getExplicitArguments().get(0);
    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)

Example 84 with XBlockExpression

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

the class XtendValidationTest method testInaccessibleMethod6.

@Test
public void testInaccessibleMethod6() throws Exception {
    XtendClass xtendClass = clazz("class C { def m() { ''.clone }}");
    helper.assertError(((XBlockExpression) ((XtendFunction) xtendClass.getMembers().get(0)).getExpression()).getExpressions().get(0), XMEMBER_FEATURE_CALL, FEATURE_NOT_VISIBLE, "The method clone", "not", "visible");
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 85 with XBlockExpression

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

the class XtendValidationTest method testInaccessibleMethod7.

@Test
public void testInaccessibleMethod7() throws Exception {
    XtendClass xtendClass = clazz("class C { def m(String s) { s.clone }}");
    helper.assertError(((XBlockExpression) ((XtendFunction) xtendClass.getMembers().get(0)).getExpression()).getExpressions().get(0), XMEMBER_FEATURE_CALL, FEATURE_NOT_VISIBLE, "The method clone", "not", "visible");
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Aggregations

XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)236 Test (org.junit.Test)210 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)198 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)169 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)126 XExpression (org.eclipse.xtext.xbase.XExpression)84 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)84 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)70 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)58 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)55 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)29 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)10 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)10 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)9 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9