use of org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl in project xtext-core by eclipse.
the class GrammarAccessFragment2 method writeGrammar.
protected void writeGrammar() {
final Wrapper<Boolean> isSaving = Wrapper.<Boolean>wrap(Boolean.valueOf(false));
final ResourceSet cloneInto = new ResourceSetImpl();
Map<String, Object> _extensionToFactoryMap = cloneInto.getResourceFactoryRegistry().getExtensionToFactoryMap();
FragmentFakingEcoreResource.FactoryImpl _factoryImpl = new FragmentFakingEcoreResource.FactoryImpl(isSaving);
_extensionToFactoryMap.put(FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX, _factoryImpl);
final ResourceSet resourceSet = EcoreUtil2.<ResourceSet>clone(cloneInto, this.getLanguage().getGrammar().eResource().getResourceSet());
EObject _head = IterableExtensions.<EObject>head(resourceSet.getResource(this.getLanguage().getGrammar().eResource().getURI(), true).getContents());
final Grammar copy = ((Grammar) _head);
String _xifexpression = null;
if ((this.xmlVersion == null)) {
_xifexpression = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
} else {
String _xblockexpression = null;
{
String _simpleName = GrammarAccessFragment2.class.getSimpleName();
String _plus = ("The property \'xmlVersion\' has been specified for this " + _simpleName);
String _plus_1 = (_plus + ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
GrammarAccessFragment2.LOG.warn(_plus_1);
_xblockexpression = GrammarUtil.getClasspathRelativePathToXmi(copy);
}
_xifexpression = _xblockexpression;
}
final String path = _xifexpression;
final URI uri = this.getProjectConfig().getRuntime().getSrcGen().getURI(path);
final Resource resource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
HashSet<Grammar> _hashSet = new HashSet<Grammar>();
this.addAllGrammarsToResource(resource, copy, _hashSet);
isSaving.set(Boolean.valueOf(true));
final Map<String, Object> saveOptions = CollectionLiterals.<String, Object>newHashMap();
if ((resource instanceof XMLResource)) {
String _elvis = null;
if (this.xmlVersion != null) {
_elvis = this.xmlVersion;
} else {
_elvis = "1.0";
}
((XMLResource) resource).setXMLVersion(_elvis);
} else {
if ((resource instanceof BinaryResourceImpl)) {
saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.valueOf(true));
}
}
try {
resource.save(saveOptions);
} catch (final Throwable _t) {
if (_t instanceof IOException) {
final IOException e = (IOException) _t;
GrammarAccessFragment2.LOG.error(e.getMessage(), e);
} else {
throw Exceptions.sneakyThrow(_t);
}
} finally {
isSaving.set(Boolean.valueOf(false));
}
}
Aggregations