Search in sources :

Example 11 with JvmFormalParameter

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

the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence_02.

@Test
public void testIgnoreVoidInParameterTypeInferrence_02() throws Exception {
    XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Number n, Void v) {null}" + " def dispatch foo(Void ignore, Object o) {null}" + "}");
    JvmGenericType type = associations.getInferredType(clazz);
    JvmOperation dispatchMethod = dispatchHelper.getDispatcherOperation(type, new DispatchHelper.DispatchSignature("foo", 2));
    JvmFormalParameter firstParameter = dispatchMethod.getParameters().get(0);
    assertEquals("java.lang.Number", firstParameter.getParameterType().getIdentifier());
    JvmFormalParameter secondParameter = dispatchMethod.getParameters().get(1);
    assertEquals("java.lang.Object", secondParameter.getParameterType().getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 12 with JvmFormalParameter

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

the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence_03.

@Test
public void testIgnoreVoidInParameterTypeInferrence_03() throws Exception {
    XtendClass clazz = clazz("class X {\n" + " def dispatch foo(String n, Void v) {null}" + " def dispatch foo(Integer i, Void v) {null}" + "}");
    JvmGenericType type = associations.getInferredType(clazz);
    JvmOperation dispatchMethod = dispatchHelper.getDispatcherOperation(type, new DispatchHelper.DispatchSignature("foo", 2));
    JvmFormalParameter firstParameter = dispatchMethod.getParameters().get(0);
    assertEquals("java.lang.Object", firstParameter.getParameterType().getIdentifier());
    JvmFormalParameter secondParameter = dispatchMethod.getParameters().get(1);
    assertEquals("java.lang.Object", secondParameter.getParameterType().getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 13 with JvmFormalParameter

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

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

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

the class ParserTest method testExtensionOnLambdaParameter_01.

@Test
public void testExtensionOnLambdaParameter_01() throws Exception {
    XtendClass clazz = clazz("class Foo { val x = [ extension String a, String b | 0 ] }");
    assertEquals(1, clazz.getMembers().size());
    XtendField f = (XtendField) clazz.getMembers().get(0);
    XClosure initializer = (XClosure) f.getInitialValue();
    List<JvmFormalParameter> parameters = initializer.getDeclaredFormalParameters();
    assertEquals(2, parameters.size());
    XtendFormalParameter firstParameter = (XtendFormalParameter) parameters.get(0);
    assertTrue(firstParameter.isExtension());
    XtendFormalParameter secondParameter = (XtendFormalParameter) parameters.get(1);
    assertFalse(secondParameter.isExtension());
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) XtendFormalParameter(org.eclipse.xtend.core.xtend.XtendFormalParameter) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)45 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)22 Test (org.junit.Test)17 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)14 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)11 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 XExpression (org.eclipse.xtext.xbase.XExpression)8 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)7 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 EObject (org.eclipse.emf.ecore.EObject)5 JvmType (org.eclipse.xtext.common.types.JvmType)5 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)5 XClosure (org.eclipse.xtext.xbase.XClosure)5 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)5 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)4 XtendField (org.eclipse.xtend.core.xtend.XtendField)4 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)4 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)4