use of org.eclipse.emf.ecore.resource.URIConverter in project dsl-devkit by dsldevkit.
the class CheckGenModelUtil method getGenModelUsingHeuristics.
/**
* Returns the genmodel for the given EPackage.
*
* @param ePackage
* the model element
* @return the genmodel
*/
private static GenModel getGenModelUsingHeuristics(final EPackage ePackage) {
final Resource res = ePackage.eResource();
ResourceSet resourceSet = res.getResourceSet();
if (resourceSet == null) {
resourceSet = new ResourceSetImpl();
resourceSet.getResources().add(res);
}
final URIConverter uriConverter = resourceSet.getURIConverter();
URI uri = uriConverter.normalize(res.getURI());
// NOPMD - We want the value before reassignment
final URI originalURI = uri;
URI baseURI = uri.trimFileExtension();
uri = baseURI.appendFileExtension(GENMODEL_EXTENSION);
uri = uriConverter.normalize(uri);
if (uri.scheme().equals("http")) /* toString().equals(EcorePackage.eNS_URI) */
{
// optimization, because we are not interested in the extension for the Ecore model.
return null;
// otherwise getResource will go on the internet to load the model and we loose 20 seconds on each call!
}
GenModel result = null;
// First try: same uri as containing ecore model, with file extension switched to genmodel
if (uriConverter.exists(uri, null)) {
result = loadGenModel(uri, ePackage, resourceSet);
}
// If the first try failed: look for any *.genmodel files in the same folder.
if (result == null) {
baseURI = baseURI.trimSegments(1);
IContainer[] folders = determineContainersToCheck(baseURI);
try {
result = findGenModelInContainers(folders, baseURI, ePackage, resourceSet);
} catch (CoreException e) {
// Ignore
}
}
if (result == null) {
// $NON-NLS-1$
throw new IllegalStateException("No genmodel found for " + originalURI);
}
return result;
}
use of org.eclipse.emf.ecore.resource.URIConverter in project ow by vtst.
the class LessHyperlinkHelper method createHyperlinksTo.
/**
* Create an hyper-link to the resource designated by an URI.
* @param from The source resource.
* @param uri The target URI.
* @param acceptor An acceptor for the hyper-link.
*/
public void createHyperlinksTo(XtextResource from, URI uri, IHyperlinkAcceptor acceptor) {
final URIConverter uriConverter = from.getResourceSet().getURIConverter();
final String hyperlinkText = uri.toString();
final URI normalized = uriConverter.normalize(uri).resolve(from.getURI());
XtextHyperlink result = getHyperlinkProvider().get();
result.setHyperlinkRegion(new Region(1, 1));
result.setURI(normalized);
result.setHyperlinkText(hyperlinkText);
acceptor.accept(result);
}
Aggregations