use of org.eclipse.xtext.common.types.JvmGenericType 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());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredJvmType.
@Test
public void testInferredJvmType() throws Exception {
XtendFile xtendFile = file("class Foo { }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
assertEquals(associations.getInferredType(xtendClass), inferredType);
assertEquals(xtendClass, associations.getXtendClass(inferredType));
assertEquals(JvmVisibility.PUBLIC, inferredType.getVisibility());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunctionWithReturnType_02.
@Test
public void testInferredFunctionWithReturnType_02() throws Exception {
XtendFile xtendFile = file("class Foo { def Iterable<String> create result: newArrayList newList() {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
assertTrue(inferredType.getMembers().get(0) instanceof JvmConstructor);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
assertFalse(xtendFunction.getReturnType() == jvmOperation.getReturnType());
assertEquals(xtendFunction.getReturnType().getType(), jvmOperation.getReturnType().getType());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class TestCaseCompiler method compile.
public void compile(String qualifiedName) throws IOException {
ResourceSet set = injector.getInstance(ResourceSet.class);
final String from = "src/" + qualifiedName.replace('.', '/') + ".xtend";
final String to = "src-gen/" + qualifiedName.replace('.', '/') + ".java";
Resource res = set.getResource(org.eclipse.emf.common.util.URI.createFileURI(from), true);
EcoreUtil.resolveAll(res);
if (!res.getErrors().isEmpty())
throw new RuntimeException(res.getErrors().toString());
final File file = new File(to);
createFolders(file);
FileWriter writer = new FileWriter(file);
IXtendJvmAssociations associations = injector.getInstance(IXtendJvmAssociations.class);
JvmModelGenerator generator = injector.getInstance(JvmModelGenerator.class);
XtendFile xtendFile = (XtendFile) res.getContents().get(0);
JvmGenericType inferredType = associations.getInferredType((XtendClass) xtendFile.getXtendTypes().get(0));
GeneratorConfig config = injector.getInstance(IGeneratorConfigProvider.class).get(inferredType);
CharSequence javaCode = generator.generateType(inferredType, config);
writer.append(javaCode);
writer.close();
System.out.println("compiled " + from + " to " + to);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class DispatchHelperTest method testVisibility_00.
@Test
public void testVisibility_00() throws Exception {
XtendClass superClazz = clazz("class Super {\n" + " def private dispatch foo(Object x) {} \n" + "}");
Resource subResource = superClazz.eResource().getResourceSet().createResource(URI.createURI("Sub.xtend", true));
subResource.load(new StringInputStream("class Sub extends Super {\n" + " def dispatch foo(String x) {}\n" + " def dispatch foo(Number x) {}\n" + "}"), null);
JvmGenericType type = (JvmGenericType) subResource.getContents().get(1);
ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
assertEquals(2, list.size());
}
Aggregations