Search in sources :

Example 46 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testInferredFunction_06.

@Test
public void testInferredFunction_06() throws Exception {
    XtendFile xtendFile = file("class Foo { def Iterable<? super CharSequence> create result: newArrayList(s) newList(String s) {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    EList<JvmMember> jvmMembers = inferredType.getMembers();
    assertEquals(4, jvmMembers.size());
    JvmMember jvmMember = jvmMembers.get(1);
    assertTrue(jvmMember instanceof JvmOperation);
    XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
    assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
    assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
    assertEquals("java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
    JvmField cacheVar = (JvmField) jvmMembers.get(2);
    assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
    assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
    JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
    assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
    assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
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) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 47 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testInferredFunction_02.

@Test
public void testInferredFunction_02() throws Exception {
    XtendFile xtendFile = file("class Foo { def create result: newArrayList(s) newList(String s) {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    EList<JvmMember> jvmMembers = inferredType.getMembers();
    assertEquals(4, jvmMembers.size());
    JvmMember jvmMember = jvmMembers.get(1);
    assertTrue(jvmMember instanceof JvmOperation);
    XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
    assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
    assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.String>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
    JvmField cacheVar = (JvmField) jvmMembers.get(2);
    assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
    assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.util.ArrayList<java.lang.String>>", cacheVar.getType().getIdentifier());
    JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
    assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
    assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
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) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 48 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction 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 49 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction 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 50 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class LinkingErrorTest method testNoException_02.

@Test
public void testNoException_02() throws Exception {
    XtendFunction function = function("def noException() {\n" + // exception case is i
    "	    val closure = [ i| return i]\n" + "	    for (x : 1..100) closure.apply(x)\n" + "	}");
    JvmTypeReference type = associations.getDirectlyInferredOperation(function).getReturnType();
    assertTrue(type.getType() instanceof JvmVoid);
    assertFalse(type.getType().eIsProxy());
    assertNoExceptions(function);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmVoid(org.eclipse.xtext.common.types.JvmVoid) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Aggregations

XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)441 Test (org.junit.Test)374 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)248 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)198 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)182 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)116 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)101 XExpression (org.eclipse.xtext.xbase.XExpression)95 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)91 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)78 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)72 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)60 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)46 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)39 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)30 EObject (org.eclipse.emf.ecore.EObject)28 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)23 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)23 RichString (org.eclipse.xtend.core.xtend.RichString)17 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16