use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class DispatchHelperTest method testSort_02.
@Test
public void testSort_02() throws Exception {
XtendClass clazz = clazz("class X {\n" + " def dispatch foo(int a, String b) {null}" + " def dispatch foo(Boolean i, Object b) {null}" + " def dispatch foo(Object i, String b) {null}" + "}");
JvmGenericType type = associations.getInferredType(clazz);
ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 2));
Iterator<JvmOperation> i = list.iterator();
assertEquals(Integer.TYPE.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
assertEquals(Boolean.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
assertEquals(Object.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence_03.
@Test
public void testIgnoreVoidInParameterTypeInferrence_03() throws Exception {
XtendClass clazz = clazz("class X {\n" + " def dispatch foo(String n, Void v) {null}" + " def dispatch foo(Integer i, Void v) {null}" + "}");
JvmGenericType type = associations.getInferredType(clazz);
JvmOperation dispatchMethod = dispatchHelper.getDispatcherOperation(type, new DispatchHelper.DispatchSignature("foo", 2));
JvmFormalParameter firstParameter = dispatchMethod.getParameters().get(0);
assertEquals("java.lang.Object", firstParameter.getParameterType().getIdentifier());
JvmFormalParameter secondParameter = dispatchMethod.getParameters().get(1);
assertEquals("java.lang.Object", secondParameter.getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class DispatchHelperTest method testSort_01.
@Test
public void testSort_01() throws Exception {
XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Integer i) {null}" + " def dispatch foo(Boolean i) {null}" + " def dispatch foo(String i) {null}" + "}");
JvmGenericType type = associations.getInferredType(clazz);
ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
Iterator<JvmOperation> i = list.iterator();
assertEquals(Integer.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
assertEquals(Boolean.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
assertEquals(String.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class EObjectLocationTests method testFullLocationInFile.
@Test
public void testFullLocationInFile() throws Exception {
String model = "class Foo extends Object { def Foo foo() {this }}";
XtendClass clazz = clazz(model);
JvmGenericType inferredType = xtendjvmAssociations.getInferredType(clazz);
assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredType));
JvmConstructor inferredConstructor = xtendjvmAssociations.getInferredConstructor(clazz);
assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredConstructor));
XtendFunction xtendFunction = (XtendFunction) clazz.getMembers().get(0);
JvmOperation inferredOperation = xtendjvmAssociations.getDirectlyInferredOperation(xtendFunction);
assertEquals(locationInFileProvider.getFullTextRegion(xtendFunction), locationInFileProvider.getFullTextRegion(inferredOperation));
}
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