use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredJvmConstructor.
@Test
public void testInferredJvmConstructor() throws Exception {
XtendFile xtendFile = file("class Foo { }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
assertEquals(1, inferredType.getMembers().size());
JvmMember inferredFirstMember = inferredType.getMembers().get(0);
assertTrue(inferredFirstMember instanceof JvmConstructor);
assertEquals(JvmVisibility.PUBLIC, inferredFirstMember.getVisibility());
assertEquals(associations.getInferredConstructor(xtendClass), inferredFirstMember);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunctionWithTypeParameter.
@Test
public void testInferredFunctionWithTypeParameter() throws Exception {
XtendFile xtendFile = file("class Foo<S> { def java.util.List<S> foo() {null} }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
assertEquals("java.util.List<S>", jvmOperation.getReturnType().getIdentifier());
JvmTypeReference argument = ((JvmParameterizedTypeReference) jvmOperation.getReturnType()).getArguments().get(0);
assertSame(inferredType, ((JvmTypeParameter) argument.getType()).getDeclarator());
XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
assertEquals("java.util.List<S>", xtendFunction.getReturnType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testNameClashWithCreateExtension_00.
@Test
public void testNameClashWithCreateExtension_00() throws Exception {
XtendFile xtendFile = file("package foo class Foo { def create new String() s(String x) { '' } String _createCache_s }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmField cacheVar = (JvmField) inferredType.getMembers().get(2);
assertEquals("_createCache_s_1", cacheVar.getSimpleName());
JvmOperation initializer = (JvmOperation) inferredType.getMembers().get(3);
assertEquals("_init_s", initializer.getSimpleName());
JvmField field = (JvmField) inferredType.getMembers().get(4);
assertEquals("_createCache_s", field.getSimpleName());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testBug_340611_05.
@Test
public void testBug_340611_05() throws Exception {
XtendFile xtendFile = file("class Bug340611 extends test.Dispatching {\n" + " override dispatch doDispatch(StringBuilder sb) {\n" + " null\n" + " }\n" + " def dispatch doDispatch(String s) {\n" + " s\n" + " }\n" + "}", false);
JvmGenericType inferredType = getInferredType(xtendFile);
assertEquals(3, IterableExtensions.size(inferredType.getDeclaredOperations()));
Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
JvmOperation dispatch = findByNameAndFirstParameterType(operations, "doDispatch", Object.class);
assertEquals("java.lang.CharSequence", dispatch.getReturnType().getIdentifier());
// two internal case methods
JvmOperation stringParam = findByNameAndFirstParameterType(operations, "_doDispatch", StringBuilder.class);
assertEquals("java.lang.StringBuilder", stringParam.getReturnType().getIdentifier());
JvmOperation objectParam = findByNameAndFirstParameterType(operations, "_doDispatch", String.class);
assertEquals("java.lang.CharSequence", objectParam.getReturnType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunction_03.
@Test
public void testInferredFunction_03() throws Exception {
XtendFile xtendFile = file("class Foo {def publicMethod(Object dummy) {} def public publicMethod() {} def protected protectedMethod() {} def private privateMethod() {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
for (JvmOperation op : inferredType.getDeclaredOperations()) {
assertEquals(JvmVisibility.get(op.getSimpleName().replace("Method", "").toUpperCase()), op.getVisibility());
}
}
Aggregations