Search in sources :

Example 66 with JvmOperation

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

the class InferredJvmModelTest method testDispatchFunction_10.

@Test
public void testDispatchFunction_10() throws Exception {
    XtendFile xtendFile = file("class Foo {\n" + "	def dispatch String someMethod(String o) {\n" + "		\"String\".someMethod\n" + "	}\n" + "	def dispatch someMethod(Object o) {\n" + "		\"String\"" + "	}\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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 67 with JvmOperation

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

the class InferredJvmModelTest method testInferredFunctionWithReturnType_06.

@Test
public void testInferredFunctionWithReturnType_06() throws Exception {
    XtendFile xtendFile = file("abstract class Foo implements Iterable<String> { override iterator() }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    assertEquals("java.util.Iterator<java.lang.String>", jvmOperation.getReturnType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 68 with JvmOperation

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

Example 69 with JvmOperation

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

Example 70 with JvmOperation

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

the class InferredJvmModelTest method testBug_340611_03.

@Test
public void testBug_340611_03() throws Exception {
    XtendFile xtendFile = file("class Bug340611 {\n" + "    def dispatch foo(Appendable appendable) {\n" + "        appendable\n" + "    }\n" + "    def dispatch foo(CharSequence charSeq) {\n" + "        charSeq\n" + "    }\n" + "}", false);
    JvmGenericType inferredType = getInferredType(xtendFile);
    assertEquals(3, IterableExtensions.size(inferredType.getDeclaredOperations()));
    // one main dispatch
    Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
    JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", Object.class);
    assertEquals("java.lang.Object", dispatch.getReturnType().getIdentifier());
    // two internal case methods
    JvmOperation stringParam = findByNameAndFirstParameterType(operations, "_foo", Appendable.class);
    assertEquals("java.lang.Object", stringParam.getReturnType().getIdentifier());
    JvmOperation objectParam = findByNameAndFirstParameterType(operations, "_foo", CharSequence.class);
    assertEquals("java.lang.Object", objectParam.getReturnType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) 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