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());
}
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());
}
}
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());
}
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());
}
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());
}
Aggregations