use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunctionWithReturnType_02.
@Test
public void testInferredFunctionWithReturnType_02() throws Exception {
XtendFile xtendFile = file("class Foo { def Iterable<String> create result: newArrayList newList() {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
assertTrue(inferredType.getMembers().get(0) instanceof JvmConstructor);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
assertFalse(xtendFunction.getReturnType() == jvmOperation.getReturnType());
assertEquals(xtendFunction.getReturnType().getType(), jvmOperation.getReturnType().getType());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testBug_340611_05.
@Test
public void testBug_340611_05() throws Exception {
XtendFile xtendFile = file("class Bug340611 extends test.Dispatching {\n" + " override dispatch doDispatch(StringBuilder sb) {\n" + " null\n" + " }\n" + " def dispatch doDispatch(String s) {\n" + " s\n" + " }\n" + "}", false);
JvmGenericType inferredType = getInferredType(xtendFile);
assertEquals(3, IterableExtensions.size(inferredType.getDeclaredOperations()));
Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
JvmOperation dispatch = findByNameAndFirstParameterType(operations, "doDispatch", Object.class);
assertEquals("java.lang.CharSequence", dispatch.getReturnType().getIdentifier());
// two internal case methods
JvmOperation stringParam = findByNameAndFirstParameterType(operations, "_doDispatch", StringBuilder.class);
assertEquals("java.lang.StringBuilder", stringParam.getReturnType().getIdentifier());
JvmOperation objectParam = findByNameAndFirstParameterType(operations, "_doDispatch", String.class);
assertEquals("java.lang.CharSequence", objectParam.getReturnType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunction_04.
@Test
public void testInferredFunction_04() throws Exception {
XtendFile xtendFile = file("class Foo { def Iterable<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<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<java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
// This used to be a bogus assertion since Iterable<CharSequence> is not assignable from ArrayList<String>
// assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testExtensionToAnnotation_02.
@Test
public void testExtensionToAnnotation_02() throws Exception {
XtendFile xtendFile = file("class C { def void m(extension String s) {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
List<JvmFormalParameter> parameters = jvmOperation.getParameters();
JvmFormalParameter singleParameter = parameters.get(0);
List<JvmAnnotationReference> annotations = singleParameter.getAnnotations();
assertEquals(1, annotations.size());
assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
use of org.eclipse.xtext.common.types.JvmOperation 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);
}
Aggregations