Skip to content

Commit

Permalink
Avoid repeated calls to getBinaryStorageURI and getURIConverter (#2732)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenporras authored Jul 10, 2023
1 parent a879d71 commit 6d1c421
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.resource.persistence;
Expand All @@ -20,6 +20,7 @@
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.generator.AbstractFileSystemAccess2;
Expand Down Expand Up @@ -62,32 +63,32 @@ public ResourceStorageLoadable getOrCreateResourceStorageLoadable(StorageAwareRe
if (loadable != null)
return loadable;
}
if (resourceSet.getURIConverter().exists(getBinaryStorageURI(resource.getURI()),
Collections.emptyMap())) {
return createResourceStorageLoadable(resourceSet.getURIConverter()
.createInputStream(getBinaryStorageURI(resource.getURI())));
URIConverter converter = resourceSet.getURIConverter();
URI storageURI = getBinaryStorageURI(resource.getURI());
if (converter.exists(storageURI, Collections.emptyMap())) {
return createResourceStorageLoadable(converter.createInputStream(storageURI));
}
return createResourceStorageLoadable(
getFileSystemAccess(resource).readBinaryFile(computeOutputPath(resource)));
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}

protected boolean doesStorageExist(StorageAwareResource resource) {
ResourceSet resourceSet = resource.getResourceSet();
ResourceStorageProviderAdapter stateProvider = getResourceStorageProviderAdapter(resourceSet);
if (stateProvider != null && stateProvider.getResourceStorageLoadable(resource) != null)
return true;
// check for next to original location, i.e. jars
if (resourceSet.getURIConverter().exists(getBinaryStorageURI(resource.getURI()),
Collections.emptyMap()))
URIConverter converter = resourceSet.getURIConverter();
if (converter.exists(getBinaryStorageURI(resource.getURI()), Collections.emptyMap()))
return true;
// if it's an archive URI, we don't need to look up the source folder-output folder scheme
if (resource.getURI().isArchive())
return false;
URI uri = getFileSystemAccess(resource).getURI(computeOutputPath(resource));
return uri != null && resourceSet.getURIConverter().exists(uri, null);
return uri != null && converter.exists(uri, null);
}

@Override
Expand Down

0 comments on commit 6d1c421

Please sign in to comment.