Search in sources :

Example 6 with XtendConstructor

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

the class XtendJvmModelInferrer method addDefaultConstructor.

protected void addDefaultConstructor(XtendClass source, JvmGenericType target) {
    for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendConstructor)
            return;
    }
    JvmConstructor constructor = typesFactory.createJvmConstructor();
    target.getMembers().add(constructor);
    associator.associate(source, constructor);
    constructor.setSimpleName(source.getName());
    constructor.setVisibility(JvmVisibility.PUBLIC);
    typeExtensions.setSynthetic(constructor, true);
}
Also used : XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor)

Example 7 with XtendConstructor

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

the class ErrorTest method testErrorModel_016.

@Test
public void testErrorModel_016() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class <T> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val String s");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("new(String ^new) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("s = ^new");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration unnamed = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _last = IterableExtensions.<XtendMember>last(unnamed.getMembers());
    final XtendConstructor constructor = ((XtendConstructor) _last);
    XExpression _expression = constructor.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XAssignment assignment = ((XAssignment) _head);
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(assignment);
    Assert.assertNotNull(resolvedTypes.getActualType(assignment));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Example 8 with XtendConstructor

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

the class ParserTest method testConstructor_01.

@Test
public void testConstructor_01() throws Exception {
    XtendConstructor constructor = constructor("new() {}");
    assertTrue(constructor.getTypeParameters().isEmpty());
    assertTrue(constructor.getExceptions().isEmpty());
    assertTrue(constructor.getParameters().isEmpty());
    assertEquals(JvmVisibility.PUBLIC, constructor.getVisibility());
}
Also used : XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) Test(org.junit.Test)

Example 9 with XtendConstructor

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

the class TypeProviderTest method constructor.

protected XtendConstructor constructor(String string, boolean validate) throws Exception {
    String clazzString = "class Foo { " + string + "}";
    XtendClass clazz = (XtendClass) file(clazzString, validate).getXtendTypes().get(0);
    return (XtendConstructor) clazz.getMembers().get(0);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor)

Example 10 with XtendConstructor

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

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