@Override protected URI getSourceContainerURI(final StorageAwareResource resource) { final URI uri = resource.getURI(); final IProjectConfig mainProject = this.projectConfigProvider.getProjectConfig(resource.getResourceSet()); if ((mainProject != null)) { final IProjectConfig project = mainProject.getWorkspaceConfig().findProjectContaining(uri); ISourceFolder _findSourceFolderContaining = null; if (project!=null) { _findSourceFolderContaining=project.findSourceFolderContaining(uri); } final ISourceFolder sourceFolder = _findSourceFolderContaining; if ((sourceFolder != null)) { return sourceFolder.getPath(); } } return super.getSourceContainerURI(resource); }
protected String getOperator(final XAbstractFeatureCall call) { String _switchResult = null; Resource _eResource = call.eResource(); final Resource res = _eResource; boolean _matched = false; if (res instanceof StorageAwareResource) { boolean _isLoadedFromStorage = ((StorageAwareResource)res).isLoadedFromStorage(); if (_isLoadedFromStorage) { _matched=true; QualifiedName _operator = this.operatorMapping.getOperator(QualifiedName.create(call.getFeature().getSimpleName())); String _string = null; if (_operator!=null) { _string=_operator.toString(); } return _string; } } if (!_matched) { _switchResult = call.getConcreteSyntaxFeatureName(); } return _switchResult; }
@Override public IResourceDescription getResourceDescription(final Resource resource) { IResourceDescription _switchResult = null; boolean _matched = false; if (resource instanceof StorageAwareResource) { IResourceDescription _resourceDescription = ((StorageAwareResource)resource).getResourceDescription(); boolean _tripleNotEquals = (_resourceDescription != null); if (_tripleNotEquals) { _matched=true; _switchResult = ((StorageAwareResource)resource).getResourceDescription(); } } if (!_matched) { _switchResult = super.getResourceDescription(resource); } return _switchResult; }
protected void readContents(final StorageAwareResource resource, final InputStream inputStream) throws IOException { Map<Object, Object> _emptyMap = CollectionLiterals.<Object, Object>emptyMap(); final BinaryResourceImpl.EObjectInputStream in = new BinaryResourceImpl.EObjectInputStream(inputStream, _emptyMap) { @Override public int readCompressedInt() throws IOException { int _xblockexpression = (int) 0; { this.resourceSet = null; _xblockexpression = super.readCompressedInt(); } return _xblockexpression; } @Override public InternalEObject loadEObject() throws IOException { final InternalEObject result = super.loadEObject(); ResourceStorageLoadable.this.handleLoadEObject(result, this); return result; } }; in.loadResource(resource); }
protected void readNodeModel(final StorageAwareResource resource, final InputStream inputStream) throws IOException { final SerializableNodeModel serializableNodeModel = new SerializableNodeModel(resource); boolean _exists = resource.getResourceSet().getURIConverter().exists(resource.getURI(), resource.getResourceSet().getLoadOptions()); boolean _not = (!_exists); if (_not) { URI _uRI = resource.getURI(); String _plus = ("Skipping loading node model for synthetic resource " + _uRI); ResourceStorageLoadable.LOG.info(_plus); return; } final InputStream stream = resource.getResourceSet().getURIConverter().createInputStream(resource.getURI()); String _encoding = resource.getEncoding(); final InputStreamReader in = new InputStreamReader(stream, _encoding); final String completeContent = CharStreams.toString(in); final DeserializationConversionContext deserializationContext = new DeserializationConversionContext(resource, completeContent); final DataInputStream dataIn = new DataInputStream(inputStream); serializableNodeModel.readObjectData(dataIn, deserializationContext); EObject _head = IterableExtensions.<EObject>head(resource.getContents()); boolean _hasErrors = deserializationContext.hasErrors(); ParseResult _parseResult = new ParseResult(_head, serializableNodeModel.root, _hasErrors); resource.setParseResult(_parseResult); }
protected void convertExternalURIsToPortableURIs(final SerializableResourceDescription description, final StorageAwareResource resource) { Iterable<IReferenceDescription> _referenceDescriptions = description.getReferenceDescriptions(); for (final IReferenceDescription ref : _referenceDescriptions) { URI _trimFragment = ref.getTargetEObjectUri().trimFragment(); URI _uRI = resource.getURI(); boolean _notEquals = (!Objects.equal(_trimFragment, _uRI)); if (_notEquals) { URI _elvis = null; URI _portableURI = resource.getPortableURIs().toPortableURI(resource, ref.getTargetEObjectUri()); if (_portableURI != null) { _elvis = _portableURI; } else { URI _targetEObjectUri = ref.getTargetEObjectUri(); _elvis = _targetEObjectUri; } ((SerializableReferenceDescription) ref).setTargetEObjectUri(_elvis); } } }
@Override public void saveResource(final StorageAwareResource resource, final IFileSystemAccessExtension3 fsa) { final String path = this.computeOutputPath(resource); final ResourceStorageFacade.MyByteArrayOutputStream bout = new ResourceStorageFacade.MyByteArrayOutputStream(); final ResourceStorageWritable outStream = this.createResourceStorageWritable(bout); try { outStream.writeResource(resource); } catch (final Throwable _t) { if (_t instanceof IOException) { final IOException e = (IOException)_t; URI _uRI = resource.getURI(); String _plus = ("Cannot write storage for " + _uRI); ResourceStorageFacade.LOG.warn(_plus, e); return; } else { throw Exceptions.sneakyThrow(_t); } } byte[] _byteArray = bout.toByteArray(); int _length = bout.length(); ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray, 0, _length); fsa.generateFile(path, _byteArrayInputStream); }
/** * @return whether a stored resource state exists for the given resource */ protected boolean doesStorageExist(final StorageAwareResource resource) { final ResourceStorageProviderAdapter stateProvider = IterableExtensions.<ResourceStorageProviderAdapter>head(Iterables.<ResourceStorageProviderAdapter>filter(resource.getResourceSet().eAdapters(), ResourceStorageProviderAdapter.class)); if (((stateProvider != null) && (stateProvider.getResourceStorageLoadable(resource) != null))) { return true; } boolean _exists = resource.getResourceSet().getURIConverter().exists(this.getBinaryStorageURI(resource.getURI()), CollectionLiterals.<Object, Object>emptyMap()); if (_exists) { return true; } boolean _isArchive = resource.getURI().isArchive(); if (_isArchive) { return false; } final AbstractFileSystemAccess2 fsa = this.getFileSystemAccess(resource); final String outputRelativePath = this.computeOutputPath(resource); final URI uri = fsa.getURI(outputRelativePath); return ((uri != null) && resource.getResourceSet().getURIConverter().exists(uri, null)); }
/** * Override which installs an {@link DirectLinkingSourceLevelURIsAdapter} instead of Xtext's * {@link org.eclipse.xtext.resource.persistence.SourceLevelURIsAdapter} so that the builder can modify * {@link org.eclipse.xtext.builder.impl.SourceLevelURICache#getSources()} and get these changes reflected in the adapter. */ @Override protected void installSourceLevelURIs(final BuildData buildData) { ResourceSet resourceSet = buildData.getResourceSet(); Iterable<URI> sourceLevelUris = Iterables.concat(buildData.getToBeUpdated(), buildData.getURIQueue()); for (URI uri : sourceLevelUris) { if (buildData.getSourceLevelURICache().getOrComputeIsSource(uri, resourceServiceProviderRegistry)) { // unload resources loaded from storage previously Resource resource = resourceSet.getResource(uri, false); if (resource instanceof StorageAwareResource && ((StorageAwareResource) resource).isLoadedFromStorage()) { resource.unload(); } } } DirectLinkingSourceLevelURIsAdapter.setSourceLevelUris(resourceSet, buildData.getSourceLevelURICache().getSources()); }
/** * Serializes the {@link InferredModelAssociator.Adapter#getSourceToInferredModelMap() source-to-inferred-element map} for the given resource. * * @param resource * resource, must not be {@code null} * @param zipOut * output stream to write to, must not be {@code null} * @throws IOException * thrown when an IO error occurs */ protected void writeAssociationsAdapter(final StorageAwareResource resource, final OutputStream zipOut) throws IOException { InferredModelAssociator.Adapter adapter = (Adapter) EcoreUtil.getAdapter(resource.eAdapters(), InferredModelAssociator.Adapter.class); ObjectOutputStream objOut = new ObjectOutputStream(zipOut); try { // sourceToTarget Map<String, Collection<String>> sourceToTarget = Maps.newHashMap(); if (adapter != null) { for (Entry<EObject, Collection<EObject>> entry : adapter.getSourceToInferredModelMap().asMap().entrySet()) { sourceToTarget.put(getURIString(entry.getKey(), resource), Sets.newHashSet(Collections2.filter(Collections2.transform(entry.getValue(), v -> getURIString(v, resource)), Objects::nonNull))); } } objOut.writeObject(sourceToTarget); } finally { objOut.flush(); } }
@Override protected void loadEntries(final StorageAwareResource resource, final ZipInputStream zipIn) { try { zipIn.getNextEntry(); readContents(resource, new BufferedInputStream(zipIn)); if (storeNodeModel) { zipIn.getNextEntry(); StringBuilder out = new StringBuilder(SOURCE_BUFFER_CAPACITY); CharStreams.copy(new InputStreamReader(zipIn, StandardCharsets.UTF_8), out); String content = out.toString(); zipIn.getNextEntry(); readNodeModel(resource, new BufferedInputStream(zipIn), content); } zipIn.getNextEntry(); readAssociationsAdapter(resource, new BufferedInputStream(zipIn)); } catch (IOException e) { throw new WrappedException(e); } }
/** * Read the node model from the given input stream. * * @param resource * target resource, must not be {@code null} * @param inputStream * input stream, must not be {@code null} * @param content * corresponding source content as required by node model, must not be {@code null} */ protected void readNodeModel(final StorageAwareResource resource, final InputStream inputStream, final String content) { try { // if this is a synthetic resource (i.e. tests or so, don't load the node model) if (!resource.getResourceSet().getURIConverter().exists(resource.getURI(), resource.getResourceSet().getLoadOptions())) { LOG.info("Skipping loading node model for synthetic resource " + resource.getURI()); //$NON-NLS-1$ return; } DeserializationConversionContext deserializationContext = new FixedDeserializationConversionContext(resource, content); DataInputStream dataIn = new DataInputStream(inputStream); SerializableNodeModel serializableNodeModel = new SerializableNodeModel(resource); serializableNodeModel.readObjectData(dataIn, deserializationContext); resource.setParseResult(new ParseResult(resource.getContents().get(0), serializableNodeModel.root, deserializationContext.hasErrors())); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
/** * Reads the {@link InferredModelAssociator.Adapter#getSourceToInferredModelMap()} map. * * @param resource * resource being deserialized, must not be {@code null} * @param stream * zip input stream, never {@code null} * @see DirectLinkingResourceStorageWritable#writeAssociationsAdapter(StorageAwareResource, java.io.OutputStream) */ protected void readAssociationsAdapter(final StorageAwareResource resource, final InputStream stream) { try { InferredModelAssociator.Adapter adapter = (Adapter) EcoreUtil.getAdapter(resource.eAdapters(), InferredModelAssociator.Adapter.class); if (adapter == null) { adapter = new InferredModelAssociator.Adapter(); resource.eAdapters().add(adapter); } ListMultimap<EObject, EObject> destinationMap = adapter.getSourceToInferredModelMap(); ObjectInputStream objIn = new ObjectInputStream(stream); @SuppressWarnings("unchecked") Map<String, Collection<String>> sourceToTargetMap = (Map<String, Collection<String>>) objIn.readObject(); for (Map.Entry<String, Collection<String>> entry : sourceToTargetMap.entrySet()) { destinationMap.putAll(getEObject(entry.getKey(), resource), Collections2.transform(entry.getValue(), v -> getEObject(v, resource))); } } catch (ClassNotFoundException | IOException e) { throw new WrappedException(e); } }
@Override protected IResolvedTypes doResolveTypes(/* @Nullable */ EObject object, /* @Nullable */ CancelIndicator monitor) { Resource resource = object.eResource(); if (resource instanceof StorageAwareResource) { if (((StorageAwareResource) resource).isLoadedFromStorage()) { throw new IllegalStateException("Type resolution is not supported on a storage-loaded resource : "+resource.getURI()); } } // TODO: remove when we switch to an Xtend scope provider without artificial feature calls EObject nonArtificialObject = getNonArtificialObject(object); // TODO end IReentrantTypeResolver reentrantResolver = getTypeResolver(nonArtificialObject); return reentrantResolver.reentrantResolve(monitor == null ? CancelIndicator.NullImpl : monitor); }
@Override protected void loadEntries(final StorageAwareResource resource, final ZipInputStream zipIn) throws IOException { super.loadEntries(resource, zipIn); if ((resource instanceof BatchLinkableResource)) { this.readAssociationsAdapter(((BatchLinkableResource)resource), zipIn); } }
@Override protected void writeEntries(final StorageAwareResource resource, final ZipOutputStream zipOut) throws IOException { super.writeEntries(resource, zipOut); if ((resource instanceof BatchLinkableResource)) { ZipEntry _zipEntry = new ZipEntry("associations"); zipOut.putNextEntry(_zipEntry); final BufferedOutputStream buffOut = new BufferedOutputStream(zipOut); try { this.writeAssociationsAdapter(((BatchLinkableResource)resource), buffOut); } finally { buffOut.flush(); zipOut.closeEntry(); } } }
public XExpression getAssociatedExpression(final JvmField field) { final Resource resource = field.eResource(); if ((resource instanceof StorageAwareResource)) { boolean _isLoadedFromStorage = ((StorageAwareResource)resource).isLoadedFromStorage(); if (_isLoadedFromStorage) { return null; } } return this.logicalContainerProvider.getAssociatedExpression(field); }
protected void generate(final List<Resource> sourceResources) { final GeneratorContext context = new GeneratorContext(); context.setCancelIndicator(CancelIndicator.NullImpl); for (final Resource it : sourceResources) { { String _lastSegment = it.getURI().lastSegment(); String _plus = ("Starting generator for input: \'" + _lastSegment); String _plus_1 = (_plus + "\'"); StandaloneBuilder.LOG.info(_plus_1); this.registerCurrentSource(it.getURI()); final LanguageAccess access = this.languageAccess(it.getURI()); final JavaIoFileSystemAccess fileSystemAccess = this.getFileSystemAccess(access); boolean _isWriteStorageResources = this.isWriteStorageResources(); if (_isWriteStorageResources) { boolean _matched = false; if (it instanceof StorageAwareResource) { IResourceStorageFacade _resourceStorageFacade = ((StorageAwareResource)it).getResourceStorageFacade(); boolean _tripleNotEquals = (_resourceStorageFacade != null); if (_tripleNotEquals) { _matched=true; ((StorageAwareResource)it).getResourceStorageFacade().saveResource(((StorageAwareResource)it), fileSystemAccess); } } } access.getGenerator().generate(it, fileSystemAccess, context); } } }
protected void loadIntoResource(final StorageAwareResource resource) throws IOException { boolean _isLoadedFromStorage = resource.isLoadedFromStorage(); boolean _not = (!_isLoadedFromStorage); if (_not) { throw new IllegalStateException("Please use StorageAwareResource#load(ResourceStorageLoadable)."); } final ZipInputStream zin = new ZipInputStream(this.in); try { this.loadEntries(resource, zin); } finally { zin.close(); } }
/** * Load entries from the storage. * Overriding methods should first delegate to super before adding their own entries. */ protected void loadEntries(final StorageAwareResource resource, final ZipInputStream zipIn) throws IOException { zipIn.getNextEntry(); BufferedInputStream _bufferedInputStream = new BufferedInputStream(zipIn); this.readContents(resource, _bufferedInputStream); zipIn.getNextEntry(); BufferedInputStream _bufferedInputStream_1 = new BufferedInputStream(zipIn); this.readResourceDescription(resource, _bufferedInputStream_1); if (this.storeNodeModel) { zipIn.getNextEntry(); BufferedInputStream _bufferedInputStream_2 = new BufferedInputStream(zipIn); this.readNodeModel(resource, _bufferedInputStream_2); } }
protected void readResourceDescription(final StorageAwareResource resource, final InputStream inputStream) throws IOException { try { final ObjectInputStream objectIn = new ObjectInputStream(inputStream); Object _readObject = objectIn.readObject(); final SerializableResourceDescription description = ((SerializableResourceDescription) _readObject); description.updateResourceURI(resource.getURI()); resource.setResourceDescription(description); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * Resolves a given portable URI fragment against the given resource. * * @param resource the resource from which global scope to look up the EObject * @param portableFragment the portable fragment pointing to the to be resolved EObject * * @return the EObject for the given portableURIFragment */ public EObject resolve(final StorageAwareResource resource, final String portableFragment) { final PortableURIs.PortableFragmentDescription desc = this.fromFragmentString(portableFragment); final EReference mock = EcoreFactory.eINSTANCE.createEReference(); mock.setEType(desc.descriptionEClass); final IScope scope = this.globalScopeProvider.getScope(resource, mock, Predicates.<IEObjectDescription>alwaysTrue()); final IEObjectDescription description = IterableExtensions.<IEObjectDescription>head(scope.getElements(desc.descriptionQualifiedName)); if ((description == null)) { return null; } final EObject container = EcoreUtil.resolve(description.getEObjectOrProxy(), resource); return this.getEObject(container, desc.descriptionRelativeFragment); }
/** * Creates and returns a portable URI from the given resource to the targetURI. * Returns <code>null</code> is no portable URI can be constructed, which is the case if the * targetObject is not itself exported or is a child of an exported EObject. * * @param sourceResource the resource from which the EObject should later be resolved * @param targetURI the target URI that should be resolvable by the created portable URI * * @return a portable URI or <code>null</code> */ public URI toPortableURI(final StorageAwareResource sourceResource, final URI targetURI) { Resource _resource = sourceResource.getResourceSet().getResource(targetURI.trimFragment(), false); EObject _eObject = null; if (_resource!=null) { _eObject=_resource.getEObject(targetURI.fragment()); } final EObject to = _eObject; boolean _or = false; if ((to == null)) { _or = true; } else { Resource _eResource = to.eResource(); ResourceSet _resourceSet = null; if (_eResource!=null) { _resourceSet=_eResource.getResourceSet(); } boolean _tripleNotEquals = (_resourceSet != null); _or = _tripleNotEquals; } if (_or) { final URI result = this.toPortableURI(sourceResource, to); if ((result != null)) { return result; } } return null; }
/** * Creates and returns a portable URI from the global scope. * Returns <code>null</code> is no portable URI can be constructed, which is the case if the * targetObject is not itself exported or is a child of an exported EObject. * * @param sourceResource the resource from which the EObject should later be resolved * @param targetObject the target object that should be resolvable by the created portable URI * * @return a portable URI or <code>null</code> */ public URI toPortableURI(final StorageAwareResource sourceResource, final EObject targetObject) { if (((targetObject == null) || targetObject.eIsProxy())) { return sourceResource.getURI().appendFragment(StorageAwareResource.UNRESOLVABLE_FRAGMENT); } final String portableFragment = this.getPortableURIFragment(targetObject); if ((portableFragment != null)) { return sourceResource.getURI().appendFragment(portableFragment); } return null; }
public void writeResource(final StorageAwareResource resource) throws IOException { boolean _isLoadedFromStorage = resource.isLoadedFromStorage(); if (_isLoadedFromStorage) { URI _uRI = resource.getURI(); String _plus = ("cannot write resources loaded from storage. URI was " + _uRI); throw new IllegalStateException(_plus); } final ZipOutputStream zipOut = new ZipOutputStream(this.out); try { this.writeEntries(resource, zipOut); } finally { zipOut.close(); } }
/** * Write entries into the storage. * Overriding methods should first delegate to super before adding their own entries. */ protected void writeEntries(final StorageAwareResource resource, final ZipOutputStream zipOut) throws IOException { final BufferedOutputStream bufferedOutput = new BufferedOutputStream(zipOut); ZipEntry _zipEntry = new ZipEntry("emf-contents"); zipOut.putNextEntry(_zipEntry); try { this.writeContents(resource, bufferedOutput); } finally { bufferedOutput.flush(); zipOut.closeEntry(); } ZipEntry _zipEntry_1 = new ZipEntry("resource-description"); zipOut.putNextEntry(_zipEntry_1); try { this.writeResourceDescription(resource, bufferedOutput); } finally { bufferedOutput.flush(); zipOut.closeEntry(); } if (this.storeNodeModel) { ZipEntry _zipEntry_2 = new ZipEntry("node-model"); zipOut.putNextEntry(_zipEntry_2); try { this.writeNodeModel(resource, bufferedOutput); } finally { bufferedOutput.flush(); zipOut.closeEntry(); } } }
protected void writeContents(final StorageAwareResource storageAwareResource, final OutputStream outputStream) throws IOException { Map<Object, Object> _emptyMap = CollectionLiterals.<Object, Object>emptyMap(); final BinaryResourceImpl.EObjectOutputStream out = new BinaryResourceImpl.EObjectOutputStream(outputStream, _emptyMap) { @Override public void writeURI(final URI uri, final String fragment) throws IOException { final URI fullURI = uri.appendFragment(fragment); URI _elvis = null; URI _portableURI = storageAwareResource.getPortableURIs().toPortableURI(storageAwareResource, fullURI); if (_portableURI != null) { _elvis = _portableURI; } else { _elvis = fullURI; } final URI uriToWrite = _elvis; super.writeURI(uriToWrite.trimFragment(), uriToWrite.fragment()); } @Override public void saveEObject(final InternalEObject internalEObject, final BinaryResourceImpl.EObjectOutputStream.Check check) throws IOException { ResourceStorageWritable.this.beforeSaveEObject(internalEObject, this); super.saveEObject(internalEObject, check); ResourceStorageWritable.this.handleSaveEObject(internalEObject, this); } }; try { out.saveResource(storageAwareResource); } finally { out.flush(); } }
protected void writeResourceDescription(final StorageAwareResource resource, final OutputStream outputStream) throws IOException { final IResourceDescription description = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource); final SerializableResourceDescription serializableDescription = SerializableResourceDescription.createCopy(description); this.convertExternalURIsToPortableURIs(serializableDescription, resource); final ObjectOutputStream out = new ObjectOutputStream(outputStream); try { out.writeObject(serializableDescription); } finally { out.flush(); } }
protected void writeNodeModel(final StorageAwareResource resource, final OutputStream outputStream) throws IOException { final DataOutputStream out = new DataOutputStream(outputStream); final SerializableNodeModel serializableNodeModel = new SerializableNodeModel(resource); final SerializationConversionContext conversionContext = new SerializationConversionContext(resource); serializableNodeModel.writeObjectData(out, conversionContext); out.flush(); }
/** * @return whether the given resource should be loaded from stored resource state */ @Override public boolean shouldLoadFromStorage(final StorageAwareResource resource) { final SourceLevelURIsAdapter adapter = SourceLevelURIsAdapter.findInstalledAdapter(resource.getResourceSet()); if ((adapter == null)) { return false; } else { boolean _contains = adapter.getSourceLevelURIs().contains(resource.getURI()); if (_contains) { return false; } } return this.doesStorageExist(resource); }
/** * Finds or creates a ResourceStorageLoadable for the given resource. * Clients should first call shouldLoadFromStorage to check whether there exists a storage version * of the given resource. * * @return an IResourceStorageLoadable */ @Override public ResourceStorageLoadable getOrCreateResourceStorageLoadable(final StorageAwareResource resource) { try { final ResourceStorageProviderAdapter stateProvider = IterableExtensions.<ResourceStorageProviderAdapter>head(Iterables.<ResourceStorageProviderAdapter>filter(resource.getResourceSet().eAdapters(), ResourceStorageProviderAdapter.class)); if ((stateProvider != null)) { final ResourceStorageLoadable inputStream = stateProvider.getResourceStorageLoadable(resource); if ((inputStream != null)) { return inputStream; } } InputStream _xifexpression = null; boolean _exists = resource.getResourceSet().getURIConverter().exists(this.getBinaryStorageURI(resource.getURI()), CollectionLiterals.<Object, Object>emptyMap()); if (_exists) { _xifexpression = resource.getResourceSet().getURIConverter().createInputStream(this.getBinaryStorageURI(resource.getURI())); } else { InputStream _xblockexpression = null; { final AbstractFileSystemAccess2 fsa = this.getFileSystemAccess(resource); final String outputRelativePath = this.computeOutputPath(resource); _xblockexpression = fsa.readBinaryFile(outputRelativePath); } _xifexpression = _xblockexpression; } final InputStream inputStream_1 = _xifexpression; return this.createResourceStorageLoadable(inputStream_1); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected AbstractFileSystemAccess2 getFileSystemAccess(final StorageAwareResource resource) { final AbstractFileSystemAccess2 fsa = this.fileSystemAccessProvider.get(); fsa.setContext(resource); final Function1<OutputConfiguration, String> _function = (OutputConfiguration it) -> { return it.getName(); }; fsa.setOutputConfigurations(IterableExtensions.<String, OutputConfiguration>toMap(this.outputConfigurationProvider.getOutputConfigurations(resource), _function)); return fsa; }
@Test public void testPortableUris() { try { final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class); Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage")); final StorageAwareResource resourceA = ((StorageAwareResource) _createResource); Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage")); final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1); StringConcatenation _builder = new StringConcatenation(); _builder.append("type B"); _builder.newLine(); resourceB.load(this.getAsStream(_builder.toString()), null); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import \'hubba:/bubba2.langatestlanguage\'"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("type A extends B"); _builder_1.newLine(); resourceA.load(this.getAsStream(_builder_1.toString()), null); final Type extended = IterableExtensions.<Type>head(IterableExtensions.<Main>head(Iterables.<Main>filter(resourceA.getContents(), Main.class)).getTypes()).getExtends(); final URI uri = EcoreUtil.getURI(extended); final URI portableURI = resourceA.getPortableURIs().toPortableURI(resourceA, uri); Assert.assertEquals(resourceA.getURI(), portableURI.trimFragment()); Assert.assertTrue(resourceA.getPortableURIs().isPortableURIFragment(portableURI.fragment())); Assert.assertSame(extended, resourceA.getEObject(portableURI.fragment())); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testPortableReferenceDescriptions() { try { final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class); Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage")); final StorageAwareResource resourceA = ((StorageAwareResource) _createResource); Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage")); final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1); StringConcatenation _builder = new StringConcatenation(); _builder.append("type B"); _builder.newLine(); resourceB.load(this.getAsStream(_builder.toString()), null); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import \'hubba:/bubba2.langatestlanguage\'"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("type A extends B"); _builder_1.newLine(); resourceA.load(this.getAsStream(_builder_1.toString()), null); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final ResourceStorageWritable writable = resourceA.getResourceStorageFacade().createResourceStorageWritable(bout); writable.writeResource(resourceA); byte[] _byteArray = bout.toByteArray(); ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray); final ResourceStorageLoadable loadable = resourceA.getResourceStorageFacade().createResourceStorageLoadable(_byteArrayInputStream); Resource _createResource_2 = resourceSet.createResource(URI.createURI("hubba:/bubba3.langatestlanguage")); final StorageAwareResource resourceC = ((StorageAwareResource) _createResource_2); resourceC.loadFromStorage(loadable); final IReferenceDescription refDesc = IterableExtensions.<IReferenceDescription>head(resourceC.getResourceDescription().getReferenceDescriptions()); EObject _head = IterableExtensions.<EObject>head(resourceB.getContents()); Assert.assertSame(IterableExtensions.<Type>head(((Main) _head).getTypes()), resourceSet.getEObject(refDesc.getTargetEObjectUri(), false)); EObject _head_1 = IterableExtensions.<EObject>head(resourceC.getContents()); Assert.assertSame(IterableExtensions.<Type>head(((Main) _head_1).getTypes()), resourceSet.getEObject(refDesc.getSourceEObjectUri(), false)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Override protected void writeNodeModel(final StorageAwareResource resource, final OutputStream outputStream) { try { DataOutputStream out = new DataOutputStream(outputStream); SerializableNodeModel serializableNodeModel = new SerializableNodeModel(resource); SerializationConversionContext conversionContext = new FixedSerializationConversionContext(resource); serializableNodeModel.writeObjectData(out, conversionContext); out.flush(); } catch (IOException e) { throw new WrappedException(e); } }
@Override public URI toPortableURI(final StorageAwareResource sourceResource, final URI uri) { String fragment = uri.fragment(); if (uriEncoder.isCrossLinkFragment(sourceResource, fragment)) { return uri.trimFragment().appendFragment(UNRESOLVED_LAZY_LINK); } return null; }
@Override public EObject resolve(final StorageAwareResource resource, final String portableFragment) { if (portableFragment.equals(UNRESOLVED_LAZY_LINK)) { return null; } return super.resolve(resource, portableFragment); }
@Override protected void loadIntoResource(final StorageAwareResource resource) { traceSet.started(ResourceLoadStorageEvent.class, resource.getURI()); try { super.loadIntoResource(resource); // CHECKSTYLE:OFF } catch (RuntimeException e) { // CHECKSTYLE:ON LOG.error("Error loading " + resource.getURI(), e); //$NON-NLS-1$ throw e instanceof WrappedException ? e : new WrappedException(e); // NOPMD } finally { traceSet.ended(ResourceLoadStorageEvent.class); } }
@Override public boolean shouldLoadFromStorage(final StorageAwareResource resource) { DirectLinkingSourceLevelURIsAdapter adapter = DirectLinkingSourceLevelURIsAdapter.findInstalledAdapter(resource.getResourceSet()); if (adapter == null) { return false; } else { if (adapter.getSourceLevelURIs().contains(resource.getURI())) { return false; } } return doesStorageExist(resource); }
/** * Checks the internal state of the resource and logs if type resolution was triggered unexpectedly. */ protected void validateResourceState(Resource resource) { if (resource instanceof StorageAwareResource && ((StorageAwareResource) resource).isLoadedFromStorage()) { LOG.error("Discouraged attempt to compute types for resource that was loaded from storage. Resource was : "+resource.getURI(), new Exception()); } }