use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testDispatchFunction_00.
@Test
public void testDispatchFunction_00() throws Exception {
XtendFile xtendFile = file("class Foo { def dispatch foo(Object x) {null} def dispatch foo(String x) {null}}");
JvmGenericType inferredType = getInferredType(xtendFile);
// one main dispatch
Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", Object.class);
assertEquals("java.lang.Object", dispatch.getReturnType().getIdentifier());
// two internal case methods
findByNameAndFirstParameterType(operations, "_foo", Object.class);
findByNameAndFirstParameterType(operations, "_foo", String.class);
for (JvmMember member : inferredType.getMembers()) {
if (member instanceof JvmExecutable) {
if (member.getSimpleName().startsWith("_"))
assertEquals(JvmVisibility.PROTECTED, member.getVisibility());
else
assertEquals(JvmVisibility.PUBLIC, member.getVisibility());
} else {
assertEquals(JvmVisibility.PRIVATE, member.getVisibility());
}
}
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testExtensionToAnnotation_01.
@Test
public void testExtensionToAnnotation_01() throws Exception {
XtendFile xtendFile = file("class C { extension String }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmField jvmField = (JvmField) inferredType.getMembers().get(1);
assertEquals("_string", jvmField.getSimpleName());
List<JvmAnnotationReference> annotations = jvmField.getAnnotations();
assertEquals(1, annotations.size());
assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
use of org.eclipse.xtext.common.types.JvmGenericType 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.xtext.common.types.JvmGenericType 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.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunctionWithReturnType_03.
@Test
public void testInferredFunctionWithReturnType_03() throws Exception {
XtendFile xtendFile = file("class Foo { def bar() { null } }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
assertEquals("java.lang.Object", jvmOperation.getReturnType().getIdentifier());
}
Aggregations