Search in sources :

Example 36 with XtendTypeDeclaration

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

the class ValidationBug433213Test method test_02.

@Test
public void test_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def T m2() {}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        final JvmTypeReference returnType = m2.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 37 with XtendTypeDeclaration

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

the class JvmModelTests method testJvmTypeParameter_05.

@Test
public void testJvmTypeParameter_05() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def < foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        final JvmOperation member = IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(clazz.getMembers(), JvmOperation.class));
        Assert.assertNull(member);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 38 with XtendTypeDeclaration

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

the class JvmModelTests method testJvmTypeParameter_07.

@Test
public void testJvmTypeParameter_07() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> String foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        final JvmOperation member = IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(clazz.getMembers(), JvmOperation.class));
        EList<JvmTypeParameter> _typeParameters = member.getTypeParameters();
        String _plus = ("" + _typeParameters);
        Assert.assertEquals(_plus, 1, member.getTypeParameters().size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 39 with XtendTypeDeclaration

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

the class ValueConverterExceptionProducesErrorTest method assertLiteral.

private void assertLiteral(final String expectation, final Resource resource) {
    EObject _head = IterableExtensions.<EObject>head(resource.getContents());
    final XtendFile file = ((XtendFile) _head);
    final XtendTypeDeclaration type = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _head_1 = IterableExtensions.<XtendMember>head(type.getMembers());
    final XtendFunction method = ((XtendFunction) _head_1);
    XExpression _expression = method.getExpression();
    final RichString body = ((RichString) _expression);
    XExpression _head_2 = IterableExtensions.<XExpression>head(body.getExpressions());
    final RichStringLiteral singleElement = ((RichStringLiteral) _head_2);
    Assert.assertEquals(expectation, singleElement.getValue());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) RichString(org.eclipse.xtend.core.xtend.RichString) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 40 with XtendTypeDeclaration

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

the class NamingTest method testNestedTypes.

@Test
public void testNestedTypes() throws Exception {
    XtendFile file = file("class Foo { static class Bar { interface Baz {} annotation FooBar {} } }");
    XtendTypeDeclaration foo = file.getXtendTypes().get(0);
    assertEquals(QualifiedName.create("Foo"), nameProvider.getFullyQualifiedName(foo));
    XtendTypeDeclaration bar = (XtendTypeDeclaration) foo.getMembers().get(0);
    assertEquals(QualifiedName.create("Foo", "Bar"), nameProvider.getFullyQualifiedName(bar));
    XtendTypeDeclaration baz = (XtendTypeDeclaration) bar.getMembers().get(0);
    assertEquals(QualifiedName.create("Foo", "Bar", "Baz"), nameProvider.getFullyQualifiedName(baz));
    XtendTypeDeclaration fooBar = (XtendTypeDeclaration) bar.getMembers().get(1);
    assertEquals(QualifiedName.create("Foo", "Bar", "FooBar"), nameProvider.getFullyQualifiedName(fooBar));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)134 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)98 Test (org.junit.Test)91 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)77 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)34 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)12 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8