use of org.eclipse.xtext.common.types.JvmOperation 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());
}
use of org.eclipse.xtext.common.types.JvmOperation 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());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunctionWithReturnType_08.
@Test
public void testInferredFunctionWithReturnType_08() throws Exception {
XtendFile xtendFile = file("abstract class Foo implements java.util.Comparator<String> { override compare(String a, String b) }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
assertEquals("int", jvmOperation.getReturnType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunctionWithReturnType_05.
@Test
public void testInferredFunctionWithReturnType_05() throws Exception {
XtendFile xtendFile = file("class Foo { def bar() { newArrayList(if (true) null as Double else null as Integer) } }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
assertEquals("java.util.ArrayList<java.lang.Number>", jvmOperation.getReturnType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testBug_340611_03.
@Test
public void testBug_340611_03() throws Exception {
XtendFile xtendFile = file("class Bug340611 {\n" + " def dispatch foo(Appendable appendable) {\n" + " appendable\n" + " }\n" + " def dispatch foo(CharSequence charSeq) {\n" + " charSeq\n" + " }\n" + "}", false);
JvmGenericType inferredType = getInferredType(xtendFile);
assertEquals(3, IterableExtensions.size(inferredType.getDeclaredOperations()));
// one main dispatch
Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", Object.class);
assertEquals("java.lang.Object", dispatch.getReturnType().getIdentifier());
// two internal case methods
JvmOperation stringParam = findByNameAndFirstParameterType(operations, "_foo", Appendable.class);
assertEquals("java.lang.Object", stringParam.getReturnType().getIdentifier());
JvmOperation objectParam = findByNameAndFirstParameterType(operations, "_foo", CharSequence.class);
assertEquals("java.lang.Object", objectParam.getReturnType().getIdentifier());
}
Aggregations