use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_2.
@Test
public void testTypeParameterReference_2() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Y y) { return y }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("Y", returnType.getIdentifier());
JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
assertEquals("Y", paramType.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testImplicitFirstArgument_04.
@Test
public void testImplicitFirstArgument_04() throws Exception {
XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + " def testExtensionMethods(CharSequence it) {\n" + " unique" + " }\n" + " extension String" + "}");
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XFeatureCall forth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmOperation forthFeature = (JvmOperation) forth.getFeature();
assertEquals("test.ImplicitFirstArgumentStatics.unique()", forthFeature.getIdentifier());
assertNull(forth.getImplicitFirstArgument());
assertNull(forth.getImplicitReceiver());
assertNull(forth.getInvalidFeatureIssueCode());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testBug345827_05.
@Test
public void testBug345827_05() throws Exception {
XtendFunction function = function("def String name(String name) {\n" + " name()" + "}");
XBlockExpression block = (XBlockExpression) function.getExpression();
XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(function);
assertSame(operation, featureCall.getFeature());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_10.
@Test
public void testTypeParameterReference_10() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Iterable<Y> iter) { for(y: iter) { return y } null }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("Y", returnType.getIdentifier());
JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
assertEquals("java.lang.Iterable<Y>", paramType.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testCreateExtension_00.
@Test
public void testCreateExtension_00() throws Exception {
XtendClass clazz = clazz("class Foo { " + " def create list: newArrayList('foo') getListWithFooAnd(String s) {" + " list" + " this.getListWithFooAnd('')" + " }" + "}");
assertEquals(1, clazz.getMembers().size());
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
Set<EObject> elements = associator.getJvmElements(func);
Iterable<JvmOperation> filter = filter(elements, JvmOperation.class);
JvmOperation initializer = filter(filter, new Predicate<JvmOperation>() {
@Override
public boolean apply(JvmOperation input) {
return input.getSimpleName().startsWith("_init_");
}
}).iterator().next();
assertEquals(initializer.getParameters().get(0), featureCall.getFeature());
XAbstractFeatureCall recursiveFeatureCall = (XAbstractFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(1);
assertEquals("Foo.getListWithFooAnd(java.lang.String)", recursiveFeatureCall.getFeature().getIdentifier());
}
Aggregations