Search in sources :

Example 41 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.

the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence_02.

@Test
public void testIgnoreVoidInParameterTypeInferrence_02() throws Exception {
    XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Number n, Void v) {null}" + " def dispatch foo(Void ignore, Object o) {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.Number", firstParameter.getParameterType().getIdentifier());
    JvmFormalParameter secondParameter = dispatchMethod.getParameters().get(1);
    assertEquals("java.lang.Object", secondParameter.getParameterType().getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 42 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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 43 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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 44 with JvmOperation

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

Example 45 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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)

Aggregations

JvmOperation (org.eclipse.xtext.common.types.JvmOperation)202 Test (org.junit.Test)127 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)101 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)73 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)38 EObject (org.eclipse.emf.ecore.EObject)30 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)26 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)22 XExpression (org.eclipse.xtext.xbase.XExpression)20 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)20 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)20 JvmField (org.eclipse.xtext.common.types.JvmField)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)15 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)15 JvmMember (org.eclipse.xtext.common.types.JvmMember)15 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10