Search in sources :

Example 1 with DispatchSignature

use of org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature in project xtext-xtend by eclipse.

the class DispatchHelperTest method testVisibility_00.

@Test
public void testVisibility_00() throws Exception {
    XtendClass superClazz = clazz("class Super {\n" + "  def private dispatch foo(Object x) {} \n" + "}");
    Resource subResource = superClazz.eResource().getResourceSet().createResource(URI.createURI("Sub.xtend", true));
    subResource.load(new StringInputStream("class Sub extends Super {\n" + "  def dispatch foo(String x) {}\n" + "  def dispatch foo(Number x) {}\n" + "}"), null);
    JvmGenericType type = (JvmGenericType) subResource.getContents().get(1);
    ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
    List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
    assertEquals(2, list.size());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 2 with DispatchSignature

use of org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature 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());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 3 with DispatchSignature

use of org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature 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());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 4 with DispatchSignature

use of org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature in project xtext-xtend by eclipse.

the class DispatchHelperTest method testSort_00.

@Test
public void testSort_00() throws Exception {
    XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Integer i) {null}" + " def dispatch foo(Comparable<?> i) {null}" + " def dispatch foo(java.io.Serializable i) {null}" + " def dispatch foo(String i) {null}" + " def dispatch foo(Number i) {null}" + " def dispatch foo(Object i) {null}" + " def dispatch foo(CharSequence 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(Number.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
    assertEquals(String.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
    assertEquals(Serializable.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
    assertEquals(CharSequence.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
    assertEquals(Comparable.class.getName(), i.next().getParameters().get(0).getParameterType().getType().getIdentifier());
    assertEquals(Object.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
    assertFalse(i.hasNext());
}
Also used : DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) Serializable(java.io.Serializable) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 5 with DispatchSignature

use of org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature in project xtext-xtend by eclipse.

the class DispatchHelperTest method testVisibility_01.

@Test
public void testVisibility_01() throws Exception {
    XtendClass superClazz = clazz("class Super {\n" + "  def dispatch foo(Object x) {} \n" + "}");
    Resource subResource = superClazz.eResource().getResourceSet().createResource(URI.createURI("Sub.xtend", true));
    subResource.load(new StringInputStream("class Sub extends Super {\n" + "  def dispatch foo(String x) {}\n" + "  def dispatch foo(Number x) {}\n" + "}"), null);
    JvmGenericType type = (JvmGenericType) subResource.getContents().get(1);
    ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
    List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
    assertEquals(3, list.size());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Aggregations

DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)5 DispatchSignature (org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature)5 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 Test (org.junit.Test)5 Resource (org.eclipse.emf.ecore.resource.Resource)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 Serializable (java.io.Serializable)1