use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class LinkingTest method testImplicitFirstArgument_01.
@Test
public void testImplicitFirstArgument_01() throws Exception {
XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + " def testExtensionMethods(CharSequence it) {\n" + " length\n" + " }\n" + " extension String" + " def length() { null }\n" + "}");
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XFeatureCall first = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmOperation firstFeature = (JvmOperation) first.getFeature();
assertEquals("java.lang.CharSequence.length()", firstFeature.getIdentifier());
assertEquals("java.lang.CharSequence", firstFeature.getDeclaringType().getQualifiedName());
assertNull(first.getImplicitFirstArgument());
XFeatureCall firstReceiver = (XFeatureCall) first.getImplicitReceiver();
assertTrue(firstReceiver.getFeature() instanceof JvmFormalParameter);
assertNull(first.getInvalidFeatureIssueCode());
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence.
@Test
public void testIgnoreVoidInParameterTypeInferrence() throws Exception {
XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Integer i) {null}" + " def dispatch foo(Number n) {null}" + " def dispatch foo(Void ignore) {null}" + "}");
JvmGenericType type = associations.getInferredType(clazz);
JvmOperation dispatchMethod = dispatchHelper.getDispatcherOperation(type, new DispatchHelper.DispatchSignature("foo", 1));
JvmFormalParameter firstParameter = dispatchMethod.getParameters().get(0);
assertEquals("java.lang.Number", firstParameter.getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testDispatchFunction_07.
@Test
public void testDispatchFunction_07() throws Exception {
XtendFile xtendFile = file("class Foo {" + "def dispatch foo(Object o, boolean b) " + "def dispatch foo(Integer i, boolean b) " + "}");
Iterable<JvmOperation> operations = getInferredType(xtendFile).getDeclaredOperations();
JvmOperation dispatcher = find(operations, new Predicate<JvmOperation>() {
@Override
public boolean apply(JvmOperation input) {
return equal("foo", input.getSimpleName());
}
});
JvmFormalParameter parameter = dispatcher.getParameters().get(1);
assertEquals("boolean", parameter.getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testDispatchFunction_09.
@Test
public void testDispatchFunction_09() throws Exception {
XtendFile xtendFile = file("import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor\n" + "import org.eclipse.xtend.core.xtend.XtendClass\n" + "import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer\n" + "class Z extends AbstractModelInferrer {\n" + " def dispatch infer(XtendClass x, IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase) {}\n" + "}\n");
Iterable<JvmOperation> operations = getInferredType(xtendFile).getDeclaredOperations();
JvmOperation dispatcher = find(operations, new Predicate<JvmOperation>() {
@Override
public boolean apply(JvmOperation input) {
return equal("infer", input.getSimpleName());
}
});
JvmFormalParameter firstParameter = dispatcher.getParameters().get(0);
assertEquals("EObject", firstParameter.getParameterType().getSimpleName());
String returnType = dispatcher.getReturnType().getIdentifier();
assertEquals("void", returnType);
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class LinkingTest method testCreateExtension_01.
@Test
public void testCreateExtension_01() throws Exception {
XtendClass clazz = clazz("class Foo { " + " def create list: newArrayList(s) getListWithFooAnd(String s) {" + " s" + " }" + "}");
assertEquals(1, clazz.getMembers().size());
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XFeatureCall featureCall = (XFeatureCall) func.getCreateExtensionInfo().getCreateExpression();
List<XExpression> arguments = featureCall.getActualArguments();
XFeatureCall argument = (XFeatureCall) arguments.get(0);
JvmFormalParameter parameter = (JvmFormalParameter) argument.getFeature();
assertEquals("s", parameter.getIdentifier());
JvmOperation operation = (JvmOperation) parameter.eContainer();
assertEquals("Foo.getListWithFooAnd(java.lang.String)", operation.getIdentifier());
XFeatureCall featureCallInInitializer = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmFormalParameter parameterInInitializer = (JvmFormalParameter) featureCallInInitializer.getFeature();
assertEquals("s", parameterInInitializer.getIdentifier());
JvmOperation initializer = (JvmOperation) parameterInInitializer.eContainer();
assertEquals("Foo._init_getListWithFooAnd(java.util.ArrayList,java.lang.String)", initializer.getIdentifier());
}
Aggregations