use of org.eclipse.xtext.common.types.JvmGenericType 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.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testDispatchFunction_11.
@Test
public void testDispatchFunction_11() throws Exception {
XtendFile xtendFile = file("class Foo {\n" + " def dispatch someMethod(Object o) {\n" + " \"String\"" + " }\n" + " def dispatch String someMethod(String o) {\n" + " \"String\".someMethod\n" + " }\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.JvmGenericType 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.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredTypeWithSelfReferringTypeParameter.
@Test
public void testInferredTypeWithSelfReferringTypeParameter() throws Exception {
XtendFile xtendFile = file("package foo class Foo <T extends Foo> {}");
JvmGenericType inferredType = getInferredType(xtendFile);
assertEquals(1, inferredType.getTypeParameters().size());
JvmTypeParameter typeParameter = inferredType.getTypeParameters().get(0);
assertEquals(1, typeParameter.getConstraints().size());
JvmTypeConstraint typeConstraint = typeParameter.getConstraints().get(0);
assertTrue(typeConstraint instanceof JvmUpperBound);
assertEquals(inferredType, ((JvmUpperBound) typeConstraint).getTypeReference().getType());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunction_05.
@Test
public void testInferredFunction_05() throws Exception {
XtendFile xtendFile = file("class Foo { def Iterable<? extends 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.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.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.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
Aggregations