use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class ModelExtensionsTest method testXtendFunction.
@Test
public void testXtendFunction() throws Exception {
XtendFile file = file("package foo class Bar { def int foo() {1}}");
XtendFunction xtendFunction = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
assertEquals("foo", xtendFunction.getName());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredTypeParameter.
@Test
public void testInferredTypeParameter() throws Exception {
XtendFile xtendFile = file("class Foo <T> { }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
assertEquals(1, inferredType.getTypeParameters().size());
assertFalse(xtendClass.getTypeParameters().get(0) == inferredType.getTypeParameters().get(0));
assertEquals(xtendClass.getTypeParameters().get(0).getIdentifier(), inferredType.getTypeParameters().get(0).getIdentifier());
}
use of org.eclipse.xtend.core.xtend.XtendClass 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());
}
use of org.eclipse.xtend.core.xtend.XtendClass 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());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunction_04.
@Test
public void testInferredFunction_04() throws Exception {
XtendFile xtendFile = file("class Foo { def Iterable<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<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<java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
// This used to be a bogus assertion since Iterable<CharSequence> is not assignable from ArrayList<String>
// assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
Aggregations