Search in sources :

Example 26 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class JvmModelTests method testClassInInterfaceIsStatic.

@Test
public void testClassInInterfaceIsStatic() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("interface Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("class C {}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmGenericType inferred = this._iXtendJvmAssociations.getInferredType(this.interfaze(_builder.toString()));
        JvmMember _head = IterableExtensions.<JvmMember>head(inferred.getMembers());
        final JvmGenericType c = ((JvmGenericType) _head);
        Assert.assertTrue(c.isStatic());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 27 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType 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 28 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class JvmModelTests method testNestedClass_01.

@Test
public void testNestedClass_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo { ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("static class Nested0 {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("interface Nested1 {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("annotation Nested2 {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("enum Nested3 {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("X");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(this.clazz(_builder.toString()));
        Assert.assertEquals(2, clazz.getMembers().size());
        JvmMember _head = IterableExtensions.<JvmMember>head(clazz.getMembers());
        Assert.assertTrue((_head instanceof JvmGenericType));
        JvmMember _head_1 = IterableExtensions.<JvmMember>head(clazz.getMembers());
        final JvmGenericType nested0 = ((JvmGenericType) _head_1);
        Assert.assertEquals("Nested0", nested0.getSimpleName());
        Assert.assertTrue(nested0.isStatic());
        Assert.assertEquals(2, nested0.getMembers().size());
        JvmMember _head_2 = IterableExtensions.<JvmMember>head(nested0.getMembers());
        Assert.assertTrue((_head_2 instanceof JvmGenericType));
        JvmMember _head_3 = IterableExtensions.<JvmMember>head(nested0.getMembers());
        final JvmGenericType nested1 = ((JvmGenericType) _head_3);
        Assert.assertEquals("Nested1", nested1.getSimpleName());
        Assert.assertTrue(nested1.isStatic());
        Assert.assertEquals(2, nested1.getMembers().size());
        JvmMember _head_4 = IterableExtensions.<JvmMember>head(nested1.getMembers());
        Assert.assertTrue((_head_4 instanceof JvmAnnotationType));
        JvmMember _head_5 = IterableExtensions.<JvmMember>head(nested1.getMembers());
        final JvmAnnotationType nested2 = ((JvmAnnotationType) _head_5);
        Assert.assertEquals("Nested2", nested2.getSimpleName());
        Assert.assertTrue(nested2.isStatic());
        Assert.assertEquals(2, nested1.getMembers().size());
        JvmMember _last = IterableExtensions.<JvmMember>last(nested1.getMembers());
        Assert.assertTrue((_last instanceof JvmEnumerationType));
        JvmMember _last_1 = IterableExtensions.<JvmMember>last(nested1.getMembers());
        final JvmEnumerationType nested3 = ((JvmEnumerationType) _last_1);
        Assert.assertEquals("Nested3", nested3.getSimpleName());
        Assert.assertTrue(nested3.isStatic());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Test(org.junit.Test)

Example 29 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class JvmModelTests method testInterfaceAbstract.

@Test
public void testInterfaceAbstract() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("interface Foo {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmGenericType inferred = this._iXtendJvmAssociations.getInferredType(this.interfaze(_builder.toString()));
        Assert.assertTrue(inferred.isAbstract());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 30 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class JvmModelTests method testAnonymousClass_01.

@Test
public void testAnonymousClass_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new Runnable() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("int field");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override run() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
        this.typeResolver.resolveTypes(operation.eResource());
        Assert.assertEquals(1, operation.getLocalClasses().size());
        final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
        Assert.assertTrue(anonymous.isFinal());
        Assert.assertFalse(anonymous.isStatic());
        Assert.assertTrue(anonymous.isLocal());
        Assert.assertFalse(anonymous.isAnonymous());
        Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
        Assert.assertEquals(2, anonymous.getSuperTypes().size());
        Assert.assertEquals("java.lang.Runnable", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
        Assert.assertEquals(3, anonymous.getMembers().size());
        final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
        Assert.assertTrue((constructor instanceof JvmConstructor));
        Assert.assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
        JvmMember _head = IterableExtensions.<JvmMember>head(anonymous.getMembers());
        Assert.assertTrue((_head instanceof JvmField));
        final JvmMember overriding = anonymous.getMembers().get(1);
        Assert.assertTrue((overriding instanceof JvmOperation));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)155 Test (org.junit.Test)106 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)23 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)23 JvmMember (org.eclipse.xtext.common.types.JvmMember)21 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)19 JvmField (org.eclipse.xtext.common.types.JvmField)19 JvmType (org.eclipse.xtext.common.types.JvmType)13 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)11 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 Check (org.eclipse.xtext.validation.Check)9 DispatchSignature (org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature)8