use of org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl in project xtext-core by eclipse.
the class UriBasedReaderTest method testIssuesInOtherResource.
@Test
public void testIssuesInOtherResource() throws Exception {
UriBasedReader reader = new UriBasedReader() {
{
getValidator().setStopOnError(false);
}
};
reader.setClasspathURIContext(getClass());
reader.addRegister(new XtextStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(new org.eclipse.xtext.XtextRuntimeModule() {
@Override
public void configureFileExtensions(Binder binder) {
binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("xtexterror");
}
});
}
@Override
public void register(Injector injector) {
EPackage.Registry.INSTANCE.put(XtextPackage.eINSTANCE.getNsURI(), XtextPackage.eINSTANCE);
IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", resourceFactory);
IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", serviceProvider);
}
});
final String errorURI = (getClass().getName() + "ResourceWithError").replace('.', '/') + ".xtexterror";
final String loadingURI = "classpath:/" + (getClass().getName() + "LoadingResourceWithError").replace('.', '/') + ".xtexterror";
reader.addUri(loadingURI);
SlotEntry slotEntry = new SlotEntry();
slotEntry.setType("Grammar");
slotEntry.setFirstOnly(true);
reader.addLoad(slotEntry);
WorkflowContextDefaultImpl ctx = new WorkflowContextDefaultImpl();
IssuesImpl issues = new IssuesImpl();
reader.checkConfiguration(issues);
assertFalse(issues.toString(), issues.hasErrors());
reader.invoke(ctx, new NullProgressMonitor(), issues);
assertTrue(ctx.get(slotEntry.getSlot()) instanceof Grammar);
assertEquals(1, issues.getErrors().length);
final String errorString = issues.getErrors()[0].toString();
assertFalse(errorString, errorString.contains(loadingURI));
assertTrue(errorString, errorString.contains(errorURI));
}
use of org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl in project xtext-core by eclipse.
the class UriBasedReaderTest method testSimple.
@Test
public void testSimple() throws Exception {
UriBasedReader reader = new UriBasedReader() {
{
getValidator().setStopOnError(false);
}
};
reader.setClasspathURIContext(getClass());
reader.addRegister(new XtextErrorStandaloneSetup());
reader.addUri("classpath:/" + getClass().getName().replace('.', '/') + ".xtexterror");
SlotEntry slotEntry = new SlotEntry();
slotEntry.setType("Grammar");
slotEntry.setFirstOnly(true);
reader.addLoad(slotEntry);
WorkflowContextDefaultImpl ctx = new WorkflowContextDefaultImpl();
IssuesImpl issues = new IssuesImpl();
reader.checkConfiguration(issues);
assertFalse(issues.toString(), issues.hasErrors());
reader.invoke(ctx, new NullProgressMonitor(), issues);
assertTrue(ctx.get(slotEntry.getSlot()) instanceof Grammar);
assertEquals(issues.toString(), 1, issues.getErrors().length);
}
use of org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl in project xtext-core by eclipse.
the class UriBasedReaderTest method testTransitiveReferences.
@SuppressWarnings("unchecked")
@Test
public void testTransitiveReferences() throws Exception {
UriBasedReader reader = new UriBasedReader();
reader.addRegister(new ImportUriTestLanguageStandaloneSetup());
reader.addUri(pathTo2("importUriSubfolder/Start.importuritestlanguage"));
SlotEntry slotEntry = new SlotEntry();
slotEntry.setType("Type");
reader.addLoad(slotEntry);
WorkflowContext ctx = new WorkflowContextDefaultImpl();
IssuesImpl issues = new IssuesImpl();
reader.checkConfiguration(issues);
try {
reader.invoke(ctx, new NullProgressMonitor(), issues);
} catch (Exception e) {
System.out.println(issues);
throw e;
}
List<Type> types = (List<Type>) ctx.get(slotEntry.getSlot());
assertEquals(3, types.size());
for (Type type : types) {
if (type.getName().equals("Foo")) {
assertEquals("Bar", type.getExtends().getName());
} else if (type.getName().equals("Bar")) {
assertEquals("Baz", type.getExtends().getName());
} else {
assertNull(type.getExtends());
}
}
}
Aggregations