Search in sources :

Example 76 with JvmGenericType

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

the class InferredJvmModelTest method testDispatchFunction_03_impl.

protected void testDispatchFunction_03_impl(boolean validation) throws Exception {
    XtendFile xtendFile = file("class Dispatcher {\n" + "	def dispatch doStuff(org.eclipse.emf.ecore.EClass model) {\n" + "		model.ETypeParameters.map(e|doStuff(e))\n" + "	}\n" + "	def dispatch doStuff(org.eclipse.emf.ecore.EPackage packageDecl) {\n" + "		packageDecl.EClassifiers.map(e|doStuff(e))\n" + "	}\n" + "	def dispatch doStuff(org.eclipse.emf.ecore.EStructuralFeature feature) {\n" + "		newArrayList(feature)\n" + "	}\n" + "}", validation);
    JvmGenericType inferredType = getInferredType(xtendFile);
    // one main dispatch
    Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
    JvmOperation dispatch = findByNameAndFirstParameterType(operations, "doStuff", ENamedElement.class);
    // TODO ultimately this should be List<? extends NamedElement>
    assertEquals("java.util.List<? extends java.lang.Object>", dispatch.getReturnType().getIdentifier());
    // three internal case methods
    JvmOperation eClassParam = findByNameAndFirstParameterType(operations, "_doStuff", EClass.class);
    assertEquals("java.util.List<? extends java.lang.Object>", eClassParam.getReturnType().getIdentifier());
    JvmOperation ePackageParam = findByNameAndFirstParameterType(operations, "_doStuff", EPackage.class);
    assertEquals("java.util.List<? extends java.lang.Object>", ePackageParam.getReturnType().getIdentifier());
    JvmOperation eStructuralFeatureParam = findByNameAndFirstParameterType(operations, "_doStuff", EStructuralFeature.class);
    assertEquals("java.util.List<? extends java.lang.Object>", eStructuralFeatureParam.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)

Example 77 with JvmGenericType

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

the class InferredJvmModelTest method testInferredFunctionWithParameter.

@Test
public void testInferredFunctionWithParameter() throws Exception {
    XtendFile xtendFile = file("class Foo { def bar(Boolean baz) { true } }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertEquals(1, jvmOperation.getParameters().size());
    JvmFormalParameter jvmParameter = jvmOperation.getParameters().get(0);
    XtendParameter xtendParameter = xtendFunction.getParameters().get(0);
    assertEquals(xtendParameter.getName(), jvmParameter.getSimpleName());
    assertEquals(xtendParameter.getParameterType().getType(), jvmParameter.getParameterType().getType());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 78 with JvmGenericType

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

Example 79 with JvmGenericType

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

Example 80 with JvmGenericType

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

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)297 Test (org.junit.Test)237 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)117 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 JvmType (org.eclipse.xtext.common.types.JvmType)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)47 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)33 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)33 JvmField (org.eclipse.xtext.common.types.JvmField)31 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)28 Resource (org.eclipse.emf.ecore.resource.Resource)28 JvmMember (org.eclipse.xtext.common.types.JvmMember)25 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)24 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)21 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)15