use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class ParserTestHelper method getResourceFromStream.
public XtextResource getResourceFromStream(InputStream in) throws IOException {
XtextResourceSet rs = resourceSet.get();
rs.setClasspathURIContext(getClass());
URI uri = URI.createURI("mytestmodel." + fileExtension);
XtextResource resource = createResource(uri);
rs.getResources().add(resource);
resource.load(in, null);
return resource;
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class XtextFormatterTest method testXtextFormatting.
@Test
public void testXtextFormatting() throws IOException {
String path = getClass().getPackage().getName().replace('.', '/');
URI u = URI.createURI("classpath:/" + path + "/XtextFormatterMessy.xtext");
XtextResourceSet resourceSet = new XtextResourceSet();
resourceSet.setClasspathURIContext(getClass());
Resource r = resourceSet.getResource(u, true);
// System.out.println(r.getWarnings());
// System.out.println(r.getErrors());
ByteArrayOutputStream formatted = new ByteArrayOutputStream();
r.save(formatted, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
// System.out.println(EmfFormatter.listToStr(r.getContents()));
// System.out.println(formatted.toString());
URI expectedURI = URI.createURI("classpath:/" + path + "/XtextFormatterExpected.xtext");
XtextResource expectedResource = (XtextResource) resourceSet.getResource(expectedURI, true);
String expected = expectedResource.getParseResult().getRootNode().getText();
assertEquals(expected.replaceAll(System.lineSeparator(), "\n"), formatted.toString().replaceAll(System.lineSeparator(), "\n"));
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class ComplexReconstrTest method testPrintGrammar.
@Test
public void testPrintGrammar() {
XtextResourceSet rs = get(XtextResourceSet.class);
rs.setClasspathURIContext(getClass());
URI u = URI.createURI("classpath:/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTestLanguage.xtextbin");
EObject o = rs.getResource(u, true).getContents().get(0);
for (Object x : o.eContents()) if (x instanceof ParserRule) {
ParserRule pr = (ParserRule) x;
if (pr.getName().toLowerCase().contains("tricky")) {
if (logger.isTraceEnabled())
logger.trace(EmfFormatter.objToStr(pr));
}
}
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class RuntimeResourceSetInitializer method getInitializedResourceSet.
public ResourceSet getInitializedResourceSet(List<String> pathes, UriFilter filter) {
ResourceSet resourceSet = resourceSetProvider.get();
Multimap<String, URI> pathToUriMap = getPathToUriMap(pathes, filter);
IAllContainersState containersState = factory.getContainersState(pathes, pathToUriMap);
resourceSet.eAdapters().add(new DelegatingIAllContainerAdapter(containersState));
for (URI uri : pathToUriMap.values()) {
resourceSet.createResource(uri);
}
return resourceSet;
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class UriBasedReader method invokeInternal.
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
ResourceSet resourceSet = getResourceSet();
for (URI uri : uris2) {
Resource resource = resourceSet.getResource(uri, true);
int numberResources;
do {
numberResources = resourceSet.getResources().size();
EcoreUtil.resolveAll(resource);
} while (numberResources != resourceSet.getResources().size());
}
getValidator().validate(resourceSet, getRegistry(), issues);
addModelElementsToContext(ctx, resourceSet);
}
Aggregations