use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractXtextResourceSetTest method testResourcesAreClearedWithNormalizedURI_01.
@Test
public void testResourcesAreClearedWithNormalizedURI_01() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createURI("/a/../foo"));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(2, rs.getURIResourceMap().size());
rs.getResources().clear();
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractXtextResourceSetTest method testResourcesAreInMapWithNormalizedURI_02.
@Test
public void testResourcesAreInMapWithNormalizedURI_02() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createURI("/a/../foo"));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(2, rs.getURIResourceMap().size());
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project vorto by eclipse.
the class XtextResourceModelParser method parseModel.
@SuppressWarnings("unchecked")
private <M> ParseModelResult<M> parseModel(URI uri, Class<M> modelClass) {
ResourceSet rs = new XtextResourceSet();
Resource resource = rs.getResource(uri, true);
if (!resource.getContents().isEmpty()) {
Collection<Resource.Diagnostic> errorDiagnostics = Lists.newArrayList();
EObject eModel = resource.getContents().get(0);
// linking errors
errorDiagnostics.addAll(getLinkingErrors(eModel));
// syntax errors
errorDiagnostics.addAll(Collections2.filter(resource.getErrors(), notXtextLinkingDiagnostics));
return ParseModelResult.newResult(errorDiagnostics, (M) eModel);
} else {
return ParseModelResult.newResult(Collections2.filter(resource.getErrors(), notXtextLinkingDiagnostics), null);
}
}
use of org.eclipse.xtext.resource.XtextResourceSet in project smarthome by eclipse.
the class ScriptEngineImpl method parseScriptIntoXTextEObject.
private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException {
XtextResourceSet resourceSet = getResourceSet();
// IS-A XtextResource
Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet));
try {
resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()), resourceSet.getLoadOptions());
} catch (IOException e) {
throw new ScriptParsingException("Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???", scriptAsString, e);
}
List<Diagnostic> errors = resource.getErrors();
if (errors.size() != 0) {
throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)", scriptAsString).addDiagnosticErrors(errors);
}
EList<EObject> contents = resource.getContents();
if (!contents.isEmpty()) {
Iterable<Issue> validationErrors = getValidationErrors(contents.get(0));
if (!validationErrors.iterator().hasNext()) {
return (XExpression) contents.get(0);
} else {
throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", scriptAsString).addValidationIssues(validationErrors);
}
} else {
return null;
}
}
use of org.eclipse.xtext.resource.XtextResourceSet in project n4js by eclipse.
the class ManifestMerger method mergeContent.
/**
* Merges the content of two {@link ProjectDescription project description} instances that are representing the
* actual N4JS manifests.
*
* @param fromLocation
* the source location. These attributes and references will be merged to the other one given with the
* {@code toLocation}.
* @param toLocation
* the target location. The project description that has to be updated with the content of the
* {@code fromLocation}.
* @return the merged project description that has been detached from its resource.
*/
public ProjectDescription mergeContent(final URI fromLocation, final URI toLocation) {
final XtextResourceSet fromResourceSet = getResourceSet(fromLocation);
final XtextResourceSet toResourceSet = getResourceSet(toLocation);
if (null == fromResourceSet || null == toResourceSet) {
return null;
}
try {
final Resource from = fromResourceSet.getResource(fromLocation, true);
final Resource to = toResourceSet.getResource(toLocation, true);
return mergeContent(from, to);
} catch (final Exception e) {
LOGGER.error("Error while trying to merge N4JS manifest content. Source URI: " + fromLocation + ". Target URI: " + toLocation + ".", e);
}
return null;
}
Aggregations