Search in sources :

Example 91 with JvmGenericType

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

the class InferredJvmModelTest method testInferredFunction_06.

@Test
public void testInferredFunction_06() throws Exception {
    XtendFile xtendFile = file("class Foo { def Iterable<? super CharSequence> create result: newArrayList(s) newList(String s) {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    EList<JvmMember> jvmMembers = inferredType.getMembers();
    assertEquals(4, jvmMembers.size());
    JvmMember jvmMember = jvmMembers.get(1);
    assertTrue(jvmMember instanceof JvmOperation);
    XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
    assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
    assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
    assertEquals("java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
    JvmField cacheVar = (JvmField) jvmMembers.get(2);
    assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
    assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
    JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
    assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
    assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) 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 92 with JvmGenericType

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

the class InferredJvmModelTest method testDispatchFunction_10.

@Test
public void testDispatchFunction_10() throws Exception {
    XtendFile xtendFile = file("class Foo {\n" + "	def dispatch String someMethod(String o) {\n" + "		\"String\".someMethod\n" + "	}\n" + "	def dispatch someMethod(Object o) {\n" + "		\"String\"" + "	}\n" + "	def dispatch someMethod(Double o) {\n" + "		\"String\"" + "	}\n" + "}");
    JvmGenericType inferredType = getInferredType(xtendFile);
    Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
    JvmOperation dispatch = findByNameAndFirstParameterType(operations, "someMethod", Object.class);
    assertEquals("java.lang.String", dispatch.getReturnType().getIdentifier());
    JvmOperation dispatchCase = findByNameAndFirstParameterType(operations, "_someMethod", Object.class);
    assertEquals("java.lang.String", dispatchCase.getReturnType().getIdentifier());
    JvmOperation dispatchCase2 = findByNameAndFirstParameterType(operations, "_someMethod", String.class);
    assertEquals("java.lang.String", dispatchCase2.getReturnType().getIdentifier());
    JvmOperation dispatchCase3 = findByNameAndFirstParameterType(operations, "_someMethod", Double.class);
    assertEquals("java.lang.String", dispatchCase3.getReturnType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 93 with JvmGenericType

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

the class InferredJvmModelTest method testInferredFunctionWithReturnType_06.

@Test
public void testInferredFunctionWithReturnType_06() throws Exception {
    XtendFile xtendFile = file("abstract class Foo implements Iterable<String> { override iterator() }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    assertEquals("java.util.Iterator<java.lang.String>", jvmOperation.getReturnType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 94 with JvmGenericType

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

the class InferredJvmModelTest method testDispatchFunction_01.

@Test
public void testDispatchFunction_01() throws Exception {
    XtendFile xtendFile = file("class Foo { def dispatch foo(Object x, String y) {null} def dispatch foo(String x) {null}}");
    JvmGenericType inferredType = getInferredType(xtendFile);
    // two dispatch methods
    Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
    JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", Object.class);
    assertEquals("java.lang.Object", dispatch.getReturnType().getIdentifier());
    assertEquals(2, dispatch.getParameters().size());
    dispatch = findByNameAndFirstParameterType(operations, "foo", String.class);
    assertEquals("java.lang.Object", dispatch.getReturnType().getIdentifier());
    assertEquals(1, dispatch.getParameters().size());
    // two internal case methods
    findByNameAndFirstParameterType(operations, "_foo", Object.class);
    findByNameAndFirstParameterType(operations, "_foo", String.class);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 95 with JvmGenericType

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

the class InferredJvmModelTest method testInferredFunctionWithReturnType_07.

@Test
public void testInferredFunctionWithReturnType_07() throws Exception {
    XtendFile xtendFile = file("abstract class Foo<T> implements Iterable<Iterable<T>> { override iterator() }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    assertEquals("java.util.Iterator<java.lang.Iterable<T>>", jvmOperation.getReturnType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)297 Test (org.junit.Test)237 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)117 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 JvmType (org.eclipse.xtext.common.types.JvmType)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)47 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)33 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)33 JvmField (org.eclipse.xtext.common.types.JvmField)31 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)28 Resource (org.eclipse.emf.ecore.resource.Resource)28 JvmMember (org.eclipse.xtext.common.types.JvmMember)25 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)24 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)21 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)15