Search in sources :

Example 61 with JvmOperation

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

the class InferredJvmModelTest method testInferredFunctionWithSelfTypeReference.

@Test
public void testInferredFunctionWithSelfTypeReference() throws Exception {
    XtendFile xtendFile = file("package foo class Foo { def Foo bar() { this } }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    assertEquals(inferredType, jvmOperation.getReturnType().getType());
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertEquals(inferredType, xtendFunction.getReturnType().getType());
}
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) Test(org.junit.Test)

Example 62 with JvmOperation

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

the class InferredJvmModelTest method testInferredFunction_03.

@Test
public void testInferredFunction_03() throws Exception {
    XtendFile xtendFile = file("class Foo {def publicMethod(Object dummy) {} def public publicMethod() {} def protected protectedMethod() {} def private privateMethod() {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    for (JvmOperation op : inferredType.getDeclaredOperations()) {
        assertEquals(JvmVisibility.get(op.getSimpleName().replace("Method", "").toUpperCase()), op.getVisibility());
    }
}
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 63 with JvmOperation

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

the class InferredJvmModelTest method testInferredFunctionWithReturnType_03.

@Test
public void testInferredFunctionWithReturnType_03() throws Exception {
    XtendFile xtendFile = file("class Foo { def bar() { null } }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    assertEquals("java.lang.Object", 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 64 with JvmOperation

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

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

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