Search in sources :

Example 21 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class ParserTest method testConstructor_02.

@Test
public void testConstructor_02() throws Exception {
    XtendConstructor constructor = constructor("protected new(int a) throws RuntimeException { super() }");
    assertTrue(constructor.getTypeParameters().isEmpty());
    assertEquals(1, constructor.getExceptions().size());
    assertEquals(1, constructor.getParameters().size());
    assertEquals(JvmVisibility.PROTECTED, constructor.getVisibility());
}
Also used : XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) Test(org.junit.Test)

Example 22 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class TypeProviderTest method testTypeOfSuperInConstructor.

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

Example 23 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor 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 24 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class TypeProviderTest method testTypeOfThisInConstructor.

@Test
public void testTypeOfThisInConstructor() throws Exception {
    XtendConstructor constructor = constructor("new(int a) {\n" + "	this()\n" + "}\n" + "new() {}");
    XBlockExpression body = (XBlockExpression) constructor.getExpression();
    XFeatureCall thisCall = (XFeatureCall) body.getExpressions().get(0);
    assertEquals("void", getType(thisCall).getIdentifier());
    assertNull(getExpectedType(thisCall));
    assertNull(getExpectedReturnType(thisCall));
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 25 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendValidationTest method testVarArgMustBeLast_1.

@Test
public void testVarArgMustBeLast_1() throws Exception {
    XtendConstructor constr = constructor("new(String... myParam, String x) { }");
    helper.assertError(constr, XtendPackage.Literals.XTEND_PARAMETER, INVALID_USE_OF_VAR_ARG);
}
Also used : XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) Test(org.junit.Test)

Aggregations

XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)28 Test (org.junit.Test)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)9 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 XExpression (org.eclipse.xtext.xbase.XExpression)7 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)5 XtendEnumLiteral (org.eclipse.xtend.core.xtend.XtendEnumLiteral)3 EObject (org.eclipse.emf.ecore.EObject)2 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)2 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2