Search in sources :

Example 31 with JvmField

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

the class InferredJvmModelTest method testNameClashWithCreateExtension_02.

@Test
public void testNameClashWithCreateExtension_02() throws Exception {
    XtendFile xtendFile = file("package foo class Foo { def create new String() s(String x) { '' } def create new String() s(Object x) { '' }}");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField cacheVar0 = (JvmField) inferredType.getMembers().get(2);
    assertEquals("_createCache_s", cacheVar0.getSimpleName());
    JvmOperation initializer0 = (JvmOperation) inferredType.getMembers().get(3);
    assertEquals("_init_s", initializer0.getSimpleName());
    JvmField cacheVar1 = (JvmField) inferredType.getMembers().get(5);
    assertEquals("_createCache_s_1", cacheVar1.getSimpleName());
    JvmOperation initializer1 = (JvmOperation) inferredType.getMembers().get(6);
    assertEquals("_init_s_1", initializer1.getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 32 with JvmField

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

the class InferredJvmModelTest method testXtendField_00.

@Test
public void testXtendField_00() throws Exception {
    XtendFile xtendFile = file("class Foo { @Inject String string }");
    JvmGenericType type = getInferredType(xtendFile);
    Iterable<JvmField> iterable = type.getDeclaredFields();
    JvmField next = iterable.iterator().next();
    assertEquals("string", next.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, next.getVisibility());
    assertEquals("java.lang.String", next.getType().getIdentifier());
    for (JvmMember member : type.getMembers()) {
        if (member instanceof JvmExecutable) {
            assertEquals(JvmVisibility.PUBLIC, member.getVisibility());
        } else {
            assertEquals(JvmVisibility.PRIVATE, member.getVisibility());
        }
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 33 with JvmField

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

the class InferredJvmModelTest method testNameClashWithCreateExtension_03.

@Test
public void testNameClashWithCreateExtension_03() throws Exception {
    XtendFile xtendFile = file("package foo class Foo { def create new String() s(String x) { '' } def create new String() s(Object x, Object y) { '' }}");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField cacheVar0 = (JvmField) inferredType.getMembers().get(2);
    assertEquals("_createCache_s", cacheVar0.getSimpleName());
    JvmOperation initializer0 = (JvmOperation) inferredType.getMembers().get(3);
    assertEquals("_init_s", initializer0.getSimpleName());
    JvmField cacheVar1 = (JvmField) inferredType.getMembers().get(5);
    assertEquals("_createCache_s_1", cacheVar1.getSimpleName());
    JvmOperation initializer1 = (JvmOperation) inferredType.getMembers().get(6);
    assertEquals("_init_s", initializer1.getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 34 with JvmField

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

the class InferredJvmModelTest method testNameClashWithCreateExtension_01.

@Test
public void testNameClashWithCreateExtension_01() throws Exception {
    XtendFile xtendFile = file("package foo class Foo { def create new String() s(String x) { '' } String _init_s }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField cacheVar = (JvmField) inferredType.getMembers().get(2);
    assertEquals("_createCache_s", cacheVar.getSimpleName());
    JvmOperation initializer = (JvmOperation) inferredType.getMembers().get(3);
    assertEquals("_init_s_1", initializer.getSimpleName());
    JvmField field = (JvmField) inferredType.getMembers().get(4);
    assertEquals("_init_s", field.getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 35 with JvmField

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

the class InferredJvmModelTest method testNameClashWithAnonymousExtension_00.

@Test
public void testNameClashWithAnonymousExtension_00() throws Exception {
    XtendFile xtendFile = file("package foo import com.google.inject.Inject class Foo { @Inject extension String String _string }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField extension = (JvmField) inferredType.getMembers().get(1);
    assertEquals("_string_1", extension.getSimpleName());
    JvmField field = (JvmField) inferredType.getMembers().get(2);
    assertEquals("_string", field.getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Aggregations

JvmField (org.eclipse.xtext.common.types.JvmField)36 Test (org.junit.Test)24 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)18 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)17 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 EObject (org.eclipse.emf.ecore.EObject)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)3 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Set (java.util.Set)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2